Skip to content

Commit 5723e8e

Browse files
committed
wip: update mappings and set pillar name
1 parent c66822f commit 5723e8e

File tree

7 files changed

+246
-126
lines changed

7 files changed

+246
-126
lines changed

tools/flakeguard/.jira_assignee_mapping.json

Lines changed: 0 additions & 47 deletions
This file was deleted.

tools/flakeguard/cmd/common.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package cmd
2+
3+
import "github.com/spf13/cobra"
4+
5+
// UserMapping holds user information.
6+
type UserMapping struct {
7+
JiraUserID string `json:"jira_user_id"`
8+
UserName string `json:"user_name"`
9+
PillarName string `json:"pillar_name"`
10+
}
11+
12+
// UserTestMapping holds a single test pattern for a user.
13+
type UserTestMapping struct {
14+
JiraUserID string `json:"jira_user_id"`
15+
Pattern string `json:"pattern"`
16+
}
17+
18+
// Shared command flags
19+
var (
20+
userMappingPath string // path to user mapping file
21+
userTestMappingPath string // path to user test mapping file
22+
)
23+
24+
// InitCommonFlags initializes the common flags for both commands.
25+
func InitCommonFlags(cmd *cobra.Command) {
26+
cmd.Flags().StringVar(&userMappingPath, "user-mapping", "user_mapping.json", "Path to the user mapping JSON file")
27+
cmd.Flags().StringVar(&userTestMappingPath, "user-test-mapping", "user_test_mapping.json", "Path to the user test mapping JSON file")
28+
}

tools/flakeguard/cmd/create_jira_tickets.go

Lines changed: 12 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ package cmd
33
import (
44
"context"
55
"encoding/csv"
6-
"encoding/json"
76
"fmt"
87
"os"
9-
"regexp"
108
"strconv"
119
"strings"
1210
"time"
@@ -23,23 +21,15 @@ import (
2321
)
2422

2523
var (
26-
csvPath string
27-
dryRun bool
28-
jiraProject string
29-
jiraIssueType string
30-
jiraSearchLabel string // defaults to "flaky_test" if empty
31-
testDBPath string
32-
assigneeMappingPath string
33-
skipExisting bool
24+
csvPath string
25+
dryRun bool
26+
jiraProject string
27+
jiraIssueType string
28+
jiraSearchLabel string // defaults to "flaky_test" if empty
29+
testDBPath string
30+
skipExisting bool
3431
)
3532

36-
// AssigneeMapping holds a regex pattern and its corresponding assignee.
37-
type AssigneeMapping struct {
38-
Pattern string `json:"pattern"`
39-
Assignee string `json:"assignee"`
40-
AssigneeName string `json:"assignee_name"`
41-
}
42-
4333
var CreateTicketsCmd = &cobra.Command{
4434
Use: "create-tickets",
4535
Short: "Interactive TUI to confirm and create Jira tickets from CSV",
@@ -55,8 +45,6 @@ ticket in a text-based UI. Press 'y' to confirm creation, 'n' to skip,
5545
already mapped to tests, so you won't be prompted again in the future.
5646
- After the TUI ends, a new CSV is produced, omitting any confirmed rows.
5747
The original CSV remains untouched.
58-
- Optionally, an assignee mapping file (JSON) can be provided to set the ticket’s assignee
59-
based on the test package. The mapping supports regex.
6048
`,
6149
RunE: func(cmd *cobra.Command, args []string) error {
6250
// 1) Validate input
@@ -128,35 +116,6 @@ ticket in a text-based UI. Press 'y' to confirm creation, 'n' to skip,
128116
return nil
129117
}
130118

131-
// Load assignee mapping (if provided)
132-
var mappings []AssigneeMapping
133-
if assigneeMappingPath != "" {
134-
mappingData, err := os.ReadFile(assigneeMappingPath)
135-
if err != nil {
136-
log.Warn().Err(err).Msg("Failed to read assignee mapping file; proceeding without assignee mapping.")
137-
} else {
138-
if err := json.Unmarshal(mappingData, &mappings); err != nil {
139-
log.Warn().Err(err).Msg("Failed to unmarshal assignee mapping; proceeding without assignee mapping.")
140-
} else {
141-
// Apply mapping: iterate over tickets and assign based on regex match.
142-
for i := range tickets {
143-
for _, mapping := range mappings {
144-
re, err := regexp.Compile(mapping.Pattern)
145-
if err != nil {
146-
log.Warn().Msgf("Invalid regex pattern %q: %v", mapping.Pattern, err)
147-
continue
148-
}
149-
if re.MatchString(tickets[i].TestPackage) {
150-
tickets[i].AssigneeId = mapping.Assignee
151-
tickets[i].AssigneeName = mapping.AssigneeName
152-
break // use first matching mapping
153-
}
154-
}
155-
}
156-
}
157-
}
158-
}
159-
160119
// 5) Attempt Jira client creation
161120
client, clientErr := jirautils.GetJiraClient()
162121
if clientErr != nil {
@@ -215,14 +174,14 @@ ticket in a text-based UI. Press 'y' to confirm creation, 'n' to skip,
215174
}
216175

217176
func init() {
218-
CreateTicketsCmd.Flags().StringVar(&csvPath, "csv-path", "", "Path to the CSV file containing flaky test data")
219-
CreateTicketsCmd.Flags().BoolVar(&dryRun, "dry-run", false, "If true, do not actually create tickets in Jira")
220-
CreateTicketsCmd.Flags().StringVar(&jiraProject, "jira-project", "", "Jira project key (or env JIRA_PROJECT_KEY)")
221-
CreateTicketsCmd.Flags().StringVar(&jiraIssueType, "jira-issue-type", "Task", "Type of Jira issue (Task, Bug, etc.)")
177+
CreateTicketsCmd.Flags().StringVar(&csvPath, "csv-path", "", "Path to CSV file with flaky tests")
178+
CreateTicketsCmd.Flags().BoolVar(&dryRun, "dry-run", false, "If true, do not create tickets in Jira")
179+
CreateTicketsCmd.Flags().StringVar(&jiraProject, "jira-project", "", "Jira project key (default: JIRA_PROJECT_KEY env)")
180+
CreateTicketsCmd.Flags().StringVar(&jiraIssueType, "jira-issue-type", "Task", "Jira issue type")
222181
CreateTicketsCmd.Flags().StringVar(&jiraSearchLabel, "jira-search-label", "", "Jira label to filter existing tickets (default: flaky_test)")
223182
CreateTicketsCmd.Flags().StringVar(&testDBPath, "test-db-path", "", "Path to the flaky test JSON database (default: ~/.flaky_tes_db.json)")
224-
CreateTicketsCmd.Flags().StringVar(&assigneeMappingPath, "assignee-mapping", "", "Path to JSON file with assignee mapping (supports regex)")
225183
CreateTicketsCmd.Flags().BoolVar(&skipExisting, "skip-existing", false, "Skip processing tickets that already have a Jira ticket ID")
184+
InitCommonFlags(CreateTicketsCmd)
226185
}
227186

228187
// -------------------------------------------------------------------------------------
@@ -473,7 +432,6 @@ func updatePromptExisting(m tmodel, msg tea.KeyMsg) (tea.Model, tea.Cmd) {
473432
t.ExistingJiraKey = m.inputValue
474433
t.ExistingTicketSource = "localdb"
475434
m.tickets[m.index] = t
476-
m.LocalDB.Set(t.TestPackage, t.TestName, t.ExistingJiraKey)
477435
m.mode = "normal"
478436
m.inputValue = ""
479437
return updateSkip(m)

0 commit comments

Comments
 (0)