Skip to content

Commit 13592be

Browse files
committed
Colors
1 parent 85bbdc5 commit 13592be

File tree

5 files changed

+329
-15
lines changed

5 files changed

+329
-15
lines changed

dist/LICENSE.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,19 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
241241
THE SOFTWARE.
242242

243243

244+
ansi-styles
245+
MIT
246+
MIT License
247+
248+
Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com)
249+
250+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
251+
252+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
253+
254+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
255+
256+
244257
before-after-hook
245258
Apache-2.0
246259
Apache License

dist/index.js

Lines changed: 283 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29229,27 +29229,38 @@ var __importStar = (this && this.__importStar) || function (mod) {
2922929229
__setModuleDefault(result, mod);
2923029230
return result;
2923129231
};
29232+
var __importDefault = (this && this.__importDefault) || function (mod) {
29233+
return (mod && mod.__esModule) ? mod : { "default": mod };
29234+
};
2923229235
Object.defineProperty(exports, "__esModule", ({ value: true }));
2923329236
const core = __importStar(__nccwpck_require__(9190));
2923429237
const github = __importStar(__nccwpck_require__(2145));
29238+
const ansi_styles_1 = __importDefault(__nccwpck_require__(7011));
2923529239
async function run() {
2923629240
try {
2923729241
const allowedIds = core.getInput('whitelisted-github-ids');
29238-
if (allowedIds === undefined || allowedIds === "") {
29239-
throw new Error("Input 'whitelisted-github-ids' was empty.");
29242+
if (!allowedIds || allowedIds === "") {
29243+
throw new Error(`Input ${ansi_styles_1.default.italic.open}whitelisted-github-ids${ansi_styles_1.default.italic.close} is missing or empty.`);
29244+
}
29245+
core.setSecret('token');
29246+
const token = core.getInput('token');
29247+
if (!token) {
29248+
throw new Error(`Input ${ansi_styles_1.default.italic.open}token${ansi_styles_1.default.italic.close} is missing.`);
2924029249
}
2924129250
const allowedUserIds = allowedIds.split(',');
29242-
const octokit = github.getOctokit(core.getInput('token'));
29251+
const octokit = github.getOctokit(token, {
29252+
userAgent: "aitsys-actions"
29253+
});
2924329254
const username = github.context.actor;
2924429255
const { data: user } = await octokit.rest.users.getByUsername({
2924529256
username: username,
2924629257
});
2924729258
const userId = user.id.toString();
2924829259
if (allowedUserIds.includes(userId)) {
29249-
console.log(`User ${userId} is allowed to run this workflow.`);
29260+
core.notice(`${ansi_styles_1.default.green.open}User ${ansi_styles_1.default.bold.open}${userId}${ansi_styles_1.default.bold.close} authorized this workflow run.${ansi_styles_1.default.green.close}`);
2925029261
}
2925129262
else {
29252-
throw new Error(`User ${userId} is not authorized to run this workflow.`);
29263+
throw new Error(`User ${ansi_styles_1.default.bold.open}${userId}${ansi_styles_1.default.bold.close} is not authorized to run this workflow. Aborting`);
2925329264
}
2925429265
}
2925529266
catch (error) {
@@ -31108,6 +31119,245 @@ function parseParams (str) {
3110831119
module.exports = parseParams
3110931120

3111031121

31122+
/***/ }),
31123+
31124+
/***/ 7011:
31125+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __nccwpck_require__) => {
31126+
31127+
"use strict";
31128+
__nccwpck_require__.r(__webpack_exports__);
31129+
/* harmony export */ __nccwpck_require__.d(__webpack_exports__, {
31130+
/* harmony export */ "backgroundColorNames": () => (/* binding */ backgroundColorNames),
31131+
/* harmony export */ "colorNames": () => (/* binding */ colorNames),
31132+
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__),
31133+
/* harmony export */ "foregroundColorNames": () => (/* binding */ foregroundColorNames),
31134+
/* harmony export */ "modifierNames": () => (/* binding */ modifierNames)
31135+
/* harmony export */ });
31136+
const ANSI_BACKGROUND_OFFSET = 10;
31137+
31138+
const wrapAnsi16 = (offset = 0) => code => `\u001B[${code + offset}m`;
31139+
31140+
const wrapAnsi256 = (offset = 0) => code => `\u001B[${38 + offset};5;${code}m`;
31141+
31142+
const wrapAnsi16m = (offset = 0) => (red, green, blue) => `\u001B[${38 + offset};2;${red};${green};${blue}m`;
31143+
31144+
const styles = {
31145+
modifier: {
31146+
reset: [0, 0],
31147+
// 21 isn't widely supported and 22 does the same thing
31148+
bold: [1, 22],
31149+
dim: [2, 22],
31150+
italic: [3, 23],
31151+
underline: [4, 24],
31152+
overline: [53, 55],
31153+
inverse: [7, 27],
31154+
hidden: [8, 28],
31155+
strikethrough: [9, 29],
31156+
},
31157+
color: {
31158+
black: [30, 39],
31159+
red: [31, 39],
31160+
green: [32, 39],
31161+
yellow: [33, 39],
31162+
blue: [34, 39],
31163+
magenta: [35, 39],
31164+
cyan: [36, 39],
31165+
white: [37, 39],
31166+
31167+
// Bright color
31168+
blackBright: [90, 39],
31169+
gray: [90, 39], // Alias of `blackBright`
31170+
grey: [90, 39], // Alias of `blackBright`
31171+
redBright: [91, 39],
31172+
greenBright: [92, 39],
31173+
yellowBright: [93, 39],
31174+
blueBright: [94, 39],
31175+
magentaBright: [95, 39],
31176+
cyanBright: [96, 39],
31177+
whiteBright: [97, 39],
31178+
},
31179+
bgColor: {
31180+
bgBlack: [40, 49],
31181+
bgRed: [41, 49],
31182+
bgGreen: [42, 49],
31183+
bgYellow: [43, 49],
31184+
bgBlue: [44, 49],
31185+
bgMagenta: [45, 49],
31186+
bgCyan: [46, 49],
31187+
bgWhite: [47, 49],
31188+
31189+
// Bright color
31190+
bgBlackBright: [100, 49],
31191+
bgGray: [100, 49], // Alias of `bgBlackBright`
31192+
bgGrey: [100, 49], // Alias of `bgBlackBright`
31193+
bgRedBright: [101, 49],
31194+
bgGreenBright: [102, 49],
31195+
bgYellowBright: [103, 49],
31196+
bgBlueBright: [104, 49],
31197+
bgMagentaBright: [105, 49],
31198+
bgCyanBright: [106, 49],
31199+
bgWhiteBright: [107, 49],
31200+
},
31201+
};
31202+
31203+
const modifierNames = Object.keys(styles.modifier);
31204+
const foregroundColorNames = Object.keys(styles.color);
31205+
const backgroundColorNames = Object.keys(styles.bgColor);
31206+
const colorNames = [...foregroundColorNames, ...backgroundColorNames];
31207+
31208+
function assembleStyles() {
31209+
const codes = new Map();
31210+
31211+
for (const [groupName, group] of Object.entries(styles)) {
31212+
for (const [styleName, style] of Object.entries(group)) {
31213+
styles[styleName] = {
31214+
open: `\u001B[${style[0]}m`,
31215+
close: `\u001B[${style[1]}m`,
31216+
};
31217+
31218+
group[styleName] = styles[styleName];
31219+
31220+
codes.set(style[0], style[1]);
31221+
}
31222+
31223+
Object.defineProperty(styles, groupName, {
31224+
value: group,
31225+
enumerable: false,
31226+
});
31227+
}
31228+
31229+
Object.defineProperty(styles, 'codes', {
31230+
value: codes,
31231+
enumerable: false,
31232+
});
31233+
31234+
styles.color.close = '\u001B[39m';
31235+
styles.bgColor.close = '\u001B[49m';
31236+
31237+
styles.color.ansi = wrapAnsi16();
31238+
styles.color.ansi256 = wrapAnsi256();
31239+
styles.color.ansi16m = wrapAnsi16m();
31240+
styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
31241+
styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
31242+
styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
31243+
31244+
// From https://github.com/Qix-/color-convert/blob/3f0e0d4e92e235796ccb17f6e85c72094a651f49/conversions.js
31245+
Object.defineProperties(styles, {
31246+
rgbToAnsi256: {
31247+
value: (red, green, blue) => {
31248+
// We use the extended greyscale palette here, with the exception of
31249+
// black and white. normal palette only has 4 greyscale shades.
31250+
if (red === green && green === blue) {
31251+
if (red < 8) {
31252+
return 16;
31253+
}
31254+
31255+
if (red > 248) {
31256+
return 231;
31257+
}
31258+
31259+
return Math.round(((red - 8) / 247) * 24) + 232;
31260+
}
31261+
31262+
return 16
31263+
+ (36 * Math.round(red / 255 * 5))
31264+
+ (6 * Math.round(green / 255 * 5))
31265+
+ Math.round(blue / 255 * 5);
31266+
},
31267+
enumerable: false,
31268+
},
31269+
hexToRgb: {
31270+
value: hex => {
31271+
const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
31272+
if (!matches) {
31273+
return [0, 0, 0];
31274+
}
31275+
31276+
let [colorString] = matches;
31277+
31278+
if (colorString.length === 3) {
31279+
colorString = [...colorString].map(character => character + character).join('');
31280+
}
31281+
31282+
const integer = Number.parseInt(colorString, 16);
31283+
31284+
return [
31285+
/* eslint-disable no-bitwise */
31286+
(integer >> 16) & 0xFF,
31287+
(integer >> 8) & 0xFF,
31288+
integer & 0xFF,
31289+
/* eslint-enable no-bitwise */
31290+
];
31291+
},
31292+
enumerable: false,
31293+
},
31294+
hexToAnsi256: {
31295+
value: hex => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
31296+
enumerable: false,
31297+
},
31298+
ansi256ToAnsi: {
31299+
value: code => {
31300+
if (code < 8) {
31301+
return 30 + code;
31302+
}
31303+
31304+
if (code < 16) {
31305+
return 90 + (code - 8);
31306+
}
31307+
31308+
let red;
31309+
let green;
31310+
let blue;
31311+
31312+
if (code >= 232) {
31313+
red = (((code - 232) * 10) + 8) / 255;
31314+
green = red;
31315+
blue = red;
31316+
} else {
31317+
code -= 16;
31318+
31319+
const remainder = code % 36;
31320+
31321+
red = Math.floor(code / 36) / 5;
31322+
green = Math.floor(remainder / 6) / 5;
31323+
blue = (remainder % 6) / 5;
31324+
}
31325+
31326+
const value = Math.max(red, green, blue) * 2;
31327+
31328+
if (value === 0) {
31329+
return 30;
31330+
}
31331+
31332+
// eslint-disable-next-line no-bitwise
31333+
let result = 30 + ((Math.round(blue) << 2) | (Math.round(green) << 1) | Math.round(red));
31334+
31335+
if (value === 2) {
31336+
result += 60;
31337+
}
31338+
31339+
return result;
31340+
},
31341+
enumerable: false,
31342+
},
31343+
rgbToAnsi: {
31344+
value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
31345+
enumerable: false,
31346+
},
31347+
hexToAnsi: {
31348+
value: hex => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
31349+
enumerable: false,
31350+
},
31351+
});
31352+
31353+
return styles;
31354+
}
31355+
31356+
const ansiStyles = assembleStyles();
31357+
31358+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (ansiStyles);
31359+
31360+
3111131361
/***/ })
3111231362

3111331363
/******/ });
@@ -31143,6 +31393,34 @@ module.exports = parseParams
3114331393
/******/ }
3114431394
/******/
3114531395
/************************************************************************/
31396+
/******/ /* webpack/runtime/define property getters */
31397+
/******/ (() => {
31398+
/******/ // define getter functions for harmony exports
31399+
/******/ __nccwpck_require__.d = (exports, definition) => {
31400+
/******/ for(var key in definition) {
31401+
/******/ if(__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key)) {
31402+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
31403+
/******/ }
31404+
/******/ }
31405+
/******/ };
31406+
/******/ })();
31407+
/******/
31408+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
31409+
/******/ (() => {
31410+
/******/ __nccwpck_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
31411+
/******/ })();
31412+
/******/
31413+
/******/ /* webpack/runtime/make namespace object */
31414+
/******/ (() => {
31415+
/******/ // define __esModule on exports
31416+
/******/ __nccwpck_require__.r = (exports) => {
31417+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
31418+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
31419+
/******/ }
31420+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
31421+
/******/ };
31422+
/******/ })();
31423+
/******/
3114631424
/******/ /* webpack/runtime/compat */
3114731425
/******/
3114831426
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";

package-lock.json

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

0 commit comments

Comments
 (0)