Skip to content

Commit

Permalink
Merge pull request drone#130 from raphendyr/stash-pull-request
Browse files Browse the repository at this point in the history
Implement parsing/handling for missing pull request webhook events for BitBucket Server (Stash) driver
  • Loading branch information
TP Honey authored Jan 12, 2022
2 parents c1649f4 + e4fe588 commit b926ba7
Show file tree
Hide file tree
Showing 15 changed files with 882 additions and 3 deletions.
10 changes: 10 additions & 0 deletions scm/driver/stash/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,16 @@ func convertPullRequest(from *pr) *scm.PullRequest {
Merged: from.State == "MERGED",
Created: time.Unix(from.CreatedDate/1000, 0),
Updated: time.Unix(from.UpdatedDate/1000, 0),
Head: scm.Reference{
Name: from.FromRef.DisplayID,
Path: from.FromRef.ID,
Sha: from.FromRef.LatestCommit,
},
Base: scm.Reference{
Name: from.ToRef.DisplayID,
Path: from.ToRef.ID,
Sha: from.ToRef.LatestCommit,
},
Author: scm.User{
Login: from.Author.User.Slug,
Name: from.Author.User.DisplayName,
Expand Down
10 changes: 10 additions & 0 deletions scm/driver/stash/testdata/pr.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@
"Link": "http://example.com:7990/projects/PRJ/repos/my-repo/pull-requests/1",
"Closed": false,
"Merged": false,
"Base": {
"Name": "master",
"Path": "refs/heads/master",
"Sha": "5c64a07cd6c0f21b753bf261ef059c7e7633c50a"
},
"Head": {
"Name": "feature/x",
"Path": "refs/heads/feature/x",
"Sha": "131cb13f4aed12e725177bc4b7c28db67839bf9f"
},
"Author": {
"Login": "jcitizen",
"Name": "Jane Citizen",
Expand Down
10 changes: 10 additions & 0 deletions scm/driver/stash/testdata/prs.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
"Link": "http://example.com:7990/projects/PRJ/repos/my-repo/pull-requests/1",
"Closed": false,
"Merged": false,
"Base": {
"Name": "master",
"Path": "refs/heads/master",
"Sha": "5c64a07cd6c0f21b753bf261ef059c7e7633c50a"
},
"Head": {
"Name": "feature/x",
"Path": "refs/heads/feature/x",
"Sha": "131cb13f4aed12e725177bc4b7c28db67839bf9f"
},
"Author": {
"Login": "jcitizen",
"Name": "Jane Citizen",
Expand Down
10 changes: 10 additions & 0 deletions scm/driver/stash/testdata/webhooks/pr_declined.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@
"Link": "",
"Closed": true,
"Merged": false,
"Base": {
"Name": "master",
"Path": "refs/heads/master",
"Sha": "823b2230a56056231c9425d63758fa87078a66b4"
},
"Head": {
"Name": "develop",
"Path": "refs/heads/develop",
"Sha": "b9eaed50a03c073b20dfa82e5e753d295e7f0e56"
},
"Author": {
"Login": "jcitizen",
"Name": "Jane Citizen",
Expand Down
54 changes: 53 additions & 1 deletion scm/driver/stash/testdata/webhooks/pr_deleted.json.golden
Original file line number Diff line number Diff line change
@@ -1 +1,53 @@
{}
{
"Action": "closed",
"Repo": {
"ID": "1",
"Namespace": "PRJ",
"Name": "my-repo",
"Perm": null,
"Branch": "master",
"Private": true,
"Clone": "",
"CloneSSH": "",
"Link": "",
"Created": "0001-01-01T00:00:00Z",
"Updated": "0001-01-01T00:00:00Z"
},
"PullRequest": {
"Number": 2,
"Title": "added LICENSE",
"Body": "added BSD license text",
"Sha": "b9eaed50a03c073b20dfa82e5e753d295e7f0e56",
"Ref": "refs/pull-requests/2/from",
"Source": "develop",
"Target": "master",
"Fork": "PRJ/my-repo",
"Link": "",
"Closed": true,
"Merged": false,
"Base": {
"Name": "master",
"Path": "refs/heads/master",
"Sha": "823b2230a56056231c9425d63758fa87078a66b4"
},
"Head": {
"Name": "develop",
"Path": "refs/heads/develop",
"Sha": "b9eaed50a03c073b20dfa82e5e753d295e7f0e56"
},
"Author": {
"Login": "jcitizen",
"Name": "Jane Citizen",
"Email": "[email protected]",
"Avatar": "https://www.gravatar.com/avatar/9e26471d35a78862c17e467d87cddedf.jpg"
},
"Created": "2018-07-05T12:21:30-07:00",
"Updated": "2018-07-05T12:30:48-07:00"
},
"Sender": {
"Login": "jcitizen",
"Name": "Jane Citizen",
"Email": "[email protected]",
"Avatar": "https://www.gravatar.com/avatar/9e26471d35a78862c17e467d87cddedf.jpg"
}
}
159 changes: 159 additions & 0 deletions scm/driver/stash/testdata/webhooks/pr_from_ref_updated.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
{
"eventKey": "pr:from_ref_updated",
"date": "2021-11-23T10:02:52+0000",
"actor": {
"name": "jcitizen",
"emailAddress": "[email protected]",
"id": 1,
"displayName": "Jane Citizen",
"active": true,
"slug": "jcitizen",
"type": "NORMAL",
"links": {
"self": [
{
"href": "http://example.com:7990/users/jcitizen"
}
]
}
},
"pullRequest": {
"id": 2,
"version": 0,
"title": "added LICENSE",
"description": "added BSD license text",
"state": "OPEN",
"open": true,
"closed": false,
"createdDate": 1637591800463,
"updatedDate": 1637661772258,
"fromRef": {
"id": "refs/heads/feature-2",
"displayId": "feature-2",
"latestCommit": "c00d0f269a9844dd168f72f6a9d78a9cff49a318",
"type": "BRANCH",
"repository": {
"slug": "my-repo",
"id": 1,
"name": "my-repo",
"hierarchyId": "5aa23c1a1280b0c0acce",
"scmId": "git",
"state": "AVAILABLE",
"statusMessage": "Available",
"forkable": true,
"project": {
"key": "PRJ",
"id": 2,
"name": "PRJ",
"public": false,
"type": "NORMAL",
"links": {
"self": [
{
"href": "http://example.com:7990/projects/PRJ"
}
]
}
},
"public": false,
"links": {
"clone": [
{
"href": "http://example.com:7990/scm/prj/my-repo.git",
"name": "http"
},
{
"href": "ssh://[email protected]:7999/prj/my-repo.git",
"name": "ssh"
}
],
"self": [
{
"href": "http://example.com:7990/projects/PRJ/repos/my-repo/browse"
}
]
}
}
},
"toRef": {
"id": "refs/heads/master",
"displayId": "master",
"type": "BRANCH",
"latestCommit": "823b2230a56056231c9425d63758fa87078a66b4",
"repository": {
"slug": "my-repo",
"id": 1,
"name": "my-repo",
"hierarchyId": "5aa23c1a1280b0c0acce",
"scmId": "git",
"state": "AVAILABLE",
"statusMessage": "Available",
"forkable": true,
"project": {
"key": "PRJ",
"id": 2,
"name": "PRJ",
"public": false,
"type": "NORMAL",
"links": {
"self": [
{
"href": "http://example.com:7990/projects/PRJ"
}
]
}
},
"public": false,
"links": {
"clone": [
{
"href": "http://example.com:7990/scm/prj/my-repo.git",
"name": "http"
},
{
"href": "ssh://[email protected]:7999/prj/my-repo.git",
"name": "ssh"
}
],
"self": [
{
"href": "http://example.com:7990/projects/PRJ/repos/my-repo/browse"
}
]
}
}
},
"locked": false,
"author": {
"user": {
"name": "jcitizen",
"emailAddress": "[email protected]",
"id": 1,
"displayName": "Jane Citizen",
"active": true,
"slug": "jcitizen",
"type": "NORMAL",
"links": {
"self": [
{
"href": "http://example.com:7990/users/jcitizen"
}
]
}
},
"role": "AUTHOR",
"approved": false,
"status": "UNAPPROVED"
},
"reviewers": [],
"participants": [],
"links": {
"self": [
{
"href": "http://example.com:7990/projects/PRJ/repos/my-repo/pull-requests/2"
}
]
}
},
"previousFromHash": "caf52ccb18c039cd9b930ed1f7b3edfb34cb92dd"
}
53 changes: 53 additions & 0 deletions scm/driver/stash/testdata/webhooks/pr_from_ref_updated.json.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"Action": "synchronized",
"Repo": {
"ID": "1",
"Namespace": "PRJ",
"Name": "my-repo",
"Perm": null,
"Branch": "master",
"Private": true,
"Clone": "http://example.com:7990/scm/prj/my-repo.git",
"CloneSSH": "ssh://[email protected]:7999/prj/my-repo.git",
"Link": "http://example.com:7990/projects/PRJ/repos/my-repo/browse",
"Created": "0001-01-01T00:00:00Z",
"Updated": "0001-01-01T00:00:00Z"
},
"PullRequest": {
"Number": 2,
"Title": "added LICENSE",
"Body": "added BSD license text",
"Sha": "c00d0f269a9844dd168f72f6a9d78a9cff49a318",
"Ref": "refs/pull-requests/2/from",
"Source": "feature-2",
"Target": "master",
"Fork": "PRJ/my-repo",
"Link": "http://example.com:7990/projects/PRJ/repos/my-repo/pull-requests/2",
"Closed": false,
"Merged": false,
"Base": {
"Name": "master",
"Path": "refs/heads/master",
"Sha": "823b2230a56056231c9425d63758fa87078a66b4"
},
"Head": {
"Name": "feature-2",
"Path": "refs/heads/feature-2",
"Sha": "c00d0f269a9844dd168f72f6a9d78a9cff49a318"
},
"Author": {
"Login": "jcitizen",
"Name": "Jane Citizen",
"Email": "[email protected]",
"Avatar": "https://www.gravatar.com/avatar/9e26471d35a78862c17e467d87cddedf.jpg"
},
"Created": "2021-11-22T14:36:40Z",
"Updated": "2021-11-23T10:02:52Z"
},
"Sender": {
"Login": "jcitizen",
"Name": "Jane Citizen",
"Email": "[email protected]",
"Avatar": "https://www.gravatar.com/avatar/9e26471d35a78862c17e467d87cddedf.jpg"
}
}
10 changes: 10 additions & 0 deletions scm/driver/stash/testdata/webhooks/pr_merged.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@
"Link": "",
"Closed": true,
"Merged": true,
"Base": {
"Name": "master",
"Path": "refs/heads/master",
"Sha": "823b2230a56056231c9425d63758fa87078a66b4"
},
"Head": {
"Name": "develop",
"Path": "refs/heads/develop",
"Sha": "b9eaed50a03c073b20dfa82e5e753d295e7f0e56"
},
"Author": {
"Login": "jcitizen",
"Name": "Jane Citizen",
Expand Down
Loading

0 comments on commit b926ba7

Please sign in to comment.