@@ -283,61 +283,46 @@ func (s *IssueSyncService) createItemFromIssue(ctx context.Context, config *mode
283283
284284 milestoneID := s .resolveMilestoneID (config , issue )
285285
286- tx , err := s .db .BeginTx (ctx , nil )
287- if err != nil {
288- return fmt .Errorf ("begin tx: %w" , err )
289- }
290- defer func () { _ = tx .Rollback () }()
291-
292- nextNum , err := s .itemRepo .GetNextWorkspaceItemNumber (tx , config .WorkspaceID )
293- if err != nil {
294- return fmt .Errorf ("get next item number: %w" , err )
295- }
296-
297286 newItem := & models.Item {
298- WorkspaceID : config .WorkspaceID ,
299- WorkspaceItemNumber : nextNum ,
300- ItemTypeID : config .DefaultItemTypeID ,
301- Title : issue .Title ,
302- Description : issue .Body ,
303- StatusID : statusID ,
304- PriorityID : config .DefaultPriorityID ,
305- AssigneeID : assigneeID ,
306- }
307- itemID , err := s .itemRepo .Create (tx , newItem )
308- if err != nil {
309- return fmt .Errorf ("create item: %w" , err )
287+ WorkspaceID : config .WorkspaceID ,
288+ ItemTypeID : config .DefaultItemTypeID ,
289+ Title : issue .Title ,
290+ Description : issue .Body ,
291+ StatusID : statusID ,
292+ PriorityID : config .DefaultPriorityID ,
293+ AssigneeID : assigneeID ,
310294 }
311295
312296 milestoneIDs := []int {}
313297 if milestoneID != nil {
314298 milestoneIDs = append (milestoneIDs , * milestoneID )
315299 }
316- if err := repository .NewMilestoneAttachRepository (s .db ).ReplaceItemMilestonesTx (ctx , tx , itemID , milestoneIDs ); err != nil {
317- return err
318- }
319-
320- now := time .Now ()
321- _ , err = tx .Exec (`
322- INSERT INTO issue_sync_items (
323- issue_sync_config_id, item_id, github_issue_number, github_issue_id,
324- github_issue_url, last_synced_at, last_github_updated_at, created_at, updated_at
325- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
326- ` ,
327- config .ID , itemID , issue .Number , issue .ID ,
328- issue .URL , now , issue .UpdatedAt , now , now ,
329- )
330- if err != nil {
331- return fmt .Errorf ("insert sync item: %w" , err )
332- }
300+ itemID , err := s .itemRepo .CreateWithRetry (ctx , newItem , func (tx database.Tx , itemID int ) error {
301+ if err := repository .NewMilestoneAttachRepository (s .db ).ReplaceItemMilestonesTx (ctx , tx , itemID , milestoneIDs ); err != nil {
302+ return err
303+ }
333304
334- // Keep item, labels, and sync metadata atomic.
335- if err := s .syncLabels (ctx , tx , config , issue , itemID ); err != nil {
336- return fmt .Errorf ("sync labels: %w" , err )
337- }
305+ now := time .Now ()
306+ if _ , err := tx .Exec (`
307+ INSERT INTO issue_sync_items (
308+ issue_sync_config_id, item_id, github_issue_number, github_issue_id,
309+ github_issue_url, last_synced_at, last_github_updated_at, created_at, updated_at
310+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
311+ ` ,
312+ config .ID , itemID , issue .Number , issue .ID ,
313+ issue .URL , now , issue .UpdatedAt , now , now ,
314+ ); err != nil {
315+ return fmt .Errorf ("insert sync item: %w" , err )
316+ }
338317
339- if err := tx .Commit (); err != nil {
340- return fmt .Errorf ("commit: %w" , err )
318+ // Keep item, labels, and sync metadata atomic.
319+ if err := s .syncLabels (ctx , tx , config , issue , itemID ); err != nil {
320+ return fmt .Errorf ("sync labels: %w" , err )
321+ }
322+ return nil
323+ })
324+ if err != nil {
325+ return fmt .Errorf ("create item from issue: %w" , err )
341326 }
342327
343328 slog .Info ("created item from GitHub issue" ,
0 commit comments