mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-27 04:11:03 +00:00
Simplified the interface
This commit is contained in:
parent
df50b7ef40
commit
67cdbd2509
12 changed files with 6 additions and 112 deletions
|
@ -202,12 +202,7 @@ func (c *config) Perm(u *model.User, owner, name string) (*model.Perm, error) {
|
|||
|
||||
// File fetches the file from the Bitbucket repository and returns its contents.
|
||||
func (c *config) File(u *model.User, r *model.Repo, b *model.Build, f string) ([]byte, error) {
|
||||
return c.FileRef(u, r, b.Commit, f)
|
||||
}
|
||||
|
||||
// FileRef fetches the file from the Bitbucket repository and returns its contents.
|
||||
func (c *config) FileRef(u *model.User, r *model.Repo, ref, f string) ([]byte, error) {
|
||||
config, err := c.newClient(u).FindSource(r.Owner, r.Name, ref, f)
|
||||
config, err := c.newClient(u).FindSource(r.Owner, r.Name, b.Commit, f)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -179,12 +179,6 @@ func (c *Config) File(u *model.User, r *model.Repo, b *model.Build, f string) ([
|
|||
return client.FindFileForRepo(r.Owner, r.Name, f, b.Ref)
|
||||
}
|
||||
|
||||
func (c *Config) FileRef(u *model.User, r *model.Repo, ref, f string) ([]byte, error) {
|
||||
client := internal.NewClientWithToken(c.URL, c.Consumer, u.Token)
|
||||
|
||||
return client.FindFileForRepo(r.Owner, r.Name, f, ref)
|
||||
}
|
||||
|
||||
// Status is not supported by the bitbucketserver driver.
|
||||
func (c *Config) Status(u *model.User, r *model.Repo, b *model.Build, link string) error {
|
||||
status := internal.BuildStatus{
|
||||
|
|
|
@ -238,16 +238,6 @@ func (c *Coding) File(u *model.User, r *model.Repo, b *model.Build, f string) ([
|
|||
return data, nil
|
||||
}
|
||||
|
||||
// FileRef fetches a file from the remote repository for the given ref
|
||||
// and returns in string format.
|
||||
func (c *Coding) FileRef(u *model.User, r *model.Repo, ref, f string) ([]byte, error) {
|
||||
data, err := c.newClient(u).GetFile(r.Owner, r.Name, ref, f)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// Status sends the commit status to the remote system.
|
||||
func (c *Coding) Status(u *model.User, r *model.Repo, b *model.Build, link string) error {
|
||||
// EMPTY: not implemented in Coding OAuth API
|
||||
|
|
|
@ -184,11 +184,6 @@ func Test_coding(t *testing.T) {
|
|||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(string(data)).Equal("pipeline:\n test:\n image: golang:1.6\n commands:\n - go test\n")
|
||||
})
|
||||
g.It("Should return file for specified ref", func() {
|
||||
data, err := c.FileRef(fakeUser, fakeRepo, "master", ".drone.yml")
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(string(data)).Equal("pipeline:\n test:\n image: golang:1.6\n commands:\n - go test\n")
|
||||
})
|
||||
})
|
||||
|
||||
g.Describe("When requesting a netrc config", func() {
|
||||
|
|
|
@ -103,11 +103,6 @@ func (c *client) File(u *model.User, r *model.Repo, b *model.Build, f string) ([
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
// File is not supported by the Gerrit driver.
|
||||
func (c *client) FileRef(u *model.User, r *model.Repo, ref, f string) ([]byte, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Status is not supported by the Gogs driver.
|
||||
func (c *client) Status(u *model.User, r *model.Repo, b *model.Build, link string) error {
|
||||
return nil
|
||||
|
|
|
@ -249,11 +249,6 @@ func (c *client) File(u *model.User, r *model.Repo, b *model.Build, f string) ([
|
|||
return cfg, err
|
||||
}
|
||||
|
||||
// FileRef fetches the file from the Gitea repository and returns its contents.
|
||||
func (c *client) FileRef(u *model.User, r *model.Repo, ref, f string) ([]byte, error) {
|
||||
return c.newClientToken(u.Token).GetFile(r.Owner, r.Name, ref, f)
|
||||
}
|
||||
|
||||
// Status is supported by the Gitea driver.
|
||||
func (c *client) Status(u *model.User, r *model.Repo, b *model.Build, link string) error {
|
||||
client := c.newClientToken(u.Token)
|
||||
|
|
|
@ -225,15 +225,10 @@ func (c *client) Perm(u *model.User, owner, name string) (*model.Perm, error) {
|
|||
|
||||
// File fetches the file from the GitHub repository and returns its contents.
|
||||
func (c *client) File(u *model.User, r *model.Repo, b *model.Build, f string) ([]byte, error) {
|
||||
return c.FileRef(u, r, b.Commit, f)
|
||||
}
|
||||
|
||||
// FileRef fetches the file from the GitHub repository and returns its contents.
|
||||
func (c *client) FileRef(u *model.User, r *model.Repo, ref, f string) ([]byte, error) {
|
||||
client := c.newClientToken(u.Token)
|
||||
|
||||
opts := new(github.RepositoryContentGetOptions)
|
||||
opts.Ref = ref
|
||||
opts.Ref = b.Commit
|
||||
data, _, _, err := client.Repositories.GetContents(r.Owner, r.Name, f, opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -325,18 +325,13 @@ func (g *Gitlab) Perm(u *model.User, owner, name string) (*model.Perm, error) {
|
|||
|
||||
// File fetches a file from the remote repository and returns in string format.
|
||||
func (g *Gitlab) File(user *model.User, repo *model.Repo, build *model.Build, f string) ([]byte, error) {
|
||||
return g.FileRef(user, repo, build.Commit, f)
|
||||
}
|
||||
|
||||
// FileRef fetches the file from the GitHub repository and returns its contents.
|
||||
func (g *Gitlab) FileRef(u *model.User, r *model.Repo, ref, f string) ([]byte, error) {
|
||||
var client = NewClient(g.URL, u.Token, g.SkipVerify)
|
||||
id, err := GetProjectId(g, client, r.Owner, r.Name)
|
||||
var client = NewClient(g.URL, user.Token, g.SkipVerify)
|
||||
id, err := GetProjectId(g, client, repo.Owner, repo.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out, err := client.RepoRawFileRef(id, ref, f)
|
||||
out, err := client.RepoRawFileRef(id, build.Commit, f)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -338,21 +338,6 @@ func (g *Gitlab) File(user *model.User, repo *model.Repo, build *model.Build, f
|
|||
return out, err
|
||||
}
|
||||
|
||||
// FileRef fetches the file from the GitHub repository and returns its contents.
|
||||
func (g *Gitlab) FileRef(u *model.User, r *model.Repo, ref, f string) ([]byte, error) {
|
||||
var client = NewClient(g.URL, u.Token, g.SkipVerify)
|
||||
id, err := GetProjectId(g, client, r.Owner, r.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out, err := client.RepoRawFileRef(id, ref, f)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, err
|
||||
}
|
||||
|
||||
// NOTE Currently gitlab doesn't support status for commits and events,
|
||||
// also if we want get MR status in gitlab we need implement a special plugin for gitlab,
|
||||
// gitlab uses API to fetch build status on client side. But for now we skip this.
|
||||
|
|
|
@ -22,9 +22,9 @@ import (
|
|||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/gogits/go-gogs-client"
|
||||
"github.com/laszlocph/drone-oss-08/model"
|
||||
"github.com/laszlocph/drone-oss-08/remote"
|
||||
"github.com/gogits/go-gogs-client"
|
||||
)
|
||||
|
||||
// Opts defines configuration options.
|
||||
|
@ -202,11 +202,6 @@ func (c *client) File(u *model.User, r *model.Repo, b *model.Build, f string) ([
|
|||
return cfg, err
|
||||
}
|
||||
|
||||
// FileRef fetches the file from the Gogs repository and returns its contents.
|
||||
func (c *client) FileRef(u *model.User, r *model.Repo, ref, f string) ([]byte, error) {
|
||||
return c.newClientToken(u.Token).GetFile(r.Owner, r.Name, ref, f)
|
||||
}
|
||||
|
||||
// Status is not supported by the Gogs driver.
|
||||
func (c *client) Status(u *model.User, r *model.Repo, b *model.Build, link string) error {
|
||||
return nil
|
||||
|
|
|
@ -98,29 +98,6 @@ func (_m *Remote) File(u *model.User, r *model.Repo, b *model.Build, f string) (
|
|||
return r0, r1
|
||||
}
|
||||
|
||||
// FileRef provides a mock function with given fields: u, r, ref, f
|
||||
func (_m *Remote) FileRef(u *model.User, r *model.Repo, ref string, f string) ([]byte, error) {
|
||||
ret := _m.Called(u, r, ref, f)
|
||||
|
||||
var r0 []byte
|
||||
if rf, ok := ret.Get(0).(func(*model.User, *model.Repo, string, string) []byte); ok {
|
||||
r0 = rf(u, r, ref, f)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]byte)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(*model.User, *model.Repo, string, string) error); ok {
|
||||
r1 = rf(u, r, ref, f)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// Hook provides a mock function with given fields: r
|
||||
func (_m *Remote) Hook(r *http.Request) (*model.Repo, *model.Build, error) {
|
||||
ret := _m.Called(r)
|
||||
|
|
|
@ -51,10 +51,6 @@ type Remote interface {
|
|||
// format.
|
||||
File(u *model.User, r *model.Repo, b *model.Build, f string) ([]byte, error)
|
||||
|
||||
// FileRef fetches a file from the remote repository for the given ref
|
||||
// and returns in string format.
|
||||
FileRef(u *model.User, r *model.Repo, ref, f string) ([]byte, error)
|
||||
|
||||
// Status sends the commit status to the remote system.
|
||||
// An example would be the GitHub pull request status.
|
||||
Status(u *model.User, r *model.Repo, b *model.Build, link string) error
|
||||
|
@ -115,18 +111,6 @@ func Perm(c context.Context, u *model.User, owner, repo string) (*model.Perm, er
|
|||
return FromContext(c).Perm(u, owner, repo)
|
||||
}
|
||||
|
||||
// File fetches a file from the remote repository and returns in string format.
|
||||
func File(c context.Context, u *model.User, r *model.Repo, b *model.Build, f string) (out []byte, err error) {
|
||||
for i := 0; i < 12; i++ {
|
||||
out, err = FromContext(c).File(u, r, b, f)
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
time.Sleep(5 * time.Second)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Status sends the commit status to the remote system.
|
||||
// An example would be the GitHub pull request status.
|
||||
func Status(c context.Context, u *model.User, r *model.Repo, b *model.Build, link string) error {
|
||||
|
@ -170,7 +154,6 @@ func Refresh(c context.Context, u *model.User) (bool, error) {
|
|||
}
|
||||
|
||||
// FileBackoff fetches the file using an exponential backoff.
|
||||
// TODO replace this with a proper backoff
|
||||
func FileBackoff(remote Remote, u *model.User, r *model.Repo, b *model.Build, f string) (out []byte, err error) {
|
||||
for i := 0; i < 5; i++ {
|
||||
select {
|
||||
|
|
Loading…
Reference in a new issue