From 7a6bd115268c96198ad74c34d7e0e792db09dc43 Mon Sep 17 00:00:00 2001 From: Ben Boyter Date: Fri, 3 Nov 2023 08:29:55 +1100 Subject: [PATCH] add in badge support for sr.ht --- README.md | 9 ++++++++- cmd/badges/main.go | 17 ++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 53bdad086..96d0536da 100644 --- a/README.md +++ b/README.md @@ -941,7 +941,7 @@ ENTRYPOINT ["scc"] ### Badges (beta) -You can use `scc` to provide badges on your github/bitbucket/gitlab open repositories. For example, [![Scc Count Badge](https://sloc.xyz/github/boyter/scc/)](https://github.com/boyter/scc/) +You can use `scc` to provide badges on your github/bitbucket/gitlab/sr.ht open repositories. For example, [![Scc Count Badge](https://sloc.xyz/github/boyter/scc/)](https://github.com/boyter/scc/) The format to do so is, https://sloc.xyz/PROVIDER/USER/REPO @@ -974,6 +974,13 @@ Note that the avg-wage value must be a positive integer otherwise it will revert You can find the source code for badges in the repository at https://github.com/boyter/scc/blob/master/cmd/badges/main.go +#### A example for each supported provider + +- github - https://sloc.xyz/github/boyter/scc/ +- sr.ht - https://sloc.xyz/sr.ht/~nektro/magnolia-desktop/ +- bitbucket - https://sloc.xyz/bitbucket/boyter/decodingcaptchas +- gitlab - https://sloc.xyz/gitlab/esr/loccount + ### Languages List of supported languages. The master version of `scc` supports 239 languages at last count. Note that this is always assumed that you built from master, and it might trail behind what is actually supported. To see what your version of `scc` supports run `scc --languages` diff --git a/cmd/badges/main.go b/cmd/badges/main.go index 5dbf36e53..675ce330c 100644 --- a/cmd/badges/main.go +++ b/cmd/badges/main.go @@ -123,7 +123,17 @@ type location struct { } func (l *location) String() string { - parse, _ := url.Parse("https://" + l.Provider + ".com/" + l.User + "/" + l.Repo + ".git") + loc := ".com/" + ext := ".git" + switch strings.ToLower(l.Provider) { + case "bitbucket": + loc = ".org/" + case "git.sr.ht": + loc = "/" + ext = "" + } + + parse, _ := url.Parse("https://" + l.Provider + loc + l.User + "/" + l.Repo + ext) return parse.String() } @@ -133,6 +143,7 @@ func (l *location) String() string { // returns an error if we get anything other than 3 parts since thats // the format we expect func processUrlPath(path string) (location, error) { + path = strings.ToLower(path) path = strings.TrimPrefix(path, "/") path = strings.TrimSuffix(path, "/") s := strings.Split(path, "/") @@ -140,6 +151,10 @@ func processUrlPath(path string) (location, error) { return location{}, errors.New("invalid path part") } + if s[0] == "sr.ht" { + s[0] = "git.sr.ht" + } + return location{ Provider: s[0], User: s[1],