Skip to content

Commit b944ff5

Browse files
author
Yang Guo
committed
support compare id and url for github
1 parent 491d0e4 commit b944ff5

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ private class RequestRoot {
109109

110110
@SerializedName("pull_request")
111111
private PullRequest pullRequest;
112+
113+
private PrRepo repository;
112114
}
113115

114116
private class PullRequest {
@@ -153,6 +155,9 @@ private class PrRepo {
153155

154156
@SerializedName("full_name")
155157
private String name;
158+
159+
@SerializedName("html_url")
160+
private String url;
156161
}
157162

158163
private class UserInfo {
@@ -214,6 +219,10 @@ else if (Objects.equals(pullRequest.state, STATE_CLOSE)) {
214219
target.setBranch(pullRequest.target.ref);
215220
target.setSha(pullRequest.target.sha);
216221

222+
// set compare id
223+
final String compareId = GitPullRequestEvent.buildCompareId(source, target);
224+
event.setCompareId(compareId);
225+
event.setCompareUrl(mr.repository.url + "/compare/" + compareId);
217226
return event;
218227
}
219228
}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,15 @@ public void should_convert_to_pr_event_obj() throws Throwable {
140140
Assert.assertEquals("1d1de876084ef656e522f360b88c1e96acf6b806", source.getSha());
141141

142142
// then: verify target info
143-
GitPullRequestInfo target = event.getSource();
144-
Assert.assertEquals("developer", target.getBranch());
143+
GitPullRequestInfo target = event.getTarget();
144+
Assert.assertEquals("master", target.getBranch());
145145
Assert.assertEquals(86284448, target.getProjectId().intValue());
146146
Assert.assertEquals("yang-guo-2016/Test", target.getProjectName());
147-
Assert.assertEquals("1d1de876084ef656e522f360b88c1e96acf6b806", source.getSha());
147+
Assert.assertEquals("4e4e3750cd468f245bd9f0f938c4b5f76e1bc5b0", target.getSha());
148+
149+
Assert.assertEquals("4e4e3750cd46...1d1de876084e", event.getCompareId());
150+
Assert.assertEquals("https://github.com/yang-guo-2016/Test/compare/4e4e3750cd46...1d1de876084e",
151+
event.getCompareUrl());
148152
}
149153

150154
private static String loadWebhookSampleJson(String classPath) throws IOException {

0 commit comments

Comments
 (0)