mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-06-07 09:58:51 +00:00
Branch list enhancements (#808)
* Allow users not logged in to access branches page (fixes a nil pointer derefernce) * Add Gogs support for branches
This commit is contained in:
parent
40b5c6a320
commit
ecc25395aa
4 changed files with 30 additions and 5 deletions
|
@ -423,7 +423,11 @@ func (c *Gitea) Deactivate(ctx context.Context, u *model.User, r *model.Repo, li
|
||||||
|
|
||||||
// Branches returns the names of all branches for the named repository.
|
// Branches returns the names of all branches for the named repository.
|
||||||
func (c *Gitea) Branches(ctx context.Context, u *model.User, r *model.Repo) ([]string, error) {
|
func (c *Gitea) Branches(ctx context.Context, u *model.User, r *model.Repo) ([]string, error) {
|
||||||
client, err := c.newClientToken(ctx, u.Token)
|
token := ""
|
||||||
|
if u != nil {
|
||||||
|
token = u.Token
|
||||||
|
}
|
||||||
|
client, err := c.newClientToken(ctx, token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -458,7 +458,11 @@ func (c *client) Activate(ctx context.Context, u *model.User, r *model.Repo, lin
|
||||||
|
|
||||||
// Branches returns the names of all branches for the named repository.
|
// Branches returns the names of all branches for the named repository.
|
||||||
func (c *client) Branches(ctx context.Context, u *model.User, r *model.Repo) ([]string, error) {
|
func (c *client) Branches(ctx context.Context, u *model.User, r *model.Repo) ([]string, error) {
|
||||||
client := c.newClientToken(ctx, u.Token)
|
token := ""
|
||||||
|
if u != nil {
|
||||||
|
token = u.Token
|
||||||
|
}
|
||||||
|
client := c.newClientToken(ctx, token)
|
||||||
|
|
||||||
githubBranches, _, err := client.Repositories.ListBranches(ctx, r.Owner, r.Name, &github.BranchListOptions{})
|
githubBranches, _, err := client.Repositories.ListBranches(ctx, r.Owner, r.Name, &github.BranchListOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -488,7 +488,11 @@ func (g *Gitlab) Deactivate(ctx context.Context, user *model.User, repo *model.R
|
||||||
|
|
||||||
// Branches returns the names of all branches for the named repository.
|
// Branches returns the names of all branches for the named repository.
|
||||||
func (g *Gitlab) Branches(ctx context.Context, user *model.User, repo *model.Repo) ([]string, error) {
|
func (g *Gitlab) Branches(ctx context.Context, user *model.User, repo *model.Repo) ([]string, error) {
|
||||||
client, err := newClient(g.URL, user.Token, g.SkipVerify)
|
token := ""
|
||||||
|
if user != nil {
|
||||||
|
token = user.Token
|
||||||
|
}
|
||||||
|
client, err := newClient(g.URL, token, g.SkipVerify)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -262,8 +262,21 @@ func (c *client) Deactivate(ctx context.Context, u *model.User, r *model.Repo, l
|
||||||
|
|
||||||
// Branches returns the names of all branches for the named repository.
|
// Branches returns the names of all branches for the named repository.
|
||||||
func (c *client) Branches(ctx context.Context, u *model.User, r *model.Repo) ([]string, error) {
|
func (c *client) Branches(ctx context.Context, u *model.User, r *model.Repo) ([]string, error) {
|
||||||
// TODO: fetch all branches
|
token := ""
|
||||||
return []string{r.Branch}, nil
|
if u != nil {
|
||||||
|
token = u.Token
|
||||||
|
}
|
||||||
|
client := c.newClientToken(token)
|
||||||
|
gogsBranches, err := client.ListRepoBranches(r.Owner, r.Name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
branches := make([]string, 0)
|
||||||
|
for _, branch := range gogsBranches {
|
||||||
|
branches = append(branches, branch.Name)
|
||||||
|
}
|
||||||
|
return branches, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hook parses the incoming Gogs hook and returns the Repository and Build
|
// Hook parses the incoming Gogs hook and returns the Repository and Build
|
||||||
|
|
Loading…
Reference in a new issue