From 934a9e9d5dfc521e7368a04d58c1d8089f8cce90 Mon Sep 17 00:00:00 2001 From: Gahan Rakholia Date: Sun, 10 Sep 2023 11:47:46 +0530 Subject: [PATCH] fix: use pointer reciever with FSM to ensure state changes are porpogated --- pkg/jira_changelog/generator.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/pkg/jira_changelog/generator.go b/pkg/jira_changelog/generator.go index 76d334b..1ae9809 100644 --- a/pkg/jira_changelog/generator.go +++ b/pkg/jira_changelog/generator.go @@ -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 }, }, @@ -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) @@ -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)