Skip to content

Commit

Permalink
Add specs
Browse files Browse the repository at this point in the history
  • Loading branch information
leopic committed Mar 3, 2020
1 parent 2c076f9 commit a5c82c7
Show file tree
Hide file tree
Showing 106 changed files with 18,096 additions and 556 deletions.
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
description: 'Human readable message with PR result'
runs:
using: 'node12'
main: 'index.js'
main: 'lib/index.js'
551 changes: 0 additions & 551 deletions index.js

This file was deleted.

109 changes: 109 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
'use strict';

const core = require('@actions/core');
const github = require('@actions/github');

const getFallbackBlocks = (jobStatus, payload) => {
const repoName = `*<${payload.repository.html_url}|${payload.repository.full_name}>*`;
const eventName = github.context.eventName;
const success = jobStatus === 'Success';
const author = `<${payload.sender.html_url}|${payload.sender.login}>`;
const emoji = success ? ':thumbsup:' : ':thumbsdown:';
const eventLink = `<${payload.repository.html_url}|${eventName}>`;

return [
{
"type": "section",
"text": `${repoName}: the result of a ${eventName} by ${author} was: ${emoji}\n Details: ${eventLink}`
}
];
};

const getField = (head, body) => {
return {
"type": "mrkdwn",
"text": `*${head}*: ${body}`
}
};

const getButton = (title, url) => {
return {
"type": "button",
"text": {
"type": "plain_text",
"text": title
},
"url": url
};
};

const getPullRequestBlocks = (jobStatus, payload) => {
const success = jobStatus === 'Success';
const pullRequest = payload.pull_request;

const repoName = `*<${payload.repository.html_url}|${payload.repository.full_name}>*`;
const firstLine = `${repoName}`;

const emoji = success ? ':thumbsup:' : ':thumbsdown:';
const prURL = pullRequest.html_url;
const pullRequestLink = `<${prURL}|${pullRequest.title} #${pullRequest.number}>`;
const secondLine = `${pullRequestLink} ${emoji}`;

const author = `<${payload.sender.html_url}|${payload.sender.login}>`;
const thirdLine = `${author} submitted a pull request`;

const textBlock = {
"type": "mrkdwn",
"text": [firstLine, secondLine, thirdLine].join('\n')
};

const divider = {
"type": "divider"
};

return [
{
"type": "section",
"text": textBlock,
"accessory": getButton('Execution Details', `${prURL}/checks`),
"fields": [
getField('Branch', pullRequest.head.ref),
getField('Sha', pullRequest.head.sha.substring(0, 7)),
getField('Changed files', pullRequest.changed_files),
getField('Commits', pullRequest.commits)
]
},
divider
];
};

const formatBlocks = obj => {
return JSON.stringify(obj).replace(/"/g, '\\"')
};

const run = () => {
try {
const jobStatus = core.getInput('job-status');
const payload = github.context.payload;
const isPR = github.context.eventName === 'pull_request';
const blocks = isPR ? getPullRequestBlocks(jobStatus, payload) : getFallbackBlocks(jobStatus, payload);

core.setOutput('blocks', formatBlocks(blocks));
} catch (error) {
core.setFailed(error.message);
}
};

module.exports = {
getPullRequestBlocks: getPullRequestBlocks,
getField: getField,
getButton: getButton,
getFallbackBlocks: getFallbackBlocks,
formatBlocks: formatBlocks,
run: run
};

if (!process.argv.join('').includes('jasmine')) {
run();
}

1 change: 1 addition & 0 deletions node_modules/.bin/jasmine

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions node_modules/balanced-match/.npmignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions node_modules/balanced-match/LICENSE.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 91 additions & 0 deletions node_modules/balanced-match/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions node_modules/balanced-match/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 77 additions & 0 deletions node_modules/balanced-match/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions node_modules/brace-expansion/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a5c82c7

Please sign in to comment.