Skip to content

Commit

Permalink
[Enhancement] API Rate Limiting (#1)
Browse files Browse the repository at this point in the history
* fixing apis

* fixing migration types
  • Loading branch information
antgrutta authored Jul 27, 2023
1 parent 5704da8 commit 973262c
Show file tree
Hide file tree
Showing 7 changed files with 704 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
## Files
/gh-migration-monitor
/gh-migration-monitor.exe
scratch.txt
47 changes: 38 additions & 9 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,35 @@ package cmd
import (
"os"

"github.com/mona-actions/gh-migration-monitor/pkg/monitor"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "gh-migration-monitor",
Short: "A brief description of your application",
Long: `A longer description that spans multiple lines and likely contains
examples and usage of using your application. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Use: "migration-monitor",
Short: "gh cli extension to monitor migration status",
Long: `gh cli extension to monitor migration status`,
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) { },

Run: func(cmd *cobra.Command, args []string) {
orgName := cmd.Flag("organization").Value.String()
token := cmd.Flag("github-token").Value.String()

// Set the GitHub Organization
os.Setenv("GHMM_GITHUB_ORGANIZATION", orgName)
viper.BindEnv("GITHUB_ORGANIZATION")

// Set the GitHub Token
os.Setenv("GHMM_GITHUB_TOKEN", token)
viper.BindEnv("GITHUB_TOKEN")

// Call the monitor
monitor.Organization()
},
}

// Execute adds all child commands to the root command and sets flags appropriately.
Expand All @@ -39,5 +52,21 @@ func init() {

// Cobra also supports local flags, which will only run
// when this action is called directly.
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")

cobra.OnInitialize(initConfig)

rootCmd.Flags().StringP("organization", "o", "", "Organization to monitor")
rootCmd.MarkFlagRequired("organization")

// Not required because we can use the github token from the environment
rootCmd.Flags().StringP("github-token", "t", "", "Github token to use")
}

func initConfig() {
// Set env prefix
viper.SetEnvPrefix("GHMM")

// Read in environment variables that match
// Specifically we are looking for GHMM_GITHUB_TOKEN
viper.AutomaticEnv()
}
26 changes: 25 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,33 @@ module github.com/mona-actions/gh-migration-monitor

go 1.19

require github.com/spf13/cobra v1.7.0
require (
github.com/gofri/go-github-ratelimit v1.0.4
github.com/shurcooL/githubv4 v0.0.0-20230424031643-6cea62ecd5a9
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.16.0
golang.org/x/oauth2 v0.9.0
)

require (
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/shurcooL/graphql v0.0.0-20220606043923-3cf50f8a0a29 // 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/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
golang.org/x/net v0.11.0 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/text v0.10.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 973262c

Please sign in to comment.