-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhance: add GetUserID to scm interface
- Loading branch information
Showing
4 changed files
with
63 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package github | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
api "github.com/go-vela/server/api/types" | ||
Check failure on line 9 in scm/github/user.go GitHub Actions / golangci[golangci] scm/github/user.go#L9
Raw output
|
||
"github.com/sirupsen/logrus" | ||
Check failure on line 10 in scm/github/user.go GitHub Actions / golangci[golangci] scm/github/user.go#L10
Raw output
|
||
) | ||
|
||
// GetUserID captures the user's scm id. | ||
func (c *client) GetUserID(ctx context.Context, u *api.User) (string, error) { | ||
c.Logger.WithFields(logrus.Fields{ | ||
"user": u.GetName(), | ||
}).Tracef("capturing scm id for %s", u.GetName()) | ||
|
||
// create GitHub OAuth client with user's token | ||
client := c.newClientToken(*u.Token) | ||
|
||
// send API call to capture user | ||
user, _, err := client.Users.Get(ctx, u.GetName()) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return fmt.Sprint(user.GetID()), nil | ||
} |
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