Skip to content

Commit f7edad1

Browse files
committed
more refactoring
1 parent fbea57a commit f7edad1

File tree

4 files changed

+15
-34
lines changed

4 files changed

+15
-34
lines changed
Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ import (
1111
"time"
1212

1313
"github.com/andygrunwald/go-jira"
14-
"github.com/briandowns/spinner"
1514
tea "github.com/charmbracelet/bubbletea"
1615
"github.com/charmbracelet/lipgloss"
1716
"github.com/rs/zerolog/log"
1817

19-
// Import mapping and other utils
2018
"github.com/smartcontractkit/chainlink-testing-framework/tools/flakeguard/jirautils"
2119
"github.com/smartcontractkit/chainlink-testing-framework/tools/flakeguard/localdb"
2220
"github.com/smartcontractkit/chainlink-testing-framework/tools/flakeguard/mapping"
@@ -176,7 +174,7 @@ Features:
176174
} // End CSV processing loop
177175

178176
if len(tickets) == 0 {
179-
log.Warn().Msg("No processable tickets found after filtering and validation.")
177+
log.Warn().Msg("No new tickets to create found after filtering and validation.")
180178
return nil
181179
}
182180

@@ -189,9 +187,6 @@ Features:
189187

190188
// 7) If Jira client exists, search for existing tickets online (for those without a key yet)
191189
if client != nil {
192-
s := spinner.New(spinner.CharSets[14], 100*time.Millisecond)
193-
s.Suffix = " Searching Jira for potentially existing tickets..."
194-
s.Start()
195190
processedCount := 0
196191
totalToSearch := 0
197192
for _, t := range tickets {
@@ -205,7 +200,6 @@ Features:
205200
if t.ExistingJiraKey == "" { // Only search if we don't have a key from DB
206201
key, searchErr := findExistingTicket(client, jiraSearchLabel, *t) // findExistingTicket needs definition
207202
processedCount++
208-
s.Suffix = fmt.Sprintf(" Searching Jira... (%d/%d)", processedCount, totalToSearch)
209203
if searchErr != nil {
210204
// Log non-fatal search error
211205
log.Warn().Err(searchErr).Str("summary", t.Summary).Msg("Jira search failed for test")
@@ -223,8 +217,6 @@ Features:
223217
}
224218
}
225219
}
226-
s.Stop()
227-
fmt.Println() // Newline after spinner
228220
}
229221

230222
// 8) Create Bubble Tea model
@@ -447,8 +439,9 @@ h3. Action Items
447439
# *Investigate:* Review logs and test code to identify the root cause of the flakiness.
448440
# *Fix:* Implement the necessary code changes or infrastructure adjustments.
449441
# *Verify:* Run the test locally multiple times and monitor in CI to confirm stability.
442+
# *Unskip:* Once confirmed stable, remove any test skip markers to re-enable the test in the CI pipeline.
450443
# *Close Ticket:* Close this ticket once the test is confirmed stable.
451-
# *Guidance:* Refer to the team's [Flaky Test Guide|https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/tools/flakeguard/e2e-flaky-test-guide.md] (Update link if needed).
444+
# *Guidance:* Refer to the team's [Flaky Test Guide|https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/tools/flakeguard/e2e-flaky-test-guide.md].
452445
`,
453446
pkgDisplay,
454447
testNameDisplay,
@@ -858,7 +851,6 @@ func updateConfirm(m createModel) (tea.Model, tea.Cmd) {
858851
assigneeForJira = t.AssigneeId
859852
if userMapping, exists := m.userMap[t.AssigneeId]; exists {
860853
pillarName = userMapping.PillarName
861-
log.Debug().Str("assignee", t.AssigneeId).Str("pillar", pillarName).Msg("Found pillar name for assignee")
862854
} else {
863855
log.Warn().Str("assignee", t.AssigneeId).Msg("Assignee ID present but no matching entry in user_mapping.json found.")
864856
}
Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@ var (
3333
userTestMappingPath string // Although not directly used for assignment here, load it for consistency/future use
3434
)
3535

36-
// TicketsCmd ... (rest of the command definition remains the same)
37-
var TicketsCmd = &cobra.Command{
38-
Use: "tickets",
39-
Short: "Manage tickets from flaky_test_db.json",
40-
Long: `Interactively manage your tickets.
36+
var ReviewTicketsCmd = &cobra.Command{
37+
Use: "review-tickets",
38+
Short: "Review tickets from --test-db-path",
39+
Long: `Interactively review tickets from --test-db-path.
4140
4241
Actions:
4342
[s] mark as skipped (and optionally post a comment to the Jira ticket)
@@ -246,14 +245,14 @@ func uniqueStrings(input []string) []string {
246245
}
247246

248247
func init() {
249-
TicketsCmd.Flags().StringVar(&ticketsJSONPath, "test-db-path", localdb.DefaultDBPath(), "Path to the JSON file containing tickets") // Use default path function
250-
TicketsCmd.Flags().BoolVar(&jiraComment, "jira-comment", true, "If true, post a comment to the Jira ticket when marking as skipped/unskipped")
251-
TicketsCmd.Flags().BoolVar(&ticketsDryRun, "dry-run", false, "If true, do not modify Jira tickets (comments, pillars) or save DB") // Updated help text
252-
TicketsCmd.Flags().BoolVar(&hideSkipped, "hide-skipped", false, "If true, do not show tests already marked as skipped")
253-
TicketsCmd.Flags().BoolVar(&missingPillars, "missing-pillars", false, "If true, only show tickets that have a Jira Key but no Pillar Name") // Updated help text
248+
ReviewTicketsCmd.Flags().StringVar(&ticketsJSONPath, "test-db-path", localdb.DefaultDBPath(), "Path to the JSON file containing tickets") // Use default path function
249+
ReviewTicketsCmd.Flags().BoolVar(&jiraComment, "jira-comment", true, "If true, post a comment to the Jira ticket when marking as skipped/unskipped")
250+
ReviewTicketsCmd.Flags().BoolVar(&ticketsDryRun, "dry-run", false, "If true, do not modify Jira tickets (comments, pillars) or save DB") // Updated help text
251+
ReviewTicketsCmd.Flags().BoolVar(&hideSkipped, "hide-skipped", false, "If true, do not show tests already marked as skipped")
252+
ReviewTicketsCmd.Flags().BoolVar(&missingPillars, "missing-pillars", false, "If true, only show tickets that have a Jira Key but no Pillar Name") // Updated help text
254253
// Make mapping paths consistent flags
255-
TicketsCmd.Flags().StringVar(&userMappingPath, "user-mapping-path", "user_mapping.json", "Path to the JSON file containing user mapping (JiraUserID -> PillarName)")
256-
TicketsCmd.Flags().StringVar(&userTestMappingPath, "user-test-mapping-path", "user_test_mapping.json", "Path to the JSON file containing user test mapping (Pattern -> JiraUserID)")
254+
ReviewTicketsCmd.Flags().StringVar(&userMappingPath, "user-mapping-path", "user_mapping.json", "Path to the JSON file containing user mapping (JiraUserID -> PillarName)")
255+
ReviewTicketsCmd.Flags().StringVar(&userTestMappingPath, "user-test-mapping-path", "user_test_mapping.json", "Path to the JSON file containing user test mapping (Pattern -> JiraUserID)")
257256
}
258257

259258
// -------------------------

tools/flakeguard/jirautils/jira.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,12 @@ func CreateTicketInJira(
112112
// For a simple text field or select list (by value):
113113
issueFields.Unknowns[pillarCustomFieldID] = map[string]interface{}{"value": pillarName}
114114
// If it's a select list by ID, it would be map[string]interface{}{"id": "12345"}
115-
log.Debug().Str("fieldId", pillarCustomFieldID).Str("value", pillarName).Msg("Adding pillar custom field")
116115
}
117116

118117
issue := jira.Issue{
119118
Fields: issueFields,
120119
}
121120

122-
log.Debug().Interface("issuePayload", issue).Msg("Jira creation payload")
123-
124121
// Use context with the API call
125122
createdIssue, resp, err := client.Issue.CreateWithContext(ctx, &issue)
126123
if err != nil {
@@ -134,7 +131,6 @@ func CreateTicketInJira(
134131
return "", fmt.Errorf("jira API returned success but issue object is nil")
135132
}
136133

137-
log.Info().Str("key", createdIssue.Key).Str("id", createdIssue.ID).Msg("Jira issue created successfully")
138134
return createdIssue.Key, nil
139135
}
140136

@@ -147,19 +143,13 @@ func DeleteTicketInJira(client *jira.Client, issueKey string) error {
147143
return fmt.Errorf("issue key cannot be empty")
148144
}
149145

150-
log.Warn().Str("key", issueKey).Msg("Attempting to permanently delete Jira ticket")
151-
152146
resp, err := client.Issue.DeleteWithContext(context.Background(), issueKey)
153147
if err != nil {
154148
errMsg := ReadJiraErrorResponse(resp)
155149
log.Error().Err(err).Str("key", issueKey).Str("responseBody", errMsg).Msg("Failed to delete Jira issue")
156150
return fmt.Errorf("failed to delete issue %s: %w; response: %s", issueKey, err, errMsg)
157151
}
158152

159-
// Check status code explicitly? Jira library might already handle non-2xx as errors.
160-
// if resp.StatusCode != http.StatusNoContent { ... }
161-
162-
log.Info().Str("key", issueKey).Msg("Jira ticket deleted successfully")
163153
return nil
164154
}
165155

tools/flakeguard/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func init() {
4343
rootCmd.AddCommand(cmd.GenerateReportCmd)
4444
rootCmd.AddCommand(cmd.GetGHArtifactLinkCmd)
4545
rootCmd.AddCommand(cmd.SendToSplunkCmd)
46-
rootCmd.AddCommand(cmd.TicketsCmd)
46+
rootCmd.AddCommand(cmd.ReviewTicketsCmd)
4747
rootCmd.AddCommand(cmd.CreateTicketsCmd)
4848
rootCmd.AddCommand(cmd.SyncJiraCmd)
4949
}

0 commit comments

Comments
 (0)