Skip to content

Commit

Permalink
Adds ratelimit handling and adds --skip-teams flag (#16)
Browse files Browse the repository at this point in the history
* add ratelimit handling on REST calls

* add --skip-teams flag to save on API calls

* fix typo on flag description
  • Loading branch information
amenocal authored May 14, 2024
1 parent a674e43 commit b4ced17
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 516 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ Usage:
Flags:
-h, --help help for sync
-m, --mapping-file string Mapping file path to use for mapping teams members handles
-k, --skip-teams Skips adding members and repos to teams that already exist to save on API requests (default "false")
-u, --source-hostname string GitHub Enterprise source hostname url (optional) Ex. https://github.example.com
-s, --source-organization string Source Organization to sync teams from
-a, --source-token string Source Organization GitHub token. Scopes: read:org, read:user, user:email
-t, --target-organization string Target Organization to sync teams from
-b, --target-token string Target Organization GitHub token. Scopes: admin:org
-z, --user-sync string User sync mode. One of: all, disable (default "none")
-z, --user-sync string User sync mode. One of: all, disable (default "none") (default "all")
```

### Mapping File Example
Expand Down
6 changes: 6 additions & 0 deletions cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var syncCmd = &cobra.Command{
mappingFile := cmd.Flag("mapping-file").Value.String()
ghHostname := cmd.Flag("source-hostname").Value.String()
userSync := cmd.Flag("user-sync").Value.String()
skipTeams := cmd.Flag("skip-teams").Value.String()

// Set ENV variables
os.Setenv("GHMT_SOURCE_ORGANIZATION", sourceOrganization)
Expand All @@ -34,6 +35,7 @@ var syncCmd = &cobra.Command{
os.Setenv("GHMT_MAPPING_FILE", mappingFile)
os.Setenv("GHMT_SOURCE_HOSTNAME", ghHostname)
os.Setenv("GHMT_USER_SYNC", userSync)
os.Setenv("GHMT_SKIP_TEAMS", skipTeams)

// Bind ENV variables in Viper
viper.BindEnv("SOURCE_ORGANIZATION")
Expand All @@ -43,6 +45,8 @@ var syncCmd = &cobra.Command{
viper.BindEnv("MAPPING_FILE")
viper.BindEnv("SOURCE_HOSTNAME")
viper.BindEnv("USER_SYNC")
viper.BindEnv("SKIP_TEAMS")

// Call syncTeams
sync.SyncTeams()
},
Expand Down Expand Up @@ -70,4 +74,6 @@ func init() {

syncCmd.Flags().StringP("user-sync", "z", "all", "User sync mode. One of: all, disable (default \"none\")")

syncCmd.Flags().BoolP("skip-teams", "k", false, "Skips adding members and repos to teams that already exist to save on API requests (default \"false\")")

}
48 changes: 23 additions & 25 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,21 @@ go 1.21
toolchain go1.21.6

require (
github.com/gofri/go-github-ratelimit v1.0.3
github.com/google/go-github/v53 v53.2.0
github.com/pterm/pterm v0.12.68
github.com/shurcooL/githubv4 v0.0.0-20230704064427-599ae7bbf278
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.16.0
golang.org/x/oauth2 v0.10.0
github.com/gofri/go-github-ratelimit v1.1.0
github.com/google/go-github/v62 v62.0.0
github.com/pterm/pterm v0.12.79
github.com/shurcooL/githubv4 v0.0.0-20240429030203-be2daab69064
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.2
golang.org/x/oauth2 v0.20.0
)

require (
atomicgo.dev/cursor v0.2.0 // indirect
atomicgo.dev/keyboard v0.2.9 // indirect
atomicgo.dev/schedule v0.1.0 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/containerd/console v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/gookit/color v1.5.4 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
Expand All @@ -31,22 +28,23 @@ require (
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/shurcooL/graphql v0.0.0-20230722043721-ed46e5a46466 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.31.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit b4ced17

Please sign in to comment.