Skip to content

feat: add support for branch update for gitness #283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
"Avatar": ""
},
"Committer": {
"Name": "",
"Email": "",
"Name": "Admin",
"Email": "[email protected]",
"Date": "0001-01-01T00:00:00Z",
"Login": "",
"Avatar": ""
Expand Down
50 changes: 50 additions & 0 deletions scm/driver/harness/testdata/webhooks/branch_updated.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"trigger": "branch_updated",
"repo": {
"id": 68,
"path": "vpCkHKsDSxK9_KYfjCTMKA/default/Repo_With_PR_checks/abhinav-git-sync",
"uid": "abhinav-git-sync",
"default_branch": "master",
"git_url": "https://git.harness.io/vpCkHKsDSxK9_KYfjCTMKA/default/Repo_With_PR_checks/abhinav-git-sync.git"
},
"principal": {
"id": 59,
"uid": "ec9UfvFwTf663F47Hlqxbg",
"display_name": "[email protected]",
"email": "[email protected]",
"type": "user",
"created": 1697617589873,
"updated": 1697617589873
},
"ref": {
"name": "refs/heads/master",
"repo": {
"id": 68,
"path": "vpCkHKsDSxK9_KYfjCTMKA/default/Repo_With_PR_checks/abhinav-git-sync",
"uid": "abhinav-git-sync",
"default_branch": "master",
"git_url": "https://git.harness.io/vpCkHKsDSxK9_KYfjCTMKA/default/Repo_With_PR_checks/abhinav-git-sync.git"
}
},
"sha": "92e21bfcddc1418079cddbb518ad6fd72917798a",
"commit": {
"sha": "92e21bfcddc1418079cddbb518ad6fd72917798a",
"message": "Create asdsad (#2)",
"author": {
"identity": {
"name": "[email protected]",
"email": "[email protected]"
},
"when": "2023-12-05T11:59:39Z"
},
"committer": {
"identity": {
"name": "Harness",
"email": "[email protected]"
},
"when": "2023-12-05T11:59:39Z"
}
},
"old_sha": "a273c385628167932e10caaa58e12550c491f241",
"forced": false
}
46 changes: 46 additions & 0 deletions scm/driver/harness/testdata/webhooks/branch_updated.json.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"Ref": "92e21bfcddc1418079cddbb518ad6fd72917798a",
"Before": "a273c385628167932e10caaa58e12550c491f241",
"After": "92e21bfcddc1418079cddbb518ad6fd72917798a",
"Repo": {
"ID": "68",
"Namespace": "",
"Name": "abhinav-git-sync",
"Perm": null,
"Branch": "master",
"Private": false,
"Clone": "https://git.harness.io/vpCkHKsDSxK9_KYfjCTMKA/default/Repo_With_PR_checks/abhinav-git-sync.git",
"CloneSSH": "",
"Link": "https://git.harness.io/vpCkHKsDSxK9_KYfjCTMKA/default/Repo_With_PR_checks/abhinav-git-sync.git",
"Created": "0001-01-01T00:00:00Z",
"Updated": "0001-01-01T00:00:00Z"
},
"Commit": {
"Sha": "92e21bfcddc1418079cddbb518ad6fd72917798a",
"Message": "Create asdsad (#2)",
"Author": {
"Name": "[email protected]",
"Email": "[email protected]",
"Date" : "0001-01-01T00:00:00Z",
"Login": "",
"Avatar": ""
},
"Committer": {
"Name": "Harness",
"Email": "[email protected]",
"Date": "0001-01-01T00:00:00Z",
"Login": "",
"Avatar": ""
},
"Link": ""
},
"Sender": {
"ID": "ec9UfvFwTf663F47Hlqxbg",
"Login": "ec9UfvFwTf663F47Hlqxbg",
"Name": "[email protected]",
"Email": "[email protected]",
"Avatar": "",
"Created": "2023-10-18T13:56:29.873+05:30",
"Updated": "2023-10-18T13:56:29.873+05:30"
}
}
6 changes: 5 additions & 1 deletion scm/driver/harness/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (s *webhookService) Parse(req *http.Request, fn scm.SecretFunc) (scm.Webhoo
// hook, err = s.parseDeleteHook(data)
// case "issues":
// hook, err = s.parseIssueHook(data)
case "branch_created":
case "branch_created", "branch_updated":
hook, err = s.parsePushHook(data)
case "pullreq_created", "pullreq_reopened", "pullreq_branch_updated":
hook, err = s.parsePullRequestHook(data)
Expand Down Expand Up @@ -230,6 +230,10 @@ func convertPushHook(src *pushHook) *scm.PushHook {
Name: src.Commit.Author.Identity.Name,
Email: src.Commit.Author.Identity.Email,
},
Committer: scm.Signature{
Name: src.Commit.Committer.Identity.Name,
Email: src.Commit.Committer.Identity.Email,
},
},
Sender: convertUser(src.Principal),
}
Expand Down
7 changes: 7 additions & 0 deletions scm/driver/harness/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ func TestWebhooks(t *testing.T) {
after: "testdata/webhooks/branch_create.json.golden",
obj: new(scm.PushHook),
},
// push branch update
{
event: "branch_updated",
before: "testdata/webhooks/branch_updated.json",
after: "testdata/webhooks/branch_updated.json.golden",
obj: new(scm.PushHook),
},
//
// pull request events
//
Expand Down