Skip to content

Commit

Permalink
fix: use pointer reciever with FSM to ensure state changes are porpog…
Browse files Browse the repository at this point in the history
…ated
  • Loading branch information
HandOfGod94 committed Sep 10, 2023
1 parent 8849362 commit 934a9e9
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions pkg/jira_changelog/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ func NewGenerator(jiraConfig jira.Config, fromRef, toRef, repoURL string) *Gener
e.Cancel(err)
return
}
g.jiraIssues = issues
g.jiraIssues = lo.Uniq(issues)
},
Before(RecordChangelog): func(ctx context.Context, e *fsm.Event) {
jiraIssues := lo.Uniq(g.jiraIssues)
slog.Debug("Total jira issues ids", "count", len(jiraIssues))
RecordChangelog: func(ctx context.Context, e *fsm.Event) {
slog.Debug("Total jira issues ids", "count", len(g.jiraIssues))
slog.Debug("Recroding changelog")

issuesByEpic := lo.GroupBy(jiraIssues, func(issue jira.Issue) string { return issue.Epic() })
issuesByEpic := lo.GroupBy(g.jiraIssues, func(issue jira.Issue) string { return issue.Epic() })

slog.Debug("Total epics", "count", len(issuesByEpic))
g.changes = issuesByEpic
},
},
Expand All @@ -90,15 +92,17 @@ func panicIfErr(err error) {
}
}

func (c Generator) Generate(ctx context.Context) *Changelog {
func (c *Generator) Generate(ctx context.Context) *Changelog {
panicIfErr(c.FSM.Event(ctx, FetchCommits))
panicIfErr(c.FSM.Event(ctx, FetchJiraIssues))
panicIfErr(c.FSM.Event(ctx, RecordChangelog))

slog.Debug("Total changelog items", "count", len(c.changes))

return NewChangelog(c.fromRef, c.toRef, c.repoURL, c.changes)
}

func (c Generator) fetchJiraIssues(commits []git.Commit) ([]jira.Issue, error) {
func (c *Generator) fetchJiraIssues(commits []git.Commit) ([]jira.Issue, error) {
slog.Debug("Total commit messages", "count", len(commits))

jiraIssues := make([]jira.Issue, 0)
Expand All @@ -115,7 +119,7 @@ func (c Generator) fetchJiraIssues(commits []git.Commit) ([]jira.Issue, error) {
return jiraIssues, nil
}

func (c Generator) fetchJiraIssue(commit git.Commit) (jira.Issue, error) {
func (c *Generator) fetchJiraIssue(commit git.Commit) (jira.Issue, error) {
issueId := jira.IssueId(commit.Message)
if issueId == "" {
slog.Warn("commit message does not contain issue jira id of the project", "commit", commit)
Expand Down

0 comments on commit 934a9e9

Please sign in to comment.