Skip to content

Commit

Permalink
refactor: move if else while initializing field
Browse files Browse the repository at this point in the history
  • Loading branch information
HandOfGod94 committed Jan 14, 2024
1 parent 2f95f9b commit 83223ca
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
26 changes: 15 additions & 11 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,27 @@ gh jira-changelog generate --config="<path-to-config-file>.yaml" --from="v0.1.0"
defer cancel()

repoURL := repoURL(ctx)
var populator messages.Populator
if usePR {
populator, err = messages.NewPullRequestPopulator(fromRef, toRef, repoURL)
} else {
populator, err = messages.NewCommitPopulator(fromRef, toRef)
}

changelog := jira_changelog.Generator{
Client: jira.NewClient(jira.NewClientOptions(jira.Options{
jira.BaseURL: viper.GetString("base_url"),
jira.ApiToken: viper.GetString("api_token"),
jira.User: viper.GetString("email_id"),
})),
Populator: populator,
FromRef: fromRef,
ToRef: toRef,
RepoURL: repoURL,
Populator: func() (populator messages.Populator) {
if usePR {
populator, err = messages.NewPullRequestPopulator(fromRef, toRef, repoURL)
} else {
populator, err = messages.NewCommitPopulator(fromRef, toRef)
}
return
}(),
FromRef: fromRef,
ToRef: toRef,
RepoURL: repoURL,
}

if err != nil {
return err
}

slog.Info("Generating changelog", "From", fromRef, "To", toRef, "repoURL", repoURL)
Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/spf13/cobra"
)

const version = "v0.3.2"
const version = "dev"

var versionCmd = &cobra.Command{
Use: "version",
Expand Down
1 change: 0 additions & 1 deletion pkg/jira_changelog/messages/pull_request_populator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ func TestRepoPath_WhenRepoURLIsInvalid(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, []string{"foo"}, result)
}

0 comments on commit 83223ca

Please sign in to comment.