-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
65 lines (56 loc) · 1.63 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import core from '@actions/core';
import { formatErrors, formatResultsTable } from '@sinedied/devto-cli';
import { publishArticles } from './lib/publish.js';
async function run() {
try {
const devtoKey = core.getInput('devto_key');
const githubToken = core.getInput('github_token');
const filesGlob = core.getInput('files');
const branch = core.getInput('branch');
const useConventionalCommits = core.getInput('conventional_commits');
const dryRun = core.getBooleanInput('dry_run');
core.setSecret(devtoKey);
core.setSecret(githubToken);
core.debug(
JSON.stringify({
devtoKey,
githubToken,
filesGlob,
branch,
useConventionalCommits,
dryRun
})
);
const results = await publishArticles({
filesGlob,
devtoKey,
githubToken,
branch,
useConventionalCommits,
dryRun
});
const output = results.map((r) => ({
id: r.article.data.id,
title: r.article.data.title,
status: r.status,
publishedStatus: r.publishedStatus,
errors: r.errors
}));
const json = JSON.stringify(output, null, 2);
core.debug('Output result_json:\n' + json);
core.setOutput('result_json', json);
let summary = `Found ${results.length} article(s)\n`;
const errors = formatErrors(results);
if (errors) {
summary += errors + '\n';
}
if (results.length > 0) {
summary += formatResultsTable(results);
}
core.debug('Output result_summary:\n' + summary);
core.setOutput('result_summary', summary);
} catch (error) {
core.setFailed(error.toString());
}
}
run();