增加构建通知
This commit is contained in:
parent
c3325c379d
commit
433887c3cf
@ -843,9 +843,11 @@ public class JenkinsBuildServiceImpl extends BaseServiceImpl<JenkinsBuild, Jenki
|
|||||||
*/
|
*/
|
||||||
private void parseCommitInfoFromActions(String actionsJson, Map<String, Object> templateParams) {
|
private void parseCommitInfoFromActions(String actionsJson, Map<String, Object> templateParams) {
|
||||||
if (actionsJson == null || actionsJson.isEmpty()) {
|
if (actionsJson == null || actionsJson.isEmpty()) {
|
||||||
|
log.debug("actionsJson 为空,跳过解析");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
log.debug("开始解析 actionsJson: {}", actionsJson);
|
||||||
JsonNode root = objectMapper.readTree(actionsJson);
|
JsonNode root = objectMapper.readTree(actionsJson);
|
||||||
|
|
||||||
// 解析 gitCommitId
|
// 解析 gitCommitId
|
||||||
@ -855,17 +857,46 @@ public class JenkinsBuildServiceImpl extends BaseServiceImpl<JenkinsBuild, Jenki
|
|||||||
|
|
||||||
// 解析 changeSets 中的 commit 信息
|
// 解析 changeSets 中的 commit 信息
|
||||||
JsonNode changeSets = root.get("changeSets");
|
JsonNode changeSets = root.get("changeSets");
|
||||||
|
log.debug("changeSets 节点: {}", changeSets);
|
||||||
|
|
||||||
if (changeSets != null && changeSets.isArray() && changeSets.size() > 0) {
|
if (changeSets != null && changeSets.isArray() && changeSets.size() > 0) {
|
||||||
|
log.debug("changeSets 数组大小: {}", changeSets.size());
|
||||||
StringBuilder commitMessages = new StringBuilder();
|
StringBuilder commitMessages = new StringBuilder();
|
||||||
for (JsonNode changeSet : changeSets) {
|
for (JsonNode changeSet : changeSets) {
|
||||||
JsonNode items = changeSet.get("items");
|
JsonNode items = changeSet.get("items");
|
||||||
|
log.debug("items 节点: {}", items);
|
||||||
|
|
||||||
if (items != null && items.isArray()) {
|
if (items != null && items.isArray()) {
|
||||||
|
log.debug("items 数组大小: {}", items.size());
|
||||||
for (JsonNode item : items) {
|
for (JsonNode item : items) {
|
||||||
|
log.debug("处理 item: {}", item);
|
||||||
|
|
||||||
// Jenkins API 返回的字段名是 msg
|
// Jenkins API 返回的字段名是 msg
|
||||||
String msg = item.has("msg") ? item.get("msg").asText() : "";
|
String msg = item.has("msg") ? item.get("msg").asText() : "";
|
||||||
String author = item.has("author") ? item.get("author").asText() : "";
|
|
||||||
|
// author 是一个对象,需要提取 fullName 或其他字段
|
||||||
|
String author = "";
|
||||||
|
if (item.has("author")) {
|
||||||
|
JsonNode authorNode = item.get("author");
|
||||||
|
log.debug("author 节点: {}", authorNode);
|
||||||
|
|
||||||
|
if (authorNode.isTextual()) {
|
||||||
|
// 如果是字符串,直接使用
|
||||||
|
author = authorNode.asText();
|
||||||
|
} else if (authorNode.isObject()) {
|
||||||
|
// 如果是对象,尝试提取 fullName
|
||||||
|
if (authorNode.has("fullName")) {
|
||||||
|
author = authorNode.get("fullName").asText();
|
||||||
|
} else if (authorNode.has("name")) {
|
||||||
|
author = authorNode.get("name").asText();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
String commitId = item.has("commitId") ? item.get("commitId").asText() : "";
|
String commitId = item.has("commitId") ? item.get("commitId").asText() : "";
|
||||||
|
|
||||||
|
log.debug("解析结果 - msg: {}, author: {}, commitId: {}", msg, author, commitId);
|
||||||
|
|
||||||
if (!msg.isEmpty()) {
|
if (!msg.isEmpty()) {
|
||||||
if (commitMessages.length() > 0) {
|
if (commitMessages.length() > 0) {
|
||||||
commitMessages.append("\n");
|
commitMessages.append("\n");
|
||||||
@ -878,11 +909,16 @@ public class JenkinsBuildServiceImpl extends BaseServiceImpl<JenkinsBuild, Jenki
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (commitMessages.length() > 0) {
|
if (commitMessages.length() > 0) {
|
||||||
|
log.info("成功解析 commitMessage: {}", commitMessages.toString());
|
||||||
templateParams.put("commitMessage", commitMessages.toString());
|
templateParams.put("commitMessage", commitMessages.toString());
|
||||||
|
} else {
|
||||||
|
log.warn("commitMessages 为空");
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log.warn("changeSets 为空或不是数组");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("解析 commit 信息失败: {}", e.getMessage());
|
log.error("解析 commit 信息失败", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user