Skip to content

Commit

Permalink
chore: Minor tidy-ups
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Aug 5, 2024
1 parent 48f873b commit 7a68dfc
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

`gitHubRelease` calls the GitHub API to retrieve the latest releases about
the given *owner-repo*, It iterates through all the versions of the release,
fetching the first entry equal to *version*
fetching the first entry equal to *version*.

It then returns structured data as defined by the [GitHub Go API
bindings](https://pkg.go.dev/github.com/google/go-github/v63/github#RepositoryRelease).
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,10 @@ func newConfig(options ...configOption) (*Config, error) {
"fromYaml": c.fromYamlTemplateFunc,
"gitHubKeys": c.gitHubKeysTemplateFunc,
"gitHubLatestRelease": c.gitHubLatestReleaseTemplateFunc,
"gitHubRelease": c.gitHubReleaseTemplateFunc,
"gitHubLatestReleaseAssetURL": c.gitHubLatestReleaseAssetURLTemplateFunc,
"gitHubReleaseAssetURL": c.gitHubReleaseAssetURLTemplateFunc,
"gitHubLatestTag": c.gitHubLatestTagTemplateFunc,
"gitHubRelease": c.gitHubReleaseTemplateFunc,
"gitHubReleaseAssetURL": c.gitHubReleaseAssetURLTemplateFunc,
"gitHubReleases": c.gitHubReleasesTemplateFunc,
"gitHubTags": c.gitHubTagsTemplateFunc,
"glob": c.globTemplateFunc,
Expand Down Expand Up @@ -477,8 +477,8 @@ func newConfig(options ...configOption) (*Config, error) {
"output": c.outputTemplateFunc,
"pass": c.passTemplateFunc,
"passFields": c.passFieldsTemplateFunc,
"passhole": c.passholeTemplateFunc,
"passRaw": c.passRawTemplateFunc,
"passhole": c.passholeTemplateFunc,
"pruneEmptyDicts": c.pruneEmptyDictsTemplateFunc,
"quoteList": c.quoteListTemplateFunc,
"rbw": c.rbwTemplateFunc,
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/githubtemplatefuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ type gitHubTagsState struct {

var (
gitHubKeysStateBucket = []byte("gitHubLatestKeysState")
gitHubVersionReleaseStateBucket = []byte("gitHubVersionReleaseState")
gitHubLatestReleaseStateBucket = []byte("gitHubLatestReleaseState")
gitHubReleasesStateBucket = []byte("gitHubReleasesState")
gitHubTagsStateBucket = []byte("gitHubTagsState")
gitHubVersionReleaseStateBucket = []byte("gitHubVersionReleaseState")
)

type gitHubData struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/statecmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ func (c *Config) runStateDumpCmd(cmd *cobra.Command, args []string) error {
"entryState": chezmoi.EntryStateBucket,
"gitHubKeysState": gitHubKeysStateBucket,
"gitHubLatestReleaseState": gitHubLatestReleaseStateBucket,
"gitHubVersionReleaseState": gitHubVersionReleaseStateBucket,
"gitHubReleasesState": gitHubReleasesStateBucket,
"gitHubTagsState": gitHubTagsStateBucket,
"gitHubVersionReleaseState": gitHubVersionReleaseStateBucket,
"gitRepoExternalState": chezmoi.GitRepoExternalStateBucket,
"scriptState": chezmoi.ScriptStateBucket,
})
Expand Down
19 changes: 8 additions & 11 deletions internal/cmd/testdata/scripts/githubtemplatefuncs.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ stdout ^ssh-rsa
exec chezmoi execute-template '{{ (gitHubLatestRelease "twpayne/chezmoi").TagName }}'
stdout ^v2\.

# test gitHubLatestRelease template function
exec chezmoi execute-template '{{ (gitHubLatestRelease "2.51.0" "twpayne/chezmoi").TagName }}'
stdout ^v2.51.0

# test gitHubLatestRelease template function
exec chezmoi execute-template '{{ (gitHubLatestRelease "2.49.0" "twpayne/chezmoi").TagName }}'
stdout ^v2.49.0

# test gitHubLatestTag template function
exec chezmoi execute-template '{{ (gitHubLatestTag "twpayne/chezmoi").Name }}'
stdout ^v2\.
Expand All @@ -24,9 +16,14 @@ stdout ^v2\.
exec chezmoi execute-template '{{ (index (gitHubTags "twpayne/chezmoi") 0).Name }}'
stdout ^v2\.

# test gitHubRelease template function
exec chezmoi execute-template '{{ (gitHubRelease "twpayne/chezmoi" "v2.49.0").TagName }}'
stdout ^v2\.49\.0

# test gitHubReleaseAssetURL template function
[!windows] exec chezmoi execute-template '{{ gitHubReleaseAssetURL "twpayne/chezmoi" "v2.50.0" (printf "chezmoi-%s-%s" .chezmoi.os .chezmoi.arch) }}'
[!windows] stdout https://github.com/twpayne/chezmoi/releases/download/v2\.50\.0/chezmoi-

# test gitHubReleases template functions
exec chezmoi execute-template '{{ (index (gitHubReleases "twpayne/chezmoi") 0).TagName }}'
stdout ^v2\.

# gitHubReleases
# gitHubTags

0 comments on commit 7a68dfc

Please sign in to comment.