Skip to content

Commit

Permalink
clean up & reduce code
Browse files Browse the repository at this point in the history
  • Loading branch information
samueljmello committed Jul 25, 2023
1 parent f0af76e commit d11fc9b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ Usage:
gh pma [flags]
Flags:
--confirm Auto respond to confirmation prompt
--confirm Auto respond to visibility alignment confirmation prompt
-c, --create-csv Whether to create a CSV file with the results.
-i, --create-issues Whether to create issues in target org repositories or not.
--ghes-api-url string Required if migrating from GHES. The domain name for your GHES instance. For example: ghes.contoso.com (default "github.com")
--github-source-org string Uses GH_SOURCE_PAT env variable or --github-source-pat option. Will fall back to GH_PAT or --github-target-pat if not set.
--github-source-pat string
--github-target-org string Uses GH_PAT env variable or --github-target-pat option.
--github-target-pat string
-h, --help help for gh
-t, --threads int Number of threads to process concurrently. Maximum of 10 allowed. Increasing this number could get your PAT blocked due to API limiting. (default 3)
--threads int Number of threads to process concurrently. Maximum of 10 allowed. Increasing this number could get your PAT blocked due to API limiting. (default 3)
-v, --version version for gh
```
17 changes: 12 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,14 @@ func Debug(message string) string {
return message
}

func DisplayRateLeft() {
// validate we have API attempts left
rateLeft, _ := ValidateApiRate(SourceRestClient, "core")
rateMessage := Cyan("API Rate Limit Left:")
OutputNotice(fmt.Sprintf("%s %d", rateMessage, rateLeft))
LF()
}

func IsTargetProvided() bool {
if GithubTargetOrg != "" {
return true
Expand Down Expand Up @@ -688,6 +696,7 @@ func Process(cmd *cobra.Command, args []string) (err error) {
LF()
OutputWarning("Alignment process abandoned.")
LF()
DisplayRateLeft()
return err
}

Expand All @@ -702,20 +711,18 @@ func Process(cmd *cobra.Command, args []string) (err error) {

// on successful processing
if err == nil {
LF()
OutputNotice(
fmt.Sprintf(
"Successfully processed %d repositories.",
len(ToProcessRepositories),
),
)
LF()
}
}

// validate we have API attempts left
rateLeft, _ := ValidateApiRate(SourceRestClient, "core")
rateMessage := Cyan("API Rate Limit Left:")
OutputNotice(fmt.Sprintf("%s %d", rateMessage, rateLeft))
LF()
DisplayRateLeft()

// always return
return err
Expand Down

0 comments on commit d11fc9b

Please sign in to comment.