Skip to content

Commit 8d93430

Browse files
committed
Refactor main.js for test coverage
1 parent fe2c2b4 commit 8d93430

File tree

5 files changed

+108
-99
lines changed

5 files changed

+108
-99
lines changed

dist/index.js

Lines changed: 56 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -378,55 +378,9 @@ module.exports._enoent = enoent;
378378
/***/ }),
379379

380380
/***/ 31:
381-
/***/ (function(module, __unusedexports, __webpack_require__) {
382-
383-
const core = __webpack_require__(470);
384-
const { GitHub, context } = __webpack_require__(469);
385-
386-
async function run() {
387-
try {
388-
// Get authenticated GitHub client (Ocktokit): https://github.com/actions/toolkit/tree/master/packages/github#usage
389-
const github = new GitHub(process.env.GITHUB_TOKEN);
390-
391-
// Get owner and repo from context of payload that triggered the action
392-
const { owner, repo } = context.repo;
393-
394-
// Get the inputs from the workflow file: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs
395-
const tagName = core.getInput('tag_name', { required: true });
381+
/***/ (function(__unusedmodule, __unusedexports, __webpack_require__) {
396382

397-
// This removes the 'refs/tags' portion of the string, i.e. from 'refs/tags/v1.10.15' to 'v1.10.15'
398-
const tag = tagName.replace('refs/tags/', '');
399-
const releaseName = core.getInput('release_name', { required: true }).replace('refs/tags/', '');
400-
const draft = core.getInput('draft', { required: false }) === 'true';
401-
const prerelease = core.getInput('prerelease', { required: false }) === 'true';
402-
403-
// Create a release
404-
// API Documentation: https://developer.github.com/v3/repos/releases/#create-a-release
405-
// Octokit Documentation: https://octokit.github.io/rest.js/#octokit-routes-repos-create-release
406-
const createReleaseResponse = await github.repos.createRelease({
407-
owner,
408-
repo,
409-
tag_name: tag,
410-
name: releaseName,
411-
draft,
412-
prerelease
413-
});
414-
415-
// Get the ID, html_url, and upload URL for the created Release from the response
416-
const {
417-
data: { id: releaseId, html_url: htmlUrl, upload_url: uploadUrl }
418-
} = createReleaseResponse;
419-
420-
// Set the output variables for use by other actions: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs
421-
core.setOutput('id', releaseId);
422-
core.setOutput('html_url', htmlUrl);
423-
core.setOutput('upload_url', uploadUrl);
424-
} catch (error) {
425-
core.setFailed(error.message);
426-
}
427-
}
428-
429-
module.exports = run;
383+
const run = __webpack_require__(760);
430384

431385
if (require.main === require.cache[eval('__filename')]) {
432386
run();
@@ -7885,6 +7839,60 @@ const request = withDefaults(endpoint.endpoint, {
78857839
exports.request = request;
78867840

78877841

7842+
/***/ }),
7843+
7844+
/***/ 760:
7845+
/***/ (function(module, __unusedexports, __webpack_require__) {
7846+
7847+
const core = __webpack_require__(470);
7848+
const { GitHub, context } = __webpack_require__(469);
7849+
7850+
async function run() {
7851+
try {
7852+
// Get authenticated GitHub client (Ocktokit): https://github.com/actions/toolkit/tree/master/packages/github#usage
7853+
const github = new GitHub(process.env.GITHUB_TOKEN);
7854+
7855+
// Get owner and repo from context of payload that triggered the action
7856+
const { owner, repo } = context.repo;
7857+
7858+
// Get the inputs from the workflow file: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs
7859+
const tagName = core.getInput('tag_name', { required: true });
7860+
7861+
// This removes the 'refs/tags' portion of the string, i.e. from 'refs/tags/v1.10.15' to 'v1.10.15'
7862+
const tag = tagName.replace('refs/tags/', '');
7863+
const releaseName = core.getInput('release_name', { required: true }).replace('refs/tags/', '');
7864+
const draft = core.getInput('draft', { required: false }) === 'true';
7865+
const prerelease = core.getInput('prerelease', { required: false }) === 'true';
7866+
7867+
// Create a release
7868+
// API Documentation: https://developer.github.com/v3/repos/releases/#create-a-release
7869+
// Octokit Documentation: https://octokit.github.io/rest.js/#octokit-routes-repos-create-release
7870+
const createReleaseResponse = await github.repos.createRelease({
7871+
owner,
7872+
repo,
7873+
tag_name: tag,
7874+
name: releaseName,
7875+
draft,
7876+
prerelease
7877+
});
7878+
7879+
// Get the ID, html_url, and upload URL for the created Release from the response
7880+
const {
7881+
data: { id: releaseId, html_url: htmlUrl, upload_url: uploadUrl }
7882+
} = createReleaseResponse;
7883+
7884+
// Set the output variables for use by other actions: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs
7885+
core.setOutput('id', releaseId);
7886+
core.setOutput('html_url', htmlUrl);
7887+
core.setOutput('upload_url', uploadUrl);
7888+
} catch (error) {
7889+
core.setFailed(error.message);
7890+
}
7891+
}
7892+
7893+
module.exports = run;
7894+
7895+
78887896
/***/ }),
78897897

78907898
/***/ 761:

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "create-release",
33
"version": "1.0.0",
4-
"description": "Generate a release",
4+
"description": "Create a release",
55
"main": "dist/index.js",
66
"scripts": {
77
"lint": "eslint 'src/**.js' 'tests/**.js' --fix",
8-
"test": "eslint 'src/**.js' 'tests/**.js' --fix && jest",
8+
"test": "eslint 'src/**.js' 'tests/**.js' && jest --coverage",
99
"build": "ncc build src/main.js",
1010
"precommit": "npm run build && git add dist/"
1111
},
@@ -40,7 +40,7 @@
4040
"jest": {
4141
"testEnvironment": "node",
4242
"collectCoverageFrom": [
43-
"src/main.js"
43+
"src/create-release.js"
4444
],
4545
"coverageThreshold": {
4646
"global": {

src/create-release.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const core = require('@actions/core');
2+
const { GitHub, context } = require('@actions/github');
3+
4+
async function run() {
5+
try {
6+
// Get authenticated GitHub client (Ocktokit): https://github.com/actions/toolkit/tree/master/packages/github#usage
7+
const github = new GitHub(process.env.GITHUB_TOKEN);
8+
9+
// Get owner and repo from context of payload that triggered the action
10+
const { owner, repo } = context.repo;
11+
12+
// Get the inputs from the workflow file: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs
13+
const tagName = core.getInput('tag_name', { required: true });
14+
15+
// This removes the 'refs/tags' portion of the string, i.e. from 'refs/tags/v1.10.15' to 'v1.10.15'
16+
const tag = tagName.replace('refs/tags/', '');
17+
const releaseName = core.getInput('release_name', { required: true }).replace('refs/tags/', '');
18+
const draft = core.getInput('draft', { required: false }) === 'true';
19+
const prerelease = core.getInput('prerelease', { required: false }) === 'true';
20+
21+
// Create a release
22+
// API Documentation: https://developer.github.com/v3/repos/releases/#create-a-release
23+
// Octokit Documentation: https://octokit.github.io/rest.js/#octokit-routes-repos-create-release
24+
const createReleaseResponse = await github.repos.createRelease({
25+
owner,
26+
repo,
27+
tag_name: tag,
28+
name: releaseName,
29+
draft,
30+
prerelease
31+
});
32+
33+
// Get the ID, html_url, and upload URL for the created Release from the response
34+
const {
35+
data: { id: releaseId, html_url: htmlUrl, upload_url: uploadUrl }
36+
} = createReleaseResponse;
37+
38+
// Set the output variables for use by other actions: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs
39+
core.setOutput('id', releaseId);
40+
core.setOutput('html_url', htmlUrl);
41+
core.setOutput('upload_url', uploadUrl);
42+
} catch (error) {
43+
core.setFailed(error.message);
44+
}
45+
}
46+
47+
module.exports = run;

src/main.js

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,4 @@
1-
const core = require('@actions/core');
2-
const { GitHub, context } = require('@actions/github');
3-
4-
async function run() {
5-
try {
6-
// Get authenticated GitHub client (Ocktokit): https://github.com/actions/toolkit/tree/master/packages/github#usage
7-
const github = new GitHub(process.env.GITHUB_TOKEN);
8-
9-
// Get owner and repo from context of payload that triggered the action
10-
const { owner, repo } = context.repo;
11-
12-
// Get the inputs from the workflow file: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs
13-
const tagName = core.getInput('tag_name', { required: true });
14-
15-
// This removes the 'refs/tags' portion of the string, i.e. from 'refs/tags/v1.10.15' to 'v1.10.15'
16-
const tag = tagName.replace('refs/tags/', '');
17-
const releaseName = core.getInput('release_name', { required: true }).replace('refs/tags/', '');
18-
const draft = core.getInput('draft', { required: false }) === 'true';
19-
const prerelease = core.getInput('prerelease', { required: false }) === 'true';
20-
21-
// Create a release
22-
// API Documentation: https://developer.github.com/v3/repos/releases/#create-a-release
23-
// Octokit Documentation: https://octokit.github.io/rest.js/#octokit-routes-repos-create-release
24-
const createReleaseResponse = await github.repos.createRelease({
25-
owner,
26-
repo,
27-
tag_name: tag,
28-
name: releaseName,
29-
draft,
30-
prerelease
31-
});
32-
33-
// Get the ID, html_url, and upload URL for the created Release from the response
34-
const {
35-
data: { id: releaseId, html_url: htmlUrl, upload_url: uploadUrl }
36-
} = createReleaseResponse;
37-
38-
// Set the output variables for use by other actions: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs
39-
core.setOutput('id', releaseId);
40-
core.setOutput('html_url', htmlUrl);
41-
core.setOutput('upload_url', uploadUrl);
42-
} catch (error) {
43-
core.setFailed(error.message);
44-
}
45-
}
46-
47-
module.exports = run;
1+
const run = require('./create-release');
482

493
if (require.main === module) {
504
run();

tests/main.test.js renamed to tests/create-release.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ jest.mock('@actions/github');
33

44
const core = require('@actions/core');
55
const { GitHub, context } = require('@actions/github');
6-
const run = require('../src/main.js');
6+
const run = require('../src/create-release.js');
77

88
/* eslint-disable no-undef */
99
describe('Create Release', () => {

0 commit comments

Comments
 (0)