Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mutli-pipeline to Gitea #225

Merged
merged 6 commits into from
Jul 5, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion remote/gitea/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"net"
"net/http"
"net/url"
"path"
"path/filepath"

"code.gitea.io/sdk/gitea"
"github.com/woodpecker-ci/woodpecker/model"
Expand Down Expand Up @@ -295,7 +297,44 @@ 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 errors string
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 {
errors += fmt.Sprintf("cannot get %s: %s", e.Path, err)
}

config := remote.FileMeta{
Name: e.Path,
Data: data,
}

configs = append(configs, &config)
ygbillet marked this conversation as resolved.
Show resolved Hide resolved
}
}

if errors != "" {
return configs, fmt.Errorf("errors get multi-pipeline: %s", errors)
}

return configs, nil
}

// Status is supported by the Gitea driver.
Expand Down