refactor(CommitMessageLinter, log): enhance logging with timestamps and improve log messages
Signed-off-by: 孙振宇 <>
This commit is contained in:
parent
67214e0120
commit
bd1aed3664
@ -10,18 +10,18 @@ class CommitMessageLinter {
|
||||
|
||||
def lint(configurations) {
|
||||
def rules = steps.libraryResource 'com/freeleaps/devops/builtins/commitlint/default.js'
|
||||
steps.log.info "Check if there has custom commit lint rules specified..."
|
||||
steps.log.info "<Commit Message Linter> Check if there has custom commit lint rules specified..."
|
||||
|
||||
if (configurations.commitLintRules != null && !configurations.commitLintRules.isEmpty()) {
|
||||
steps.log.info "Custom commit lint rules found, using custom rules files: ${configurations.commitLintRules}"
|
||||
steps.log.info "<Commit Message Linter> Custom commit lint rules found, using custom rules files: ${configurations.commitLintRules}"
|
||||
rules = configurations.commitLintRules
|
||||
} else {
|
||||
steps.log.info "No custom commit lint rules found, using built-in rules at: ${defaultRules}"
|
||||
steps.log.info "<Commit Message Linter> No custom commit lint rules found, using built-in rules at: ${defaultRule}"
|
||||
steps.sh "echo ${rules} > .commitlintrc.js"
|
||||
rules = '.commitlintrc.js'
|
||||
}
|
||||
|
||||
steps.log.info "Linting commit messages from HEAD..."
|
||||
steps.log.info "<Commit Message Linter> Linting commit messages from HEAD..."
|
||||
|
||||
steps.dir(steps.env.workspace) {
|
||||
steps.sh "commitlint --verbose -g ${rules} -f HEAD^"
|
||||
|
||||
@ -1,13 +1,22 @@
|
||||
#!groovy
|
||||
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
|
||||
def getTimestamp() {
|
||||
// 定义时间戳格式,例如:2023-10-05 14:30:00
|
||||
def dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
|
||||
return dateFormat.format(new Date())
|
||||
}
|
||||
|
||||
def info(message) {
|
||||
echo "[INFO] ${message}"
|
||||
echo "[${getTimestamp()}] [INFO] ${message}"
|
||||
}
|
||||
|
||||
def warn(message) {
|
||||
echo "[WARN] ${message}"
|
||||
echo "[${getTimestamp()}] [WARN] ${message}"
|
||||
}
|
||||
|
||||
def error(message) {
|
||||
echo "[ERROR] ${message}"
|
||||
echo "[${getTimestamp()}] [ERROR] ${message}"
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user