Skip to content
This repository was archived by the owner on Sep 10, 2024. It is now read-only.

Commit ca45e2b

Browse files
feat: better message, more commit details, louder... (#296)
1 parent 8fd4df7 commit ca45e2b

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/push-alert.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,26 @@ export async function runPushAlert(args) {
1515
const commit = process.env.GITHUB_SHA;
1616
const reviewed = await verifyCommitReview(client, commit);
1717
if (reviewed === false){
18+
const commitDetails = await client.git.getCommit({
19+
repo: github.context.repo.repo,
20+
owner: github.context.repo.owner,
21+
commit_sha: commit,
22+
});
23+
1824
//notify channel
1925
var github_commit_url = `https://github.com/${github.context.repo.owner}/${github.context.repo.repo}/commit/${commit}`;
26+
const message = `:red-c: @channel Unreviewed Commit in \`${github.context.repo.owner}/${github.context.repo.repo}\`\n` +
27+
'\n' +
28+
`*Commit:* <${github_commit_url}|${commit.slice(0, 6)}>\n` +
29+
`*Author:* <https://github.com/${encodeURIComponent(commitDetails.data.author.name)}|${safeSlackString(commitDetails.data.author.name)}>\n` +
30+
`*Committer:* <https://github.com/${encodeURIComponent(commitDetails.data.committer.name)}|${safeSlackString(commitDetails.data.committer.name)}>\n` +
31+
'*Message:*\n' +
32+
'```\n'
33+
safeSlackString(commitDetails.data.message) +
34+
'\n```';
2035
const req = request.post(args.slackEndpoint,{
2136
json:{
22-
text:`Unreviewed Commit from ${github_commit_url}`,
37+
text: message,
2338
channel: `#${args.alertChannel}`
2439
}
2540
}, (error, res, body) => {
@@ -42,6 +57,10 @@ export async function runPushAlert(args) {
4257
}
4358
}
4459

60+
function safeSlackString(s: string): string {
61+
return s.replace(/\&/g, '&amp;').replace(/\</g, '&lt;').replace(/\>/g, '&gt;');
62+
}
63+
4564
async function verifyCommitReview(
4665
client: InstanceType<typeof GitHub>,
4766
commit_sha: string

0 commit comments

Comments
 (0)