Skip to content

Commit a802ce1

Browse files
feat: add support for branch update for gitness (#283)
1 parent 1050b3d commit a802ce1

File tree

5 files changed

+110
-3
lines changed

5 files changed

+110
-3
lines changed

scm/driver/harness/testdata/webhooks/branch_create.json.golden

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
"Avatar": ""
2727
},
2828
"Committer": {
29-
"Name": "",
30-
"Email": "",
29+
"Name": "Admin",
30+
"Email": "[email protected]",
3131
"Date": "0001-01-01T00:00:00Z",
3232
"Login": "",
3333
"Avatar": ""
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"trigger": "branch_updated",
3+
"repo": {
4+
"id": 68,
5+
"path": "vpCkHKsDSxK9_KYfjCTMKA/default/Repo_With_PR_checks/abhinav-git-sync",
6+
"uid": "abhinav-git-sync",
7+
"default_branch": "master",
8+
"git_url": "https://git.harness.io/vpCkHKsDSxK9_KYfjCTMKA/default/Repo_With_PR_checks/abhinav-git-sync.git"
9+
},
10+
"principal": {
11+
"id": 59,
12+
"uid": "ec9UfvFwTf663F47Hlqxbg",
13+
"display_name": "[email protected]",
14+
"email": "[email protected]",
15+
"type": "user",
16+
"created": 1697617589873,
17+
"updated": 1697617589873
18+
},
19+
"ref": {
20+
"name": "refs/heads/master",
21+
"repo": {
22+
"id": 68,
23+
"path": "vpCkHKsDSxK9_KYfjCTMKA/default/Repo_With_PR_checks/abhinav-git-sync",
24+
"uid": "abhinav-git-sync",
25+
"default_branch": "master",
26+
"git_url": "https://git.harness.io/vpCkHKsDSxK9_KYfjCTMKA/default/Repo_With_PR_checks/abhinav-git-sync.git"
27+
}
28+
},
29+
"sha": "92e21bfcddc1418079cddbb518ad6fd72917798a",
30+
"commit": {
31+
"sha": "92e21bfcddc1418079cddbb518ad6fd72917798a",
32+
"message": "Create asdsad (#2)",
33+
"author": {
34+
"identity": {
35+
"name": "[email protected]",
36+
"email": "[email protected]"
37+
},
38+
"when": "2023-12-05T11:59:39Z"
39+
},
40+
"committer": {
41+
"identity": {
42+
"name": "Harness",
43+
"email": "[email protected]"
44+
},
45+
"when": "2023-12-05T11:59:39Z"
46+
}
47+
},
48+
"old_sha": "a273c385628167932e10caaa58e12550c491f241",
49+
"forced": false
50+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"Ref": "92e21bfcddc1418079cddbb518ad6fd72917798a",
3+
"Before": "a273c385628167932e10caaa58e12550c491f241",
4+
"After": "92e21bfcddc1418079cddbb518ad6fd72917798a",
5+
"Repo": {
6+
"ID": "68",
7+
"Namespace": "",
8+
"Name": "abhinav-git-sync",
9+
"Perm": null,
10+
"Branch": "master",
11+
"Private": false,
12+
"Clone": "https://git.harness.io/vpCkHKsDSxK9_KYfjCTMKA/default/Repo_With_PR_checks/abhinav-git-sync.git",
13+
"CloneSSH": "",
14+
"Link": "https://git.harness.io/vpCkHKsDSxK9_KYfjCTMKA/default/Repo_With_PR_checks/abhinav-git-sync.git",
15+
"Created": "0001-01-01T00:00:00Z",
16+
"Updated": "0001-01-01T00:00:00Z"
17+
},
18+
"Commit": {
19+
"Sha": "92e21bfcddc1418079cddbb518ad6fd72917798a",
20+
"Message": "Create asdsad (#2)",
21+
"Author": {
22+
"Name": "[email protected]",
23+
"Email": "[email protected]",
24+
"Date" : "0001-01-01T00:00:00Z",
25+
"Login": "",
26+
"Avatar": ""
27+
},
28+
"Committer": {
29+
"Name": "Harness",
30+
"Email": "[email protected]",
31+
"Date": "0001-01-01T00:00:00Z",
32+
"Login": "",
33+
"Avatar": ""
34+
},
35+
"Link": ""
36+
},
37+
"Sender": {
38+
"ID": "ec9UfvFwTf663F47Hlqxbg",
39+
"Login": "ec9UfvFwTf663F47Hlqxbg",
40+
"Name": "[email protected]",
41+
"Email": "[email protected]",
42+
"Avatar": "",
43+
"Created": "2023-10-18T13:56:29.873+05:30",
44+
"Updated": "2023-10-18T13:56:29.873+05:30"
45+
}
46+
}

scm/driver/harness/webhook.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (s *webhookService) Parse(req *http.Request, fn scm.SecretFunc) (scm.Webhoo
3737
// hook, err = s.parseDeleteHook(data)
3838
// case "issues":
3939
// hook, err = s.parseIssueHook(data)
40-
case "branch_created":
40+
case "branch_created", "branch_updated":
4141
hook, err = s.parsePushHook(data)
4242
case "pullreq_created", "pullreq_reopened", "pullreq_branch_updated":
4343
hook, err = s.parsePullRequestHook(data)
@@ -230,6 +230,10 @@ func convertPushHook(src *pushHook) *scm.PushHook {
230230
Name: src.Commit.Author.Identity.Name,
231231
Email: src.Commit.Author.Identity.Email,
232232
},
233+
Committer: scm.Signature{
234+
Name: src.Commit.Committer.Identity.Name,
235+
Email: src.Commit.Committer.Identity.Email,
236+
},
233237
},
234238
Sender: convertUser(src.Principal),
235239
}

scm/driver/harness/webhook_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ func TestWebhooks(t *testing.T) {
3333
after: "testdata/webhooks/branch_create.json.golden",
3434
obj: new(scm.PushHook),
3535
},
36+
// push branch update
37+
{
38+
event: "branch_updated",
39+
before: "testdata/webhooks/branch_updated.json",
40+
after: "testdata/webhooks/branch_updated.json.golden",
41+
obj: new(scm.PushHook),
42+
},
3643
//
3744
// pull request events
3845
//

0 commit comments

Comments
 (0)