Skip to content

Commit

Permalink
feat: add ignore codes to github retry client
Browse files Browse the repository at this point in the history
  • Loading branch information
ZackarySantana committed Oct 15, 2024
1 parent c9fcf30 commit 6784535
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion thirdparty/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,18 @@ var (
type retryConfig struct {
retry bool
retry404 bool
// ignoreCodes are http status codes that the retry function should ignore
// and not retry on.
ignoreCodes []int
}

func (c *retryConfig) shouldIgnoreCode(statusCode int) bool {
for _, ignoreCode := range c.ignoreCodes {
if statusCode == ignoreCode {
return true
}
}
return false
}

func githubShouldRetry(caller string, config retryConfig) utility.HTTPRetryFunction {
Expand Down Expand Up @@ -263,6 +275,10 @@ func githubShouldRetry(caller string, config retryConfig) utility.HTTPRetryFunct
return true
}

if config.shouldIgnoreCode(resp.StatusCode) {
return false
}

if resp.StatusCode >= http.StatusBadRequest {
grip.Error(message.Fields{
"message": "bad response code from github",
Expand Down Expand Up @@ -379,7 +395,8 @@ func RevokeInstallationToken(ctx context.Context, token string) error {
))
defer span.End()

githubClient := getGithubClient(token, caller, retryConfig{retry: true})
// Ignore unauthorized responses since the token may have already been revoked.
githubClient := getGithubClient(token, caller, retryConfig{retry: true, ignoreCodes: []int{http.StatusUnauthorized}})
defer githubClient.Close()
resp, err := githubClient.Apps.RevokeInstallationToken(ctx)
if resp != nil {
Expand Down

0 comments on commit 6784535

Please sign in to comment.