我使用ScriptRunner连接BitBucket,我的BitBucket是数据中心。
我为合并拉取请求时编写了一个监听器,就像这样
PullRequestMergedEvent pullRequestMergedEvent = event
def pullRequest = pullRequestMergedEvent.getPullRequest()
for (int i = 0 ; i < pullRequest.getReviewers().size() ; i++) {
def getReviewers = pullRequest.getReviewers()
log.warn("getReviewers=${getReviewers}")
def getUser = pullRequest.getReviewers().getAt(i).getUser()
log.warn("getUser=${getUser}")
def commitDate = pullRequest.getReviewers().getAt(i).getLastReviewedCommit()
log.warn("commitDate=${commitDate}")
}
在日志中它向我显示:
pullRequest.getReviewers().size() : 1
getReviewers=[InternalPullRequestParticipant{lastReviewedCommit=a52b5014247ae31d7b10ebc962315d630bb20dfe, role=REVIEWER, status=APPROVED, user=InternalNormalUser{id=3, username=admin}}]
getUser=InternalNormalUser{id=3, username=admin}
lastReviewedCommit=a52b5014247ae31d7b10ebc962315d630bb20dfe
如何以
lastReviewedCommit
格式获取创建提交 ("yyyy-MM-dd'T'HH:mm:ss'Z'"
) 的日期?
我们可以使用带有所需格式化程序的格式化方法
追加以下 2 行
def formattedDate = commitDate.format("yyyy-MM-dd'T'HH:mm:ss'Z'")
log.warn("formattedDate=${formattedDate}")
编辑如果上述解决方案按照下面的评论不起作用
我们可以调用命令来获取 ISO 格式的提交详细信息
git show -s --format=%ci ${commitHash}
为了利用这一点,我们可以创建辅助函数
def getCommitDate(String commitHash) {
def command = "git show -s --format=%ci ${commitHash}"
def process = command.execute()
process.waitFor()
if (process.exitValue() == 0) {
def commitDate = process.in.text.trim()
return commitDate
} else {
log.warn("Error executing git command: ${process.err.text}")
return null
}
}
并调用此方法来获取commitDate
def commitDate = getCommitDate(lastReviewedCommit)