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

Commit

Permalink
feat: better message, more commit details, louder... (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshallOfSound authored Aug 8, 2023
1 parent 8fd4df7 commit ca45e2b
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/push-alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,26 @@ export async function runPushAlert(args) {
const commit = process.env.GITHUB_SHA;
const reviewed = await verifyCommitReview(client, commit);
if (reviewed === false){
const commitDetails = await client.git.getCommit({
repo: github.context.repo.repo,
owner: github.context.repo.owner,
commit_sha: commit,
});

//notify channel
var github_commit_url = `https://github.com/${github.context.repo.owner}/${github.context.repo.repo}/commit/${commit}`;
const message = `:red-c: @channel Unreviewed Commit in \`${github.context.repo.owner}/${github.context.repo.repo}\`\n` +
'\n' +
`*Commit:* <${github_commit_url}|${commit.slice(0, 6)}>\n` +
`*Author:* <https://github.com/${encodeURIComponent(commitDetails.data.author.name)}|${safeSlackString(commitDetails.data.author.name)}>\n` +
`*Committer:* <https://github.com/${encodeURIComponent(commitDetails.data.committer.name)}|${safeSlackString(commitDetails.data.committer.name)}>\n` +
'*Message:*\n' +
'```\n'
safeSlackString(commitDetails.data.message) +
'\n```';
const req = request.post(args.slackEndpoint,{
json:{
text:`Unreviewed Commit from ${github_commit_url}`,
text: message,
channel: `#${args.alertChannel}`
}
}, (error, res, body) => {
Expand All @@ -42,6 +57,10 @@ export async function runPushAlert(args) {
}
}

function safeSlackString(s: string): string {
return s.replace(/\&/g, '&amp;').replace(/\</g, '&lt;').replace(/\>/g, '&gt;');
}

async function verifyCommitReview(
client: InstanceType<typeof GitHub>,
commit_sha: string
Expand Down

0 comments on commit ca45e2b

Please sign in to comment.