From f989aa36cec9e2c601fd2fedc14968244025063f Mon Sep 17 00:00:00 2001 From: AlexNg Date: Wed, 16 Oct 2024 21:48:42 +0800 Subject: [PATCH 1/6] fix: Check for non OK status codes Signed-off-by: AlexNg --- internal/license/store.go | 4 ++++ internal/license/types.go | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/internal/license/store.go b/internal/license/store.go index e2cf615..01086d1 100644 --- a/internal/license/store.go +++ b/internal/license/store.go @@ -53,6 +53,10 @@ func GetLicenses() (*[]License, error) { } defer res.Body.Close() + if res.StatusCode != http.StatusOK { + return nil, fmt.Errorf("unexpected status code: %d", res.StatusCode) + } + log.Debugln("Reading http stream") body, err := io.ReadAll(res.Body) if err != nil { diff --git a/internal/license/types.go b/internal/license/types.go index 8e3d915..bffca88 100644 --- a/internal/license/types.go +++ b/internal/license/types.go @@ -41,6 +41,10 @@ func (license *License) GetLicenseText() (string, error) { } defer res.Body.Close() + if res.StatusCode != http.StatusOK { + return "", fmt.Errorf("unexpected status code: %d", res.StatusCode) + } + body, err := io.ReadAll(res.Body) if err != nil { return "", err From 8683a7478a99f562f71b8ad76f4a1d2b7cee9333 Mon Sep 17 00:00:00 2001 From: AlexNg Date: Wed, 16 Oct 2024 21:57:18 +0800 Subject: [PATCH 2/6] feat: Add logging for fetching license text Signed-off-by: AlexNg --- internal/license/store.go | 6 +++--- internal/license/types.go | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/internal/license/store.go b/internal/license/store.go index 01086d1..42dc1f6 100644 --- a/internal/license/store.go +++ b/internal/license/store.go @@ -39,7 +39,7 @@ func GetLicenses() (*[]License, error) { } url := GetLicenseFetchUrl() - log.Infof("Fetching licenses from %s...\n", url) + log.Infof("fetching licenses from %s...\n", url) req, err := http.NewRequest(http.MethodGet, url, http.NoBody) if err != nil { return nil, err @@ -57,7 +57,7 @@ func GetLicenses() (*[]License, error) { return nil, fmt.Errorf("unexpected status code: %d", res.StatusCode) } - log.Debugln("Reading http stream") + log.Debugln("reading http stream") body, err := io.ReadAll(res.Body) if err != nil { return nil, err @@ -67,7 +67,7 @@ func GetLicenses() (*[]License, error) { Licenses []License `json:"licenses"` } - log.Debugln("Unmarshalling license json") + log.Debugln("unmarshalling license json") if err := json.Unmarshal(body, &l); err != nil { return nil, err } diff --git a/internal/license/types.go b/internal/license/types.go index bffca88..a39ded8 100644 --- a/internal/license/types.go +++ b/internal/license/types.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "github.com/caffeine-addictt/waku/internal/log" "github.com/goccy/go-json" ) @@ -28,7 +29,10 @@ type License struct { } func (license *License) GetLicenseText() (string, error) { - req, err := http.NewRequest(http.MethodGet, GetLicenseFetchUrl()+license.Filename, http.NoBody) + url := GetLicenseFetchUrl() + license.Filename + log.Infof("fetching license text from %s...\n", url) + + req, err := http.NewRequest(http.MethodGet, url, http.NoBody) if err != nil { return "", err } @@ -45,12 +49,14 @@ func (license *License) GetLicenseText() (string, error) { return "", fmt.Errorf("unexpected status code: %d", res.StatusCode) } + log.Debugln("reading http stream") body, err := io.ReadAll(res.Body) if err != nil { return "", err } txt := string(body) + log.Debugln("replacing [year] with current year") for i := range license.Wants { if license.Wants[i] == "year" { txt = strings.ReplaceAll(txt, "[year]", fmt.Sprintf("%d", time.Now().UTC().Year())) From 9cb1ed1b26a1d1dd616449b93ab951818f0c693a Mon Sep 17 00:00:00 2001 From: AlexNg Date: Wed, 16 Oct 2024 21:58:08 +0800 Subject: [PATCH 3/6] fix: invalid license text url Closes #165 Signed-off-by: AlexNg --- internal/license/store.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/license/store.go b/internal/license/store.go index 42dc1f6..47da4e0 100644 --- a/internal/license/store.go +++ b/internal/license/store.go @@ -27,7 +27,6 @@ func GetLicenseFetchUrl() string { } else { url = fmt.Sprintf(BASE_URL, "v"+version.Version) } - url += LICENSE_LIST return url } @@ -38,7 +37,7 @@ func GetLicenses() (*[]License, error) { return Licenses, nil } - url := GetLicenseFetchUrl() + url := GetLicenseFetchUrl() + LICENSE_LIST log.Infof("fetching licenses from %s...\n", url) req, err := http.NewRequest(http.MethodGet, url, http.NoBody) if err != nil { From 0ff709ddb4908e04461f1e72766ce6adda69a29a Mon Sep 17 00:00:00 2001 From: AlexNg Date: Wed, 16 Oct 2024 21:59:46 +0800 Subject: [PATCH 4/6] fix: logging missing newline Signed-off-by: AlexNg --- cmd/commands/new.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/commands/new.go b/cmd/commands/new.go index 8bc51c4..9cd8a50 100644 --- a/cmd/commands/new.go +++ b/cmd/commands/new.go @@ -209,7 +209,7 @@ var NewCmd = &cobra.Command{ ignoreRules = template.ResolveIncludes(ignoreRules, types.NewSet(".git/", "LICENSE")) ignoredPaths := template.ResolveIncludes(types.NewSet(paths...), ignoreRules) - log.Debugf("resolved files to write: %v", ignoredPaths) + log.Debugf("resolved files to write: %v\n", ignoredPaths) // Handle writing files cmd.Println("writing files...") From 0db8ece7bab33a21f9e22d2e014de55ff60641d8 Mon Sep 17 00:00:00 2001 From: AlexNg Date: Wed, 16 Oct 2024 21:59:59 +0800 Subject: [PATCH 5/6] fix: logging using cmd instead of log Signed-off-by: AlexNg --- cmd/commands/new.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/commands/new.go b/cmd/commands/new.go index 9cd8a50..6cd46db 100644 --- a/cmd/commands/new.go +++ b/cmd/commands/new.go @@ -212,7 +212,7 @@ var NewCmd = &cobra.Command{ log.Debugf("resolved files to write: %v\n", ignoredPaths) // Handle writing files - cmd.Println("writing files...") + log.Infoln("writing files...") finalTmpl["Name"] = name finalTmpl["License"] = license.Name finalTmpl["Spdx"] = license.Spdx From 65d869237476312cd253efbf3b3808628f4c4670 Mon Sep 17 00:00:00 2001 From: AlexNg Date: Wed, 16 Oct 2024 22:04:03 +0800 Subject: [PATCH 6/6] chor: bump 0.7.1 -> 0.7.2 Signed-off-by: AlexNg --- pkg/version/version.go | 2 +- www/docs/configuration/introduction.md | 4 ++-- www/docs/install.md | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/version/version.go b/pkg/version/version.go index 5f74a78..7a2ed99 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -1,4 +1,4 @@ package version // The current app version -const Version = "0.7.1" +const Version = "0.7.2" diff --git a/www/docs/configuration/introduction.md b/www/docs/configuration/introduction.md index 6960b00..b4cabcb 100644 --- a/www/docs/configuration/introduction.md +++ b/www/docs/configuration/introduction.md @@ -20,10 +20,10 @@ for better editor support. https://waku.ngjx.org/static/schema.json ``` -Or you can pin a specific version like `v0.7.1`: +Or you can pin a specific version like `v0.7.2`: ```text -https://raw.githubusercontent.com/caffeine-addictt/waku/v0.7.1/www/docs/static/schema.json +https://raw.githubusercontent.com/caffeine-addictt/waku/v0.7.2/www/docs/static/schema.json ``` Simply add the `$schema` property to your `configuration` file: diff --git a/www/docs/install.md b/www/docs/install.md index 03b0454..1db613f 100644 --- a/www/docs/install.md +++ b/www/docs/install.md @@ -102,17 +102,17 @@ All artifacts are checksummed, and the checksum file is signed with [cosign][]. and `checksums.txt.sig` files from the [releases][] page. ```sh - curl -O 'https://github.com/caffeine-addictt/waku/releases/download/v0.7.1/checksums.txt' + curl -O 'https://github.com/caffeine-addictt/waku/releases/download/v0.7.2/checksums.txt' ``` 1. Verify checksums signature: ```bash cosign verify-blob \ - --certificate-identity 'https://github.com/caffeine-addictt/waku/.github/workflows/release.yml@refs/tags/v0.7.1' \ + --certificate-identity 'https://github.com/caffeine-addictt/waku/.github/workflows/release.yml@refs/tags/v0.7.2' \ --certificate-oidc-issuer 'https://token.actions.githubusercontent.com' \ - --cert 'https://github.com/caffeine-addictt/waku/releases/download/v0.7.1/checksums.txt.pem' \ - --signature 'https://github.com/caffeine-addictt/waku/releases/download/v0.7.1/checksums.txt.sig' \ + --cert 'https://github.com/caffeine-addictt/waku/releases/download/v0.7.2/checksums.txt.pem' \ + --signature 'https://github.com/caffeine-addictt/waku/releases/download/v0.7.2/checksums.txt.sig' \ ./checksums.txt ``` @@ -130,7 +130,7 @@ Verify the signature: ```sh cosign verify \ - --certificate-identity 'https://github.com/caffeine-addictt/waku/.github/workflows/release.yml@refs/tags/v0.7.1' \ + --certificate-identity 'https://github.com/caffeine-addictt/waku/.github/workflows/release.yml@refs/tags/v0.7.2' \ --certificate-oidc-issuer 'https://token.actions.githubusercontent.com' \ caffeinec/waku ```