diff --git a/server/remote/gitea/gitea.go b/server/remote/gitea/gitea.go index fea560dc3..8423fdd03 100644 --- a/server/remote/gitea/gitea.go +++ b/server/remote/gitea/gitea.go @@ -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 } diff --git a/server/remote/github/github.go b/server/remote/github/github.go index 90f50b5a0..34b11a8bf 100644 --- a/server/remote/github/github.go +++ b/server/remote/github/github.go @@ -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 { diff --git a/server/remote/gitlab/gitlab.go b/server/remote/gitlab/gitlab.go index 26f2877a1..70be780ca 100644 --- a/server/remote/gitlab/gitlab.go +++ b/server/remote/gitlab/gitlab.go @@ -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 } diff --git a/server/remote/gogs/gogs.go b/server/remote/gogs/gogs.go index b458314dd..ef18f88d1 100644 --- a/server/remote/gogs/gogs.go +++ b/server/remote/gogs/gogs.go @@ -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