Skip to content

Commit

Permalink
add initial skeleton with cli options
Browse files Browse the repository at this point in the history
  • Loading branch information
HandOfGod94 committed Jun 24, 2023
1 parent 64d7f04 commit 09a96fa
Show file tree
Hide file tree
Showing 8 changed files with 587 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
APP_NAME=jira-changelog
APP_NAME=jira_changelog

all: clean fmt tidy build install

Expand Down
24 changes: 18 additions & 6 deletions cmd/generate.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"fmt"

jira "github.com/handofgod94/jira_changelog/pkg/jira_changelog"
"github.com/spf13/cobra"
"golang.org/x/exp/slog"
)

var (
fromRef string
toRef string
)

var generateCmd = &cobra.Command{
Use: "generate",
Short: "Generates changelog",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("generate called")
changelog := jira.Changelog{
JiraConfig: jira.JiraConfig{ProjectUrl: projectUrl, ProjectName: projectName, ApiToken: apiToken},
GitConfig: jira.GitConfig{FromRef: fromRef, ToRef: toRef},
}
slog.Info("Generating changelog", "Jira Config", changelog.JiraConfig, "Git Config", changelog.GitConfig)
changelog.Generate()
},
}

func init() {
generateCmd.Flags().StringVar(&fromRef, "from", "", "Git ref to start from")
generateCmd.Flags().StringVar(&toRef, "to", "main", "Git ref to end at")

generateCmd.MarkFlagRequired("from")

rootCmd.AddCommand(generateCmd)
}
56 changes: 47 additions & 9 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"fmt"
"net/url"
"os"

"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var (
cfgFile string
projectUrl string
projectName string
apiToken string
)

var rootCmd = &cobra.Command{
Use: "jira-changelog",
Short: "Changelog generator using jira issues",
Long: `Most of our changelog tools solely focus on commits. While the orgs usually use jira to track issues.
When generating changelog why not combine both commits and jira issues to generate a changelog.
`,
Run: func(cmd *cobra.Command, args []string) {},
When generating changelog why not combine both commits and jira issues to generate a changelog.`,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
_, err := url.Parse(projectUrl)
if err != nil {
return err
}
return nil
},
}

func Execute() {
Expand All @@ -26,7 +38,33 @@ func Execute() {
}

func init() {
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.jira-changelog.yaml)")
rootCmd.PersistentFlags().StringP("project-url", "p", "", "jira project url")
rootCmd.PersistentFlags().StringP("api-token", "t", "", "API token for jira")
cobra.OnInitialize(initConfig)

rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is ./.jira_changelog.yaml)")
rootCmd.PersistentFlags().StringVarP(&projectUrl, "project_url", "u", "", "jira project url")
rootCmd.PersistentFlags().StringVarP(&apiToken, "api_token", "t", "", "API token for jira")
rootCmd.PersistentFlags().StringVarP(&projectName, "project_name", "p", "", "Project name in jira. usually the acronym")

rootCmd.MarkPersistentFlagRequired("project_url")
rootCmd.MarkPersistentFlagRequired("api_token")
rootCmd.MarkPersistentFlagRequired("project_name")
}

func initConfig() {
if cfgFile != "" {
viper.SetConfigFile(cfgFile)
} else {
cwd, err := os.Getwd()
cobra.CheckErr(err)

viper.AddConfigPath(cwd)
viper.SetConfigType("yaml")
viper.SetConfigName(".jira_changelog")
}

viper.AutomaticEnv()

if err := viper.ReadInConfig(); err == nil {
fmt.Println("Using config file:", viper.ConfigFileUsed())
}
}
21 changes: 19 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
module github.com/handofgod94/jira-changelog
module github.com/handofgod94/jira_changelog

go 1.20

require github.com/spf13/cobra v1.7.0
require (
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.16.0
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1
)

require (
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
479 changes: 479 additions & 0 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package main

import "github.com/handofgod94/jira-changelog/cmd"
import "github.com/handofgod94/jira_changelog/cmd"

func main() {
cmd.Execute()
Expand Down
12 changes: 12 additions & 0 deletions pkg/jira_changelog/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package jira_changelog

type JiraConfig struct {
ProjectUrl string
ProjectName string
ApiToken string
}

type GitConfig struct {
FromRef string
ToRef string
}
10 changes: 10 additions & 0 deletions pkg/jira_changelog/generator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package jira_changelog

type Changelog struct {
JiraConfig JiraConfig
GitConfig GitConfig
}

func (c Changelog) Generate() {

}

0 comments on commit 09a96fa

Please sign in to comment.