@@ -519,6 +519,163 @@ const (
519519 }
520520}`
521521
522+ samplePullRequestApprovedData = `{
523+ "date": "2024-08-08T14:58:09+0200",
524+ "actor": {
525+ "emailAddress": "[email protected] ", 526+ "displayName": "User One",
527+ "name": "user1",
528+ "active": true,
529+ "links": {"self": [{"href": "https://stash-ui.example.com/users/user1"}]},
530+ "id": 1,
531+ "type": "NORMAL",
532+ "slug": "user1"
533+ },
534+ "eventKey": "pr:reviewer:approved",
535+ "pullRequest": {
536+ "author": {
537+ "approved": false,
538+ "role": "AUTHOR",
539+ "user": {
540+ "emailAddress": "[email protected] ", 541+ "displayName": "User Two",
542+ "name": "user2",
543+ "active": true,
544+ "links": {"self": [{"href": "https://stash-ui.example.com/users/user2"}]},
545+ "id": 2,
546+ "type": "NORMAL",
547+ "slug": "user2"
548+ },
549+ "status": "UNAPPROVED"
550+ },
551+ "description": "Approved!",
552+ "updatedDate": 1723045050014,
553+ "title": "fix error",
554+ "version": 4,
555+ "reviewers": [{
556+ "approved": true,
557+ "role": "REVIEWER",
558+ "user": {
559+ "emailAddress": "[email protected] ", 560+ "displayName": "User One",
561+ "name": "user1",
562+ "active": true,
563+ "links": {"self": [{"href": "https://stash-ui.example.com/users/user1"}]},
564+ "id": 1,
565+ "type": "NORMAL",
566+ "slug": "user1"
567+ },
568+ "lastReviewedCommit": "836204e0cbf06ce4ebfb878be21fb383d8c12e62",
569+ "status": "APPROVED"
570+ }],
571+ "toRef": {
572+ "latestCommit": "4755079fa762299a4d99512ca18703db80d42a35",
573+ "id": "refs/heads/main-branch",
574+ "displayId": "main-branch",
575+ "type": "BRANCH",
576+ "repository": {
577+ "archived": false,
578+ "public": false,
579+ "hierarchyId": "7087f8beac6eb0d81cd8",
580+ "name": "app-repo",
581+ "forkable": true,
582+ "project": {
583+ "public": false,
584+ "name": "Project - Mobile",
585+ "description": "Internal mobile repository",
586+ "links": {"self": [{"href": "https://stash-ui.example.com/projects/PROJ"}]},
587+ "id": 1,
588+ "type": "NORMAL",
589+ "key": "PROJ"
590+ },
591+ "links": {
592+ "clone": [
593+ {
594+ "name": "http",
595+ "href": "https://stash-ui.example.com/scm/proj/app-repo.git"
596+ },
597+ {
598+ "name": "ssh",
599+ "href": "ssh://[email protected] :7999/proj/app-repo.git" 600+ }
601+ ],
602+ "self": [{"href": "https://stash-ui.example.com/projects/PROJ/repos/app-repo/browse"}]
603+ },
604+ "id": 84,
605+ "scmId": "git",
606+ "state": "AVAILABLE",
607+ "slug": "app-repo",
608+ "statusMessage": "Available"
609+ }
610+ },
611+ "createdDate": 1723023559286,
612+ "closed": false,
613+ "fromRef": {
614+ "latestCommit": "836204e0cbf06ce4ebfb878be21fb383d8c12e62",
615+ "id": "refs/heads/test-fix-error",
616+ "displayId": "test-fix-error",
617+ "type": "BRANCH",
618+ "repository": {
619+ "archived": false,
620+ "public": false,
621+ "hierarchyId": "7087f8beac6eb0d81cd8",
622+ "name": "app-repo",
623+ "forkable": true,
624+ "project": {
625+ "public": false,
626+ "name": "Project - Mobile",
627+ "description": "Internal mobile repository",
628+ "links": {"self": [{"href": "https://stash-ui.example.com/projects/PROJ"}]},
629+ "id": 1,
630+ "type": "NORMAL",
631+ "key": "PROJ"
632+ },
633+ "links": {
634+ "clone": [
635+ {
636+ "name": "http",
637+ "href": "https://stash-ui.example.com/scm/proj/app-repo.git"
638+ },
639+ {
640+ "name": "ssh",
641+ "href": "ssh://[email protected] :7999/proj/app-repo.git" 642+ }
643+ ],
644+ "self": [{"href": "https://stash-ui.example.com/projects/PROJ/repos/app-repo/browse"}]
645+ },
646+ "id": 84,
647+ "scmId": "git",
648+ "state": "AVAILABLE",
649+ "slug": "app-repo",
650+ "statusMessage": "Available"
651+ }
652+ },
653+ "links": {"self": [{"href": "https://stash-ui.example.com/projects/PROJ/repos/app-repo/pull-requests/1"}]},
654+ "id": 1,
655+ "state": "OPEN",
656+ "locked": false,
657+ "open": true,
658+ "participants": []
659+ },
660+ "participant": {
661+ "approved": true,
662+ "role": "REVIEWER",
663+ "user": {
664+ "emailAddress": "[email protected] ", 665+ "displayName": "User One",
666+ "name": "user1",
667+ "active": true,
668+ "links": {"self": [{"href": "https://stash-ui.example.com/users/user1"}]},
669+ "id": 1,
670+ "type": "NORMAL",
671+ "slug": "user1"
672+ },
673+ "lastReviewedCommit": "836204e0cbf06ce4ebfb878be21fb383d8c12e62",
674+ "status": "APPROVED"
675+ },
676+ "previousStatus": "NEEDS_WORK"
677+ }`
678+
522679 samplePingData = `{
523680 "test": true
524681}`
@@ -1193,7 +1350,7 @@ func Test_isAcceptEventType(t *testing.T) {
11931350 {
11941351 for _ , anAction := range []string {"" ,
11951352 "a" , "not-an-action" ,
1196- "repo:forked" , "repo:modified" , "repo:comment:added" , "repo:comment:edited" , "repo:comment:deleted" , "pr:reviewer:approved" ,
1353+ "repo:forked" , "repo:modified" , "repo:comment:added" , "repo:comment:edited" , "repo:comment:deleted" ,
11971354 "pr:reviewer:unapproved" , "pr:reviewer:needs_work" , "pr:declined" , "pr:deleted" ,
11981355 "pr:comment:added" , "pr:comment:updated" , "pr:comment:deleted" ,
11991356 } {
@@ -1401,6 +1558,33 @@ func Test_HookProvider_TransformRequest(t *testing.T) {
14011558 require .Equal (t , false , hookTransformResult .DontWaitForTriggerResponse )
14021559 }
14031560
1561+ t .Log ("Test with Sample Pull Request approved Data" )
1562+ {
1563+ request := http.Request {
1564+ Header : http.Header {
1565+ "X-Event-Key" : {"pr:reviewer:approved" },
1566+ "Content-Type" : {"application/json; charset=utf-8" },
1567+ },
1568+ Body : ioutil .NopCloser (strings .NewReader (samplePullRequestApprovedData )),
1569+ }
1570+ hookTransformResult := provider .TransformRequest (& request )
1571+ require .NoError (t , hookTransformResult .Error )
1572+ require .False (t , hookTransformResult .ShouldSkip )
1573+ require .Equal (t , []bitriseapi.TriggerAPIParamsModel {
1574+ {
1575+ BuildParams : bitriseapi.BuildParamsModel {
1576+ CommitHash : "836204e0cbf06ce4ebfb878be21fb383d8c12e62" ,
1577+ CommitMessage : "fix error" ,
1578+ Branch : "test-fix-error" ,
1579+ BranchDest : "main-branch" ,
1580+ PullRequestID : & intOne ,
1581+ },
1582+ TriggeredBy : "webhook-bitbucket-server/user1" ,
1583+ },
1584+ }, hookTransformResult .TriggerAPIParams )
1585+ require .Equal (t , false , hookTransformResult .DontWaitForTriggerResponse )
1586+ }
1587+
14041588 t .Log ("Test with Sample Pull Request merged data" )
14051589 {
14061590 request := http.Request {
0 commit comments