mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-30 10:11:23 +02:00
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:
parent
ee3e4bb189
commit
c699ea5789
@ -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.
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user