Allow to change status context again (#674)

* use flag value

* fix test

* sed -i 's/STATUS_CONTEXT/WOODPECKER_STATUS_CONTEXT/g'

* docs

* Update docs/docs/91-migrations.md

Co-authored-by: Anbraten <anton@ju60.de>
This commit is contained in:
6543 2022-01-29 20:37:36 +01:00 committed by GitHub
parent b6e47a3f4a
commit edbf6a3ba9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 11 additions and 26 deletions

View file

@ -209,6 +209,12 @@ var flags = []cli.Flag{
// //
// remote parameters // remote parameters
// //
&cli.StringFlag{
EnvVars: []string{"WOODPECKER_STATUS_CONTEXT", "WOODPECKER_GITHUB_CONTEXT", "WOODPECKER_GITEA_CONTEXT"},
Name: "status-context",
Usage: "status context prefix",
Value: "ci/woodpecker",
},
&cli.BoolFlag{ &cli.BoolFlag{
Name: "flat-permissions", Name: "flat-permissions",
Usage: "no remote call for permissions should be made", Usage: "no remote call for permissions should be made",
@ -227,12 +233,6 @@ var flags = []cli.Flag{
Usage: "github server address", Usage: "github server address",
Value: "https://github.com", Value: "https://github.com",
}, },
&cli.StringFlag{
EnvVars: []string{"WOODPECKER_GITHUB_CONTEXT"},
Name: "github-context",
Usage: "github status context",
Value: "continuous-integration/woodpecker",
},
&cli.StringFlag{ &cli.StringFlag{
EnvVars: []string{"WOODPECKER_GITHUB_CLIENT"}, EnvVars: []string{"WOODPECKER_GITHUB_CLIENT"},
Name: "github-client", Name: "github-client",
@ -332,12 +332,6 @@ var flags = []cli.Flag{
Name: "gitea-secret", Name: "gitea-secret",
Usage: "gitea oauth2 client 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{ &cli.StringFlag{
EnvVars: []string{"WOODPECKER_GITEA_GIT_USERNAME"}, EnvVars: []string{"WOODPECKER_GITEA_GIT_USERNAME"},
Name: "gitea-git-username", Name: "gitea-git-username",

View file

@ -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.Port = c.String("server-addr")
server.Config.Server.Docs = c.String("docs") 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.Server.SessionExpires = c.Duration("session-expires")
server.Config.Pipeline.Networks = c.StringSlice("network") server.Config.Pipeline.Networks = c.StringSlice("network")
server.Config.Pipeline.Volumes = c.StringSlice("volume") server.Config.Pipeline.Volumes = c.StringSlice("volume")

View file

@ -229,7 +229,6 @@ func setupGitea(c *cli.Context) (remote.Remote, error) {
} }
opts := gitea.Opts{ opts := gitea.Opts{
URL: strings.TrimRight(server.String(), "/"), URL: strings.TrimRight(server.String(), "/"),
Context: c.String("gitea-context"),
Username: c.String("gitea-git-username"), Username: c.String("gitea-git-username"),
Password: c.String("gitea-git-password"), Password: c.String("gitea-git-password"),
Client: c.String("gitea-client"), Client: c.String("gitea-client"),
@ -276,7 +275,6 @@ func setupGitlab(c *cli.Context) (remote.Remote, error) {
func setupGithub(c *cli.Context) (remote.Remote, error) { func setupGithub(c *cli.Context) (remote.Remote, error) {
opts := github.Opts{ opts := 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-secret"), Secret: c.String("github-secret"),
Scopes: c.StringSlice("github-scope"), Scopes: c.StringSlice("github-scope"),

View file

@ -67,6 +67,8 @@ Some versions need some changes to the server configuration or the pipeline conf
- Dropped support for manually setting the agents platform with `WOODPECKER_PLATFORM`. The platform is now automatically detected. - Dropped support for manually setting the agents platform with `WOODPECKER_PLATFORM`. The platform is now automatically detected.
- Use `WOODPECKER_STATUS_CONTEXT` instead of the deprecated options `WOODPECKER_GITHUB_CONTEXT` and `WOODPECKER_GITEA_CONTEXT`.
## 0.14.0 ## 0.14.0
No breaking changes No breaking changes

View file

@ -56,6 +56,7 @@ var Config = struct {
Port string Port string
Pass string Pass string
Docs string Docs string
StatusContext string
SessionExpires time.Duration SessionExpires time.Duration
// Open bool // Open bool
// Orgs map[string]struct{} // Orgs map[string]struct{}

View file

@ -7,10 +7,8 @@ import (
"github.com/woodpecker-ci/woodpecker/server/model" "github.com/woodpecker-ci/woodpecker/server/model"
) )
const base = "ci/woodpecker"
func GetBuildStatusContext(repo *model.Repo, build *model.Build, proc *model.Proc) string { func GetBuildStatusContext(repo *model.Repo, build *model.Build, proc *model.Proc) string {
name := base name := server.Config.Server.StatusContext
switch build.Event { switch build.Event {
case model.EventPull: case model.EventPull:

View file

@ -57,7 +57,6 @@ type Gitea struct {
// Opts defines configuration options. // Opts defines configuration options.
type Opts struct { type Opts struct {
URL string // Gitea server url. URL string // Gitea server url.
Context string // Context to display in status check
Client string // OAuth2 Client ID Client string // OAuth2 Client ID
Secret string // OAuth2 Client Secret Secret string // OAuth2 Client Secret
Username string // Optional machine account username. Username string // Optional machine account username.
@ -79,7 +78,6 @@ func New(opts Opts) (remote.Remote, error) {
} }
return &Gitea{ return &Gitea{
URL: opts.URL, URL: opts.URL,
Context: opts.Context,
Machine: u.Host, Machine: u.Host,
ClientID: opts.Client, ClientID: opts.Client,
ClientSecret: opts.Secret, ClientSecret: opts.Secret,

View file

@ -46,14 +46,12 @@ func Test_gitea(t *testing.T) {
g.It("Should return client with specified options", func() { g.It("Should return client with specified options", func() {
remote, _ := New(Opts{ remote, _ := New(Opts{
URL: "http://localhost:8080", URL: "http://localhost:8080",
Context: "continuous-integration/test",
Username: "someuser", Username: "someuser",
Password: "password", Password: "password",
SkipVerify: true, SkipVerify: true,
PrivateMode: true, PrivateMode: true,
}) })
g.Assert(remote.(*Gitea).URL).Equal("http://localhost:8080") 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).Machine).Equal("localhost")
g.Assert(remote.(*Gitea).Username).Equal("someuser") g.Assert(remote.(*Gitea).Username).Equal("someuser")
g.Assert(remote.(*Gitea).Password).Equal("password") g.Assert(remote.(*Gitea).Password).Equal("password")

View file

@ -45,7 +45,6 @@ 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
@ -70,7 +69,6 @@ func New(opts Opts) (remote.Remote, error) {
r := &client{ r := &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,
@ -91,7 +89,6 @@ 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

View file

@ -52,7 +52,6 @@ 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/")
@ -63,7 +62,6 @@ 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"})