Skip to content

Commit 0d928e9

Browse files
committed
create branch before compare 为 null 的bug
1 parent 25915f7 commit 0d928e9

File tree

5 files changed

+16
-9
lines changed

5 files changed

+16
-9
lines changed

platform-api/src/main/java/com/flow/platform/api/git/GitEventEnvConverter.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ public static Map<String, String> convert(GitEvent event) {
104104
// TODO: multi change log
105105
if (pt.getCommits().size() > 0) {
106106
info.put(GitEnvs.FLOW_GIT_CHANGELOG.name(), pt.getCommits().get(0).getMessage());
107-
}
108-
109-
if (Objects.equals(pt.getType(), GitEventType.TAG)) {
107+
} else if (Objects.equals(pt.getType(), GitEventType.TAG)) {
110108
info.put(GitEnvs.FLOW_GIT_CHANGELOG.name(), pt.getMessage());
111109
}
112110

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,18 +207,25 @@ public GitEvent convert(String json) throws GitException {
207207

208208
private GitEvent convertBranch(ChangeHelper changeHelper, GitPushTagEvent event) {
209209
event.setRef("refs/heads/" + changeHelper.afterPush.branchName);
210-
event.setBefore(changeHelper.beforePush.target.hash);
210+
211+
212+
// set commit message
211213
event.setMessage(changeHelper.afterPush.target.message);
212214

213215
// set compare value
214216
event.setCompareUrl(changeHelper.diff.html.value);
215217

216-
// set compare id
217-
final String compareId = GitPushTagEvent.buildCompareId(event);
218-
event.setCompareId(compareId);
219218

220-
event.setCommits(new ArrayList<>(changeHelper.commits.size()));
219+
// create branch before_push is null
220+
if (changeHelper.beforePush != null) {
221+
event.setBefore(changeHelper.beforePush.target.hash);
221222

223+
// set compare id
224+
final String compareId = GitPushTagEvent.buildCompareId(event);
225+
event.setCompareId(compareId);
226+
}
227+
228+
event.setCommits(new ArrayList<>(changeHelper.commits.size()));
222229
for (CommitHelper commit : changeHelper.commits) {
223230
GitEventCommit eventCommit = new GitEventCommit();
224231
eventCommit.setId(commit.hash);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public GitEvent convert(String json) throws GitException {
115115
// for create tag event
116116
if (event.getRef().startsWith("refs/tags")) {
117117
event.setType(GitEventType.TAG);
118+
event.setUserEmail(helper.user.name);
118119
}
119120

120121
// for branch push event

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public class GitHookEventFactory {
6969
bitbucketAdaptors.put(Hooks.EVENT_TYPE_PUSH, new PushAndTagAdapter(BITBUCKET, PUSH));
7070
bitbucketAdaptors.put(Hooks.EVENT_TYPE_PR_MERGERED, new BitbucketEvents.PullRequestAdapter(BITBUCKET, PR));
7171
bitbucketAdaptors.put(Hooks.EVENT_TYPE_PR_CREATED, new BitbucketEvents.PullRequestAdapter(BITBUCKET, PR));
72+
bitbucketAdaptors.put(Hooks.EVENT_TYPE_PR_UPDATED, new BitbucketEvents.PullRequestAdapter(BITBUCKET, PR));
7273
adaptors.put(Hooks.HEADER, bitbucketAdaptors);
7374
}
7475

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void should_convert_to_tag_event_obj() throws Throwable {
9393

9494
Assert.assertEquals("benqyang2006", tagEvent.getUserId());
9595
Assert.assertEquals("benqyang2006", tagEvent.getUsername());
96-
Assert.assertEquals(null, tagEvent.getUserEmail());
96+
Assert.assertEquals("benqyang2006", tagEvent.getUserEmail());
9797

9898
Assert.assertEquals("b972e2edd91e...v1.0", tagEvent.getCompareId());
9999
Assert.assertEquals("https://coding.net/u/benqyang2006/p/flowclibasic/git/compare/b972e2edd91e...v1.0",

0 commit comments

Comments
 (0)