From f51a72a992ae766fc371b8ad9009650a46d74e58 Mon Sep 17 00:00:00 2001 From: Timothy Yin Date: Mon, 9 Feb 2026 17:20:17 +0800 Subject: [PATCH] Update vars/notifyLark.groovy --- vars/notifyLark.groovy | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/vars/notifyLark.groovy b/vars/notifyLark.groovy index 425e708..47bad05 100644 --- a/vars/notifyLark.groovy +++ b/vars/notifyLark.groovy @@ -1,3 +1,34 @@ +def buildCommitDiffMarkdown() { + def changeSets = currentBuild.changeSets + + if (!changeSets || changeSets.isEmpty()) { + return '_本次构建无代码变更_' + } + + def commits = [] + + changeSets.each { cs -> + cs.items.each { item -> + def author = item.author?.fullName ?: 'unknown' + def msg = item.msg?.trim()?.replaceAll('[\\r\\n]+', ' ') + commits << "- **${msg}**(${author})" + } + } + + if (commits.isEmpty()) { + return '_本次构建无代码变更_' + } + + // 防止消息过长(飞书卡片有长度限制) + def maxCommits = 5 + if (commits.size() > maxCommits) { + commits = commits.take(maxCommits) + commits << "_……以及更多提交_" + } + + return commits.join('\n') +} + def call(Map args = [:]) { // ===== 参数 ===== @@ -32,7 +63,8 @@ def call(Map args = [:]) { ABORTED : "已中止" ][buildStatus] ?: "未知状态" - def commitDiff = "[查看变更记录](${buildUrl}changes)" + // def commitDiff = "[查看变更记录](${buildUrl}changes)" + def commitDiff = buildCommitDiffMarkdown() // ===== 凭证 ===== withCredentials([