Skip to content

Commit

Permalink
Merge branch 'master' of ssh://github.com/elifesciences/maintainers-txt
Browse files Browse the repository at this point in the history
  • Loading branch information
lsh-0 committed Apr 12, 2024
2 parents 72474f9 + 937a33f commit 8cc1d6e
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ maintainers-txt
linux-amd64
linux-amd64.sha256
alias-map.json
output.svg
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ and `alias-map.json` might look like:
{"jdoe": "[email protected]"}
```

### Graph

To generate a simple pie chart from the output of the `maintainers-txt`:

GITHUB_TOKEN=your-github-token ./maintainers-txt > report.json
go run . graph

## Licence

Copyright © 2024 eLife Sciences
Expand Down
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ go 1.20

require (
github.com/google/go-github/v55 v55.0.0
github.com/wcharczuk/go-chart/v2 v2.1.1
golang.org/x/oauth2 v0.18.0
)

require (
github.com/ProtonMail/go-crypto v1.0.0 // indirect
github.com/blend/go-sdk v1.20220411.3 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/go-querystring v1.1.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/image v0.11.0 // indirect
golang.org/x/sys v0.18.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.33.0 // indirect
Expand Down
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
github.com/ProtonMail/go-crypto v1.0.0 h1:LRuvITjQWX+WIfr930YHG2HNfjR1uOfyf5vE0kC2U78=
github.com/ProtonMail/go-crypto v1.0.0/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0=
github.com/blend/go-sdk v1.20220411.3 h1:GFV4/FQX5UzXLPwWV03gP811pj7B8J2sbuq+GJQofXc=
github.com/blend/go-sdk v1.20220411.3/go.mod h1:7lnH8fTi6U4i1fArEXRyOIY2E1X4MALg09qsQqY1+ak=
github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
Expand All @@ -15,13 +19,17 @@ github.com/google/go-github/v55 v55.0.0 h1:4pp/1tNMB9X/LuAhs5i0KQAE40NmiR/y6prLN
github.com/google/go-github/v55 v55.0.0/go.mod h1:JLahOTA1DnXzhxEymmFF5PP2tSS9JVNj68mSZNDwskA=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/wcharczuk/go-chart/v2 v2.1.1 h1:2u7na789qiD5WzccZsFz4MJWOJP72G+2kUuJoSNqWnE=
github.com/wcharczuk/go-chart/v2 v2.1.1/go.mod h1:CyCAUt2oqvfhCl6Q5ZvAZwItgpQKZOkCJGb+VGv6l14=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/image v0.11.0 h1:ds2RoQvBvYTiJkwpSFDwCcDFNX7DqjL2WsUgTNk0Ooo=
golang.org/x/image v0.11.0/go.mod h1:bglhjqbqVuEb9e9+eNR45Jfu7D+T4Qan+NhQk8Ck2P8=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
Expand Down Expand Up @@ -58,6 +66,7 @@ golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
Expand Down
51 changes: 51 additions & 0 deletions graph.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package main

import (
"encoding/json"
"fmt"
"os"

"github.com/wcharczuk/go-chart/v2"
)

func graph() {
report_file := "report.json"
report_bytes, err := os.ReadFile(report_file)
panicOnErr(err, "reading report.json")

dest := map[string][]string{}
json.Unmarshal(report_bytes, &dest)

// each slice of the chart is a person,
// the value of each slice is the sum of each percentage
// of each repository they are responsible for.

person_value_idx := map[string]float64{}
for _, person_list := range dest {
num_people := float64(len(person_list))
for _, person := range person_list {
person_value, present := person_value_idx[person]
if !present {
person_value = 0
}
person_value += 1.0 / num_people
person_value_idx[person] = person_value
}
}

vals := []chart.Value{}
for person, value := range person_value_idx {
vals = append(vals, chart.Value{Value: value, Label: person})
}

pie := chart.PieChart{
Width: 512,
Height: 512,
Values: vals,
}

f, _ := os.Create("output.svg")
defer f.Close()
pie.Render(chart.SVG, f)
fmt.Println("wrote output.svg")
}
15 changes: 13 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func fetch_repos(org_name, token string) []*github.Repository {
return repo_list
}

func main() {
func report() {
args := os.Args[1:]

token := github_token()
Expand Down Expand Up @@ -243,7 +243,7 @@ func main() {
if file_exists(path) {
raw_maintainers[repo.GetName()] = slurp(path)
} else {
// https://raw.githubusercontent.com/elifesciences/github-repo-security-alerts/master/maintainers.txt
// https://raw.githubusercontent.com/elifesciences/example-repo/master/maintainers.txt
urltem := "https://raw.githubusercontent.com/%s/%s/%s/maintainers.txt"
url := fmt.Sprintf(urltem, org_name, repo.GetName(), repo.GetDefaultBranch())

Expand Down Expand Up @@ -295,3 +295,14 @@ func main() {
os.Exit(1)
}
}

// ---

func main() {
args := os.Args[1:]
if len(args) == 0 || args[0] != "graph" {
report()
} else {
graph()
}
}
43 changes: 26 additions & 17 deletions manage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ if test ! "$cmd"; then
echo "available commands:"
echo " build build project"
echo " clean removes generated files"
echo " release build project for distribution"
echo " deps.update update project dependencies"
echo " release build project for distribution"
exit 1
fi

Expand All @@ -24,6 +24,20 @@ if test "$cmd" = "build"; then
-v
exit 0

elif test "$cmd" = "clean"; then
# *--maintainers.txt - downloaded from repositories
# linux-amd64* linux-arm64* - generated by the 'release' command.
shopt -s nullglob # continue when glob below is empty
rm -fv *--maintainers.txt linux-amd64* linux-arm64*
exit 0

elif test "$cmd" = "deps.update"; then
# -u 'update modules [...] to use newer minor or patch releases when available'
go get -u
go mod tidy
./manage.sh build
exit 0

elif test "$cmd" = "release"; then
# GOOS is 'Go OS' and is being explicit in which OS to build for.
# CGO_ENABLED=0 skips CGO and linking against glibc to build static binaries.
Expand All @@ -38,33 +52,28 @@ elif test "$cmd" = "release"; then
-v \
-o linux-amd64
sha256sum linux-amd64 > linux-amd64.sha256

GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build \
-ldflags="-s -w" \
-trimpath \
-v \
-o linux-arm64
sha256sum linux-arm64 > linux-arm64.sha256

echo ---
echo "wrote linux-amd64"
echo "wrote linux-amd64.sha256"
echo "wrote linux-arm64"
echo "wrote linux-arm64.sha256"
exit 0

elif test "$cmd" = "deps.update"; then
elif test "$cmd" = "update-deps"; then
# -u 'update modules [...] to use newer minor or patch releases when available'
go get -u
go mod tidy
./manage.sh build
exit 0

elif test "$cmd" = "clean"; then
shopt -s nullglob # continue when glob below is empty
for file in *--maintainers.txt; do # created during normal operation
rm "$file"
echo "deleted: $file"
done
tbd=( linux-amd64 linux-amd64.sha256 )
for file in "${tbd[@]}"; do # created with ./manage.sh release
if [ -e "$file" ]; then
rm "$file"
echo "deleted $file"
fi
done
exit 0

# ...

fi
Expand Down

0 comments on commit 8cc1d6e

Please sign in to comment.