Compare commits
7 Commits
5e92e2f564
...
fe0097a5e3
Author | SHA1 | Date |
---|---|---|
sudo pacman -Syu | fe0097a5e3 | |
sudo pacman -Syu | f9aed5bf32 | |
sudo pacman -Syu | e1b77493c6 | |
sudo pacman -Syu | 4d1cae4002 | |
sudo pacman -Syu | 22d16a8947 | |
sudo pacman -Syu | 7927f61d3c | |
sudo pacman -Syu | af2cde423d |
54
CHANGELOG.md
54
CHANGELOG.md
|
@ -1,5 +1,59 @@
|
|||
# CHANGELOG
|
||||
|
||||
## v0.6.0 (2023-08-15)
|
||||
|
||||
### Added
|
||||
|
||||
- feat: use conc pool to speed up (2023-08-15)
|
||||
|
||||
- feat: make github client optional (2023-08-15)
|
||||
|
||||
- feat: print consistency with tabwriter (2023-08-15)
|
||||
|
||||
- feat: print star of module (2023-08-15)
|
||||
|
||||
- feat: add github client (2023-08-15)
|
||||
|
||||
### Others
|
||||
|
||||
- refactor: move init github client (2023-08-15)
|
||||
|
||||
- chore(deps): bump github.com/make-go-great/color-go from 0.4.1 to 0.5.0 (2023-07-17)
|
||||
|
||||
- chore: update github action (2023-07-01)
|
||||
|
||||
- chore: sync golangci-lint (2023-06-29)
|
||||
|
||||
- chore(deps): bump github.com/urfave/cli/v2 from 2.25.6 to 2.25.7 (2023-06-19)
|
||||
|
||||
- chore(deps): bump github.com/urfave/cli/v2 from 2.25.5 to 2.25.6 (2023-06-13)
|
||||
|
||||
- chore(deps): bump github.com/urfave/cli/v2 from 2.25.4 to 2.25.5 (2023-05-30)
|
||||
|
||||
- chore(deps): bump github.com/urfave/cli/v2 from 2.25.3 to 2.25.4 (2023-05-29)
|
||||
|
||||
- chore(deps): bump github.com/urfave/cli/v2 from 2.25.2 to 2.25.3 (2023-05-02)
|
||||
|
||||
- chore(deps): bump github.com/urfave/cli/v2 from 2.25.1 to 2.25.2 (2023-05-01)
|
||||
|
||||
- chore(deps): bump github.com/urfave/cli/v2 from 2.25.0 to 2.25.1 (2023-03-27)
|
||||
|
||||
- chore(deps): bump actions/setup-go from 3 to 4 (2023-03-22)
|
||||
|
||||
- chore(deps): bump goreleaser/goreleaser-action from 3 to 4 (2023-03-22)
|
||||
|
||||
- chore: update dependabot (2023-03-22)
|
||||
|
||||
- chore(deps): bump github.com/urfave/cli/v2 from 2.24.4 to 2.25.0 (2023-03-06)
|
||||
|
||||
- chore: update make (2023-02-26)
|
||||
|
||||
- chore: update lint (2023-02-25)
|
||||
|
||||
- chore: run go mod tidy first (2023-02-25)
|
||||
|
||||
- chore(changelog): generate v0.5.0 (2023-02-25)
|
||||
|
||||
## v0.5.0 (2023-02-25)
|
||||
|
||||
### Added
|
||||
|
|
|
@ -23,6 +23,10 @@ update-go-mod --deps-url "https://example.txt"
|
|||
|
||||
# Don't do anythin
|
||||
update-go-mod --dry-run
|
||||
|
||||
# Take a look
|
||||
# Require GitHub access token in ~/.netrc
|
||||
update-go-mod overlook
|
||||
```
|
||||
|
||||
## Thanks
|
||||
|
|
|
@ -1,8 +1,54 @@
|
|||
package main
|
||||
|
||||
import "github.com/haunt98/update-go-mod/internal/cli"
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/google/go-github/v53/github"
|
||||
"golang.org/x/oauth2"
|
||||
|
||||
"github.com/make-go-great/netrc-go"
|
||||
|
||||
"github.com/haunt98/update-go-mod/internal/cli"
|
||||
)
|
||||
|
||||
const (
|
||||
netrcPath = "~/.netrc"
|
||||
netrcMachineGitHub = "github.com"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := cli.NewApp()
|
||||
app := cli.NewApp(
|
||||
initGitHubClient(),
|
||||
)
|
||||
app.Run()
|
||||
}
|
||||
|
||||
func initGitHubClient() *github.Client {
|
||||
netrcData, err := netrc.ParseFile(netrcPath)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var ghAccessToken string
|
||||
for _, machine := range netrcData.Machines {
|
||||
if machine.Name == netrcMachineGitHub {
|
||||
ghAccessToken = machine.Password
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if ghAccessToken == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
ghTokenSrc := oauth2.StaticTokenSource(
|
||||
&oauth2.Token{
|
||||
AccessToken: strings.TrimSpace(ghAccessToken),
|
||||
},
|
||||
)
|
||||
ghHTTPClient := oauth2.NewClient(context.Background(), ghTokenSrc)
|
||||
ghClient := github.NewClient(ghHTTPClient)
|
||||
|
||||
return ghClient
|
||||
}
|
||||
|
|
16
go.mod
16
go.mod
|
@ -3,16 +3,30 @@ module github.com/haunt98/update-go-mod
|
|||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/google/go-github/v53 v53.2.0
|
||||
github.com/make-go-great/color-go v0.5.0
|
||||
github.com/make-go-great/netrc-go v0.0.2
|
||||
github.com/sourcegraph/conc v0.3.0
|
||||
github.com/urfave/cli/v2 v2.25.7
|
||||
golang.org/x/oauth2 v0.8.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
|
||||
github.com/cloudflare/circl v1.3.3 // indirect
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
|
||||
github.com/fatih/color v1.15.0 // indirect
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/google/go-querystring v1.1.0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.17 // indirect
|
||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
|
||||
golang.org/x/sys v0.6.0 // indirect
|
||||
go.uber.org/atomic v1.7.0 // indirect
|
||||
go.uber.org/multierr v1.9.0 // indirect
|
||||
golang.org/x/crypto v0.7.0 // indirect
|
||||
golang.org/x/net v0.10.0 // indirect
|
||||
golang.org/x/sys v0.8.0 // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/protobuf v1.28.0 // indirect
|
||||
)
|
||||
|
|
64
go.sum
64
go.sum
|
@ -1,20 +1,80 @@
|
|||
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 h1:wPbRQzjjwFc0ih8puEVAOFGELsn1zoIIYdxvML7mDxA=
|
||||
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8/go.mod h1:I0gYDMZ6Z5GRU7l58bNFSkPTFN6Yl12dsUlAZ8xy98g=
|
||||
github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
|
||||
github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I=
|
||||
github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs=
|
||||
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
|
||||
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
|
||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
|
||||
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/google/go-github/v53 v53.2.0 h1:wvz3FyF53v4BK+AsnvCmeNhf8AkTaeh2SoYu/XUvTtI=
|
||||
github.com/google/go-github/v53 v53.2.0/go.mod h1:XhFRObz+m/l+UCm9b7KSIC3lT3NWSXGt7mOsAWEloao=
|
||||
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/make-go-great/color-go v0.5.0 h1:iCSIBybwoo+ctK3QdSWPJPAl05/a3tBrxvOURZRT1qA=
|
||||
github.com/make-go-great/color-go v0.5.0/go.mod h1:GoWscSdNNxjxsQdQCgGlUoADdRHqjmuBMsdr+Rb/QQM=
|
||||
github.com/make-go-great/netrc-go v0.0.2 h1:+slj+cMcNL+W/xbHvLPJ8DyTrjcfzQt7bYWZtNV+Isg=
|
||||
github.com/make-go-great/netrc-go v0.0.2/go.mod h1:fwFh8yeVT+d88SzIyH+0dWyfgcba8SUchzFuQXlhwws=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
|
||||
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
|
||||
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs=
|
||||
github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
|
||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
|
||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
|
||||
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
|
||||
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
|
||||
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
|
||||
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.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
|
||||
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
|
||||
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
|
||||
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||
golang.org/x/oauth2 v0.8.0 h1:6dkIjl3j3LtZ/O3sTgZTMsLKSftL/B8Zgq4huOIIUu8=
|
||||
golang.org/x/oauth2 v0.8.0/go.mod h1:yr7u4HXZRm1R1kBWqr/xKNqewf0plRYoB7sla+BCIXE=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
|
||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
|
||||
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
|
||||
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
|
|
|
@ -3,6 +3,7 @@ package cli
|
|||
import (
|
||||
"log"
|
||||
|
||||
"github.com/google/go-github/v53/github"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
|
@ -11,7 +12,8 @@ const (
|
|||
)
|
||||
|
||||
type action struct {
|
||||
flags struct {
|
||||
ghClient *github.Client
|
||||
flags struct {
|
||||
depsFile string
|
||||
depsURL string
|
||||
verbose bool
|
||||
|
|
|
@ -0,0 +1,117 @@
|
|||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
"sort"
|
||||
"sync"
|
||||
"text/tabwriter"
|
||||
"time"
|
||||
|
||||
"github.com/sourcegraph/conc/pool"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
const maxPoolGoroutine = 8
|
||||
|
||||
var reGitHub = regexp.MustCompile(`github\.com/([^/]*)/([^/]*)`)
|
||||
|
||||
type GitHubRepoData struct {
|
||||
UpdatedAt time.Time
|
||||
Name string
|
||||
Star int
|
||||
}
|
||||
|
||||
func (a *action) Overlook(c *cli.Context) error {
|
||||
// Optional
|
||||
if a.ghClient == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
a.getFlags(c)
|
||||
|
||||
mapImportedModules, err := a.runGetImportedModules(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(mapImportedModules) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
listGHRepoData := make([]GitHubRepoData, 0, len(mapImportedModules))
|
||||
// To avoid duplicate
|
||||
mGHRepoData := make(map[string]struct{})
|
||||
|
||||
p := pool.New().WithMaxGoroutines(maxPoolGoroutine)
|
||||
var mMutex sync.RWMutex
|
||||
var listMutex sync.Mutex
|
||||
for module := range mapImportedModules {
|
||||
module := module
|
||||
p.Go(func() {
|
||||
if !reGitHub.MatchString(module) {
|
||||
return
|
||||
}
|
||||
|
||||
parts := reGitHub.FindStringSubmatch(module)
|
||||
if len(parts) != 3 {
|
||||
return
|
||||
}
|
||||
|
||||
ghRepoName := parts[0]
|
||||
mMutex.RLock()
|
||||
if _, ok := mGHRepoData[ghRepoName]; ok {
|
||||
mMutex.RUnlock()
|
||||
return
|
||||
}
|
||||
mMutex.RUnlock()
|
||||
|
||||
mMutex.Lock()
|
||||
mGHRepoData[ghRepoName] = struct{}{}
|
||||
mMutex.Unlock()
|
||||
|
||||
owner := parts[1]
|
||||
repo := parts[2]
|
||||
|
||||
ghRepo, _, err := a.ghClient.Repositories.Get(context.Background(), owner, repo)
|
||||
if err != nil {
|
||||
a.log("Failed to get GitHub %s/%s: %s\n", owner, repo, err)
|
||||
}
|
||||
|
||||
var ghStar int
|
||||
if ghRepo.StargazersCount != nil {
|
||||
ghStar = *ghRepo.StargazersCount
|
||||
}
|
||||
|
||||
var ghUpdatedAt time.Time
|
||||
if ghRepo.UpdatedAt != nil {
|
||||
ghUpdatedAt = ghRepo.UpdatedAt.Time
|
||||
}
|
||||
|
||||
listMutex.Lock()
|
||||
listGHRepoData = append(listGHRepoData, GitHubRepoData{
|
||||
UpdatedAt: ghUpdatedAt,
|
||||
Name: ghRepoName,
|
||||
Star: ghStar,
|
||||
})
|
||||
listMutex.Unlock()
|
||||
})
|
||||
}
|
||||
p.Wait()
|
||||
|
||||
// Sort for consistency
|
||||
sort.Slice(listGHRepoData, func(i, j int) bool {
|
||||
return listGHRepoData[i].Name < listGHRepoData[j].Name
|
||||
})
|
||||
|
||||
// Print
|
||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
|
||||
for _, r := range listGHRepoData {
|
||||
fmt.Fprintf(w, "Module %s\t%d\t⭐\tLast updated %s\n", r.Name, r.Star, r.UpdatedAt.Format(time.DateOnly))
|
||||
}
|
||||
w.Flush()
|
||||
|
||||
return nil
|
||||
}
|
|
@ -3,6 +3,7 @@ package cli
|
|||
import (
|
||||
"os"
|
||||
|
||||
"github.com/google/go-github/v53/github"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
||||
"github.com/make-go-great/color-go"
|
||||
|
@ -15,6 +16,9 @@ const (
|
|||
commandRunName = "run"
|
||||
commandRunUsage = "run the program"
|
||||
|
||||
commandOverlookName = "overlook"
|
||||
commandOverlookUsage = "take a quick lock"
|
||||
|
||||
flagVerboseName = "verbose"
|
||||
flagVerboseUsage = "show what is going on"
|
||||
|
||||
|
@ -34,8 +38,12 @@ type App struct {
|
|||
cliApp *cli.App
|
||||
}
|
||||
|
||||
func NewApp() *App {
|
||||
a := &action{}
|
||||
func NewApp(
|
||||
ghClient *github.Client,
|
||||
) *App {
|
||||
a := &action{
|
||||
ghClient: ghClient,
|
||||
}
|
||||
|
||||
cliApp := &cli.App{
|
||||
Name: name,
|
||||
|
@ -65,6 +73,18 @@ func NewApp() *App {
|
|||
},
|
||||
Action: a.Run,
|
||||
},
|
||||
{
|
||||
Name: commandOverlookName,
|
||||
Usage: commandOverlookUsage,
|
||||
Flags: []cli.Flag{
|
||||
&cli.BoolFlag{
|
||||
Name: flagVerboseName,
|
||||
Aliases: aliasFlagVerbose,
|
||||
Usage: flagVerboseUsage,
|
||||
},
|
||||
},
|
||||
Action: a.Overlook,
|
||||
},
|
||||
},
|
||||
Action: a.RunHelp,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue