Skip to content

Commit

Permalink
fix viper binding with repo_url
Browse files Browse the repository at this point in the history
  • Loading branch information
HandOfGod94 committed Sep 3, 2023
1 parent e9f34fc commit acc6467
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ gh jira-changelog generate --config="<path-to-config-file>.yaml" --from="v0.1.0"
Flags:
--from string Git ref to start from
-h, --help help for generate
--repo_url string Repo URL. Used to generate diff url. Currently only github is supported
--to string Git ref to end at (default "main")
--write_to string File stream to write the changelog (default "/dev/stdout")
Expand All @@ -118,4 +117,5 @@ Global Flags:
--config string config file (default is ./.jira_changelog.yaml)
--email_id string email id of the user
-v, --log_level string log level. options: debug, info, warn, error (default "error")
--repo_url string Repo URL. Used to generate diff url. Currently only github is supported
```
8 changes: 3 additions & 5 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ var (
fromRef string
toRef string
writeTo string
repoURL string
DefaultTimeout = 5 * time.Second
requiredFlags = []string{"base_url", "email_id", "api_token", "repo_url"}
)
Expand Down Expand Up @@ -79,17 +78,17 @@ gh jira-changelog generate --config="<path-to-config-file>.yaml" --from="v0.1.0"

changelog := jira_changelog.NewGenerator(
jira.Config{
BaseUrl: viper.GetString("base_url"),
BaseURL: viper.GetString("base_url"),
ApiToken: viper.GetString("api_token"),
User: viper.GetString("email_id"),
},
fromRef,
toRef,
repoURL,
viper.GetString("repo_url"),
)

slog.Info("Generating changelog", "JiraConfig", changelog.JiraConfig,
"From", fromRef, "To", toRef, "repoURL", repoURL)
"From", fromRef, "To", toRef, "repoURL", viper.GetString("repo_url"))
changelog.Generate(ctx).Render(writer(writeTo))
},
}
Expand All @@ -115,7 +114,6 @@ func init() {
generateCmd.Flags().StringVar(&fromRef, "from", "", "Git ref to start from")
generateCmd.Flags().StringVar(&toRef, "to", "main", "Git ref to end at")
generateCmd.Flags().StringVar(&writeTo, "write_to", "/dev/stdout", "File stream to write the changelog")
generateCmd.Flags().StringVar(&repoURL, "repo_url", "", "Repo URL. Used to generate diff url. Currently only github is supported")

generateCmd.MarkFlagRequired("from")

Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func init() {
rootCmd.PersistentFlags().String("email_id", "", "email id of the user")
rootCmd.PersistentFlags().StringP("api_token", "t", "", "API token for jira")
rootCmd.PersistentFlags().StringP("log_level", "v", "error", "log level. options: debug, info, warn, error")
rootCmd.PersistentFlags().StringVar(&repoURL, "repo_url", "", "Repo URL. Used to generate diff url. Currently only github is supported")
rootCmd.PersistentFlags().String("repo_url", "", "Repo URL. Used to generate diff url. Currently only github is supported")

viper.BindPFlags(rootCmd.PersistentFlags())
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/jira_changelog/jira/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (c *client) attachDefaultHeaders(r *http.Request) {
}

func (c *client) FetchIssue(issueId string) (Issue, error) {
requestUrl, err := url.JoinPath(c.config.BaseUrl, "rest", "api", "3", "issue", issueId)
requestUrl, err := url.JoinPath(c.config.BaseURL, "rest", "api", "3", "issue", issueId)
slog.Debug("Preparing fetch request", "url", requestUrl)
if err != nil {
return Issue{}, fmt.Errorf("failed to create request url. %w", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/jira_changelog/jira/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package jira

type Config struct {
BaseUrl string
BaseURL string
User string
ApiToken string
}

0 comments on commit acc6467

Please sign in to comment.