Add context to gitea status

Signed-off-by: Jonas Franz <info@jonasfranz.software>
This commit is contained in:
Jonas Franz 2018-03-10 20:09:14 +01:00
parent a1d1d49852
commit 6a32935011
No known key found for this signature in database
GPG key ID: 506AEEBE80BEDECD
4 changed files with 25 additions and 13 deletions

View file

@ -1,11 +1,11 @@
// Copyright 2018 Drone.IO Inc. // Copyright 2018 Drone.IO Inc.
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
// //
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
// //
// Unless required by applicable law or agreed to in writing, software // Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, // distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -310,6 +310,12 @@ var flags = []cli.Flag{
Usage: "gitea server address", Usage: "gitea server address",
Value: "https://try.gitea.io", Value: "https://try.gitea.io",
}, },
cli.StringFlag{
EnvVar: "DRONE_GITEA_CONTEXT",
Name: "gitea-context",
Usage: "gitea status context",
Value: "continuous-integration/drone",
},
cli.StringFlag{ cli.StringFlag{
EnvVar: "DRONE_GITEA_GIT_USERNAME", EnvVar: "DRONE_GITEA_GIT_USERNAME",
Name: "gitea-git-username", Name: "gitea-git-username",

View file

@ -1,11 +1,11 @@
// Copyright 2018 Drone.IO Inc. // Copyright 2018 Drone.IO Inc.
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
// //
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
// //
// Unless required by applicable law or agreed to in writing, software // Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, // distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -115,6 +115,7 @@ func setupGogs(c *cli.Context) (remote.Remote, error) {
func setupGitea(c *cli.Context) (remote.Remote, error) { func setupGitea(c *cli.Context) (remote.Remote, error) {
return gitea.New(gitea.Opts{ return gitea.New(gitea.Opts{
URL: c.String("gitea-server"), URL: c.String("gitea-server"),
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"),
PrivateMode: c.Bool("gitea-private-mode"), PrivateMode: c.Bool("gitea-private-mode"),

View file

@ -1,11 +1,11 @@
// Copyright 2018 Drone.IO Inc. // Copyright 2018 Drone.IO Inc.
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
// //
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
// //
// Unless required by applicable law or agreed to in writing, software // Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, // distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -29,6 +29,7 @@ import (
// 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
Username string // Optional machine account username. Username string // Optional machine account username.
Password string // Optional machine account password. Password string // Optional machine account password.
PrivateMode bool // Gitea is running in private mode. PrivateMode bool // Gitea is running in private mode.
@ -37,6 +38,7 @@ type Opts struct {
type client struct { type client struct {
URL string URL string
Context string
Machine string Machine string
Username string Username string
Password string Password string
@ -111,6 +113,7 @@ func New(opts Opts) (remote.Remote, error) {
} }
return &client{ return &client{
URL: opts.URL, URL: opts.URL,
Context: opts.Context,
Machine: url.Host, Machine: url.Host,
Username: opts.Username, Username: opts.Username,
Password: opts.Password, Password: opts.Password,
@ -266,7 +269,7 @@ func (c *client) Status(u *model.User, r *model.Repo, b *model.Build, link strin
State: status, State: status,
TargetURL: link, TargetURL: link,
Description: desc, Description: desc,
Context: "", Context: c.Context,
}, },
) )

View file

@ -1,11 +1,11 @@
// Copyright 2018 Drone.IO Inc. // Copyright 2018 Drone.IO Inc.
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
// //
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
// //
// Unless required by applicable law or agreed to in writing, software // Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, // distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -44,12 +44,14 @@ 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.(*client).URL).Equal("http://localhost:8080") g.Assert(remote.(*client).URL).Equal("http://localhost:8080")
g.Assert(remote.(*client).Context).Equal("continuous-integration/test")
g.Assert(remote.(*client).Machine).Equal("localhost") g.Assert(remote.(*client).Machine).Equal("localhost")
g.Assert(remote.(*client).Username).Equal("someuser") g.Assert(remote.(*client).Username).Equal("someuser")
g.Assert(remote.(*client).Password).Equal("password") g.Assert(remote.(*client).Password).Equal("password")