Skip to content

Commit

Permalink
Merge pull request #10 from hashicorp/fix-init-panic
Browse files Browse the repository at this point in the history
Fix a panic when repo has no license on init cmd
  • Loading branch information
CalebAlbers committed Jan 27, 2023
2 parents a50f166 + 55b628a commit 03e9b36
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,19 @@ for any unknown values. If you are running this command in CI, please use the
// Try to autodiscover license and year
if repo, err := github.DiscoverRepo(); err == nil {
client := github.NewGHClient().Raw()
data, _, _ := client.Repositories.Get(context.Background(), repo.Owner, repo.Name)

// fall back to GitHub repo creation year if --year wasn't set
if !cmd.Flags().Changed("year") {
newConfig.Project.CopyrightYear = data.CreatedAt.Year()
}
data, _, err := client.Repositories.Get(context.Background(), repo.Owner, repo.Name)
if err == nil {
cobra.CheckErr(err)
// fall back to GitHub repo creation year if --year wasn't set
if !cmd.Flags().Changed("year") {
newConfig.Project.CopyrightYear = data.CreatedAt.Year()
}

// fall back to GitHub's reported SPDX identifier if --spdx wasn't set
if !cmd.Flags().Changed("spdx") {
newConfig.Project.License = *data.GetLicense().SPDXID
// fall back to GitHub's reported SPDX identifier if --spdx wasn't set
if !cmd.Flags().Changed("spdx") {
license := data.GetLicense()
newConfig.Project.License = license.GetSPDXID()
}
}
}

Expand Down

0 comments on commit 03e9b36

Please sign in to comment.