From 433887c3cf85f5e01249512d7928f3f69e044074 Mon Sep 17 00:00:00 2001 From: dengqichen Date: Mon, 1 Dec 2025 10:23:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9E=84=E5=BB=BA=E9=80=9A?= =?UTF-8?q?=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/JenkinsBuildServiceImpl.java | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/com/qqchen/deploy/backend/deploy/service/impl/JenkinsBuildServiceImpl.java b/backend/src/main/java/com/qqchen/deploy/backend/deploy/service/impl/JenkinsBuildServiceImpl.java index 991250e9..9a7b7733 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/deploy/service/impl/JenkinsBuildServiceImpl.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/deploy/service/impl/JenkinsBuildServiceImpl.java @@ -843,9 +843,11 @@ public class JenkinsBuildServiceImpl extends BaseServiceImpl templateParams) { if (actionsJson == null || actionsJson.isEmpty()) { + log.debug("actionsJson 为空,跳过解析"); return; } try { + log.debug("开始解析 actionsJson: {}", actionsJson); JsonNode root = objectMapper.readTree(actionsJson); // 解析 gitCommitId @@ -855,17 +857,46 @@ public class JenkinsBuildServiceImpl extends BaseServiceImpl 0) { + log.debug("changeSets 数组大小: {}", changeSets.size()); StringBuilder commitMessages = new StringBuilder(); for (JsonNode changeSet : changeSets) { JsonNode items = changeSet.get("items"); + log.debug("items 节点: {}", items); + if (items != null && items.isArray()) { + log.debug("items 数组大小: {}", items.size()); for (JsonNode item : items) { + log.debug("处理 item: {}", item); + // Jenkins API 返回的字段名是 msg 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() : ""; + log.debug("解析结果 - msg: {}, author: {}, commitId: {}", msg, author, commitId); + if (!msg.isEmpty()) { if (commitMessages.length() > 0) { commitMessages.append("\n"); @@ -878,11 +909,16 @@ public class JenkinsBuildServiceImpl extends BaseServiceImpl 0) { + log.info("成功解析 commitMessage: {}", commitMessages.toString()); templateParams.put("commitMessage", commitMessages.toString()); + } else { + log.warn("commitMessages 为空"); } + } else { + log.warn("changeSets 为空或不是数组"); } } catch (Exception e) { - log.warn("解析 commit 信息失败: {}", e.getMessage()); + log.error("解析 commit 信息失败", e); } }