Skip to content
This repository has been archived by the owner on Mar 4, 2021. It is now read-only.

Commit

Permalink
Refactor main.js for test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
IAmHughes committed Sep 27, 2019
1 parent fe2c2b4 commit 8d93430
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 99 deletions.
104 changes: 56 additions & 48 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,55 +378,9 @@ module.exports._enoent = enoent;
/***/ }),

/***/ 31:
/***/ (function(module, __unusedexports, __webpack_require__) {

const core = __webpack_require__(470);
const { GitHub, context } = __webpack_require__(469);

async function run() {
try {
// Get authenticated GitHub client (Ocktokit): https://github.com/actions/toolkit/tree/master/packages/github#usage
const github = new GitHub(process.env.GITHUB_TOKEN);

// Get owner and repo from context of payload that triggered the action
const { owner, repo } = context.repo;

// Get the inputs from the workflow file: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs
const tagName = core.getInput('tag_name', { required: true });
/***/ (function(__unusedmodule, __unusedexports, __webpack_require__) {

// This removes the 'refs/tags' portion of the string, i.e. from 'refs/tags/v1.10.15' to 'v1.10.15'
const tag = tagName.replace('refs/tags/', '');
const releaseName = core.getInput('release_name', { required: true }).replace('refs/tags/', '');
const draft = core.getInput('draft', { required: false }) === 'true';
const prerelease = core.getInput('prerelease', { required: false }) === 'true';

// Create a release
// API Documentation: https://developer.github.com/v3/repos/releases/#create-a-release
// Octokit Documentation: https://octokit.github.io/rest.js/#octokit-routes-repos-create-release
const createReleaseResponse = await github.repos.createRelease({
owner,
repo,
tag_name: tag,
name: releaseName,
draft,
prerelease
});

// Get the ID, html_url, and upload URL for the created Release from the response
const {
data: { id: releaseId, html_url: htmlUrl, upload_url: uploadUrl }
} = createReleaseResponse;

// Set the output variables for use by other actions: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs
core.setOutput('id', releaseId);
core.setOutput('html_url', htmlUrl);
core.setOutput('upload_url', uploadUrl);
} catch (error) {
core.setFailed(error.message);
}
}

module.exports = run;
const run = __webpack_require__(760);

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


/***/ }),

/***/ 760:
/***/ (function(module, __unusedexports, __webpack_require__) {

const core = __webpack_require__(470);
const { GitHub, context } = __webpack_require__(469);

async function run() {
try {
// Get authenticated GitHub client (Ocktokit): https://github.com/actions/toolkit/tree/master/packages/github#usage
const github = new GitHub(process.env.GITHUB_TOKEN);

// Get owner and repo from context of payload that triggered the action
const { owner, repo } = context.repo;

// Get the inputs from the workflow file: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs
const tagName = core.getInput('tag_name', { required: true });

// This removes the 'refs/tags' portion of the string, i.e. from 'refs/tags/v1.10.15' to 'v1.10.15'
const tag = tagName.replace('refs/tags/', '');
const releaseName = core.getInput('release_name', { required: true }).replace('refs/tags/', '');
const draft = core.getInput('draft', { required: false }) === 'true';
const prerelease = core.getInput('prerelease', { required: false }) === 'true';

// Create a release
// API Documentation: https://developer.github.com/v3/repos/releases/#create-a-release
// Octokit Documentation: https://octokit.github.io/rest.js/#octokit-routes-repos-create-release
const createReleaseResponse = await github.repos.createRelease({
owner,
repo,
tag_name: tag,
name: releaseName,
draft,
prerelease
});

// Get the ID, html_url, and upload URL for the created Release from the response
const {
data: { id: releaseId, html_url: htmlUrl, upload_url: uploadUrl }
} = createReleaseResponse;

// Set the output variables for use by other actions: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs
core.setOutput('id', releaseId);
core.setOutput('html_url', htmlUrl);
core.setOutput('upload_url', uploadUrl);
} catch (error) {
core.setFailed(error.message);
}
}

module.exports = run;


/***/ }),

/***/ 761:
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "create-release",
"version": "1.0.0",
"description": "Generate a release",
"description": "Create a release",
"main": "dist/index.js",
"scripts": {
"lint": "eslint 'src/**.js' 'tests/**.js' --fix",
"test": "eslint 'src/**.js' 'tests/**.js' --fix && jest",
"test": "eslint 'src/**.js' 'tests/**.js' && jest --coverage",
"build": "ncc build src/main.js",
"precommit": "npm run build && git add dist/"
},
Expand Down Expand Up @@ -40,7 +40,7 @@
"jest": {
"testEnvironment": "node",
"collectCoverageFrom": [
"src/main.js"
"src/create-release.js"
],
"coverageThreshold": {
"global": {
Expand Down
47 changes: 47 additions & 0 deletions src/create-release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const core = require('@actions/core');
const { GitHub, context } = require('@actions/github');

async function run() {
try {
// Get authenticated GitHub client (Ocktokit): https://github.com/actions/toolkit/tree/master/packages/github#usage
const github = new GitHub(process.env.GITHUB_TOKEN);

// Get owner and repo from context of payload that triggered the action
const { owner, repo } = context.repo;

// Get the inputs from the workflow file: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs
const tagName = core.getInput('tag_name', { required: true });

// This removes the 'refs/tags' portion of the string, i.e. from 'refs/tags/v1.10.15' to 'v1.10.15'
const tag = tagName.replace('refs/tags/', '');
const releaseName = core.getInput('release_name', { required: true }).replace('refs/tags/', '');
const draft = core.getInput('draft', { required: false }) === 'true';
const prerelease = core.getInput('prerelease', { required: false }) === 'true';

// Create a release
// API Documentation: https://developer.github.com/v3/repos/releases/#create-a-release
// Octokit Documentation: https://octokit.github.io/rest.js/#octokit-routes-repos-create-release
const createReleaseResponse = await github.repos.createRelease({
owner,
repo,
tag_name: tag,
name: releaseName,
draft,
prerelease
});

// Get the ID, html_url, and upload URL for the created Release from the response
const {
data: { id: releaseId, html_url: htmlUrl, upload_url: uploadUrl }
} = createReleaseResponse;

// Set the output variables for use by other actions: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs
core.setOutput('id', releaseId);
core.setOutput('html_url', htmlUrl);
core.setOutput('upload_url', uploadUrl);
} catch (error) {
core.setFailed(error.message);
}
}

module.exports = run;
48 changes: 1 addition & 47 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,4 @@
const core = require('@actions/core');
const { GitHub, context } = require('@actions/github');

async function run() {
try {
// Get authenticated GitHub client (Ocktokit): https://github.com/actions/toolkit/tree/master/packages/github#usage
const github = new GitHub(process.env.GITHUB_TOKEN);

// Get owner and repo from context of payload that triggered the action
const { owner, repo } = context.repo;

// Get the inputs from the workflow file: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs
const tagName = core.getInput('tag_name', { required: true });

// This removes the 'refs/tags' portion of the string, i.e. from 'refs/tags/v1.10.15' to 'v1.10.15'
const tag = tagName.replace('refs/tags/', '');
const releaseName = core.getInput('release_name', { required: true }).replace('refs/tags/', '');
const draft = core.getInput('draft', { required: false }) === 'true';
const prerelease = core.getInput('prerelease', { required: false }) === 'true';

// Create a release
// API Documentation: https://developer.github.com/v3/repos/releases/#create-a-release
// Octokit Documentation: https://octokit.github.io/rest.js/#octokit-routes-repos-create-release
const createReleaseResponse = await github.repos.createRelease({
owner,
repo,
tag_name: tag,
name: releaseName,
draft,
prerelease
});

// Get the ID, html_url, and upload URL for the created Release from the response
const {
data: { id: releaseId, html_url: htmlUrl, upload_url: uploadUrl }
} = createReleaseResponse;

// Set the output variables for use by other actions: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs
core.setOutput('id', releaseId);
core.setOutput('html_url', htmlUrl);
core.setOutput('upload_url', uploadUrl);
} catch (error) {
core.setFailed(error.message);
}
}

module.exports = run;
const run = require('./create-release');

if (require.main === module) {
run();
Expand Down
2 changes: 1 addition & 1 deletion tests/main.test.js → tests/create-release.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ jest.mock('@actions/github');

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

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

0 comments on commit 8d93430

Please sign in to comment.