Skip to content

Commit a772fa5

Browse files
committed
add bitbucket pr test
1 parent 0d928e9 commit a772fa5

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

platform-util-git/src/main/java/com/flow/platform/util/git/hooks/BitbucketEvents.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.flow.platform.util.git.model.GitEventCommit;
2323
import com.flow.platform.util.git.model.GitEventType;
2424
import com.flow.platform.util.git.model.GitPullRequestEvent;
25+
import com.flow.platform.util.git.model.GitPullRequestEvent.State;
2526
import com.flow.platform.util.git.model.GitPullRequestInfo;
2627
import com.flow.platform.util.git.model.GitPushTagEvent;
2728
import com.flow.platform.util.git.model.GitSource;
@@ -320,14 +321,16 @@ public GitEvent convert(String json) throws GitException {
320321

321322
if (Objects.equals(rootHelper.pullRequest.state, STATE_OPEN)) {
322323
event.setAction(STATE_OPEN);
323-
event.setSubmitter(rootHelper.creator.username);
324+
event.setState(State.OPEN);
324325
}
325326

326327
if (Objects.equals(rootHelper.pullRequest.state, STATE_CLOSE)) {
327328
event.setAction(STATE_CLOSE);
328-
event.setSubmitter(rootHelper.creator.username);
329+
event.setState(State.CLOSE);
330+
event.setMergedBy(rootHelper.pullRequest.author.username);
329331
}
330332

333+
event.setSubmitter(rootHelper.creator.username);
331334
event.setDescription(rootHelper.pullRequest.description);
332335
event.setTitle(rootHelper.pullRequest.title);
333336
event.setUrl(rootHelper.pullRequest.diff.html.value);
@@ -337,10 +340,12 @@ public GitEvent convert(String json) throws GitException {
337340
//can't get user email
338341
event.setUserEmail(rootHelper.creator.username);
339342

343+
// set source info
340344
event.getSource().setBranch(rootHelper.pullRequest.source.branch.name);
341345
event.getSource().setSha(rootHelper.pullRequest.source.commit.hash);
342346
event.getSource().setProjectName(rootHelper.pullRequest.source.repository.fullName);
343347

348+
// set target info
344349
event.getTarget().setBranch(rootHelper.pullRequest.destination.branch.name);
345350
event.getTarget().setSha(rootHelper.pullRequest.destination.commit.hash);
346351
event.getTarget().setProjectName(rootHelper.pullRequest.destination.repository.fullName);

platform-util-git/src/test/java/com/flow/platform/util/git/test/BitbucketWebhooksEventTest.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.flow.platform.util.git.hooks.GitHookEventFactory;
2121
import com.flow.platform.util.git.model.GitEventType;
2222
import com.flow.platform.util.git.model.GitPullRequestEvent;
23+
import com.flow.platform.util.git.model.GitPullRequestInfo;
2324
import com.flow.platform.util.git.model.GitPushTagEvent;
2425
import com.flow.platform.util.git.model.GitSource;
2526
import com.google.common.io.Files;
@@ -53,7 +54,8 @@ public void should_convert_to_push_event_obj() throws Throwable {
5354
Assert.assertEquals(
5455
"https://bitbucket.org/CodingWill/info/branches/compare/200b5197debd10e0ca341e640422368b145eb254..9429d1ee9fa16dc53d4dc5a0937693330aeda8bb",
5556
event.getCompareUrl());
56-
Assert.assertEquals("https://bitbucket.org/CodingWill/info/commits/200b5197debd10e0ca341e640422368b145eb254", event.getHeadCommitUrl());
57+
Assert.assertEquals("https://bitbucket.org/CodingWill/info/commits/200b5197debd10e0ca341e640422368b145eb254",
58+
event.getHeadCommitUrl());
5759
Assert.assertEquals("add 5\n", event.getMessage());
5860
Assert.assertEquals("CodingWill", event.getUsername());
5961
Assert.assertEquals("CodingWill", event.getUserEmail());
@@ -74,7 +76,8 @@ public void should_convert_to_tag_event_obj() throws Throwable {
7476
Assert.assertEquals("CodingWill", event.getUserEmail());
7577
Assert.assertEquals("CodingWill", event.getUsername());
7678
Assert.assertEquals("add tag\n", event.getMessage());
77-
Assert.assertEquals("https://bitbucket.org/CodingWill/info/commits/86edd5e14fd18bcf923b8eca522319896b2090e4", event.getHeadCommitUrl());
79+
Assert.assertEquals("https://bitbucket.org/CodingWill/info/commits/86edd5e14fd18bcf923b8eca522319896b2090e4",
80+
event.getHeadCommitUrl());
7881
Assert.assertEquals("86edd5e14fd18bcf923b8eca522319896b2090e4", event.getAfter());
7982
Assert.assertEquals(0, event.getCommits().size());
8083
}
@@ -89,6 +92,21 @@ public void should_convert_to_pr_open_event_obj() throws Throwable {
8992
Assert.assertNotNull(event);
9093
Assert.assertEquals(GitSource.BITBUCKET, event.getGitSource());
9194
Assert.assertEquals(GitEventType.PR, event.getType());
95+
96+
Assert.assertEquals("", event.getDescription());
97+
Assert.assertEquals("https://bitbucket.org/CodingWill/info/pull-requests/6", event.getUrl());
98+
Assert.assertEquals("CodingWill", event.getSubmitter());
99+
Assert.assertNull(event.getMergedBy());
100+
101+
GitPullRequestInfo source = event.getSource();
102+
Assert.assertEquals("feature/1", source.getBranch());
103+
Assert.assertEquals("ac66189104f3", source.getSha());
104+
Assert.assertEquals("CodingWill/info", source.getProjectName());
105+
106+
GitPullRequestInfo target = event.getTarget();
107+
Assert.assertEquals("master", target.getBranch());
108+
Assert.assertEquals("eb612981e942", target.getSha());
109+
Assert.assertEquals("CodingWill/info", target.getProjectName());
92110
}
93111

94112
@Test
@@ -101,6 +119,20 @@ public void should_convert_to_pr_close_event_obj() throws Throwable {
101119
Assert.assertNotNull(event);
102120
Assert.assertEquals(GitSource.BITBUCKET, event.getGitSource());
103121
Assert.assertEquals(GitEventType.PR, event.getType());
122+
123+
Assert.assertEquals("https://bitbucket.org/CodingWill/info/pull-requests/3", event.getUrl());
124+
Assert.assertEquals("CodingWill", event.getSubmitter());
125+
Assert.assertNotNull(event.getMergedBy());
126+
127+
GitPullRequestInfo source = event.getSource();
128+
Assert.assertEquals("develop", source.getBranch());
129+
Assert.assertEquals("61d01698184b", source.getSha());
130+
Assert.assertEquals("CodingWill/info", source.getProjectName());
131+
132+
GitPullRequestInfo target = event.getTarget();
133+
Assert.assertEquals("feature/test", target.getBranch());
134+
Assert.assertEquals("c7d2fca28131", target.getSha());
135+
Assert.assertEquals("CodingWill/info", target.getProjectName());
104136
}
105137

106138

0 commit comments

Comments
 (0)