mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-04-26 21:44:44 +00:00
added logging
This commit is contained in:
parent
bd25f57fa7
commit
0795dce4ed
4 changed files with 34 additions and 19 deletions
|
@ -175,10 +175,16 @@ func (c *client) Perm(u *model.User, owner, name string) (*model.Perm, error) {
|
||||||
// File fetches the file from the Gogs repository and returns its contents.
|
// File fetches the file from the Gogs repository and returns its contents.
|
||||||
func (c *client) File(u *model.User, r *model.Repo, b *model.Build, f string) ([]byte, error) {
|
func (c *client) File(u *model.User, r *model.Repo, b *model.Build, f string) ([]byte, error) {
|
||||||
client := c.newClientToken(u.Token)
|
client := c.newClientToken(u.Token)
|
||||||
buildRef := b.Commit
|
ref := b.Commit
|
||||||
if buildRef == "" {
|
|
||||||
|
// TODO gogs does not yet return a sha with the pull request
|
||||||
|
// so unfortunately we need to use the pull request branch.
|
||||||
|
if b.Event == model.EventPull {
|
||||||
|
ref = b.Branch
|
||||||
|
}
|
||||||
|
if ref == "" {
|
||||||
// Remove refs/tags or refs/heads, Gogs needs a short ref
|
// Remove refs/tags or refs/heads, Gogs needs a short ref
|
||||||
buildRef = strings.TrimPrefix(
|
ref = strings.TrimPrefix(
|
||||||
strings.TrimPrefix(
|
strings.TrimPrefix(
|
||||||
b.Ref,
|
b.Ref,
|
||||||
"refs/heads/",
|
"refs/heads/",
|
||||||
|
@ -186,7 +192,7 @@ func (c *client) File(u *model.User, r *model.Repo, b *model.Build, f string) ([
|
||||||
"refs/tags/",
|
"refs/tags/",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
cfg, err := client.GetFile(r.Owner, r.Name, buildRef, f)
|
cfg, err := client.GetFile(r.Owner, r.Name, ref, f)
|
||||||
return cfg, err
|
return cfg, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -137,15 +137,15 @@ func buildFromPullRequest(hook *pullRequestHook) *model.Build {
|
||||||
Commit: hook.PullRequest.Head.Sha,
|
Commit: hook.PullRequest.Head.Sha,
|
||||||
Link: hook.PullRequest.URL,
|
Link: hook.PullRequest.URL,
|
||||||
Ref: fmt.Sprintf("refs/pull/%d/head", hook.Number),
|
Ref: fmt.Sprintf("refs/pull/%d/head", hook.Number),
|
||||||
Branch: hook.PullRequest.Base.Ref,
|
Branch: hook.PullRequest.BaseBranch,
|
||||||
Message: hook.PullRequest.Title,
|
Message: hook.PullRequest.Title,
|
||||||
Author: hook.PullRequest.User.Username,
|
Author: hook.PullRequest.User.Username,
|
||||||
Avatar: avatar,
|
Avatar: avatar,
|
||||||
Sender: sender,
|
Sender: sender,
|
||||||
Title: hook.PullRequest.Title,
|
Title: hook.PullRequest.Title,
|
||||||
Refspec: fmt.Sprintf("%s:%s",
|
Refspec: fmt.Sprintf("%s:%s",
|
||||||
hook.PullRequest.Head.Ref,
|
hook.PullRequest.HeadBranch,
|
||||||
hook.PullRequest.Base.Ref,
|
hook.PullRequest.BaseBranch,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
return build
|
return build
|
||||||
|
|
|
@ -53,15 +53,16 @@ type pullRequestHook struct {
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Avatar string `json:"avatar_url"`
|
Avatar string `json:"avatar_url"`
|
||||||
} `json:"user"`
|
} `json:"user"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Body string `json:"body"`
|
Body string `json:"body"`
|
||||||
Labels []string `json:"labels"`
|
Labels []string `json:"labels"`
|
||||||
State string `json:"state"`
|
State string `json:"state"`
|
||||||
URL string `json:"html_url"`
|
URL string `json:"html_url"`
|
||||||
Mergeable bool `json:"mergeable"`
|
Mergeable bool `json:"mergeable"`
|
||||||
Merged bool `json:"merged"`
|
Merged bool `json:"merged"`
|
||||||
MergeBase string `json:"merge_base"`
|
MergeBase string `json:"merge_base"`
|
||||||
Base struct {
|
BaseBranch string `json:"base_branch"`
|
||||||
|
Base struct {
|
||||||
Label string `json:"label"`
|
Label string `json:"label"`
|
||||||
Ref string `json:"ref"`
|
Ref string `json:"ref"`
|
||||||
Sha string `json:"sha"`
|
Sha string `json:"sha"`
|
||||||
|
@ -80,7 +81,8 @@ type pullRequestHook struct {
|
||||||
} `json:"owner"`
|
} `json:"owner"`
|
||||||
} `json:"repo"`
|
} `json:"repo"`
|
||||||
} `json:"base"`
|
} `json:"base"`
|
||||||
Head struct {
|
HeadBranch string `json:"head_branch"`
|
||||||
|
Head struct {
|
||||||
Label string `json:"label"`
|
Label string `json:"label"`
|
||||||
Ref string `json:"ref"`
|
Ref string `json:"ref"`
|
||||||
Sha string `json:"sha"`
|
Sha string `json:"sha"`
|
||||||
|
|
|
@ -159,11 +159,13 @@ func PostHook(c *gin.Context) {
|
||||||
// secrets have skip-verify flag
|
// secrets have skip-verify flag
|
||||||
|
|
||||||
if build.Event == model.EventPull {
|
if build.Event == model.EventPull {
|
||||||
old, ferr := remote_.FileRef(user, repo, build.Ref, cfg.Yaml)
|
old, ferr := remote_.FileRef(user, repo, build.Branch, cfg.Yaml)
|
||||||
if ferr != nil {
|
if ferr != nil {
|
||||||
build.Status = model.StatusBlocked
|
build.Status = model.StatusBlocked
|
||||||
|
logrus.Debugf("cannot fetch base yaml: status: blocked")
|
||||||
} else if bytes.Equal(old, raw) {
|
} else if bytes.Equal(old, raw) {
|
||||||
build.Status = model.StatusPending
|
build.Status = model.StatusPending
|
||||||
|
logrus.Debugf("base yaml matches head yaml: status: accepted")
|
||||||
} else {
|
} else {
|
||||||
// this block is executed if the target yaml file
|
// this block is executed if the target yaml file
|
||||||
// does not match the base yaml.
|
// does not match the base yaml.
|
||||||
|
@ -174,6 +176,7 @@ func PostHook(c *gin.Context) {
|
||||||
sender, uerr := store.GetUserLogin(c, build.Sender)
|
sender, uerr := store.GetUserLogin(c, build.Sender)
|
||||||
if uerr != nil {
|
if uerr != nil {
|
||||||
build.Status = model.StatusBlocked
|
build.Status = model.StatusBlocked
|
||||||
|
logrus.Debugf("sender does not have a drone account: status: blocked")
|
||||||
} else {
|
} else {
|
||||||
if refresher, ok := remote_.(remote.Refresher); ok {
|
if refresher, ok := remote_.(remote.Refresher); ok {
|
||||||
ok, _ := refresher.Refresh(sender)
|
ok, _ := refresher.Refresh(sender)
|
||||||
|
@ -184,8 +187,12 @@ func PostHook(c *gin.Context) {
|
||||||
// if the sender does not have push access to the
|
// if the sender does not have push access to the
|
||||||
// repository the pull request should be blocked.
|
// repository the pull request should be blocked.
|
||||||
perm, perr := remote_.Perm(sender, repo.Owner, repo.Name)
|
perm, perr := remote_.Perm(sender, repo.Owner, repo.Name)
|
||||||
if perr != nil || perm.Push == false {
|
if perr == nil && perm.Push == true {
|
||||||
|
build.Status = model.StatusPending
|
||||||
|
logrus.Debugf("sender %s has push access: status: accepted", sender.Login)
|
||||||
|
} else {
|
||||||
build.Status = model.StatusBlocked
|
build.Status = model.StatusBlocked
|
||||||
|
logrus.Debugf("sender %s does not have push access: status: blocked", sender.Login)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue