我有一个代码提交回购。
我有一个带有“发送到”=“亚马逊 SNS”的推送触发器设置。
在 SNS,我有一些电子邮件订阅者连接到通知事件。
因此,每当任何开发人员针对 repo 执行 git push 时,项目开发人员都会收到一封电子邮件。
该电子邮件类似于:
有没有办法在该通知中添加 git push 或提交消息?
我有一个代码提交回购。
我有一个带有“发送到”=“亚马逊 SNS”的推送触发器设置。
在 SNS,我有一些电子邮件订阅者连接到通知事件。
因此,每当任何开发人员针对 repo 执行 git push 时,项目开发人员都会收到一封电子邮件。
该电子邮件类似于:
有没有办法在该通知中添加 git push 或提交消息?
虽然该信息不是直接从触发器有效负载提供的,但它确实提供了参考更新列表。每个新的/更新的引用(通常是一个分支)都包含提交 ID。如果您要配置 AWS Lambda 触发器,您可以从触发器负载中获取这些提交 ID,然后将它们与 CodeCommit 的“GetCommit”api 一起使用来检索提交消息。然后,您可以将新的有效负载发送到 SNS 以通过电子邮件发送。
关于 GetCommit 的信息:http: //docs.aws.amazon.com/codecommit/latest/APIReference/API_GetCommit.html
使用 AWS CodeCommit 设置 Lambda 触发器示例:http: //docs.aws.amazon.com/codecommit/latest/userguide/how-to-notify-lambda.html
如果您在持续集成服务器(jenkins、travis 等)中接收到 aws 有效负载并且您能够克隆存储库(如果您要构建您的应用程序),您将能够使用 git 工具获取消息,该工具是如果要克隆存储库,则已安装
这是从 aws 代码提交触发器到我的 ci 服务器的通知负载:
{
"Type": "Notification",
"MessageId": "296892a1a77b",
"TopicArn": "arn:aws:sns:us-bar-1:123456:TopicFoo",
"Subject": "UPDATE: AWS CodeCommit us-bar-1 push: my-awesome-repo",
"Message": ".....",
"Timestamp": "2021-06-23T20:57:15.040Z",
"SignatureVersion": "1",
"SigningCertURL": "https://sns.us-bar-1.amazonaws.com/SimpleNotificationService-foo-.pem",
"UnsubscribeURL": "https://foo.bar"
}
消息字段是字符串化的:s
{\"Records\":[{\"awsRegion\":\"us-bar-1\",\"codecommit\":{\"references\":[{\"commit\":\"fb28ebbec522cc403\",\"ref\":\"refs/heads/mybranch\"}]},\"customData\":null,\"eventId\":\"d1dab883\",\"eventName\":\"ReferenceChanges\",\"eventPartNumber\":1,\"eventSource\":\"aws:codecommit\",\"eventSourceARN\":\"arn:aws:codecommit:us-bar-1:123456:my-awesome-repo\",\"eventTime\":\"2021-06-23T20:57:15.005+0000\",\"eventTotalParts\":1,\"eventTriggerConfigId\":\"e4ea5f3bec6c\",\"eventTriggerName\":\"my_ci_server_notification\",\"eventVersion\":\"1.0\",\"userIdentityARN\":\"arn:aws:iam::123456:user/jane_doe\"}]}
但是替换\"
为"
,我们会得到一个可读的json
{
"Records": [{
"awsRegion": "us-bar-1",
"codecommit": {
"references": [{
"commit": "fb28ebbec522cc403",
"ref": "refs/heads/mybranch"
}]
},
"customData": null,
"eventId": "d1dab883",
"eventName": "ReferenceChanges",
"eventPartNumber": 1,
"eventSource": "aws:codecommit",
"eventSourceARN": "arn:aws:codecommit:us-bar-1:123456:my-awesome-repo",
"eventTime": "2021-06-23T20:57:15.005+0000",
"eventTotalParts": 1,
"eventTriggerConfigId": "e4ea5f3bec6c",
"eventTriggerName": "my_ci_server_notification",
"eventVersion": "1.0",
"userIdentityARN": "arn:aws:iam::123456:user/jane_doe"
}]
}
我们可以在其中提取部分中的提交 id: references.commit
"references": [{
"commit": "fb28ebbec522cc403",
"ref": "refs/heads/mybranch"
}]
最后使用 git shell 工具获取消息:S
git log --format=%B -n 1 fb28ebbec522cc403