Skip to content

Commit

Permalink
Add all parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
dkrizic committed May 13, 2024
1 parent 346c6f1 commit 0cde146
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea/
.env
2 changes: 1 addition & 1 deletion action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ inputs:
required: true
runs:
using: 'docker'
image: 'docker://ghcr.io/prodyna/changelog-json:v1.9'
image: 'docker://ghcr.io/prodyna/changelog-json:v0.5'
env:
GITHUB_TOKEN: ${{ inputs.github-token }}
12 changes: 9 additions & 3 deletions changelog/generate.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package changelog

type Config struct {
GitHubToken string
Repositories string
Organization string
}

type ChangelogGenerator struct {
githubToken string
config *Config
}

func New(githubToken string) (*ChangelogGenerator, error) {
func New(config Config) (*ChangelogGenerator, error) {
return &ChangelogGenerator{
githubToken: githubToken,
config: &config,
}, nil
}

Expand Down
30 changes: 23 additions & 7 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,29 @@ import (
)

const (
keyVerbose = "verbose"
keyVerboseEnvironment = "VERBOSE"
keyGithubToken = "github-token"
keyGithubTokenEnvironment = "GITHUB_TOKEN"
keyVerbose = "verbose"
keyVerboseEnvironment = "VERBOSE"
keyGithubToken = "github-token"
keyGithubTokenEnvironment = "GITHUB_TOKEN"
keyRepositories = "repositories"
keyRepositoriesEnvironment = "REPOSITORIES"
keyOrganization = "organization"
keyOrganizationEnvironment = "ORGANIZATION"
)

type Config struct {
Verbose *int
GithubToken string
Verbose *int
GithubToken string
Repositories string
Organization string
}

func New() (*Config, error) {
c := Config{}
verbose := flag.Int(keyVerbose, lookupEnvOrInt(keyVerboseEnvironment, 0), "Verbosity level, 0=info, 1=debug. Overrides the environment variable VERBOSE.")
flag.StringVar(&c.GithubToken, keyGithubToken, lookupEnvOrString("GITHUB_TOKEN", ""), "The GitHub Token to use for authentication.")
flag.StringVar(&c.GithubToken, keyGithubToken, lookupEnvOrString(keyGithubTokenEnvironment, ""), "The GitHub Token to use for authentication.")
flag.StringVar(&c.Repositories, keyRepositories, lookupEnvOrString(keyRepositoriesEnvironment, ""), "The repositories to generate changelog for.")
flag.StringVar(&c.Organization, keyOrganization, lookupEnvOrString(keyOrganizationEnvironment, ""), "The organization to generate changelog for.")
flag.Parse()

level := slog.LevelError
Expand All @@ -46,6 +54,14 @@ func New() (*Config, error) {
return nil, fmt.Errorf("missing required environment variable: %s", keyGithubToken)
}

if c.Repositories == "" {
return nil, fmt.Errorf("missing required environment variable: %s", keyRepositories)
}

if c.Organization == "" {
return nil, fmt.Errorf("missing required environment variable: %s", keyOrganization)
}

return &c, nil
}

Expand Down
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ func main() {

slog.Debug("config loaded")

generator, err := changelog.New(c.GithubToken)
generator, err := changelog.New(changelog.Config{
GitHubToken: c.GithubToken,
Repositories: c.Repositories,
Organization: c.Organization,
})
if err != nil {
slog.Error("unable to create changelog generator", "error", err)
os.Exit(1)
Expand Down

0 comments on commit 0cde146

Please sign in to comment.