Skip to content
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

Allow specifying colors #482

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ inputs:
number:
description: The number of the issue or pull request.
required: false
colors:
description: The labels' color to be set. Separate multiple colors with line breaks, each color will be assigned to the label at the matching index.
required: false
runs:
using: node12
main: dist/index.js
Expand Down
124 changes: 76 additions & 48 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,40 @@ function run() {
return;
}
const octokit = github.getOctokit(githubToken);
yield octokit.rest.issues.addLabels({
const { data: githubLabels } = yield octokit.rest.issues.addLabels({
labels,
owner,
repo,
issue_number: number
});
const githubLabelsByName = githubLabels
.reduce((acc, label) => (Object.assign(Object.assign({}, acc), { [label.name]: label })), {});
const colors = core
.getInput('colors')
.split('\n')
.filter(c => c !== '')
.slice(0, labels.length);
for (const [i, color] of colors.entries()) {
const name = labels[i];
const githubLabel = githubLabelsByName[name];
if (!githubLabel || githubLabel.color == color) {
continue;
}
try {
yield octokit.rest.issues.updateLabel({
owner,
repo,
name,
color
});
core.info(`Updated color for label "${githubLabel.name}" from #${githubLabel.color} to #${color}`);
}
catch (e) {
if (e instanceof Error) {
core.error(e);
}
}
}
}
catch (e) {
if (e instanceof Error) {
Expand Down Expand Up @@ -3760,7 +3788,7 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau

var endpoint = __nccwpck_require__(9440);
var universalUserAgent = __nccwpck_require__(5030);
var isPlainObject = __nccwpck_require__(9062);
var isPlainObject = __nccwpck_require__(3287);
var nodeFetch = _interopDefault(__nccwpck_require__(467));
var requestError = __nccwpck_require__(537);

Expand Down Expand Up @@ -3931,52 +3959,6 @@ exports.request = request;
//# sourceMappingURL=index.js.map


/***/ }),

/***/ 9062:
/***/ ((__unused_webpack_module, exports) => {

"use strict";


Object.defineProperty(exports, "__esModule", ({ value: true }));

/*!
* is-plain-object <https://github.com/jonschlinkert/is-plain-object>
*
* Copyright (c) 2014-2017, Jon Schlinkert.
* Released under the MIT License.
*/

function isObject(o) {
return Object.prototype.toString.call(o) === '[object Object]';
}

function isPlainObject(o) {
var ctor,prot;

if (isObject(o) === false) return false;

// If has modified constructor
ctor = o.constructor;
if (ctor === undefined) return true;

// If has modified prototype
prot = ctor.prototype;
if (isObject(prot) === false) return false;

// If constructor does not have an Object-specific method
if (prot.hasOwnProperty('isPrototypeOf') === false) {
return false;
}

// Most likely a plain Object
return true;
}

exports.isPlainObject = isPlainObject;


/***/ }),

/***/ 3682:
Expand Down Expand Up @@ -6750,6 +6732,52 @@ module.exports.array = (stream, options) => getStream(stream, Object.assign({},
module.exports.MaxBufferError = MaxBufferError;


/***/ }),

/***/ 3287:
/***/ ((__unused_webpack_module, exports) => {

"use strict";


Object.defineProperty(exports, "__esModule", ({ value: true }));

/*!
* is-plain-object <https://github.com/jonschlinkert/is-plain-object>
*
* Copyright (c) 2014-2017, Jon Schlinkert.
* Released under the MIT License.
*/

function isObject(o) {
return Object.prototype.toString.call(o) === '[object Object]';
}

function isPlainObject(o) {
var ctor,prot;

if (isObject(o) === false) return false;

// If has modified constructor
ctor = o.constructor;
if (ctor === undefined) return true;

// If has modified prototype
prot = ctor.prototype;
if (isObject(prot) === false) return false;

// If constructor does not have an Object-specific method
if (prot.hasOwnProperty('isPrototypeOf') === false) {
return false;
}

// Most likely a plain Object
return true;
}

exports.isPlainObject = isPlainObject;


/***/ }),

/***/ 1554:
Expand Down
31 changes: 30 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,41 @@ async function run(): Promise<void> {
}

const octokit = github.getOctokit(githubToken);
await octokit.rest.issues.addLabels({
const { data: githubLabels } = await octokit.rest.issues.addLabels({
labels,
owner,
repo,
issue_number: number
});
const githubLabelsByName: { [label: string]: (typeof githubLabels)[0] } = githubLabels
.reduce((acc, label) => ({ ...acc, [label.name]: label }), {});

const colors = core
.getInput('colors')
.split('\n')
.filter(c => c !== '')
.slice(0, labels.length);

for (const [i, color] of colors.entries()) {
const name = labels[i];
const githubLabel = githubLabelsByName[name];
if (!githubLabel || githubLabel.color == color) {
continue;
}
try {
await octokit.rest.issues.updateLabel({
owner,
repo,
name,
color
});
core.info(`Updated color for label "${githubLabel.name}" from #${githubLabel.color} to #${color}`);
} catch (e) {
if (e instanceof Error) {
core.error(e);
}
}
}
} catch (e) {
if (e instanceof Error) {
core.error(e);
Expand Down
Loading