Skip to content

Commit

Permalink
Release 0.7.0 (#19)
Browse files Browse the repository at this point in the history
- Add new flag no-repo to all tools
- Fix an issue with the use of an unbuffered channel in `signal.Notify` call
- Run builds with Go 1.17 in CI
  • Loading branch information
pmatseykanets authored Sep 11, 2021
1 parent d213b71 commit f229c20
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 68 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
name: "Build ${{ matrix.go }}"
strategy:
matrix:
go: ["1.15", "1.16"]
go: ["1.15", "1.16", "1.17"]
runs-on: ubuntu-latest
env:
GO111MODULE: on
Expand Down Expand Up @@ -40,7 +40,7 @@ jobs:
run: go test -vet=off -race -coverprofile=coverage.txt -covermode=atomic ./...

- name: Upload code coverage
if: matrix.go == '1.15'
if: matrix.go == '1.16'
timeout-minutes: 1
continue-on-error: true
run: bash <(curl -s https://codecov.io/bash)
Expand Down
1 change: 1 addition & 0 deletions cmd/gh-find/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Flags:
-no-private Don't include private repositories
-no-public Don't include public repositories
-path= The pattern to match the pathname
-no-repo= The pattern to reject repository names
-repo= The pattern to match repository names
-size= Limit results based on the file size [+-]<d><u>
-token Prompt for an Access Token
Expand Down
32 changes: 21 additions & 11 deletions cmd/gh-find/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Flags:
-no-path= The pattern to reject the pathname
-no-private Don't include private repositories
-no-public Don't include public repositories
-no-repo= The pattern to reject repository names
-path= The pattern to match the pathname
-repo= The pattern to match repository names
-size= Limit results based on the file size [+-]<d><u>
Expand Down Expand Up @@ -115,6 +116,7 @@ type config struct {
noPrivate bool // Don't include private repositories.
noPublic bool // Don't include public repositories.
noFork bool // Don't include fork repositories.
noRepoRegexp *regexp.Regexp // The pattern to reject repository names.
}

type finder struct {
Expand Down Expand Up @@ -147,10 +149,10 @@ func readConfig() (config, error) {
config := config{}

var (
showVersion, showHelp bool
grep, noGrep, repo, fsize string
name, path, noName, noPath stringList
err error
showVersion, showHelp bool
grep, noGrep, repo, noRepo, fsize string
name, path, noName, noPath stringList
err error
)
flag.BoolVar(&config.archived, "archived", config.archived, "Include archived repositories")
flag.StringVar(&config.branch, "branch", "", "The branch name if different from the default")
Expand All @@ -170,6 +172,7 @@ func readConfig() (config, error) {
flag.Var(&noPath, "no-path", "The pattern to reject the pathname")
flag.BoolVar(&config.noPrivate, "no-private", config.noPrivate, "Don't include private repositories")
flag.BoolVar(&config.noPublic, "no-public", config.noPublic, "Don't include public repositories")
flag.StringVar(&noRepo, "no-repo", "", "The pattern to reject repository names")
flag.Var(&path, "path", "The pattern to match the pathname")
flag.StringVar(&repo, "repo", "", "The pattern to match repository names")
flag.StringVar(&fsize, "size", "", "Limit results based on the file size [+-]<d><u>")
Expand Down Expand Up @@ -241,6 +244,12 @@ func readConfig() (config, error) {
}
}

if noRepo != "" {
if config.noRepoRegexp, err = regexp.Compile(noRepo); err != nil {
return config, fmt.Errorf("invalid no-repo pattern: %s", err)
}
}

switch t := config.ftype; t {
case "", typeFile, typeDir: // Empty or valid.
default:
Expand Down Expand Up @@ -344,13 +353,14 @@ func run(ctx context.Context) error {

func (f *finder) find(ctx context.Context) error {
repos, err := gh.NewRepoFinder(f.gh).Find(ctx, gh.RepoFilter{
Owner: f.config.owner,
Repo: f.config.repo,
RepoRegexp: f.config.repoRegexp,
Archived: f.config.archived,
NoPrivate: f.config.noPrivate,
NoPublic: f.config.noPublic,
NoFork: f.config.noFork,
Owner: f.config.owner,
Repo: f.config.repo,
RepoRegexp: f.config.repoRegexp,
Archived: f.config.archived,
NoPrivate: f.config.noPrivate,
NoPublic: f.config.noPublic,
NoFork: f.config.noFork,
NoRepoRegexp: f.config.noRepoRegexp,
})
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions cmd/gh-go-rdeps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Usage: gh-go-rdeps [flags] <owner> <path>
Flags:
-help Print this information and exit
-no-repo= The pattern to reject repository names
-repo The pattern to match repository names
-token Prompt for an Access Token
-version Print the version and exit
Expand Down
26 changes: 18 additions & 8 deletions cmd/gh-go-rdeps/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ Usage: gh-go-rdeps [flags] <owner> <path>
Flags:
-help Print this information and exit
-repo The pattern to match repository names
-no-repo= The pattern to reject repository names
-repo= The pattern to match repository names
-token Prompt for an Access Token
-version Print the version and exit
`
Expand All @@ -45,10 +46,11 @@ func main() {
}

type config struct {
owner string
modpath string
repoRegexp *regexp.Regexp
token bool // Propmt for an access token.
owner string
modpath string
repoRegexp *regexp.Regexp
token bool // Propmt for an access token.
noRepoRegexp *regexp.Regexp // The pattern to reject repository names.
}

type finder struct {
Expand All @@ -68,11 +70,12 @@ func readConfig() (config, error) {

var (
showVersion, showHelp bool
repo string
repo, noRepo string
err error
)

flag.BoolVar(&showHelp, "help", showHelp, "Print this information and exit")
flag.StringVar(&noRepo, "no-repo", "", "The pattern to reject repository names")
flag.StringVar(&repo, "repo", "", "The pattern to match repository names")
flag.BoolVar(&config.token, "token", config.token, "Prompt for Access Token")
flag.BoolVar(&showVersion, "version", showVersion, "Print version and exit")
Expand Down Expand Up @@ -112,6 +115,12 @@ func readConfig() (config, error) {
}
}

if noRepo != "" {
if config.noRepoRegexp, err = regexp.Compile(noRepo); err != nil {
return config, fmt.Errorf("invalid no-repo pattern: %s", err)
}
}

return config, nil
}

Expand Down Expand Up @@ -146,8 +155,9 @@ func run(ctx context.Context) error {

func (f *finder) find(ctx context.Context) error {
repos, err := gh.NewRepoFinder(f.gh).Find(ctx, gh.RepoFilter{
Owner: f.config.owner,
RepoRegexp: f.config.repoRegexp,
Owner: f.config.owner,
RepoRegexp: f.config.repoRegexp,
NoRepoRegexp: f.config.noRepoRegexp,
})
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions cmd/gh-pr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Flags:
-no-fork Don't include fork repositories
-no-private Don't include private repositories
-no-public Don't include public repositories
-no-repo= The pattern to reject repository names
-repo= The pattern to match repository names
-review= The GitHub user login to request the PR review from
-script= The script to apply changes
Expand Down
60 changes: 35 additions & 25 deletions cmd/gh-pr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Flags:
-no-fork Don't include fork repositories
-no-private Don't include private repositories
-no-public Don't include public repositories
-no-repo= The pattern to reject repository names
-repo= The pattern to match repository names
-review= The GitHub user login to request the PR review from
-script= The script to apply changes
Expand All @@ -59,20 +60,21 @@ func main() {
}

type config struct {
owner string
repo string
repoRegexp *regexp.Regexp // The pattern to match respository names.
branch string // The branch name if different from the default.
desc string // The PR description.
reviewers []string // The GitHub user login to request the PR review from.
assignees []string // The GitHub user login to assign the PR to.
script string // The body of the script.
shell string // The shell to use to run the script.
title string // The PR title.
token bool // Propmt for an access token.
noPrivate bool // Don't include private repositories.
noPublic bool // Don't include public repositories.
noFork bool // Don't include fork repositories.
owner string
repo string
repoRegexp *regexp.Regexp // The pattern to match respository names.
branch string // The branch name if different from the default.
desc string // The PR description.
reviewers []string // The GitHub user login to request the PR review from.
assignees []string // The GitHub user login to assign the PR to.
script string // The body of the script.
shell string // The shell to use to run the script.
title string // The PR title.
token bool // Propmt for an access token.
noPrivate bool // Don't include private repositories.
noPublic bool // Don't include public repositories.
noFork bool // Don't include fork repositories.
noRepoRegexp *regexp.Regexp // The pattern to reject repository names.
}

type prmaker struct {
Expand Down Expand Up @@ -108,10 +110,10 @@ func readConfig() (config, error) {
}

var (
showVersion, showHelp bool
repo, scriptFile string
review, assign stringList
err error
showVersion, showHelp bool
repo, noRepo, scriptFile string
review, assign stringList
err error
)
flag.Var(&assign, "assign", "The GitHub user login to assign the PR to")
flag.StringVar(&config.branch, "branch", "", "The PR branch name")
Expand All @@ -120,6 +122,7 @@ func readConfig() (config, error) {
flag.BoolVar(&config.noFork, "no-fork", config.noFork, "Don't include fork repositories")
flag.BoolVar(&config.noPrivate, "no-private", config.noPrivate, "Don't include private repositories")
flag.BoolVar(&config.noPublic, "no-public", config.noPublic, "Don't include public repositories")
flag.StringVar(&noRepo, "no-repo", "", "The pattern to reject repository names")
flag.StringVar(&repo, "repo", "", "The pattern to match repository names")
flag.Var(&review, "review", "The GitHub user login to request the PR review from")
flag.StringVar(&config.script, "script", "", "The script to apply PR changes")
Expand Down Expand Up @@ -220,6 +223,12 @@ func readConfig() (config, error) {
}
}

if noRepo != "" {
if config.noRepoRegexp, err = regexp.Compile(noRepo); err != nil {
return config, fmt.Errorf("invalid no-repo pattern: %s", err)
}
}

return config, nil
}

Expand Down Expand Up @@ -266,13 +275,14 @@ func (p *prmaker) create(ctx context.Context) error {
}()

repos, err := gh.NewRepoFinder(p.gh).Find(ctx, gh.RepoFilter{
Owner: p.config.owner,
Repo: p.config.repo,
RepoRegexp: p.config.repoRegexp,
Archived: false,
NoPrivate: p.config.noPrivate,
NoPublic: p.config.noPublic,
NoFork: p.config.noFork,
Owner: p.config.owner,
Repo: p.config.repo,
RepoRegexp: p.config.repoRegexp,
Archived: false,
NoPrivate: p.config.noPrivate,
NoPublic: p.config.noPublic,
NoFork: p.config.noFork,
NoRepoRegexp: p.config.noRepoRegexp,
})
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions cmd/gh-purge-artifacts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Usage: gh-purge-artifacts [flags] [owner][/repo]
Flags:
-help Print this information and exit
-dry-run Dry run
-no-repo= The pattern to reject repository names
-repo The pattern to match repository names
-token Prompt for an Access Token
-version Print the version and exit
Expand Down
21 changes: 15 additions & 6 deletions cmd/gh-purge-artifacts/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Usage: gh-purge-artifacts [flags] [owner][/repo]
Flags:
-help Print this information and exit
-dry-run Dry run
-no-repo= The pattern to reject repository names
-repo= The pattern to match repository names
-token Prompt for an Access Token
-version Print the version and exit
Expand All @@ -43,11 +44,12 @@ func main() {
}

type config struct {
owner string
repo string
repoRegexp *regexp.Regexp
dryRun bool
token bool // Propmt for an access token.
owner string
repo string
repoRegexp *regexp.Regexp
dryRun bool
token bool // Propmt for an access token.
noRepoRegexp *regexp.Regexp // The pattern to reject repository names.
}

type purger struct {
Expand All @@ -67,11 +69,12 @@ func readConfig() (config, error) {

var (
showVersion, showHelp bool
repo string
repo, noRepo string
err error
)
flag.BoolVar(&config.dryRun, "dry-run", config.dryRun, "Dry run")
flag.BoolVar(&showHelp, "help", showHelp, "Print this information and exit")
flag.StringVar(&noRepo, "no-repo", "", "The pattern to reject repository names")
flag.StringVar(&repo, "repo", "", "The pattern to match repository names")
flag.BoolVar(&config.token, "token", config.token, "Prompt for Access Token")
flag.BoolVar(&showVersion, "version", showVersion, "Print version and exit")
Expand Down Expand Up @@ -111,6 +114,12 @@ func readConfig() (config, error) {
}
}

if noRepo != "" {
if config.noRepoRegexp, err = regexp.Compile(noRepo); err != nil {
return config, fmt.Errorf("invalid no-repo pattern: %s", err)
}
}

return config, nil
}

Expand Down
19 changes: 12 additions & 7 deletions github/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ func NewRepoFinder(client *github.Client) *RepoFinder {

// RepoFilter represents criteria used to filter repositories.
type RepoFilter struct {
Owner string // The owner name. Can be a user or an organization.
Repo string // The repository name when in single-repo mode.
RepoRegexp *regexp.Regexp // The pattern to match repository names.
Archived bool // Include archived repositories.
NoPrivate bool // Don't inlucde private repositories.
NoPublic bool // Don't include public repositories.
NoFork bool // Don't include forks.
Owner string // The owner name. Can be a user or an organization.
Repo string // The repository name when in single-repo mode.
RepoRegexp *regexp.Regexp // The pattern to match repository names.
Archived bool // Include archived repositories.
NoPrivate bool // Don't inlucde private repositories.
NoPublic bool // Don't include public repositories.
NoFork bool // Don't include forks.
NoRepoRegexp *regexp.Regexp // The pattern to reject repository names.
}

// Find repositories using a given filter.
Expand Down Expand Up @@ -143,6 +144,10 @@ func apply(repos []*github.Repository, filter RepoFilter) []*github.Repository {
continue
}

if filter.NoRepoRegexp != nil && filter.NoRepoRegexp.MatchString(repo.GetName()) {
continue
}

filtered[n] = repo
n++
}
Expand Down
Loading

0 comments on commit f229c20

Please sign in to comment.