Skip to content

Commit 1f16458

Browse files
author
yang.guo
authored
Merge pull request #135 from FlowCI/feature/api/git_webhook_bitbucket
Feature/api/git webhook bitbucket
2 parents 2b6899a + ec53b77 commit 1f16458

File tree

24 files changed

+2200
-19
lines changed

24 files changed

+2200
-19
lines changed

platform-api/src/main/java/com/flow/platform/api/controller/GitWebHookController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public void onEventReceived(@RequestHeader HttpHeaders headers, HttpServletReque
8787
// extract git related env variables from event, and temporary set to node for git loading
8888
final Map<String, String> gitEnvs = GitEventEnvConverter.convert(hookEvent);
8989

90-
if (!allowEventType(flow, gitEnvs)) {
90+
if (!canExecuteGitEvent(flow, gitEnvs)) {
9191
LOGGER.warn("The git event not match flow settings");
9292
return;
9393
}
@@ -103,7 +103,7 @@ public void onEventReceived(@RequestHeader HttpHeaders headers, HttpServletReque
103103
}
104104
}
105105

106-
private boolean allowEventType(Node flow, Map<String, String> gitEnvs) {
106+
private boolean canExecuteGitEvent(Node flow, Map<String, String> gitEnvs) {
107107
String gitEventType = gitEnvs.get(GitEnvs.FLOW_GIT_EVENT_TYPE.name());
108108
String gitBranch = gitEnvs.get(GitEnvs.FLOW_GIT_BRANCH.name());
109109

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.Collections;
2929
import java.util.HashMap;
3030
import java.util.Map;
31+
import java.util.Objects;
3132

3233
/**
3334
* Extract required GitEnv from git event
@@ -76,6 +77,12 @@ public static Map<String, String> convert(GitEvent event) {
7677
info.put(GitEnvs.FLOW_GIT_AUTHOR.name(), pr.getMergedBy());
7778
}
7879

80+
// set commit id and url from PR request id and pr url
81+
if (pr.getRequestId() != null && pr.getUrl() != null) {
82+
info.put(GitEnvs.FLOW_GIT_COMMIT_ID.name(), pr.getRequestId().toString());
83+
info.put(GitEnvs.FLOW_GIT_COMMIT_URL.name(), pr.getUrl());
84+
}
85+
7986
info.put(GitEnvs.FLOW_GIT_CHANGELOG.name(), pr.getTitle());
8087
info.put(GitEnvs.FLOW_GIT_PR_URL.name(), pr.getUrl());
8188
return info;
@@ -97,6 +104,8 @@ public static Map<String, String> convert(GitEvent event) {
97104
// TODO: multi change log
98105
if (pt.getCommits().size() > 0) {
99106
info.put(GitEnvs.FLOW_GIT_CHANGELOG.name(), pt.getCommits().get(0).getMessage());
107+
} else if (Objects.equals(pt.getType(), GitEventType.TAG)) {
108+
info.put(GitEnvs.FLOW_GIT_CHANGELOG.name(), pt.getMessage());
100109
}
101110

102111
return info;

platform-api/src/main/java/com/flow/platform/api/service/CredentialServiceImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,11 @@ public void delete(String name) {
116116
public RSAKeyPair generateRsaKey() {
117117
String comment = "FLOWCI";
118118
int type = KeyPair.RSA;
119+
final int keySize = 2048; // default 1024, bitbucket support at least 2048
119120
JSch jsch = new JSch();
120121

121122
try {
122-
KeyPair kpair = KeyPair.genKeyPair(jsch, type);
123+
KeyPair kpair = KeyPair.genKeyPair(jsch, type, keySize);
123124
RSAKeyPair pair = new RSAKeyPair();
124125

125126
// private key

platform-control-center/src/main/java/com/flow/platform/cc/consumer/CmdQueueConsumer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,15 @@ public void onQueueItem(Message message) {
9696
LOGGER.trace("wait for idle agent time out %s seconds for cmd %s", idleAgentTimeout, cmdId);
9797
}
9898

99-
// reset cmd status to pending, record num of retry
100-
int retry = item.getRetry() - 1;
10199
Cmd cmd = cmdService.find(cmdId);
100+
101+
// do not re-enqueue if cmd been stopped or killed
102102
if (cmd.getStatus() == CmdStatus.STOPPED || cmd.getStatus() == CmdStatus.KILLED) {
103103
return;
104104
}
105105

106+
// reset cmd status to pending, record num of retry
107+
int retry = item.getRetry() - 1;
106108
cmd.setStatus(CmdStatus.PENDING);
107109
cmd.setRetry(retry);
108110
cmdService.save(cmd);

0 commit comments

Comments
 (0)