mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-02-04 18:21:06 +02:00
add support for CI_COMMIT_PULLREQUEST_TITLE
This commit is contained in:
parent
a5448360b6
commit
b7caae6163
@ -73,6 +73,7 @@ This is the reference list of all environment variables available to your pipeli
|
||||
| `CI_COMMIT_TAG` | commit tag name (empty if event is not `tag`) | `v1.10.3` |
|
||||
| `CI_COMMIT_PULL_REQUEST` | commit pull request number (empty if event is not `pull_request` or `pull_request_closed`) | `1` |
|
||||
| `CI_COMMIT_PULL_REQUEST_LABELS` | labels assigned to pull request (empty if event is not `pull_request` or `pull_request_closed`) | `server` |
|
||||
| `CI_COMMIT_PULL_REQUEST_TITLE` | commit pull request title (empty if event is not `pull_request` or `pull_request_closed`) | `server` |
|
||||
| `CI_COMMIT_MESSAGE` | commit message | `Initial commit` |
|
||||
| `CI_COMMIT_AUTHOR` | commit author username | `john-doe` |
|
||||
| `CI_COMMIT_AUTHOR_EMAIL` | commit author email address | `john-doe@example.com` |
|
||||
|
@ -76,6 +76,7 @@ func (m *Metadata) Environ() map[string]string {
|
||||
"CI_COMMIT_AUTHOR_AVATAR": m.Curr.Commit.Author.Avatar,
|
||||
"CI_COMMIT_TAG": "", // will be set if event is tag
|
||||
"CI_COMMIT_PULL_REQUEST": "", // will be set if event is pull_request or pull_request_closed
|
||||
"CI_COMMIT_PULL_REQUEST_TITLE": "", // will be set if event is pull_request or pull_request_closed
|
||||
"CI_COMMIT_PULL_REQUEST_LABELS": "", // will be set if event is pull_request or pull_request_closed
|
||||
|
||||
"CI_PIPELINE_NUMBER": strconv.FormatInt(m.Curr.Number, 10),
|
||||
@ -137,6 +138,7 @@ func (m *Metadata) Environ() map[string]string {
|
||||
}
|
||||
if m.Curr.Event == EventPull || m.Curr.Event == EventPullClosed {
|
||||
params["CI_COMMIT_PULL_REQUEST"] = pullRegexp.FindString(m.Curr.Commit.Ref)
|
||||
params["CI_COMMIT_PULL_REQUEST_TITLE"] = pullRegexp.FindString(m.Curr.Commit.PullRequestTitle)
|
||||
params["CI_COMMIT_PULL_REQUEST_LABELS"] = strings.Join(m.Curr.Commit.PullRequestLabels, ",")
|
||||
}
|
||||
|
||||
|
@ -68,6 +68,7 @@ type (
|
||||
Author Author `json:"author,omitempty"`
|
||||
ChangedFiles []string `json:"changed_files,omitempty"`
|
||||
PullRequestLabels []string `json:"labels,omitempty"`
|
||||
PullRequestTitle string `json:"title,omitempty"`
|
||||
IsPrerelease bool `json:"is_prerelease,omitempty"`
|
||||
}
|
||||
|
||||
|
@ -176,13 +176,14 @@ func convertPullHook(from *internal.PullRequestHook) *model.Pipeline {
|
||||
from.PullRequest.Source.Branch.Name,
|
||||
from.PullRequest.Dest.Branch.Name,
|
||||
),
|
||||
ForgeURL: from.PullRequest.Links.HTML.Href,
|
||||
Branch: from.PullRequest.Source.Branch.Name,
|
||||
Message: from.PullRequest.Title,
|
||||
Avatar: from.Actor.Links.Avatar.Href,
|
||||
Author: from.Actor.Login,
|
||||
Sender: from.Actor.Login,
|
||||
Timestamp: from.PullRequest.Updated.UTC().Unix(),
|
||||
ForgeURL: from.PullRequest.Links.HTML.Href,
|
||||
Branch: from.PullRequest.Source.Branch.Name,
|
||||
Message: from.PullRequest.Title,
|
||||
PullRequestTitle: from.PullRequest.Title,
|
||||
Avatar: from.Actor.Links.Avatar.Href,
|
||||
Author: from.Actor.Login,
|
||||
Sender: from.Actor.Login,
|
||||
Timestamp: from.PullRequest.Updated.UTC().Unix(),
|
||||
}
|
||||
|
||||
if from.PullRequest.State == stateClosed {
|
||||
|
@ -145,6 +145,7 @@ func Test_helper(t *testing.T) {
|
||||
g.Assert(pipeline.Ref).Equal("refs/pull-requests/1/from")
|
||||
g.Assert(pipeline.Refspec).Equal("change:main")
|
||||
g.Assert(pipeline.Message).Equal(hook.PullRequest.Title)
|
||||
g.Assert(pipeline.PullRequestTitle).Equal(hook.PullRequest.Title)
|
||||
g.Assert(pipeline.Timestamp).Equal(hook.PullRequest.Updated.Unix())
|
||||
})
|
||||
|
||||
|
@ -171,6 +171,7 @@ func pipelineFromPullRequest(hook *pullRequestHook) *model.Pipeline {
|
||||
hook.PullRequest.Base.Ref,
|
||||
),
|
||||
PullRequestLabels: convertLabels(hook.PullRequest.Labels),
|
||||
PullRequestTitle: hook.PullRequest.Title,
|
||||
}
|
||||
|
||||
return pipeline
|
||||
|
@ -217,6 +217,7 @@ func TestForgejoParser(t *testing.T) {
|
||||
Email: "gordon@golang.org",
|
||||
ForgeURL: "http://forgejo.golang.org/gordon/hello-world/pull/1",
|
||||
PullRequestLabels: []string{},
|
||||
PullRequestTitle: "Update the README with new information",
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -259,6 +260,7 @@ func TestForgejoParser(t *testing.T) {
|
||||
"Kind/Bug",
|
||||
"Kind/Security",
|
||||
},
|
||||
PullRequestTitle: "New Pull",
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -297,6 +299,7 @@ func TestForgejoParser(t *testing.T) {
|
||||
Email: "anbraten@sender.forgejo.com",
|
||||
ForgeURL: "https://forgejo.com/anbraten/test-repo/pulls/1",
|
||||
PullRequestLabels: []string{},
|
||||
PullRequestTitle: "Adjust file",
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -335,6 +338,7 @@ func TestForgejoParser(t *testing.T) {
|
||||
Email: "anbraten@noreply.forgejo.com",
|
||||
ForgeURL: "https://forgejo.com/anbraten/test-repo/pulls/1",
|
||||
PullRequestLabels: []string{},
|
||||
PullRequestTitle: "Adjust file",
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -172,6 +172,7 @@ func pipelineFromPullRequest(hook *pullRequestHook) *model.Pipeline {
|
||||
hook.PullRequest.Base.Ref,
|
||||
),
|
||||
PullRequestLabels: convertLabels(hook.PullRequest.Labels),
|
||||
PullRequestTitle: hook.PullRequest.Title,
|
||||
}
|
||||
|
||||
return pipeline
|
||||
|
@ -218,6 +218,7 @@ func TestGiteaParser(t *testing.T) {
|
||||
Email: "gordon@golang.org",
|
||||
ForgeURL: "http://gitea.golang.org/gordon/hello-world/pull/1",
|
||||
PullRequestLabels: []string{},
|
||||
PullRequestTitle: "Update the README with new information",
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -260,6 +261,7 @@ func TestGiteaParser(t *testing.T) {
|
||||
"Kind/Bug",
|
||||
"Kind/Security",
|
||||
},
|
||||
PullRequestTitle: "New Pull",
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -298,6 +300,7 @@ func TestGiteaParser(t *testing.T) {
|
||||
Email: "anbraten@sender.gitea.com",
|
||||
ForgeURL: "https://gitea.com/anbraten/test-repo/pulls/1",
|
||||
PullRequestLabels: []string{},
|
||||
PullRequestTitle: "Adjust file",
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -336,6 +339,7 @@ func TestGiteaParser(t *testing.T) {
|
||||
Email: "anbraten@noreply.gitea.com",
|
||||
ForgeURL: "https://gitea.com/anbraten/test-repo/pulls/1",
|
||||
PullRequestLabels: []string{},
|
||||
PullRequestTitle: "Adjust file",
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -173,6 +173,7 @@ func parsePullHook(hook *github.PullRequestEvent, merge bool) (*github.PullReque
|
||||
hook.GetPullRequest().GetBase().GetRef(),
|
||||
),
|
||||
PullRequestLabels: convertLabels(hook.GetPullRequest().Labels),
|
||||
PullRequestTitle: hook.GetPullRequest().GetTitle(),
|
||||
}
|
||||
if merge {
|
||||
pipeline.Ref = fmt.Sprintf(mergeRefs, hook.GetPullRequest().GetNumber())
|
||||
|
@ -89,6 +89,7 @@ func Test_parser(t *testing.T) {
|
||||
g.Assert(b).IsNotNil()
|
||||
g.Assert(p).IsNotNil()
|
||||
g.Assert(b.Event).Equal(model.EventPull)
|
||||
g.Assert(b.PullRequestTitle).Equal(b.Message)
|
||||
})
|
||||
g.It("should handle a PR closed hook when PR got closed", func() {
|
||||
req := testHookRequest([]byte(fixtures.HookPullRequestClosed), hookPull)
|
||||
|
@ -138,6 +138,7 @@ func convertMergeRequestHook(hook *gitlab.MergeEvent, req *http.Request) (int, *
|
||||
pipeline.Title = obj.Title
|
||||
pipeline.ForgeURL = obj.URL
|
||||
pipeline.PullRequestLabels = convertLabels(hook.Labels)
|
||||
pipeline.PullRequestTitle = obj.Title
|
||||
|
||||
return obj.IID, repo, pipeline, nil
|
||||
}
|
||||
|
@ -51,6 +51,7 @@ type Pipeline struct {
|
||||
ChangedFiles []string `json:"changed_files,omitempty" xorm:"LONGTEXT 'changed_files'"`
|
||||
AdditionalVariables map[string]string `json:"variables,omitempty" xorm:"json 'additional_variables'"`
|
||||
PullRequestLabels []string `json:"pr_labels,omitempty" xorm:"json 'pr_labels'"`
|
||||
PullRequestTitle string `json:"pr_title,omitempty" xorm:"json 'pr_title'"`
|
||||
IsPrerelease bool `json:"is_prerelease,omitempty" xorm:"is_prerelease"`
|
||||
} // @name Pipeline
|
||||
|
||||
|
@ -131,6 +131,7 @@ func metadataPipelineFromModelPipeline(pipeline *model.Pipeline, includeParent b
|
||||
},
|
||||
ChangedFiles: pipeline.ChangedFiles,
|
||||
PullRequestLabels: pipeline.PullRequestLabels,
|
||||
PullRequestTitle: pipeline.PullRequestTitle,
|
||||
IsPrerelease: pipeline.IsPrerelease,
|
||||
},
|
||||
Cron: cron,
|
||||
|
@ -45,7 +45,7 @@ func TestMetadataFromStruct(t *testing.T) {
|
||||
expectedEnviron: map[string]string{
|
||||
"CI": "woodpecker",
|
||||
"CI_COMMIT_AUTHOR": "", "CI_COMMIT_AUTHOR_AVATAR": "", "CI_COMMIT_AUTHOR_EMAIL": "", "CI_COMMIT_BRANCH": "",
|
||||
"CI_COMMIT_MESSAGE": "", "CI_COMMIT_PULL_REQUEST": "", "CI_COMMIT_PULL_REQUEST_LABELS": "", "CI_COMMIT_REF": "", "CI_COMMIT_REFSPEC": "", "CI_COMMIT_SHA": "", "CI_COMMIT_SOURCE_BRANCH": "",
|
||||
"CI_COMMIT_MESSAGE": "", "CI_COMMIT_PULL_REQUEST": "", "CI_COMMIT_PULL_REQUEST_TITLE": "", "CI_COMMIT_PULL_REQUEST_LABELS": "", "CI_COMMIT_REF": "", "CI_COMMIT_REFSPEC": "", "CI_COMMIT_SHA": "", "CI_COMMIT_SOURCE_BRANCH": "",
|
||||
"CI_COMMIT_TAG": "", "CI_COMMIT_TARGET_BRANCH": "", "CI_FORGE_TYPE": "", "CI_FORGE_URL": "",
|
||||
"CI_PIPELINE_CREATED": "0", "CI_PIPELINE_DEPLOY_TARGET": "", "CI_PIPELINE_DEPLOY_TASK": "", "CI_PIPELINE_EVENT": "", "CI_PIPELINE_FILES": "[]", "CI_PIPELINE_NUMBER": "0",
|
||||
"CI_PIPELINE_PARENT": "0", "CI_PIPELINE_STARTED": "0", "CI_PIPELINE_URL": "/repos/0/pipeline/0", "CI_PIPELINE_FORGE_URL": "",
|
||||
@ -80,7 +80,7 @@ func TestMetadataFromStruct(t *testing.T) {
|
||||
expectedEnviron: map[string]string{
|
||||
"CI": "woodpecker",
|
||||
"CI_COMMIT_AUTHOR": "", "CI_COMMIT_AUTHOR_AVATAR": "", "CI_COMMIT_AUTHOR_EMAIL": "", "CI_COMMIT_BRANCH": "",
|
||||
"CI_COMMIT_MESSAGE": "", "CI_COMMIT_PULL_REQUEST": "", "CI_COMMIT_PULL_REQUEST_LABELS": "", "CI_COMMIT_REF": "", "CI_COMMIT_REFSPEC": "", "CI_COMMIT_SHA": "", "CI_COMMIT_SOURCE_BRANCH": "",
|
||||
"CI_COMMIT_MESSAGE": "", "CI_COMMIT_PULL_REQUEST": "", "CI_COMMIT_PULL_REQUEST_TITLE": "", "CI_COMMIT_PULL_REQUEST_LABELS": "", "CI_COMMIT_REF": "", "CI_COMMIT_REFSPEC": "", "CI_COMMIT_SHA": "", "CI_COMMIT_SOURCE_BRANCH": "",
|
||||
"CI_COMMIT_TAG": "", "CI_COMMIT_TARGET_BRANCH": "", "CI_FORGE_TYPE": "gitea", "CI_FORGE_URL": "https://gitea.com",
|
||||
"CI_PIPELINE_CREATED": "0", "CI_PIPELINE_DEPLOY_TARGET": "", "CI_PIPELINE_DEPLOY_TASK": "", "CI_PIPELINE_EVENT": "", "CI_PIPELINE_FILES": `["test.go","markdown file.md"]`,
|
||||
"CI_PIPELINE_NUMBER": "3", "CI_PIPELINE_PARENT": "0", "CI_PIPELINE_STARTED": "0", "CI_PIPELINE_URL": "https://example.com/repos/0/pipeline/3", "CI_PIPELINE_FORGE_URL": "",
|
||||
|
Loading…
x
Reference in New Issue
Block a user