mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-10-21 19:48:21 +00:00
refactoring github package to increase test coverage
This commit is contained in:
@@ -90,13 +90,15 @@ func setupGitlab(c *cli.Context) (remote.Remote, error) {
|
||||
|
||||
// helper function to setup the GitHub remote from the CLI arguments.
|
||||
func setupGithub(c *cli.Context) (remote.Remote, error) {
|
||||
return github.New(
|
||||
c.String("github-server"),
|
||||
c.String("github-client"),
|
||||
c.String("github-sercret"),
|
||||
c.StringSlice("github-scope"),
|
||||
c.Bool("github-private-mode"),
|
||||
c.Bool("github-skip-verify"),
|
||||
c.BoolT("github-merge-ref"),
|
||||
)
|
||||
return github.New(github.Opts{
|
||||
URL: c.String("github-server"),
|
||||
Client: c.String("github-client"),
|
||||
Secret: c.String("github-sercret"),
|
||||
Scopes: c.StringSlice("github-scope"),
|
||||
Username: c.String("github-git-username"),
|
||||
Password: c.String("github-git-password"),
|
||||
PrivateMode: c.Bool("github-private-mode"),
|
||||
SkipVerify: c.Bool("github-skip-verify"),
|
||||
MergeRef: c.BoolT("github-merge-ref"),
|
||||
})
|
||||
}
|
||||
|
@@ -8,14 +8,18 @@ import (
|
||||
// AuthorizeAgent authorizes requsts from build agents to access the queue.
|
||||
func AuthorizeAgent(c *gin.Context) {
|
||||
secret := c.MustGet("agent").(string)
|
||||
if secret == "" {
|
||||
c.String(401, "invalid or empty token.")
|
||||
return
|
||||
}
|
||||
|
||||
parsed, err := token.ParseRequest(c.Request, func(t *token.Token) (string, error) {
|
||||
return secret, nil
|
||||
})
|
||||
if err != nil {
|
||||
c.AbortWithError(403, err)
|
||||
c.String(500, "invalid or empty token. %s", err)
|
||||
} else if parsed.Kind != token.AgentToken {
|
||||
c.AbortWithStatus(403)
|
||||
c.String(403, "invalid token. please use an agent token")
|
||||
} else {
|
||||
c.Next()
|
||||
}
|
||||
|
Reference in New Issue
Block a user