mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-04-11 06:14:11 +00:00
if commit already exist close https://codeberg.org/Codeberg-CI/feedback/issues/52
This commit is contained in:
parent
ba4de28590
commit
9e3dceda48
4 changed files with 182 additions and 8 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"`
|
||||
|
|
Loading…
Reference in a new issue