Remove default branch fallbacks (#2065)

This commit is contained in:
Anbraten 2023-07-30 18:28:52 +02:00 committed by GitHub
parent 4731eeb5db
commit 5a812e3254
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 34 deletions

View file

@ -77,7 +77,7 @@ func (c *config) URL() string {
// Login authenticates an account with Bitbucket using the oauth2 protocol. The
// Bitbucket account details are returned when the user is successfully authenticated.
func (c *config) Login(ctx context.Context, w http.ResponseWriter, req *http.Request) (*model.User, error) {
config := c.newConfig(server.Config.Server.Host)
config := c.newOAuth2Config()
// get the OAuth errors
if err := req.FormValue("error"); err != "" {
@ -122,7 +122,7 @@ func (c *config) Auth(ctx context.Context, token, secret string) (string, error)
// Refresh refreshes the Bitbucket oauth2 access token. If the token is
// refreshed the user is updated and a true value is returned.
func (c *config) Refresh(ctx context.Context, user *model.User) (bool, error) {
config := c.newConfig("")
config := c.newOAuth2Config()
source := config.TokenSource(
ctx, &oauth2.Token{RefreshToken: user.Secret})
@ -369,7 +369,7 @@ func (c *config) newClientToken(ctx context.Context, token, secret string) *inte
}
// helper function to return the bitbucket oauth2 config
func (c *config) newConfig(redirect string) *oauth2.Config {
func (c *config) newOAuth2Config() *oauth2.Config {
return &oauth2.Config{
ClientID: c.Client,
ClientSecret: c.Secret,
@ -377,7 +377,7 @@ func (c *config) newConfig(redirect string) *oauth2.Config {
AuthURL: fmt.Sprintf("%s/site/oauth2/authorize", c.url),
TokenURL: fmt.Sprintf("%s/site/oauth2/access_token", c.url),
},
RedirectURL: fmt.Sprintf("%s/authorize", redirect),
RedirectURL: fmt.Sprintf("%s/authorize", server.Config.Server.OAuthHost),
}
}

View file

@ -59,7 +59,7 @@ func convertRepo(from *internal.Repo, perm *internal.RepoPerm) *model.Repo {
IsSCMPrivate: from.IsPrivate,
Avatar: from.Owner.Links.Avatar.Href,
SCMKind: model.SCMKind(from.Scm),
Branch: "master",
Branch: from.Mainbranch.Name,
Perm: convertPerm(perm),
}
if repo.SCMKind == model.RepoHg {

View file

@ -99,15 +99,19 @@ type LinkClone struct {
}
type Repo struct {
UUID string `json:"uuid"`
Owner Account `json:"owner"`
Name string `json:"name"`
FullName string `json:"full_name"`
Language string `json:"language"`
IsPrivate bool `json:"is_private"`
Scm string `json:"scm"`
Desc string `json:"desc"`
Links Links `json:"links"`
UUID string `json:"uuid"`
Owner Account `json:"owner"`
Name string `json:"name"`
FullName string `json:"full_name"`
Language string `json:"language"`
IsPrivate bool `json:"is_private"`
Scm string `json:"scm"`
Desc string `json:"desc"`
Links Links `json:"links"`
Mainbranch struct {
Type string `json:"type"`
Name string `json:"name"`
} `json:"mainbranch"`
}
type RepoResp struct {

View file

@ -23,8 +23,6 @@ import (
"github.com/woodpecker-ci/woodpecker/server/model"
)
const defaultBranch = "master"
const (
statusPending = "pending"
statusSuccess = "success"
@ -97,9 +95,6 @@ func convertRepo(from *github.Repository) *model.Repo {
Perm: convertPerm(from.GetPermissions()),
SCMKind: model.RepoGit,
}
if len(repo.Branch) == 0 {
repo.Branch = defaultBranch
}
return repo
}
@ -156,9 +151,6 @@ func convertRepoHook(eventRepo *github.PushEventRepository) *model.Repo {
Branch: eventRepo.GetDefaultBranch(),
SCMKind: model.RepoGit,
}
if repo.Branch == "" {
repo.Branch = defaultBranch
}
if repo.FullName == "" {
repo.FullName = repo.Owner + "/" + repo.Name
}

View file

@ -132,9 +132,6 @@ func parseDeployHook(hook *github.DeploymentEvent) (*model.Repo, *model.Pipeline
// if the ref is a sha or short sha we need to manually construct the ref.
if strings.HasPrefix(pipeline.Commit, pipeline.Ref) || pipeline.Commit == pipeline.Ref {
pipeline.Branch = hook.GetRepo().GetDefaultBranch()
if pipeline.Branch == "" {
pipeline.Branch = defaultBranch
}
pipeline.Ref = fmt.Sprintf("refs/heads/%s", pipeline.Branch)
}
// if the ref is a branch we should make sure it has refs/heads prefix

View file

@ -53,10 +53,6 @@ func (g *GitLab) convertGitLabRepo(_repo *gitlab.Project) (*model.Repo, error) {
},
}
if len(repo.Branch) == 0 { // TODO: do we need that?
repo.Branch = "master"
}
if len(repo.Avatar) != 0 && !strings.HasPrefix(repo.Avatar, "http") {
repo.Avatar = fmt.Sprintf("%s/%s", g.url, repo.Avatar)
}
@ -101,11 +97,7 @@ func convertMergeRequestHook(hook *gitlab.MergeEvent, req *http.Request) (int, *
repo.Clone = target.HTTPURL
}
if target.DefaultBranch != "" {
repo.Branch = target.DefaultBranch
} else {
repo.Branch = "master"
}
repo.Branch = target.DefaultBranch
if target.AvatarURL != "" {
repo.Avatar = target.AvatarURL