-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #62 in Gitstrap.applyRepo Bug caused the inability to create repo if it does not exist with apply command. Several GitHub API methods return boolean responses indicated by the HTTP status code in the response (true indicated by a 204, false indicated by a 404) PR: #64
- Loading branch information
Showing
4 changed files
with
33 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package github | ||
|
||
import ( | ||
"net/http" | ||
|
||
gh "github.com/google/go-github/v33/github" | ||
) | ||
|
||
// resolveResponseByErr determines the result from a GitHub API response. | ||
// In some cases it is necessary to interpret the "404" response | ||
// as "false" condition e.g. response on get repositoty request. | ||
// Also several GitHub API methods return boolean responses indicated by the HTTP | ||
// status code in the response (true indicated by a 204, false indicated by a | ||
// 404). This helper function will determine that result and hide the 404 | ||
// error if present. Any other error will be returned through as-is. | ||
func resolveResponseByErr(err error) (bool, error) { | ||
if err == nil { | ||
return true, nil | ||
} | ||
if err, ok := err.(*gh.ErrorResponse); ok && err.Response.StatusCode == http.StatusNotFound { | ||
// Simply false. In this one case, we do not pass the error through. | ||
return false, nil | ||
} | ||
|
||
// some other real error occurred | ||
return false, err | ||
} |