@@ -92,10 +92,12 @@ ticket in a text-based UI. Press 'y' to confirm creation, 'n' to skip,
9292 }
9393 ft := rowToFlakyTicket (row )
9494 ft .RowIndex = i + 1
95+
96+ // Check local DB for known Jira ticket
9597 if ft .Valid {
96- // Check local DB for known Jira ticket
9798 if ticketID , found := db .Get (ft .TestPackage , ft .TestName ); found {
9899 ft .ExistingJiraKey = ticketID
100+ ft .ExistingTicketSource = "localdb" // <--- mark source as localdb
99101 }
100102 }
101103 tickets = append (tickets , ft )
@@ -116,13 +118,14 @@ ticket in a text-based UI. Press 'y' to confirm creation, 'n' to skip,
116118 if client != nil {
117119 for i := range tickets {
118120 t := & tickets [i ]
121+ // if valid, no local db ticket, let's see if Jira has one
119122 if t .Valid && t .ExistingJiraKey == "" {
120123 key , err := findExistingTicket (client , jiraSearchLabel , * t )
121124 if err != nil {
122125 log .Warn ().Msgf ("Search failed for %q: %v" , t .Summary , err )
123126 } else if key != "" {
124127 t .ExistingJiraKey = key
125- // Also save in local DB so we don't ask again next time
128+ t . ExistingTicketSource = "jira" // <--- mark source as jira
126129 db .Set (t .TestPackage , t .TestName , key )
127130 }
128131 }
@@ -149,6 +152,9 @@ ticket in a text-based UI. Press 'y' to confirm creation, 'n' to skip,
149152 // 9) Save local DB with any new knowledge
150153 if err := localdb .SaveDB (fm .LocalDB ); err != nil {
151154 log .Error ().Err (err ).Msg ("Failed to save local DB" )
155+ } else {
156+ // Let the user know we updated it
157+ fmt .Printf ("Local DB has been updated at: %s\n " , localdb .FilePath ())
152158 }
153159
154160 // 10) Write remaining CSV
@@ -176,15 +182,16 @@ func init() {
176182// -------------------------------------------------------------------------------------
177183
178184type FlakyTicket struct {
179- RowIndex int
180- Confirmed bool
181- Valid bool
182- InvalidReason string
183- TestName string
184- TestPackage string
185- Summary string
186- Description string
187- ExistingJiraKey string
185+ RowIndex int
186+ Confirmed bool
187+ Valid bool
188+ InvalidReason string
189+ TestName string
190+ TestPackage string
191+ Summary string
192+ Description string
193+ ExistingJiraKey string
194+ ExistingTicketSource string // "localdb" or "jira" (if found)
188195}
189196
190197// rowToFlakyTicket: build a ticket from one CSV row (index assumptions: pkg=0, testName=2, flakeRate=7, logs=9).
@@ -355,8 +362,7 @@ func updateNormalMode(m model, msg tea.KeyMsg) (tea.Model, tea.Cmd) {
355362 case "n" :
356363 return updateSkip (m )
357364 case "e" :
358- // Remove the condition requiring an empty ExistingJiraKey
359- // so we ALWAYS enter prompt mode when user presses "e".
365+ // <--- Always prompt for a known ticket ID (even if one exists).
360366 m .mode = "promptExisting"
361367 m .inputValue = ""
362368 return m , nil
@@ -378,6 +384,7 @@ func updatePromptExisting(m model, msg tea.KeyMsg) (tea.Model, tea.Cmd) {
378384 // store the typed string
379385 t := m .tickets [m .index ]
380386 t .ExistingJiraKey = m .inputValue
387+ t .ExistingTicketSource = "localdb" // user manually provided => treat like local db
381388 m .tickets [m .index ] = t
382389
383390 // update local DB
@@ -409,6 +416,7 @@ func updateConfirm(m model) (tea.Model, tea.Cmd) {
409416 log .Info ().Msgf ("Created Jira ticket: %s (summary=%q)" , issueKey , t .Summary )
410417 t .Confirmed = true
411418 t .ExistingJiraKey = issueKey
419+ t .ExistingTicketSource = "jira"
412420 // store in local DB so we won't prompt again
413421 m .LocalDB .Set (t .TestPackage , t .TestName , issueKey )
414422 }
@@ -446,6 +454,7 @@ func (m model) View() string {
446454 return finalView (m )
447455 }
448456
457+ // Sub-mode: prompt for existing ticket ID
449458 if m .mode == "promptExisting" {
450459 return fmt .Sprintf (
451460 "Enter existing Jira ticket ID for test %q:\n \n %s\n \n (Press Enter to confirm, Esc to cancel)" ,
@@ -491,15 +500,24 @@ func (m model) View() string {
491500 descHeader := descHeaderStyle .Render ("\n Description:\n " )
492501 descBody := descBodyStyle .Render (t .Description )
493502
503+ // Build existing line AFTER the description
494504 var existingLine string
495505 if t .ExistingJiraKey != "" {
506+ prefix := "Existing ticket found"
507+ switch t .ExistingTicketSource {
508+ case "localdb" :
509+ prefix = "Existing ticket found in local db"
510+ case "jira" :
511+ prefix = "Existing ticket found in jira"
512+ }
496513 domain := os .Getenv ("JIRA_DOMAIN" )
497514 link := t .ExistingJiraKey
498515 if domain != "" {
516+ // Turn "DX-204" into a link if we have a domain
499517 link = fmt .Sprintf ("https://%s/browse/%s" , domain , t .ExistingJiraKey )
500518 }
501519 existingLine = existingStyle .Render (
502- fmt .Sprintf ("\n Existing ticket found : %s" , link ),
520+ fmt .Sprintf ("\n %s : %s" , prefix , link ),
503521 )
504522 }
505523
@@ -511,13 +529,15 @@ func (m model) View() string {
511529 fmt .Sprintf ("\n Press [y] to confirm%s, [n] to skip, [e] to enter existing ticket, [q] to quit." , dryRunLabel ),
512530 )
513531
514- return fmt .Sprintf ("%s\n \n %s%s\n %s\n %s\n %s\n " ,
532+ // Show summary, description, then existing line at the bottom, then help text
533+ return fmt .Sprintf (
534+ "%s\n \n %s\n %s%s\n %s\n %s\n " ,
515535 header ,
516536 sum ,
537+ descHeader ,
538+ descBody ,
517539 existingLine ,
518- descHeader + descBody ,
519540 help ,
520- "" ,
521541 )
522542}
523543
0 commit comments