Skip to content
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

Allow to change status context again #674

Merged
merged 9 commits into from
Jan 29, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions cmd/server/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ var flags = []cli.Flag{
//
// remote parameters
//
&cli.StringFlag{
EnvVars: []string{"STATUS_CONTEXT", "WOODPECKER_GITHUB_CONTEXT", "WOODPECKER_GITEA_CONTEXT"},
6543 marked this conversation as resolved.
Show resolved Hide resolved
Name: "status-context",
Usage: "status context prefix",
Value: "ci/woodpecker",
},
&cli.BoolFlag{
Name: "flat-permissions",
Usage: "no remote call for permissions should be made",
Expand All @@ -227,12 +233,6 @@ var flags = []cli.Flag{
Usage: "github server address",
Value: "https://github.com",
},
&cli.StringFlag{
EnvVars: []string{"WOODPECKER_GITHUB_CONTEXT"},
Name: "github-context",
Usage: "github status context",
Value: "continuous-integration/woodpecker",
},
&cli.StringFlag{
EnvVars: []string{"WOODPECKER_GITHUB_CLIENT"},
Name: "github-client",
Expand Down Expand Up @@ -332,12 +332,6 @@ var flags = []cli.Flag{
Name: "gitea-secret",
Usage: "gitea oauth2 client secret",
},
&cli.StringFlag{
EnvVars: []string{"WOODPECKER_GITEA_CONTEXT"},
Name: "gitea-context",
Usage: "gitea status context",
Value: "continuous-integration/woodpecker",
},
&cli.StringFlag{
EnvVars: []string{"WOODPECKER_GITEA_GIT_USERNAME"},
Name: "gitea-git-username",
Expand Down
1 change: 1 addition & 0 deletions cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ func setupEvilGlobals(c *cli.Context, v store.Store, r remote.Remote) {
}
server.Config.Server.Port = c.String("server-addr")
server.Config.Server.Docs = c.String("docs")
server.Config.Server.StatusContext = c.String("status-context")
server.Config.Server.SessionExpires = c.Duration("session-expires")
server.Config.Pipeline.Networks = c.StringSlice("network")
server.Config.Pipeline.Volumes = c.StringSlice("volume")
Expand Down
2 changes: 0 additions & 2 deletions cmd/server/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ func setupGitea(c *cli.Context) (remote.Remote, error) {
}
opts := gitea.Opts{
URL: strings.TrimRight(server.String(), "/"),
Context: c.String("gitea-context"),
Username: c.String("gitea-git-username"),
Password: c.String("gitea-git-password"),
Client: c.String("gitea-client"),
Expand Down Expand Up @@ -276,7 +275,6 @@ func setupGitlab(c *cli.Context) (remote.Remote, error) {
func setupGithub(c *cli.Context) (remote.Remote, error) {
opts := github.Opts{
URL: c.String("github-server"),
Context: c.String("github-context"),
Client: c.String("github-client"),
Secret: c.String("github-secret"),
Scopes: c.StringSlice("github-scope"),
Expand Down
1 change: 1 addition & 0 deletions server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ var Config = struct {
Port string
Pass string
Docs string
StatusContext string
SessionExpires time.Duration
// Open bool
// Orgs map[string]struct{}
Expand Down
4 changes: 1 addition & 3 deletions server/remote/common/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import (
"github.com/woodpecker-ci/woodpecker/server/model"
)

const base = "ci/woodpecker"

func GetBuildStatusContext(repo *model.Repo, build *model.Build, proc *model.Proc) string {
name := base
name := server.Config.Server.StatusContext

switch build.Event {
case model.EventPull:
Expand Down
2 changes: 0 additions & 2 deletions server/remote/gitea/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ type Gitea struct {
// Opts defines configuration options.
type Opts struct {
URL string // Gitea server url.
Context string // Context to display in status check
Client string // OAuth2 Client ID
Secret string // OAuth2 Client Secret
Username string // Optional machine account username.
Expand All @@ -79,7 +78,6 @@ func New(opts Opts) (remote.Remote, error) {
}
return &Gitea{
URL: opts.URL,
Context: opts.Context,
Machine: u.Host,
ClientID: opts.Client,
ClientSecret: opts.Secret,
Expand Down
2 changes: 0 additions & 2 deletions server/remote/gitea/gitea_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,12 @@ func Test_gitea(t *testing.T) {
g.It("Should return client with specified options", func() {
remote, _ := New(Opts{
URL: "http://localhost:8080",
Context: "continuous-integration/test",
Username: "someuser",
Password: "password",
SkipVerify: true,
PrivateMode: true,
})
g.Assert(remote.(*Gitea).URL).Equal("http://localhost:8080")
g.Assert(remote.(*Gitea).Context).Equal("continuous-integration/test")
g.Assert(remote.(*Gitea).Machine).Equal("localhost")
g.Assert(remote.(*Gitea).Username).Equal("someuser")
g.Assert(remote.(*Gitea).Password).Equal("password")
Expand Down
3 changes: 0 additions & 3 deletions server/remote/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ const (
// Opts defines configuration options.
type Opts struct {
URL string // GitHub server url.
Context string // Context to display in status check
Client string // GitHub oauth client id.
Secret string // GitHub oauth client secret.
Scopes []string // GitHub oauth scopes
Expand All @@ -70,7 +69,6 @@ func New(opts Opts) (remote.Remote, error) {
r := &client{
API: defaultAPI,
URL: defaultURL,
Context: opts.Context,
Client: opts.Client,
Secret: opts.Secret,
Scopes: opts.Scopes,
Expand All @@ -91,7 +89,6 @@ func New(opts Opts) (remote.Remote, error) {

type client struct {
URL string
Context string
API string
Client string
Secret string
Expand Down
2 changes: 0 additions & 2 deletions server/remote/github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ func Test_github(t *testing.T) {
Password: "password",
SkipVerify: true,
PrivateMode: true,
Context: "continuous-integration/test",
})
g.Assert(remote.(*client).URL).Equal("http://localhost:8080")
g.Assert(remote.(*client).API).Equal("http://localhost:8080/api/v3/")
Expand All @@ -63,7 +62,6 @@ func Test_github(t *testing.T) {
g.Assert(remote.(*client).Secret).Equal("I1NiIsInR5")
g.Assert(remote.(*client).SkipVerify).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() {
_, err := New(Opts{URL: "%gh&%ij"})
Expand Down