Skip to content

Commit

Permalink
[npm] run publish
Browse files Browse the repository at this point in the history
  • Loading branch information
8398a7 committed Aug 19, 2019
1 parent 2f40446 commit 208967a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 36 deletions.
4 changes: 2 additions & 2 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ function run() {
case 'auto':
throw new Error('not implement');
case 'success':
payload = slack_1.successPayload(text);
payload = yield slack_1.successPayload(text);
break;
case 'failure':
payload = slack_1.failurePayload(text, failedMention);
payload = yield slack_1.failurePayload(text, failedMention);
break;
default:
payload = JSON.parse(core.getInput('payload'));
Expand Down
86 changes: 52 additions & 34 deletions lib/slack.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,44 +27,62 @@ function Send(payload) {
});
}
exports.Send = Send;
const client = new github.GitHub(process.env.GITHUB_TOKEN);
function successPayload(text) {
const payload = {
text: 'Succeeded Workflow',
attachments: [
{
color: 'good',
author_name: 'action-slack',
fields: [
{ title: 'repo', value: github.context.repo.repo, short: true },
{ title: 'sha', value: github.context.sha, short: true },
{ title: 'actor', value: github.context.actor, short: true },
{ title: 'eventName', value: github.context.eventName, short: true },
{ title: 'ref', value: github.context.ref, short: true },
{ title: 'workflow', value: github.context.workflow, short: true },
],
},
],
};
if (text !== '') {
payload.text = text;
}
return payload;
return __awaiter(this, void 0, void 0, function* () {
const { sha } = github.context;
const { owner, repo } = github.context.repo;
const commit = yield client.repos.getCommit({ owner, repo, ref: sha });
const { author } = commit.data.commit;
const payload = {
text: 'Succeeded Workflow',
attachments: [
{
color: 'good',
author_name: 'action-slack',
fields: [
{ title: 'repo', value: repo, short: true },
{ title: 'message', value: commit.data.commit.message, short: true },
{
title: 'commit',
value: `<https://github.com/${owner}/${repo}/commit/${sha}|${sha}>`,
short: true,
},
{
title: 'author',
value: `${author.name}<${author.email}>`,
short: true,
},
{ title: 'eventName', value: github.context.eventName, short: true },
{ title: 'ref', value: github.context.ref, short: true },
{ title: 'workflow', value: github.context.workflow, short: true },
],
},
],
};
if (text !== '') {
payload.text = text;
}
return payload;
});
}
exports.successPayload = successPayload;
function failurePayload(text, mention) {
const payload = successPayload(text);
payload.text = '';
if (mention !== '') {
payload.text = `<!${mention}> `;
}
payload.text += `Failed Workflow`;
if (text !== '') {
payload.text = text;
}
if (payload.attachments !== undefined) {
payload.attachments[0].color = 'danger';
}
return payload;
return __awaiter(this, void 0, void 0, function* () {
const payload = yield successPayload(text);
payload.text = '';
if (mention !== '') {
payload.text = `<!${mention}> `;
}
payload.text += `Failed Workflow`;
if (text !== '') {
payload.text = text;
}
if (payload.attachments !== undefined) {
payload.attachments[0].color = 'danger';
}
return payload;
});
}
exports.failurePayload = failurePayload;
function newWebhook() {
Expand Down

0 comments on commit 208967a

Please sign in to comment.