From 6784535566b9a57821bdb6b68f693f99278fc466 Mon Sep 17 00:00:00 2001 From: Zackary Santana <64446617+ZackarySantana@users.noreply.github.com> Date: Tue, 15 Oct 2024 10:16:01 -0400 Subject: [PATCH] feat: add ignore codes to github retry client --- thirdparty/github.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/thirdparty/github.go b/thirdparty/github.go index b0ee12c3931..26fe704870c 100644 --- a/thirdparty/github.go +++ b/thirdparty/github.go @@ -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 { @@ -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", @@ -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 {