Skip to content

Commit

Permalink
Branch list enhancements (#808)
Browse files Browse the repository at this point in the history
* Allow users not logged in to access branches page
  (fixes a nil pointer derefernce)

* Add Gogs support for branches
  • Loading branch information
qwerty287 committed Feb 26, 2022
1 parent 40b5c6a commit ecc2539
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
6 changes: 5 additions & 1 deletion server/remote/gitea/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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 {
return nil, err
}
Expand Down
6 changes: 5 additions & 1 deletion server/remote/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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{})
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion server/remote/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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 {
return nil, err
}
Expand Down
17 changes: 15 additions & 2 deletions server/remote/gogs/gogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
func (c *client) Branches(ctx context.Context, u *model.User, r *model.Repo) ([]string, error) {
// TODO: fetch all branches
return []string{r.Branch}, nil
token := ""
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
Expand Down

0 comments on commit ecc2539

Please sign in to comment.