我正在尝试强制执行以“BPSD-XXXXX”开头的提交,并且无法弄清楚如何在推送后强制执行此 lambda 函数,但在代码实际推送到 AWS Codecommit 之前。
下面的 lambda 函数强制执行提交字符串,但直到实际推送代码之后。推送代码时,我为 Codecommit 设置了触发器。
我意识到触发器是问题所在,但是是否有一个触发器可以在完全推送实际发生之前以某种方式检查提交消息?还是在推动发生时?
var aws = require('aws-sdk');
//aws.config.update({region:'us-east-2'});
var codecommit = new aws.CodeCommit({ apiVersion: '2015-04-13' });
exports.handler = function (event, context) {
//console.log(JSON.stringify(event));
for (var reference of event.Records[0].codecommit.references) {
let commitId = reference.commit;
let repo = event.Records[0].eventSourceARN.split(':').pop();
console.log('commitId', commitId);
console.log('repo', repo);
codecommit.getCommit({ repositoryName: repo, commitId: commitId }, function (error, data) {
if (error)
throw error;
console.log('message:', data.commit.message);
if (!/^(BPSD-[0-9]+|Merge)/.test(data.commit.message))
throw new Error("Your commit message is missing either a JIRA Issue ('BPSD-XXXX') or 'Merge'");
});
}
};
如果提交消息不包含“BPSD-XXXXX”,我希望不推送代码