-
Notifications
You must be signed in to change notification settings - Fork 50
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
add pr:reviewer:approved as a valid event for Bitbucket Server #198
Open
brentvvosselen
wants to merge
1
commit into
bitrise-io:master
Choose a base branch
from
brentvvosselen:introduce-pr-approved-bb-server
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -519,6 +519,163 @@ const ( | |
} | ||
}` | ||
|
||
samplePullRequestApprovedData = `{ | ||
"date": "2024-08-08T14:58:09+0200", | ||
"actor": { | ||
"emailAddress": "[email protected]", | ||
"displayName": "User One", | ||
"name": "user1", | ||
"active": true, | ||
"links": {"self": [{"href": "https://stash-ui.example.com/users/user1"}]}, | ||
"id": 1, | ||
"type": "NORMAL", | ||
"slug": "user1" | ||
}, | ||
"eventKey": "pr:reviewer:approved", | ||
"pullRequest": { | ||
"author": { | ||
"approved": false, | ||
"role": "AUTHOR", | ||
"user": { | ||
"emailAddress": "[email protected]", | ||
"displayName": "User Two", | ||
"name": "user2", | ||
"active": true, | ||
"links": {"self": [{"href": "https://stash-ui.example.com/users/user2"}]}, | ||
"id": 2, | ||
"type": "NORMAL", | ||
"slug": "user2" | ||
}, | ||
"status": "UNAPPROVED" | ||
}, | ||
"description": "Approved!", | ||
"updatedDate": 1723045050014, | ||
"title": "fix error", | ||
"version": 4, | ||
"reviewers": [{ | ||
"approved": true, | ||
"role": "REVIEWER", | ||
"user": { | ||
"emailAddress": "[email protected]", | ||
"displayName": "User One", | ||
"name": "user1", | ||
"active": true, | ||
"links": {"self": [{"href": "https://stash-ui.example.com/users/user1"}]}, | ||
"id": 1, | ||
"type": "NORMAL", | ||
"slug": "user1" | ||
}, | ||
"lastReviewedCommit": "836204e0cbf06ce4ebfb878be21fb383d8c12e62", | ||
"status": "APPROVED" | ||
}], | ||
"toRef": { | ||
"latestCommit": "4755079fa762299a4d99512ca18703db80d42a35", | ||
"id": "refs/heads/main-branch", | ||
"displayId": "main-branch", | ||
"type": "BRANCH", | ||
"repository": { | ||
"archived": false, | ||
"public": false, | ||
"hierarchyId": "7087f8beac6eb0d81cd8", | ||
"name": "app-repo", | ||
"forkable": true, | ||
"project": { | ||
"public": false, | ||
"name": "Project - Mobile", | ||
"description": "Internal mobile repository", | ||
"links": {"self": [{"href": "https://stash-ui.example.com/projects/PROJ"}]}, | ||
"id": 1, | ||
"type": "NORMAL", | ||
"key": "PROJ" | ||
}, | ||
"links": { | ||
"clone": [ | ||
{ | ||
"name": "http", | ||
"href": "https://stash-ui.example.com/scm/proj/app-repo.git" | ||
}, | ||
{ | ||
"name": "ssh", | ||
"href": "ssh://[email protected]:7999/proj/app-repo.git" | ||
} | ||
], | ||
"self": [{"href": "https://stash-ui.example.com/projects/PROJ/repos/app-repo/browse"}] | ||
}, | ||
"id": 84, | ||
"scmId": "git", | ||
"state": "AVAILABLE", | ||
"slug": "app-repo", | ||
"statusMessage": "Available" | ||
} | ||
}, | ||
"createdDate": 1723023559286, | ||
"closed": false, | ||
"fromRef": { | ||
"latestCommit": "836204e0cbf06ce4ebfb878be21fb383d8c12e62", | ||
"id": "refs/heads/test-fix-error", | ||
"displayId": "test-fix-error", | ||
"type": "BRANCH", | ||
"repository": { | ||
"archived": false, | ||
"public": false, | ||
"hierarchyId": "7087f8beac6eb0d81cd8", | ||
"name": "app-repo", | ||
"forkable": true, | ||
"project": { | ||
"public": false, | ||
"name": "Project - Mobile", | ||
"description": "Internal mobile repository", | ||
"links": {"self": [{"href": "https://stash-ui.example.com/projects/PROJ"}]}, | ||
"id": 1, | ||
"type": "NORMAL", | ||
"key": "PROJ" | ||
}, | ||
"links": { | ||
"clone": [ | ||
{ | ||
"name": "http", | ||
"href": "https://stash-ui.example.com/scm/proj/app-repo.git" | ||
}, | ||
{ | ||
"name": "ssh", | ||
"href": "ssh://[email protected]:7999/proj/app-repo.git" | ||
} | ||
], | ||
"self": [{"href": "https://stash-ui.example.com/projects/PROJ/repos/app-repo/browse"}] | ||
}, | ||
"id": 84, | ||
"scmId": "git", | ||
"state": "AVAILABLE", | ||
"slug": "app-repo", | ||
"statusMessage": "Available" | ||
} | ||
}, | ||
"links": {"self": [{"href": "https://stash-ui.example.com/projects/PROJ/repos/app-repo/pull-requests/1"}]}, | ||
"id": 1, | ||
"state": "OPEN", | ||
"locked": false, | ||
"open": true, | ||
"participants": [] | ||
}, | ||
"participant": { | ||
"approved": true, | ||
"role": "REVIEWER", | ||
"user": { | ||
"emailAddress": "[email protected]", | ||
"displayName": "User One", | ||
"name": "user1", | ||
"active": true, | ||
"links": {"self": [{"href": "https://stash-ui.example.com/users/user1"}]}, | ||
"id": 1, | ||
"type": "NORMAL", | ||
"slug": "user1" | ||
}, | ||
"lastReviewedCommit": "836204e0cbf06ce4ebfb878be21fb383d8c12e62", | ||
"status": "APPROVED" | ||
}, | ||
"previousStatus": "NEEDS_WORK" | ||
}` | ||
|
||
samplePingData = `{ | ||
"test": true | ||
}` | ||
|
@@ -1193,7 +1350,7 @@ func Test_isAcceptEventType(t *testing.T) { | |
{ | ||
for _, anAction := range []string{"", | ||
"a", "not-an-action", | ||
"repo:forked", "repo:modified", "repo:comment:added", "repo:comment:edited", "repo:comment:deleted", "pr:reviewer:approved", | ||
"repo:forked", "repo:modified", "repo:comment:added", "repo:comment:edited", "repo:comment:deleted", | ||
"pr:reviewer:unapproved", "pr:reviewer:needs_work", "pr:declined", "pr:deleted", | ||
"pr:comment:added", "pr:comment:updated", "pr:comment:deleted", | ||
} { | ||
|
@@ -1401,6 +1558,33 @@ func Test_HookProvider_TransformRequest(t *testing.T) { | |
require.Equal(t, false, hookTransformResult.DontWaitForTriggerResponse) | ||
} | ||
|
||
t.Log("Test with Sample Pull Request approved Data") | ||
{ | ||
request := http.Request{ | ||
Header: http.Header{ | ||
"X-Event-Key": {"pr:reviewer:approved"}, | ||
"Content-Type": {"application/json; charset=utf-8"}, | ||
}, | ||
Body: ioutil.NopCloser(strings.NewReader(samplePullRequestApprovedData)), | ||
} | ||
hookTransformResult := provider.TransformRequest(&request) | ||
require.NoError(t, hookTransformResult.Error) | ||
require.False(t, hookTransformResult.ShouldSkip) | ||
require.Equal(t, []bitriseapi.TriggerAPIParamsModel{ | ||
{ | ||
BuildParams: bitriseapi.BuildParamsModel{ | ||
CommitHash: "836204e0cbf06ce4ebfb878be21fb383d8c12e62", | ||
CommitMessage: "fix error", | ||
Branch: "test-fix-error", | ||
BranchDest: "main-branch", | ||
PullRequestID: &intOne, | ||
}, | ||
TriggeredBy: "webhook-bitbucket-server/user1", | ||
}, | ||
}, hookTransformResult.TriggerAPIParams) | ||
require.Equal(t, false, hookTransformResult.DontWaitForTriggerResponse) | ||
} | ||
|
||
t.Log("Test with Sample Pull Request merged data") | ||
{ | ||
request := http.Request{ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: with the current implementation the
approved
event will call the Bitrise Build Trigger API with the same parameters as the regular push/pull-request events.This means that the Trigger API will have no information (no parameter passed) indicating that this was an approve event, and so no filtering can be applied on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @viktorbenei,
I am aware that this will indeed be the case. From my perspective, the pr:approved event is also a pull-request event coming from Bitbucket Server so I presume we can consider this as equal in Bitrise.
If this is blocking for this PR, I can try to have another look at it, but some directions would come in handy as I'm not too familiar with both Go as this codebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any updates on this?