Skip to content

Commit

Permalink
add ESLint, cleanup action (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Simek authored Apr 26, 2021
1 parent 6030630 commit 2ce66cc
Show file tree
Hide file tree
Showing 5 changed files with 787 additions and 19 deletions.
25 changes: 25 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"env": {
"commonjs": true,
"es2021": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 12
},
"rules": {
"indent": [
"error",
2
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
]
}
}
30 changes: 14 additions & 16 deletions action.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const core = require('@actions/core');
const github = require('@actions/github');
const lockfile = require("@yarnpkg/lockfile");
const lockfile = require('@yarnpkg/lockfile');
const fs = require('fs');
const path = require('path');
const { markdownTable } = require('markdown-table');
Expand All @@ -14,44 +14,44 @@ const diff = (previous, current) => {
Object.keys(previousPackages).forEach((key) => {
changes[key] = {
previous: previousPackages[key].version,
current: "-",
status: "🗑️ **REMOVED**"
current: '-',
status: '🗑️ **REMOVED**'
};
});

Object.keys(currentPackages).forEach((key) => {
if (!changes[key]) {
changes[key] = {
previous: "-",
previous: '-',
current: currentPackages[key].version,
status: "✨ **NEW**"
status: '✨ **NEW**'
};
} else {
if (changes[key].previous === currentPackages[key].version) {
delete changes[key];
} else {
changes[key].current = currentPackages[key].version;
changes[key].status = "⬆️ **UPDATED**";
changes[key].status = '⬆️ **UPDATED**';
}
}
});

return changes;
}
};

const formatNameAndVersion = (obj) => {
const packages = {};

Object.keys(obj.object).forEach((key) => {
const names = key.split("@");
const name = names[0] === "" ? "@" + names[1] : names[0];
const names = key.split('@');
const name = names[0] === '' ? '@' + names[1] : names[0];
packages[name] = { name, version: obj.object[key].version };
});

return packages;
}
};

async function run() {
const run = async () => {
try {
const octokit = github.getOctokit(core.getInput('token'));
const { owner, repo, number } = github.context.issue;
Expand All @@ -64,7 +64,7 @@ async function run() {
const lockPath = path.resolve(process.cwd(), core.getInput('path'));

if (!fs.existsSync(lockPath)) {
throw new Error(`${lockPath} does not exist!`)
throw new Error(`${lockPath} does not exist!`);
}

const content = await fs.readFileSync(lockPath, { encoding: 'utf8' });
Expand All @@ -77,16 +77,14 @@ async function run() {
}

const masterLock = lockfile.parse(await response.text());

const lockChanges = diff(masterLock, updatedLock);
console.warn(lockChanges)

const diffsTable = markdownTable([
['Name', 'Status', 'Previous', 'Current'],
...Object.entries(lockChanges).map(([key, value]) => (
['`' + key + '`', value.status, value.previous, value.current]
)).sort((a, b) => a[0].localeCompare(b[0]))
])
]);

await octokit.issues.createComment({
owner,
Expand All @@ -98,6 +96,6 @@ async function run() {
} catch (error) {
core.setFailed(error.message);
}
}
};

run();
Loading

0 comments on commit 2ce66cc

Please sign in to comment.