Skip to content

Use TypeScript #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
183 changes: 130 additions & 53 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ module.exports =
/******/ // the startup function
/******/ function startup() {
/******/ // Load entry module and return exports
/******/ return __webpack_require__(31);
/******/ return __webpack_require__(131);
/******/ };
/******/ // initialize runtime
/******/ runtime(__webpack_require__);
/******/
/******/ // run startup
/******/ return startup();
Expand Down Expand Up @@ -390,57 +392,6 @@ module.exports._parse = parse;
module.exports._enoent = enoent;


/***/ }),

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

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

process.on('unhandledRejection', handleError)
main().catch(handleError)

async function main() {
const AsyncFunction = Object.getPrototypeOf(async () => {}).constructor
const token = core.getInput('github-token', {required: true})
const debug = core.getInput('debug')
const userAgent = core.getInput('user-agent')
const previews = core.getInput('previews')
const opts = {}
if (debug === 'true') opts.log = console
if (userAgent != null) opts.userAgent = userAgent
if (previews != null) opts.previews = previews.split(',')
const client = new GitHub(token, opts)
const script = core.getInput('script', {required: true})
const fn = new AsyncFunction('require', 'github', 'context', script)
const result = await fn(require, client, context)

let encoding = core.getInput('result-encoding')
encoding = encoding ? encoding : 'json'

let output

switch (encoding) {
case 'json':
output = JSON.stringify(result)
break
case 'string':
output = String(result)
break
default:
throw new Error('"result-encoding" must be either "string" or "json"')
}

core.setOutput('result', output)
}

function handleError(err) {
console.error(err)
core.setFailed(err.message)
}


/***/ }),

/***/ 34:
Expand Down Expand Up @@ -1517,6 +1468,74 @@ module.exports = uniq;

module.exports = require("child_process");

/***/ }),

/***/ 131:
/***/ (function(__unusedmodule, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _actions_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(470);
/* harmony import */ var _actions_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_actions_core__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _actions_github__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(469);
/* harmony import */ var _actions_github__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_actions_github__WEBPACK_IMPORTED_MODULE_1__);
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};


process.on('unhandledRejection', handleError);
main().catch(handleError);
function main() {
return __awaiter(this, void 0, void 0, function* () {
const AsyncFunction = Object.getPrototypeOf(() => __awaiter(this, void 0, void 0, function* () { })).constructor;
const token = _actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput('github-token', { required: true });
const debug = _actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput('debug');
const userAgent = _actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput('user-agent');
const previews = _actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput('previews');
const opts = {};
if (debug === 'true')
opts.log = console;
if (userAgent != null)
opts.userAgent = userAgent;
if (previews != null)
opts.previews = previews.split(',');
const client = new _actions_github__WEBPACK_IMPORTED_MODULE_1__.GitHub(token, opts);
const script = _actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput('script', { required: true });
const fn = new AsyncFunction('require', 'github', 'context', script);
const result = yield fn(__webpack_require__(875), client, _actions_github__WEBPACK_IMPORTED_MODULE_1__.context);
let encoding = _actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput('result-encoding');
encoding = encoding ? encoding : 'json';
let output;
switch (encoding) {
case 'json':
output = JSON.stringify(result);
break;
case 'string':
output = String(result);
break;
default:
throw new Error('"result-encoding" must be either "string" or "json"');
}
_actions_core__WEBPACK_IMPORTED_MODULE_0__.setOutput('result', output);
});
}
function handleError(err) {
console.error(err);
if (err && err.message) {
_actions_core__WEBPACK_IMPORTED_MODULE_0__.setFailed(err.message);
}
else {
_actions_core__WEBPACK_IMPORTED_MODULE_0__.setFailed(`Unhandled error: ${err}`);
}
}


/***/ }),

/***/ 143:
Expand Down Expand Up @@ -9524,6 +9543,25 @@ module.exports = function (str) {
};


/***/ }),

/***/ 875:
/***/ (function(module) {

function webpackEmptyContext(req) {
if (typeof req === 'number' && __webpack_require__.m[req])
return __webpack_require__(req);
try { return require(req) }
catch (e) { if (e.code !== 'MODULE_NOT_FOUND') throw e }
var e = new Error("Cannot find module '" + req + "'");
e.code = 'MODULE_NOT_FOUND';
throw e;
}
webpackEmptyContext.keys = function() { return []; };
webpackEmptyContext.resolve = webpackEmptyContext;
module.exports = webpackEmptyContext;
webpackEmptyContext.id = 875;

/***/ }),

/***/ 881:
Expand Down Expand Up @@ -11235,4 +11273,43 @@ function onceStrict (fn) {

/***/ })

/******/ });
/******/ },
/******/ function(__webpack_require__) { // webpackRuntimeModules
/******/ "use strict";
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ !function() {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ }();
/******/
/******/ /* webpack/runtime/compat get default export */
/******/ !function() {
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/ }();
/******/
/******/ /* webpack/runtime/define property getter */
/******/ !function() {
/******/ // define getter function for harmony exports
/******/ var hasOwnProperty = Object.prototype.hasOwnProperty;
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!hasOwnProperty.call(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/ }();
/******/
/******/ }
);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"main": "dist/index.js",
"scripts": {
"build": "ncc build src/main.js",
"build": "ncc build src/main.ts",
"precommit": "npm run build && git add dist/"
},
"author": "GitHub",
Expand Down
15 changes: 10 additions & 5 deletions src/main.js → src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const core = require('@actions/core')
const {GitHub, context} = require('@actions/github')
import * as core from '@actions/core'
import {context, GitHub} from '@actions/github'

process.on('unhandledRejection', handleError)
main().catch(handleError)
Expand All @@ -10,7 +10,7 @@ async function main() {
const debug = core.getInput('debug')
const userAgent = core.getInput('user-agent')
const previews = core.getInput('previews')
const opts = {}
const opts: {[key: string]: any} = {}
if (debug === 'true') opts.log = console
if (userAgent != null) opts.userAgent = userAgent
if (previews != null) opts.previews = previews.split(',')
Expand Down Expand Up @@ -38,7 +38,12 @@ async function main() {
core.setOutput('result', output)
}

function handleError(err) {
function handleError(err: any) {
console.error(err)
core.setFailed(err.message)

if (err && err.message) {
core.setFailed(err.message)
} else {
core.setFailed(`Unhandled error: ${err}`)
}
}
8 changes: 8 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"target": "es2015",
"moduleResolution": "node",
"strict": true,
"forceConsistentCasingInFileNames": true
}
}