From 7a68dfc6a2b2c6154ba6305d32df8e0bae3076df Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 5 Aug 2024 22:54:00 +0000 Subject: [PATCH] chore: Minor tidy-ups --- .../github-functions/gitHubRelease.md | 2 +- internal/cmd/config.go | 6 +++--- internal/cmd/githubtemplatefuncs.go | 2 +- internal/cmd/statecmd.go | 2 +- .../scripts/githubtemplatefuncs.txtar | 19 ++++++++----------- 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/assets/chezmoi.io/docs/reference/templates/github-functions/gitHubRelease.md b/assets/chezmoi.io/docs/reference/templates/github-functions/gitHubRelease.md index b522999c412..cc2635b05ac 100644 --- a/assets/chezmoi.io/docs/reference/templates/github-functions/gitHubRelease.md +++ b/assets/chezmoi.io/docs/reference/templates/github-functions/gitHubRelease.md @@ -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). diff --git a/internal/cmd/config.go b/internal/cmd/config.go index 5d9fcf63f02..71286ded8fb 100644 --- a/internal/cmd/config.go +++ b/internal/cmd/config.go @@ -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, @@ -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, diff --git a/internal/cmd/githubtemplatefuncs.go b/internal/cmd/githubtemplatefuncs.go index 0b022d349fe..686e4d50ff4 100644 --- a/internal/cmd/githubtemplatefuncs.go +++ b/internal/cmd/githubtemplatefuncs.go @@ -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 { diff --git a/internal/cmd/statecmd.go b/internal/cmd/statecmd.go index 102a7981e65..24c64da7fd4 100644 --- a/internal/cmd/statecmd.go +++ b/internal/cmd/statecmd.go @@ -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, }) diff --git a/internal/cmd/testdata/scripts/githubtemplatefuncs.txtar b/internal/cmd/testdata/scripts/githubtemplatefuncs.txtar index 79a3c93da00..1d0e9ba34c1 100644 --- a/internal/cmd/testdata/scripts/githubtemplatefuncs.txtar +++ b/internal/cmd/testdata/scripts/githubtemplatefuncs.txtar @@ -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\. @@ -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