mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2026-03-16 17:54:07 +01:00
Directly fetch directory contents (#4842)
This commit is contained in:
@@ -20,8 +20,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path"
|
|
||||||
"path/filepath"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -287,22 +285,16 @@ func (c *Forgejo) Dir(ctx context.Context, u *model.User, r *model.Repo, b *mode
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// List files in repository. Path from root
|
// List files in repository
|
||||||
tree, _, err := client.GetTrees(r.Owner, r.Name, b.Commit, true)
|
contents, _, err := client.ListContents(r.Owner, r.Name, b.Commit, f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
f = path.Clean(f) // We clean path and remove trailing slash
|
for _, e := range contents {
|
||||||
f += "/" + "*" // construct pattern for match i.e. file in subdir
|
if e.Type == "file" {
|
||||||
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(ctx, u, r, b, e.Path)
|
data, err := c.File(ctx, u, r, b, e.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, &forge_types.ErrConfigNotFound{}) {
|
|
||||||
return nil, fmt.Errorf("git tree reported existence of file but we got: %s", err.Error())
|
|
||||||
}
|
|
||||||
return nil, fmt.Errorf("multi-pipeline cannot get %s: %w", e.Path, err)
|
return nil, fmt.Errorf("multi-pipeline cannot get %s: %w", e.Path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,8 +22,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path"
|
|
||||||
"path/filepath"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -289,22 +287,16 @@ func (c *Gitea) Dir(ctx context.Context, u *model.User, r *model.Repo, b *model.
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// List files in repository. Path from root
|
// List files in repository
|
||||||
tree, _, err := client.GetTrees(r.Owner, r.Name, b.Commit, true)
|
contents, _, err := client.ListContents(r.Owner, r.Name, b.Commit, f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
f = path.Clean(f) // We clean path and remove trailing slash
|
for _, e := range contents {
|
||||||
f += "/" + "*" // construct pattern for match i.e. file in subdir
|
if e.Type == "file" {
|
||||||
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(ctx, u, r, b, e.Path)
|
data, err := c.File(ctx, u, r, b, e.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, &forge_types.ErrConfigNotFound{}) {
|
|
||||||
return nil, fmt.Errorf("git tree reported existence of file but we got: %s", err.Error())
|
|
||||||
}
|
|
||||||
return nil, fmt.Errorf("multi-pipeline cannot get %s: %w", e.Path, err)
|
return nil, fmt.Errorf("multi-pipeline cannot get %s: %w", e.Path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user