Skip to content

Commit

Permalink
add in badge support for sr.ht
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed Nov 2, 2023
1 parent 09919b3 commit 7a6bd11
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`
Expand Down
17 changes: 16 additions & 1 deletion cmd/badges/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand All @@ -133,13 +143,18 @@ 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, "/")
if len(s) != 3 {
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],
Expand Down

0 comments on commit 7a6bd11

Please sign in to comment.