Skip to content

Commit

Permalink
custom lock path note in comment, dependencies bump (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
Simek authored Jul 15, 2021
1 parent d12a7de commit 573d067
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 169 deletions.
10 changes: 2 additions & 8 deletions dist/index.js

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
"optimize": "svgo -f ./assets"
},
"dependencies": {
"@actions/core": "^1.2.7",
"@actions/github": "^4.0.0",
"@actions/core": "^1.4.0",
"@actions/github": "^5.0.0",
"@yarnpkg/lockfile": "^1.1.0",
"compare-versions": "^3.6.0",
"js-base64": "^3.6.0",
"markdown-table": "^3.0.0"
"js-base64": "^3.6.1",
"markdown-table": "^3.0.1"
},
"devDependencies": {
"eslint": "^7.25.0",
"eslint": "^7.30.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"prettier": "^2.2.1",
"svgo": "^2.3.0"
"prettier": "^2.3.2",
"svgo": "^2.3.1"
}
}
31 changes: 10 additions & 21 deletions src/action.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { getInput, setFailed } = require('@actions/core');
const { getBooleanInput, getInput, setFailed } = require('@actions/core');
const { context, getOctokit } = require('@actions/github');
const lockfile = require('@yarnpkg/lockfile');
const fs = require('fs');
Expand All @@ -9,22 +9,8 @@ const { STATUS, countStatuses, createTable, createSummary, diffLocks } = require

const COMMENT_HEADER = '## `yarn.lock` changes';

const getBooleanInput = (input) => {
const trueValues = ['true', 'yes', 'y', 'on'];
const falseValues = ['false', 'no', 'n', 'off'];
const inputValue = getInput(input).toLowerCase();

if (trueValues.includes(inputValue)) {
return true;
} else if (falseValues.includes(inputValue)) {
return false;
}

throw TypeError(`💥 Wrong boolean value of the input '${input}', aborting!`);
};

const getCommentId = async (octokit, oktokitParams, issueNumber) => {
const currentComments = await octokit.issues.listComments({
const currentComments = await octokit.rest.issues.listComments({
...oktokitParams,
issue_number: issueNumber,
per_page: 100
Expand Down Expand Up @@ -66,7 +52,7 @@ const run = async () => {
throw Error('💥 It looks like lock does not exist in this PR, aborting!');
}

const content = await fs.readFileSync(lockPath, { encoding: 'utf8' });
const content = fs.readFileSync(lockPath, { encoding: 'utf8' });
const updatedLock = lockfile.parse(content);

const baseTree = await octokit.request('GET /repos/{owner}/{repo}/git/trees/{branch}:{path}', {
Expand Down Expand Up @@ -106,10 +92,13 @@ const run = async () => {

const collapsed = lockChangesCount >= collapsibleThreshold;
const changesSummary = collapsed ? '### Summary\n' + createSummary(lockChanges) : '';
const lockPathNote = inputPath !== 'yarn.lock' ? '> Lock path: `' + inputPath + '`\n' : '';

const body =
COMMENT_HEADER +
'\n' +
lockPathNote +
'\n' +
changesSummary +
'\n' +
'<details' +
Expand All @@ -122,28 +111,28 @@ const run = async () => {

if (updateComment) {
if (commentId) {
await octokit.issues.updateComment({
await octokit.rest.issues.updateComment({
...oktokitParams,
comment_id: commentId,
body
});
} else {
await octokit.issues.createComment({
await octokit.rest.issues.createComment({
...oktokitParams,
issue_number: number,
body
});
}
} else {
await octokit.issues.createComment({
await octokit.rest.issues.createComment({
...oktokitParams,
issue_number: number,
body
});
}
} else {
if (updateComment && commentId) {
await octokit.issues.deleteComment({
await octokit.rest.issues.deleteComment({
...oktokitParams,
comment_id: commentId
});
Expand Down
Loading

0 comments on commit 573d067

Please sign in to comment.