-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Make av auth status output less confusing
- Loading branch information
Travis DePrato
committed
Nov 30, 2023
1 parent
b058d60
commit 8f89a79
Showing
5 changed files
with
93 additions
and
19 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,11 @@ | ||
package gh | ||
|
||
import "strings" | ||
|
||
// IsHTTPUnauthorized returns true if the given error is an HTTP 401 Unauthorized error. | ||
func IsHTTPUnauthorized(err error) bool { | ||
// This is a bit fragile because it relies on the error message from the | ||
// GraphQL package. It doesn't export proper error types so we have to check | ||
// the string. | ||
return strings.Contains(err.Error(), "status code: 401") | ||
} |
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,19 @@ | ||
package gh | ||
|
||
import "context" | ||
|
||
type Viewer struct { | ||
Name string `graphql:"name"` | ||
Login string `graphql:"login"` | ||
} | ||
|
||
func (c *Client) Viewer(ctx context.Context) (*Viewer, error) { | ||
var query struct { | ||
Viewer Viewer `graphql:"viewer"` | ||
} | ||
err := c.query(ctx, &query, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &query.Viewer, nil | ||
} |