@@ -249,37 +249,23 @@ func SyncProjectBugFixWorkflowToJira(c *gin.Context) {
249249 }
250250 }
251251
252- // Also post GitHub comment for updates (not just creates)
253- if isUpdate {
254- userID , _ := c .Get ("userID" )
255- userIDStr , _ := userID .(string )
256- githubToken , err := git .GetGitHubToken (c .Request .Context (), reqK8s , reqDyn , project , userIDStr )
257- if err == nil && githubToken != "" {
258- owner , repo , issueNumber , err := github .ParseGitHubIssueURL (workflow .GithubIssueURL )
259- if err == nil {
260- comment := formatGitHubJiraUpdateComment (jiraTaskKey , jiraTaskURL , workflow )
261- ctx := context .Background ()
262- _ , err = github .AddComment (ctx , owner , repo , issueNumber , githubToken , comment )
263- if err != nil {
264- // Non-fatal: Log but continue
265- fmt .Printf ("Warning: Failed to add Jira update to GitHub Issue: %v\n " , err )
266- } else {
267- fmt .Printf ("Posted Jira update comment to GitHub Issue #%d\n " , issueNumber )
268- }
269- }
270- }
271- }
252+ // Note: Only post GitHub comment on initial creation, not on updates
253+ // This prevents spamming the GitHub Issue with repeated sync comments
272254
273255 // T055: Update BugFixWorkflow CR with jiraTaskKey, jiraTaskURL, and lastSyncedAt
256+ // Use backend service account client for CR write (following handlers/sessions.go:417 pattern)
274257 workflow .JiraTaskKey = & jiraTaskKey
275258 workflow .JiraTaskURL = & jiraTaskURL
276259 syncedAt := time .Now ().UTC ().Format (time .RFC3339 )
277260 workflow .LastSyncedAt = & syncedAt
278261
279- err = crd .UpsertProjectBugFixWorkflowCR (reqDyn , workflow )
262+ serviceAccountClient := GetServiceAccountDynamicClient ()
263+ err = crd .UpsertProjectBugFixWorkflowCR (serviceAccountClient , workflow )
280264 if err != nil {
281- // Try to continue even if CR update fails
265+ // Log error and continue - Jira sync itself succeeded
282266 fmt .Printf ("Warning: Failed to update workflow CR with Jira info: %v\n " , err )
267+ } else {
268+ fmt .Printf ("Successfully updated workflow CR with Jira info: %s -> %s\n " , workflowID , jiraTaskKey )
283269 }
284270
285271 // Broadcast success
@@ -467,6 +453,7 @@ func getSuccessMessage(created bool, jiraTaskKey string) string {
467453}
468454
469455// attachGistsToJira fetches Gist content and attaches it as markdown files to the Jira issue
456+ // Only attaches if the file doesn't already exist to prevent duplicates
470457func attachGistsToJira (c * gin.Context , workflow * types.BugFixWorkflow , jiraBase , jiraTaskKey , authHeader string , reqK8s * kubernetes.Clientset , reqDyn dynamic.Interface , project string ) {
471458 if workflow .Annotations == nil {
472459 return
@@ -483,34 +470,51 @@ func attachGistsToJira(c *gin.Context, workflow *types.BugFixWorkflow, jiraBase,
483470
484471 ctx := c .Request .Context ()
485472
473+ // Get existing attachments to avoid duplicates
474+ existingAttachments , err := jira .GetJiraIssueAttachments (ctx , jiraBase , jiraTaskKey , authHeader )
475+ if err != nil {
476+ fmt .Printf ("Warning: Failed to get existing Jira attachments: %v (will attempt upload anyway)\n " , err )
477+ existingAttachments = make (map [string ]bool ) // Continue with empty map
478+ }
479+
486480 // Attach bug-review Gist if available
487481 if bugReviewGist := workflow .Annotations ["bug-review-gist-url" ]; bugReviewGist != "" {
488- fmt .Printf ( "Fetching bug-review Gist from %s \n " , bugReviewGist )
489- gistContent , err := github . GetGist ( ctx , bugReviewGist , githubToken )
490- if err != nil {
491- fmt .Printf ("Warning: Failed to fetch bug-review Gist: %v \n " , err )
482+ filename := fmt .Sprintf ( " bug-review-issue-%d.md " , workflow . GithubIssueNumber )
483+
484+ if existingAttachments [ filename ] {
485+ fmt .Printf ("Skipping %s - already attached to %s \n " , filename , jiraTaskKey )
492486 } else {
493- filename := fmt .Sprintf ("bug-review-issue-%d.md" , workflow .GithubIssueNumber )
494- if attachErr := jira .AttachFileToJiraIssue (ctx , jiraBase , jiraTaskKey , authHeader , filename , []byte (gistContent )); attachErr != nil {
495- fmt .Printf ("Warning: Failed to attach bug-review.md to %s: %v\n " , jiraTaskKey , attachErr )
487+ fmt .Printf ("Fetching bug-review Gist from %s\n " , bugReviewGist )
488+ gistContent , err := github .GetGist (ctx , bugReviewGist , githubToken )
489+ if err != nil {
490+ fmt .Printf ("Warning: Failed to fetch bug-review Gist: %v\n " , err )
496491 } else {
497- fmt .Printf ("Successfully attached %s to %s\n " , filename , jiraTaskKey )
492+ if attachErr := jira .AttachFileToJiraIssue (ctx , jiraBase , jiraTaskKey , authHeader , filename , []byte (gistContent )); attachErr != nil {
493+ fmt .Printf ("Warning: Failed to attach %s to %s: %v\n " , filename , jiraTaskKey , attachErr )
494+ } else {
495+ fmt .Printf ("Successfully attached %s to %s\n " , filename , jiraTaskKey )
496+ }
498497 }
499498 }
500499 }
501500
502501 // Attach implementation Gist if available
503502 if implGist := workflow .Annotations ["implementation-gist-url" ]; implGist != "" {
504- fmt .Printf ( "Fetching implementation Gist from %s \n " , implGist )
505- gistContent , err := github . GetGist ( ctx , implGist , githubToken )
506- if err != nil {
507- fmt .Printf ("Warning: Failed to fetch implementation Gist: %v \n " , err )
503+ filename := fmt .Sprintf ( " implementation-issue-%d.md " , workflow . GithubIssueNumber )
504+
505+ if existingAttachments [ filename ] {
506+ fmt .Printf ("Skipping %s - already attached to %s \n " , filename , jiraTaskKey )
508507 } else {
509- filename := fmt .Sprintf ("implementation-issue-%d.md" , workflow .GithubIssueNumber )
510- if attachErr := jira .AttachFileToJiraIssue (ctx , jiraBase , jiraTaskKey , authHeader , filename , []byte (gistContent )); attachErr != nil {
511- fmt .Printf ("Warning: Failed to attach implementation.md to %s: %v\n " , jiraTaskKey , attachErr )
508+ fmt .Printf ("Fetching implementation Gist from %s\n " , implGist )
509+ gistContent , err := github .GetGist (ctx , implGist , githubToken )
510+ if err != nil {
511+ fmt .Printf ("Warning: Failed to fetch implementation Gist: %v\n " , err )
512512 } else {
513- fmt .Printf ("Successfully attached %s to %s\n " , filename , jiraTaskKey )
513+ if attachErr := jira .AttachFileToJiraIssue (ctx , jiraBase , jiraTaskKey , authHeader , filename , []byte (gistContent )); attachErr != nil {
514+ fmt .Printf ("Warning: Failed to attach %s to %s: %v\n " , filename , jiraTaskKey , attachErr )
515+ } else {
516+ fmt .Printf ("Successfully attached %s to %s\n " , filename , jiraTaskKey )
517+ }
514518 }
515519 }
516520 }
0 commit comments