mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-01-24 08:08:38 +00:00
Remove default branch fallbacks (#2065)
This commit is contained in:
parent
4731eeb5db
commit
5a812e3254
6 changed files with 19 additions and 34 deletions
|
@ -77,7 +77,7 @@ func (c *config) URL() string {
|
||||||
// Login authenticates an account with Bitbucket using the oauth2 protocol. The
|
// Login authenticates an account with Bitbucket using the oauth2 protocol. The
|
||||||
// Bitbucket account details are returned when the user is successfully authenticated.
|
// 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) {
|
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
|
// get the OAuth errors
|
||||||
if err := req.FormValue("error"); err != "" {
|
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
|
// Refresh refreshes the Bitbucket oauth2 access token. If the token is
|
||||||
// refreshed the user is updated and a true value is returned.
|
// refreshed the user is updated and a true value is returned.
|
||||||
func (c *config) Refresh(ctx context.Context, user *model.User) (bool, error) {
|
func (c *config) Refresh(ctx context.Context, user *model.User) (bool, error) {
|
||||||
config := c.newConfig("")
|
config := c.newOAuth2Config()
|
||||||
source := config.TokenSource(
|
source := config.TokenSource(
|
||||||
ctx, &oauth2.Token{RefreshToken: user.Secret})
|
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
|
// 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{
|
return &oauth2.Config{
|
||||||
ClientID: c.Client,
|
ClientID: c.Client,
|
||||||
ClientSecret: c.Secret,
|
ClientSecret: c.Secret,
|
||||||
|
@ -377,7 +377,7 @@ func (c *config) newConfig(redirect string) *oauth2.Config {
|
||||||
AuthURL: fmt.Sprintf("%s/site/oauth2/authorize", c.url),
|
AuthURL: fmt.Sprintf("%s/site/oauth2/authorize", c.url),
|
||||||
TokenURL: fmt.Sprintf("%s/site/oauth2/access_token", 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),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ func convertRepo(from *internal.Repo, perm *internal.RepoPerm) *model.Repo {
|
||||||
IsSCMPrivate: from.IsPrivate,
|
IsSCMPrivate: from.IsPrivate,
|
||||||
Avatar: from.Owner.Links.Avatar.Href,
|
Avatar: from.Owner.Links.Avatar.Href,
|
||||||
SCMKind: model.SCMKind(from.Scm),
|
SCMKind: model.SCMKind(from.Scm),
|
||||||
Branch: "master",
|
Branch: from.Mainbranch.Name,
|
||||||
Perm: convertPerm(perm),
|
Perm: convertPerm(perm),
|
||||||
}
|
}
|
||||||
if repo.SCMKind == model.RepoHg {
|
if repo.SCMKind == model.RepoHg {
|
||||||
|
|
|
@ -99,15 +99,19 @@ type LinkClone struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Repo struct {
|
type Repo struct {
|
||||||
UUID string `json:"uuid"`
|
UUID string `json:"uuid"`
|
||||||
Owner Account `json:"owner"`
|
Owner Account `json:"owner"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
FullName string `json:"full_name"`
|
FullName string `json:"full_name"`
|
||||||
Language string `json:"language"`
|
Language string `json:"language"`
|
||||||
IsPrivate bool `json:"is_private"`
|
IsPrivate bool `json:"is_private"`
|
||||||
Scm string `json:"scm"`
|
Scm string `json:"scm"`
|
||||||
Desc string `json:"desc"`
|
Desc string `json:"desc"`
|
||||||
Links Links `json:"links"`
|
Links Links `json:"links"`
|
||||||
|
Mainbranch struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
} `json:"mainbranch"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type RepoResp struct {
|
type RepoResp struct {
|
||||||
|
|
|
@ -23,8 +23,6 @@ import (
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
const defaultBranch = "master"
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
statusPending = "pending"
|
statusPending = "pending"
|
||||||
statusSuccess = "success"
|
statusSuccess = "success"
|
||||||
|
@ -97,9 +95,6 @@ func convertRepo(from *github.Repository) *model.Repo {
|
||||||
Perm: convertPerm(from.GetPermissions()),
|
Perm: convertPerm(from.GetPermissions()),
|
||||||
SCMKind: model.RepoGit,
|
SCMKind: model.RepoGit,
|
||||||
}
|
}
|
||||||
if len(repo.Branch) == 0 {
|
|
||||||
repo.Branch = defaultBranch
|
|
||||||
}
|
|
||||||
return repo
|
return repo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,9 +151,6 @@ func convertRepoHook(eventRepo *github.PushEventRepository) *model.Repo {
|
||||||
Branch: eventRepo.GetDefaultBranch(),
|
Branch: eventRepo.GetDefaultBranch(),
|
||||||
SCMKind: model.RepoGit,
|
SCMKind: model.RepoGit,
|
||||||
}
|
}
|
||||||
if repo.Branch == "" {
|
|
||||||
repo.Branch = defaultBranch
|
|
||||||
}
|
|
||||||
if repo.FullName == "" {
|
if repo.FullName == "" {
|
||||||
repo.FullName = repo.Owner + "/" + repo.Name
|
repo.FullName = repo.Owner + "/" + repo.Name
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 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 {
|
if strings.HasPrefix(pipeline.Commit, pipeline.Ref) || pipeline.Commit == pipeline.Ref {
|
||||||
pipeline.Branch = hook.GetRepo().GetDefaultBranch()
|
pipeline.Branch = hook.GetRepo().GetDefaultBranch()
|
||||||
if pipeline.Branch == "" {
|
|
||||||
pipeline.Branch = defaultBranch
|
|
||||||
}
|
|
||||||
pipeline.Ref = fmt.Sprintf("refs/heads/%s", pipeline.Branch)
|
pipeline.Ref = fmt.Sprintf("refs/heads/%s", pipeline.Branch)
|
||||||
}
|
}
|
||||||
// if the ref is a branch we should make sure it has refs/heads prefix
|
// if the ref is a branch we should make sure it has refs/heads prefix
|
||||||
|
|
|
@ -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") {
|
if len(repo.Avatar) != 0 && !strings.HasPrefix(repo.Avatar, "http") {
|
||||||
repo.Avatar = fmt.Sprintf("%s/%s", g.url, repo.Avatar)
|
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
|
repo.Clone = target.HTTPURL
|
||||||
}
|
}
|
||||||
|
|
||||||
if target.DefaultBranch != "" {
|
repo.Branch = target.DefaultBranch
|
||||||
repo.Branch = target.DefaultBranch
|
|
||||||
} else {
|
|
||||||
repo.Branch = "master"
|
|
||||||
}
|
|
||||||
|
|
||||||
if target.AvatarURL != "" {
|
if target.AvatarURL != "" {
|
||||||
repo.Avatar = target.AvatarURL
|
repo.Avatar = target.AvatarURL
|
||||||
|
|
Loading…
Reference in a new issue