Skip to content

Commit

Permalink
Updating component when it's not on the issue
Browse files Browse the repository at this point in the history
Signed-off-by: Laszlo Gecse <[email protected]>
  • Loading branch information
lgecse committed Aug 7, 2023
1 parent 5c5ef25 commit f514c5c
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions internal/jira/issue/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ func DidIssueChange(cfg *config.Config, ghIssue *gogh.Issue, jIssue *gojira.Issu
anyDifferent = true
}

if GetMissingComponents(cfg, jIssue) != nil {
anyDifferent = true
}

if len(ghIssue.Labels) > 0 { //nolint:nestif // TODO(lint)
ghLabels := githubLabelsToStrSlice(ghIssue.Labels)

Expand Down Expand Up @@ -211,6 +215,11 @@ func UpdateIssue(
ID: jIssue.ID,
}

missingComponents := GetMissingComponents(cfg, jIssue)
for i := range missingComponents {
issue.Fields.Components = append(issue.Fields.Components, missingComponents[i])
}

_, err := jClient.UpdateIssue(issue)
if err != nil {
return fmt.Errorf("updating Jira issue: %w", err)
Expand All @@ -233,6 +242,33 @@ func UpdateIssue(
return nil
}

// GetMissingComponents compares configurated components with the Jira issue
// components. Returns the components that are missing from the Jira issue.
func GetMissingComponents(cfg *config.Config, jIssue *gojira.Issue) []*gojira.Component {
var returnComponents []*gojira.Component

components := cfg.GetJiraComponents()
for i := range components {
configComponent := *components[i]

found := false

for j := range jIssue.Fields.Components {
issueComponent := *jIssue.Fields.Components[j]

if issueComponent.Name == configComponent.Name {
found = true
break
}
}

if !found {
returnComponents = append(returnComponents, &configComponent)
}
}
return returnComponents
}

// CreateIssue generates a Jira issue from the various fields on the given GitHub issue, then
// sends it to the Jira API.
func CreateIssue(cfg *config.Config, issue *gogh.Issue, ghClient github.Client, jClient jira.Client) error {
Expand Down

0 comments on commit f514c5c

Please sign in to comment.