mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-04-26 21:44:44 +00:00
Add modifiable context for Github status API
This commit is contained in:
parent
c888fb3152
commit
837446825d
4 changed files with 16 additions and 4 deletions
|
@ -99,6 +99,12 @@ var serverCmd = cli.Command{
|
||||||
Usage: "github server address",
|
Usage: "github server address",
|
||||||
Value: "https://github.com",
|
Value: "https://github.com",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
EnvVar: "DRONE_GITHUB_CONTEXT",
|
||||||
|
Name: "github-context",
|
||||||
|
Usage: "github status context",
|
||||||
|
Value: "continuous-integration/drone",
|
||||||
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
EnvVar: "DRONE_GITHUB_CLIENT",
|
EnvVar: "DRONE_GITHUB_CLIENT",
|
||||||
Name: "github-client",
|
Name: "github-client",
|
||||||
|
|
|
@ -27,6 +27,7 @@ const (
|
||||||
// Opts defines configuration options.
|
// Opts defines configuration options.
|
||||||
type Opts struct {
|
type Opts struct {
|
||||||
URL string // GitHub server url.
|
URL string // GitHub server url.
|
||||||
|
Context string // Context to display in status check
|
||||||
Client string // GitHub oauth client id.
|
Client string // GitHub oauth client id.
|
||||||
Secret string // GitHub oauth client secret.
|
Secret string // GitHub oauth client secret.
|
||||||
Scopes []string // GitHub oauth scopes
|
Scopes []string // GitHub oauth scopes
|
||||||
|
@ -51,6 +52,7 @@ func New(opts Opts) (remote.Remote, error) {
|
||||||
remote := &client{
|
remote := &client{
|
||||||
API: defaultAPI,
|
API: defaultAPI,
|
||||||
URL: defaultURL,
|
URL: defaultURL,
|
||||||
|
Context: opts.Context,
|
||||||
Client: opts.Client,
|
Client: opts.Client,
|
||||||
Secret: opts.Secret,
|
Secret: opts.Secret,
|
||||||
Scopes: opts.Scopes,
|
Scopes: opts.Scopes,
|
||||||
|
@ -70,6 +72,7 @@ func New(opts Opts) (remote.Remote, error) {
|
||||||
|
|
||||||
type client struct {
|
type client struct {
|
||||||
URL string
|
URL string
|
||||||
|
Context string
|
||||||
API string
|
API string
|
||||||
Client string
|
Client string
|
||||||
Secret string
|
Secret string
|
||||||
|
@ -261,7 +264,7 @@ func (c *client) newConfig(redirect string) *oauth2.Config {
|
||||||
return &oauth2.Config{
|
return &oauth2.Config{
|
||||||
ClientID: c.Client,
|
ClientID: c.Client,
|
||||||
ClientSecret: c.Secret,
|
ClientSecret: c.Secret,
|
||||||
Scopes: c.Scopes,
|
Scopes: c.Scopes,
|
||||||
Endpoint: oauth2.Endpoint{
|
Endpoint: oauth2.Endpoint{
|
||||||
AuthURL: fmt.Sprintf("%s/login/oauth/authorize", c.URL),
|
AuthURL: fmt.Sprintf("%s/login/oauth/authorize", c.URL),
|
||||||
TokenURL: fmt.Sprintf("%s/login/oauth/access_token", c.URL),
|
TokenURL: fmt.Sprintf("%s/login/oauth/access_token", c.URL),
|
||||||
|
@ -345,12 +348,12 @@ func (c *client) Status(u *model.User, r *model.Repo, b *model.Build, link strin
|
||||||
case "deployment":
|
case "deployment":
|
||||||
return deploymentStatus(client, r, b, link)
|
return deploymentStatus(client, r, b, link)
|
||||||
default:
|
default:
|
||||||
return repoStatus(client, r, b, link)
|
return repoStatus(client, r, b, link, c.Context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func repoStatus(client *github.Client, r *model.Repo, b *model.Build, link string) error {
|
func repoStatus(client *github.Client, r *model.Repo, b *model.Build, link, ctx string) error {
|
||||||
context := "continuous-integration/drone"
|
context := ctx
|
||||||
switch b.Event {
|
switch b.Event {
|
||||||
case model.EventPull:
|
case model.EventPull:
|
||||||
context += "/pr"
|
context += "/pr"
|
||||||
|
|
|
@ -37,6 +37,7 @@ func Test_github(t *testing.T) {
|
||||||
Password: "password",
|
Password: "password",
|
||||||
SkipVerify: true,
|
SkipVerify: true,
|
||||||
PrivateMode: true,
|
PrivateMode: true,
|
||||||
|
Context: "continuous-integration/test",
|
||||||
})
|
})
|
||||||
g.Assert(remote.(*client).URL).Equal("http://localhost:8080")
|
g.Assert(remote.(*client).URL).Equal("http://localhost:8080")
|
||||||
g.Assert(remote.(*client).API).Equal("http://localhost:8080/api/v3/")
|
g.Assert(remote.(*client).API).Equal("http://localhost:8080/api/v3/")
|
||||||
|
@ -47,6 +48,7 @@ func Test_github(t *testing.T) {
|
||||||
g.Assert(remote.(*client).Secret).Equal("I1NiIsInR5")
|
g.Assert(remote.(*client).Secret).Equal("I1NiIsInR5")
|
||||||
g.Assert(remote.(*client).SkipVerify).Equal(true)
|
g.Assert(remote.(*client).SkipVerify).Equal(true)
|
||||||
g.Assert(remote.(*client).PrivateMode).Equal(true)
|
g.Assert(remote.(*client).PrivateMode).Equal(true)
|
||||||
|
g.Assert(remote.(*client).Context).Equal("continuous-integration/test")
|
||||||
})
|
})
|
||||||
g.It("Should handle malformed url", func() {
|
g.It("Should handle malformed url", func() {
|
||||||
_, err := New(Opts{URL: "%gh&%ij"})
|
_, err := New(Opts{URL: "%gh&%ij"})
|
||||||
|
|
|
@ -92,6 +92,7 @@ func setupGitlab(c *cli.Context) (remote.Remote, error) {
|
||||||
func setupGithub(c *cli.Context) (remote.Remote, error) {
|
func setupGithub(c *cli.Context) (remote.Remote, error) {
|
||||||
return github.New(github.Opts{
|
return github.New(github.Opts{
|
||||||
URL: c.String("github-server"),
|
URL: c.String("github-server"),
|
||||||
|
Context: c.String("github-context"),
|
||||||
Client: c.String("github-client"),
|
Client: c.String("github-client"),
|
||||||
Secret: c.String("github-sercret"),
|
Secret: c.String("github-sercret"),
|
||||||
Scopes: c.StringSlice("github-scope"),
|
Scopes: c.StringSlice("github-scope"),
|
||||||
|
|
Loading…
Reference in a new issue