Add mutli-pipeline to Gitea (#225)

* Add mutli-pipeline to Gitea client
* Add multi-pipeline to Gitea OAuth client

ref: https://woodpecker.laszlo.cloud/multi-pipeline/

Signed-off-by: Yves-Gaël BILLET <ygbillet@ifotec.com>
Co-authored-by: Yves-Gaël Billet <yg.billet@gmail.com>
This commit is contained in:
ygbillet 2021-07-05 19:33:02 +02:00 committed by GitHub
parent ee3e4bb189
commit c699ea5789
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 66 additions and 2 deletions

View file

@ -23,6 +23,8 @@ import (
"net"
"net/http"
"net/url"
"path"
"path/filepath"
"code.gitea.io/sdk/gitea"
"github.com/woodpecker-ci/woodpecker/model"
@ -297,7 +299,37 @@ func (c *client) File(u *model.User, r *model.Repo, b *model.Build, f string) ([
}
func (c *client) Dir(u *model.User, r *model.Repo, b *model.Build, f string) ([]*remote.FileMeta, error) {
return nil, fmt.Errorf("Not implemented")
var configs []*remote.FileMeta
client, err := c.newClientToken(u.Token)
if err != nil {
return nil, err
}
// List files in repository. Path from root
tree, _, err := client.GetTrees(r.Owner, r.Name, b.Commit, true)
if err != nil {
return nil, err
}
f = path.Clean(f) // We clean path and remove trailing slash
f += "/" + "*" // construct pattern for match i.e. file in subdir
for _, e := range tree.Entries {
// Filter path matching pattern and type file (blob)
if m, _ := filepath.Match(f, e.Path); m && e.Type == "blob" {
data, err := c.File(u, r, b, e.Path)
if err != nil {
return nil, fmt.Errorf("multi-pipeline cannot get %s: %s", e.Path, err)
}
configs = append(configs, &remote.FileMeta{
Name: e.Path,
Data: data,
})
}
}
return configs, nil
}
// Status is supported by the Gitea driver.

View file

@ -23,6 +23,8 @@ import (
"net"
"net/http"
"net/url"
"path"
"path/filepath"
"code.gitea.io/sdk/gitea"
"github.com/woodpecker-ci/woodpecker/model"
@ -280,7 +282,37 @@ func (c *oauthclient) File(u *model.User, r *model.Repo, b *model.Build, f strin
}
func (c *oauthclient) Dir(u *model.User, r *model.Repo, b *model.Build, f string) ([]*remote.FileMeta, error) {
return nil, fmt.Errorf("Not implemented")
var configs []*remote.FileMeta
client, err := c.newClientToken(u.Token)
if err != nil {
return nil, err
}
// List files in repository. Path from root
tree, _, err := client.GetTrees(r.Owner, r.Name, b.Commit, true)
if err != nil {
return nil, err
}
f = path.Clean(f) // We clean path and remove trailing slash
f += "/" + "*" // construct pattern for match i.e. file in subdir
for _, e := range tree.Entries {
// Filter path matching pattern and type file (blob)
if m, _ := filepath.Match(f, e.Path); m && e.Type == "blob" {
data, err := c.File(u, r, b, e.Path)
if err != nil {
return nil, fmt.Errorf("multi-pipeline cannot get %s: %s", e.Path, err)
}
configs = append(configs, &remote.FileMeta{
Name: e.Path,
Data: data,
})
}
}
return configs, nil
}
// Status is supported by the Gitea driver.