Skip to content

Commit 9116c86

Browse files
committed
fix: cleanup lint/review errors
- out-of-order functions - extra semicolons - extra escaping - mutation of lists
1 parent 1fdbe60 commit 9116c86

File tree

3 files changed

+141
-147
lines changed

3 files changed

+141
-147
lines changed

dist/main/index.js

Lines changed: 70 additions & 73 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/main/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.js

Lines changed: 70 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -7,77 +7,10 @@ const lcovTotal = require("lcov-total");
77
const os = require('os');
88
const path = require('path');
99

10-
async function run() {
11-
try {
12-
await exec.exec('sudo apt-get install -y lcov');
13-
14-
const tmpPath = path.resolve(os.tmpdir(), github.context.action);
15-
const workingDirectory = ensureTrailingSlash(core.getInput('working-directory').trim() || './');
16-
const coverageFilesPattern = core.getInput('coverage-files');
17-
const globber = await glob.create(coverageFilesPattern);
18-
const coverageFiles = await globber.glob();
19-
20-
await genhtml(coverageFiles, tmpPath, workingDirectory);
21-
22-
const coverageFile = await mergeCoverages(coverageFiles, tmpPath);
23-
const totalCoverage = lcovTotal(coverageFile);
24-
const minimumCoverage = core.getInput('minimum-coverage');
25-
const gitHubToken = core.getInput('github-token').trim();
26-
const errorMessage = `The code coverage is too low. Expected at least ${minimumCoverage}.`;
27-
const isFailure = totalCoverage < minimumCoverage;
28-
29-
if (gitHubToken !== '') {
30-
const octokit = await github.getOctokit(gitHubToken);
31-
const prs = pullRequests(github);
32-
for (let i=0; i < prs.length; i++) {
33-
const pr = prs[i];
34-
console.log(`Calculating coverage for PR ${pr.number}, sha ${pr.head.sha}...`);
35-
const summary = await summarize(coverageFile);
36-
const details = await detail(coverageFile, pr, octokit, workingDirectory);
37-
const shaShort = pr.head.sha.substr(0, 7);
38-
let body = `### Coverage of commit [<code>${shaShort}</code>](${pr.number}/commits/${pr.head.sha})
39-
<pre>${summary}
40-
41-
Files changed coverage rate:${details}</pre>
42-
43-
[Download coverage report](../actions/runs/${github.context.runId})
44-
`;
45-
46-
if (isFailure) {
47-
body += `\n:no_entry: ${errorMessage}`;
48-
}
49-
50-
console.log("Posting body:");
51-
console.log(body);
52-
53-
try {
54-
await octokit.issues.createComment({
55-
issue_number: pr.number,
56-
body: body,
57-
...ownerRepo(pr.url)
58-
});
59-
} catch (error) {
60-
console.log("Unable to post coverage report.");
61-
console.log(error);
62-
}
63-
};
64-
} else {
65-
console.log("No GITHUB_TOKEN, not posting.");
66-
}
67-
68-
if (isFailure) {
69-
throw Error(errorMessage);
70-
}
71-
} catch (error) {
72-
console.error(error);
73-
core.setFailed(error.message);
74-
}
75-
}
76-
7710
function pullRequests(github) {
7811
if (github.context.eventName === "pull_request") {
7912
return [github.context.payload.pull_request];
80-
};
13+
}
8114
if (github.context.eventName == "workflow_run") {
8215
if (github.context.payload.workflow_run.pull_requests.length > 0) {
8316
return github.context.payload.workflow_run.pull_requests;
@@ -97,7 +30,7 @@ function pullRequests(github) {
9730
}
9831

9932
function ownerRepo(url) {
100-
const match = url.match(/\/repos\/(?<owner>[^\/]+)\/(?<repo>[^\/]+)\/pulls\//);
33+
const match = url.match(/\/repos\/(?<owner>[^/]+)\/(?<repo>[^/]+)\/pulls\//);
10134
return {
10235
owner: match[1],
10336
repo: match[2],
@@ -115,10 +48,7 @@ function ensureTrailingSlash(path) {
11548
async function genhtml(coverageFiles, tmpPath, workingDirectory) {
11649
const artifactName = core.getInput('artifact-name').trim();
11750
const artifactPath = path.resolve(tmpPath, 'html').trim();
118-
const args = [...coverageFiles, '--rc', 'lcov_branch_coverage=1'];
119-
120-
args.push('--output-directory');
121-
args.push(artifactPath);
51+
const args = [...coverageFiles, '--rc', 'lcov_branch_coverage=1', '--output-directory', artifactPath];
12252

12353
await exec.exec('genhtml', args, { cwd: workingDirectory });
12454

@@ -238,4 +168,71 @@ async function detail(coverageFile, pull_request, octokit, workingDirectory) {
238168
return '\n ' + lines.join('\n ');
239169
}
240170

171+
async function run() {
172+
try {
173+
await exec.exec('sudo apt-get install -y lcov');
174+
175+
const tmpPath = path.resolve(os.tmpdir(), github.context.action);
176+
const workingDirectory = ensureTrailingSlash(core.getInput('working-directory').trim() || './');
177+
const coverageFilesPattern = core.getInput('coverage-files');
178+
const globber = await glob.create(coverageFilesPattern);
179+
const coverageFiles = await globber.glob();
180+
181+
await genhtml(coverageFiles, tmpPath, workingDirectory);
182+
183+
const coverageFile = await mergeCoverages(coverageFiles, tmpPath);
184+
const totalCoverage = lcovTotal(coverageFile);
185+
const minimumCoverage = core.getInput('minimum-coverage');
186+
const gitHubToken = core.getInput('github-token').trim();
187+
const errorMessage = `The code coverage is too low. Expected at least ${minimumCoverage}.`;
188+
const isFailure = totalCoverage < minimumCoverage;
189+
190+
if (gitHubToken !== '') {
191+
const octokit = await github.getOctokit(gitHubToken);
192+
const prs = pullRequests(github);
193+
for (let i=0; i < prs.length; i++) {
194+
const pr = prs[i];
195+
console.log(`Calculating coverage for PR ${pr.number}, sha ${pr.head.sha}...`);
196+
const summary = await summarize(coverageFile);
197+
const details = await detail(coverageFile, pr, octokit, workingDirectory);
198+
const shaShort = pr.head.sha.substr(0, 7);
199+
let body = `### Coverage of commit [<code>${shaShort}</code>](${pr.number}/commits/${pr.head.sha})
200+
<pre>${summary}
201+
202+
Files changed coverage rate:${details}</pre>
203+
204+
[Download coverage report](../actions/runs/${github.context.runId})
205+
`;
206+
207+
if (isFailure) {
208+
body += `\n:no_entry: ${errorMessage}`;
209+
}
210+
211+
console.log("Posting body:");
212+
console.log(body);
213+
214+
try {
215+
await octokit.issues.createComment({
216+
issue_number: pr.number,
217+
body: body,
218+
...ownerRepo(pr.url)
219+
});
220+
} catch (error) {
221+
console.log("Unable to post coverage report.");
222+
console.log(error);
223+
}
224+
}
225+
} else {
226+
console.log("No GITHUB_TOKEN, not posting.");
227+
}
228+
229+
if (isFailure) {
230+
throw Error(errorMessage);
231+
}
232+
} catch (error) {
233+
console.error(error);
234+
core.setFailed(error.message);
235+
}
236+
}
237+
241238
run();

0 commit comments

Comments
 (0)