mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-23 00:46:30 +00:00
Extract commit message from branch creation (#1150)
if commit already exist close https://codeberg.org/Codeberg-CI/feedback/issues/52
This commit is contained in:
parent
3f2af06bbc
commit
4afddc2821
5 changed files with 183 additions and 10 deletions
|
@ -69,6 +69,155 @@ const HookPush = `
|
|||
}
|
||||
`
|
||||
|
||||
// HookPushBranch is a sample Gitea push hook where a new branch was created from an existing commit
|
||||
const HookPushBranch = `
|
||||
{
|
||||
"ref": "refs/heads/fdsafdsa",
|
||||
"before": "0000000000000000000000000000000000000000",
|
||||
"after": "28c3613ae62640216bea5e7dc71aa65356e4298b",
|
||||
"compare_url": "https://codeberg.org/meisam/woodpecktester/compare/master...28c3613ae62640216bea5e7dc71aa65356e4298b",
|
||||
"commits": [],
|
||||
"head_commit": {
|
||||
"id": "28c3613ae62640216bea5e7dc71aa65356e4298b",
|
||||
"message": "Delete '.woodpecker/.check.yml'\n",
|
||||
"url": "https://codeberg.org/meisam/woodpecktester/commit/28c3613ae62640216bea5e7dc71aa65356e4298b",
|
||||
"author": {
|
||||
"name": "meisam",
|
||||
"email": "meisam@noreply.codeberg.org",
|
||||
"username": "meisam"
|
||||
},
|
||||
"committer": {
|
||||
"name": "meisam",
|
||||
"email": "meisam@noreply.codeberg.org",
|
||||
"username": "meisam"
|
||||
},
|
||||
"verification": null,
|
||||
"timestamp": "2022-07-12T21:09:27+02:00",
|
||||
"added": [],
|
||||
"removed": [
|
||||
".woodpecker/.check.yml"
|
||||
],
|
||||
"modified": []
|
||||
},
|
||||
"repository": {
|
||||
"id": 50820,
|
||||
"owner": {
|
||||
"id": 14844,
|
||||
"login": "meisam",
|
||||
"full_name": "",
|
||||
"email": "meisam@noreply.codeberg.org",
|
||||
"avatar_url": "https://codeberg.org/avatars/96512da76a14cf44e0bb32d1640e878e",
|
||||
"language": "",
|
||||
"is_admin": false,
|
||||
"last_login": "0001-01-01T00:00:00Z",
|
||||
"created": "2020-10-08T11:19:12+02:00",
|
||||
"restricted": false,
|
||||
"active": false,
|
||||
"prohibit_login": false,
|
||||
"location": "",
|
||||
"website": "",
|
||||
"description": "Materials engineer, physics enthusiast, large collection of the bad programming habits, always happy to fix the old ones and make new mistakes!",
|
||||
"visibility": "public",
|
||||
"followers_count": 0,
|
||||
"following_count": 0,
|
||||
"starred_repos_count": 0,
|
||||
"username": "meisam"
|
||||
},
|
||||
"name": "woodpecktester",
|
||||
"full_name": "meisam/woodpecktester",
|
||||
"description": "Just for testing the Woodpecker CI and reporting bugs",
|
||||
"empty": false,
|
||||
"private": false,
|
||||
"fork": false,
|
||||
"template": false,
|
||||
"parent": null,
|
||||
"mirror": false,
|
||||
"size": 367,
|
||||
"language": "",
|
||||
"languages_url": "https://codeberg.org/api/v1/repos/meisam/woodpecktester/languages",
|
||||
"html_url": "https://codeberg.org/meisam/woodpecktester",
|
||||
"ssh_url": "git@codeberg.org:meisam/woodpecktester.git",
|
||||
"clone_url": "https://codeberg.org/meisam/woodpecktester.git",
|
||||
"original_url": "",
|
||||
"website": "",
|
||||
"stars_count": 0,
|
||||
"forks_count": 0,
|
||||
"watchers_count": 1,
|
||||
"open_issues_count": 0,
|
||||
"open_pr_counter": 0,
|
||||
"release_counter": 0,
|
||||
"default_branch": "master",
|
||||
"archived": false,
|
||||
"created_at": "2022-07-04T00:34:39+02:00",
|
||||
"updated_at": "2022-07-24T20:31:29+02:00",
|
||||
"permissions": {
|
||||
"admin": true,
|
||||
"push": true,
|
||||
"pull": true
|
||||
},
|
||||
"has_issues": true,
|
||||
"internal_tracker": {
|
||||
"enable_time_tracker": true,
|
||||
"allow_only_contributors_to_track_time": true,
|
||||
"enable_issue_dependencies": true
|
||||
},
|
||||
"has_wiki": true,
|
||||
"has_pull_requests": true,
|
||||
"has_projects": true,
|
||||
"ignore_whitespace_conflicts": false,
|
||||
"allow_merge_commits": true,
|
||||
"allow_rebase": true,
|
||||
"allow_rebase_explicit": true,
|
||||
"allow_squash_merge": true,
|
||||
"default_merge_style": "merge",
|
||||
"avatar_url": "",
|
||||
"internal": false,
|
||||
"mirror_interval": "",
|
||||
"mirror_updated": "0001-01-01T00:00:00Z",
|
||||
"repo_transfer": null
|
||||
},
|
||||
"pusher": {
|
||||
"id": 2628,
|
||||
"login": "6543",
|
||||
"full_name": "",
|
||||
"email": "6543@obermui.de",
|
||||
"avatar_url": "https://codeberg.org/avatars/09a234c768cb9bca78f6b2f82d6af173",
|
||||
"language": "",
|
||||
"is_admin": false,
|
||||
"last_login": "0001-01-01T00:00:00Z",
|
||||
"created": "2019-10-12T05:05:49+02:00",
|
||||
"restricted": false,
|
||||
"active": false,
|
||||
"prohibit_login": false,
|
||||
"location": "",
|
||||
"visibility": "public",
|
||||
"followers_count": 22,
|
||||
"following_count": 16,
|
||||
"starred_repos_count": 55,
|
||||
"username": "6543"
|
||||
},
|
||||
"sender": {
|
||||
"id": 2628,
|
||||
"login": "6543",
|
||||
"full_name": "",
|
||||
"email": "6543@obermui.de",
|
||||
"avatar_url": "https://codeberg.org/avatars/09a234c768cb9bca78f6b2f82d6af173",
|
||||
"language": "",
|
||||
"is_admin": false,
|
||||
"last_login": "0001-01-01T00:00:00Z",
|
||||
"created": "2019-10-12T05:05:49+02:00",
|
||||
"restricted": false,
|
||||
"active": false,
|
||||
"prohibit_login": false,
|
||||
"visibility": "public",
|
||||
"followers_count": 22,
|
||||
"following_count": 16,
|
||||
"starred_repos_count": 55,
|
||||
"username": "6543"
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
// HookPushTag is a sample Gitea tag hook
|
||||
const HookPushTag = `{
|
||||
"sha": "ef98532add3b2feb7a137426bba1248724367df5",
|
||||
|
|
|
@ -84,6 +84,8 @@ func buildFromPush(hook *pushHook) *model.Build {
|
|||
link := hook.Compare
|
||||
if len(hook.Commits) > 0 {
|
||||
message = hook.Commits[0].Message
|
||||
} else {
|
||||
message = hook.HeadCommit.Message
|
||||
}
|
||||
|
||||
if len(hook.Commits) == 1 {
|
||||
|
@ -115,6 +117,10 @@ func getChangedFilesFromPushHook(hook *pushHook) []string {
|
|||
files = append(files, c.Modified...)
|
||||
}
|
||||
|
||||
files = append(files, hook.HeadCommit.Added...)
|
||||
files = append(files, hook.HeadCommit.Removed...)
|
||||
files = append(files, hook.HeadCommit.Modified...)
|
||||
|
||||
return utils.DedupStrings(files)
|
||||
}
|
||||
|
||||
|
|
|
@ -53,5 +53,20 @@ func Test_parser(t *testing.T) {
|
|||
g.Assert(utils.EqualStringSlice(b.ChangedFiles, []string{"CHANGELOG.md", "app/controller/application.rb"})).IsTrue()
|
||||
})
|
||||
})
|
||||
g.Describe("given a push hook from an branch creation", func() {
|
||||
g.It("should extract repository and build details", func() {
|
||||
buf := bytes.NewBufferString(fixtures.HookPushBranch)
|
||||
req, _ := http.NewRequest("POST", "/hook", buf)
|
||||
req.Header = http.Header{}
|
||||
req.Header.Set(hookEvent, hookPush)
|
||||
r, b, err := parseHook(req)
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(r).IsNotNil()
|
||||
g.Assert(b).IsNotNil()
|
||||
g.Assert(b.Event).Equal(model.EventPush)
|
||||
g.Assert(b.Message).Equal("Delete '.woodpecker/.check.yml'\n")
|
||||
g.Assert(b.ChangedFiles).Equal([]string{".woodpecker/.check.yml"})
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -14,6 +14,15 @@
|
|||
|
||||
package gitea
|
||||
|
||||
type commit struct {
|
||||
ID string `json:"id"`
|
||||
Message string `json:"message"`
|
||||
URL string `json:"url"`
|
||||
Added []string `json:"added"`
|
||||
Removed []string `json:"removed"`
|
||||
Modified []string `json:"modified"`
|
||||
}
|
||||
|
||||
type pushHook struct {
|
||||
Sha string `json:"sha"`
|
||||
Ref string `json:"ref"`
|
||||
|
@ -42,14 +51,9 @@ type pushHook struct {
|
|||
} `json:"owner"`
|
||||
} `json:"repository"`
|
||||
|
||||
Commits []struct {
|
||||
ID string `json:"id"`
|
||||
Message string `json:"message"`
|
||||
URL string `json:"url"`
|
||||
Added []string `json:"added"`
|
||||
Removed []string `json:"removed"`
|
||||
Modified []string `json:"modified"`
|
||||
} `json:"commits"`
|
||||
Commits []commit `json:"commits"`
|
||||
|
||||
HeadCommit commit `json:"head_commit"`
|
||||
|
||||
Sender struct {
|
||||
ID int64 `json:"id"`
|
||||
|
|
3
web/components.d.ts
vendored
3
web/components.d.ts
vendored
|
@ -36,7 +36,6 @@ declare module '@vue/runtime-core' {
|
|||
IEntypoDotsTwoVertical: typeof import('~icons/entypo/dots-two-vertical')['default']
|
||||
IGgTrash: typeof import('~icons/gg/trash')['default']
|
||||
IIcBaselineDarkMode: typeof import('~icons/ic/baseline-dark-mode')['default']
|
||||
IIcBaselineDownload: typeof import('~icons/ic/baseline-download')['default']
|
||||
IIcBaselineDownloadForOffline: typeof import('~icons/ic/baseline-download-for-offline')['default']
|
||||
IIcBaselineEdit: typeof import('~icons/ic/baseline-edit')['default']
|
||||
IIcBaselineFileDownload: typeof import('~icons/ic/baseline-file-download')['default']
|
||||
|
@ -53,10 +52,10 @@ declare module '@vue/runtime-core' {
|
|||
IMdiFormatListBulleted: typeof import('~icons/mdi/format-list-bulleted')['default']
|
||||
IMdiGithub: typeof import('~icons/mdi/github')['default']
|
||||
IMdiLoading: typeof import('~icons/mdi/loading')['default']
|
||||
IMdiSync: typeof import('~icons/mdi/sync')['default']
|
||||
IMdiSourceBranch: typeof import('~icons/mdi/source-branch')['default']
|
||||
IMdisourceCommit: typeof import('~icons/mdi/source-commit')['default']
|
||||
IMdiSourcePull: typeof import('~icons/mdi/source-pull')['default']
|
||||
IMdiSync: typeof import('~icons/mdi/sync')['default']
|
||||
IMdiTagOutline: typeof import('~icons/mdi/tag-outline')['default']
|
||||
InputField: typeof import('./src/components/form/InputField.vue')['default']
|
||||
IOcticonSkip24: typeof import('~icons/octicon/skip24')['default']
|
||||
|
|
Loading…
Reference in a new issue