-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add scope support to access tokens #185
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,12 @@ var ( | |
s := fmt.Sprintf("%v", t.IsActive) | ||
return s, len(s) | ||
}}, | ||
{"SCOPE", func(t hub.Token) (string, int) { | ||
if len(t.Scopes) == 0 { | ||
return "", 0 | ||
} | ||
return t.Scopes[0][5:], len(t.Scopes[0]) - 5 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess |
||
}}, | ||
} | ||
) | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -46,11 +46,19 @@ type Token struct { | |||||||||
IsActive bool | ||||||||||
Token string | ||||||||||
Description string | ||||||||||
Scopes []string | ||||||||||
} | ||||||||||
|
||||||||||
// CreateToken creates a Personal Access Token and returns the token field only once | ||||||||||
func (c *Client) CreateToken(description string) (*Token, error) { | ||||||||||
data, err := json.Marshal(hubTokenRequest{Description: description}) | ||||||||||
func (c *Client) CreateToken(description string, scope string) (*Token, error) { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
|
||||||||||
tokenRequest := hubTokenRequest{Description: description} | ||||||||||
if len(scope) > 0 { | ||||||||||
scopes := []string{scope} | ||||||||||
scopes[0] = "repo:" + scope | ||||||||||
tokenRequest.Scopes = scopes | ||||||||||
Comment on lines
+56
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Am I missing something? Why can’t it be
Suggested change
? |
||||||||||
} | ||||||||||
|
||||||||||
data, err := json.Marshal(tokenRequest) | ||||||||||
if err != nil { | ||||||||||
return nil, err | ||||||||||
} | ||||||||||
|
@@ -190,8 +198,9 @@ func (c *Client) getTokensPage(url string) ([]Token, int, string, error) { | |||||||||
} | ||||||||||
|
||||||||||
type hubTokenRequest struct { | ||||||||||
Description string `json:"token_label,omitempty"` | ||||||||||
IsActive bool `json:"is_active"` | ||||||||||
Description string `json:"token_label,omitempty"` | ||||||||||
Scopes []string `json:"scopes,omitempty"` | ||||||||||
IsActive bool `json:"is_active"` | ||||||||||
} | ||||||||||
|
||||||||||
type hubTokenResponse struct { | ||||||||||
|
@@ -212,6 +221,7 @@ type hubTokenResult struct { | |||||||||
IsActive bool `json:"is_active"` | ||||||||||
Token string `json:"token"` | ||||||||||
TokenLabel string `json:"token_label"` | ||||||||||
Scopes []string `json:"scopes"` | ||||||||||
} | ||||||||||
|
||||||||||
func convertToken(response hubTokenResult) (Token, error) { | ||||||||||
|
@@ -230,5 +240,6 @@ func convertToken(response hubTokenResult) (Token, error) { | |||||||||
IsActive: response.IsActive, | ||||||||||
Token: response.Token, | ||||||||||
Description: response.TokenLabel, | ||||||||||
Scopes: response.Scopes, | ||||||||||
}, nil | ||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would extract these into a
[]string
and use it withstrings.Join
to build the description for the flag l.78