Make label comparison case insensitive (#517)

* Make label comparison case insensitive

* PR Feedback
This commit is contained in:
Luke Tomlinson 2021-07-12 13:56:58 -04:00 committed by GitHub
parent d901397e11
commit a78d0b721e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 70 additions and 108 deletions

154
dist/index.js vendored
View File

@ -233,6 +233,7 @@ const is_date_more_recent_than_1 = __nccwpck_require__(1473);
const is_valid_date_1 = __nccwpck_require__(891); const is_valid_date_1 = __nccwpck_require__(891);
const is_boolean_1 = __nccwpck_require__(8236); const is_boolean_1 = __nccwpck_require__(8236);
const is_labeled_1 = __nccwpck_require__(6792); const is_labeled_1 = __nccwpck_require__(6792);
const clean_label_1 = __nccwpck_require__(7752);
const should_mark_when_stale_1 = __nccwpck_require__(2461); const should_mark_when_stale_1 = __nccwpck_require__(2461);
const words_to_list_1 = __nccwpck_require__(1883); const words_to_list_1 = __nccwpck_require__(1883);
const assignees_1 = __nccwpck_require__(7236); const assignees_1 = __nccwpck_require__(7236);
@ -540,7 +541,7 @@ class IssuesProcessor {
}); });
const events = yield this.client.paginate(options); const events = yield this.client.paginate(options);
const reversedEvents = events.reverse(); const reversedEvents = events.reverse();
const staleLabeledEvent = reversedEvents.find(event => event.event === 'labeled' && event.label.name === label); const staleLabeledEvent = reversedEvents.find(event => event.event === 'labeled' && clean_label_1.cleanLabel(event.label.name) === clean_label_1.cleanLabel(label));
if (!staleLabeledEvent) { if (!staleLabeledEvent) {
// Must be old rather than labeled // Must be old rather than labeled
return undefined; return undefined;
@ -608,7 +609,8 @@ class IssuesProcessor {
} }
// find any comments since the date // find any comments since the date
const comments = yield this.listIssueComments(issue.number, sinceDate); const comments = yield this.listIssueComments(issue.number, sinceDate);
const filteredComments = comments.filter(comment => comment.user.type === 'User' && comment.body.toLowerCase() !== staleMessage.toLowerCase()); const filteredComments = comments.filter(comment => comment.user.type === 'User' &&
comment.body.toLowerCase() !== staleMessage.toLowerCase());
issueLogger.info(`Comments that are not the stale comment or another bot: ${logger_service_1.LoggerService.cyan(filteredComments.length)}`); issueLogger.info(`Comments that are not the stale comment or another bot: ${logger_service_1.LoggerService.cyan(filteredComments.length)}`);
// if there are any user comments returned // if there are any user comments returned
return filteredComments.length > 0; return filteredComments.length > 0;
@ -1730,6 +1732,33 @@ var Option;
})(Option = exports.Option || (exports.Option = {})); })(Option = exports.Option || (exports.Option = {}));
/***/ }),
/***/ 7752:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.cleanLabel = void 0;
const lodash_deburr_1 = __importDefault(__nccwpck_require__(1601));
/**
* @description
* Clean a label by lowercasing it and deburring it for consistency
*
* @param {string} label A raw GitHub label
*
* @return {string} A lowercased, deburred version of the passed in label
*/
function cleanLabel(label) {
return lodash_deburr_1.default(label.toLowerCase());
}
exports.cleanLabel = cleanLabel;
/***/ }), /***/ }),
/***/ 965: /***/ 965:
@ -1816,16 +1845,13 @@ exports.isBoolean = isBoolean;
/***/ }), /***/ }),
/***/ 6792: /***/ 6792:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
"use strict"; "use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.isLabeled = void 0; exports.isLabeled = void 0;
const lodash_deburr_1 = __importDefault(__nccwpck_require__(1601)); const clean_label_1 = __nccwpck_require__(7752);
/** /**
* @description * @description
* Check if the given label is listed as a label of the given issue * Check if the given label is listed as a label of the given issue
@ -1837,13 +1863,10 @@ const lodash_deburr_1 = __importDefault(__nccwpck_require__(1601));
*/ */
function isLabeled(issue, label) { function isLabeled(issue, label) {
return !!issue.labels.find((issueLabel) => { return !!issue.labels.find((issueLabel) => {
return cleanLabel(label) === cleanLabel(issueLabel.name); return clean_label_1.cleanLabel(label) === clean_label_1.cleanLabel(issueLabel.name);
}); });
} }
exports.isLabeled = isLabeled; exports.isLabeled = isLabeled;
function cleanLabel(label) {
return lodash_deburr_1.default(label.toLowerCase());
}
/***/ }), /***/ }),
@ -5777,16 +5800,13 @@ ansiEscapes.iTerm = {
/***/ }), /***/ }),
/***/ 2068: /***/ 2068:
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __nccwpck_require__) => { /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
"use strict"; "use strict";
__nccwpck_require__.r(__webpack_exports__); /* module decorator */ module = __nccwpck_require__.nmd(module);
/* harmony export */ __nccwpck_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => __WEBPACK_DEFAULT_EXPORT__
/* harmony export */ });
const ANSI_BACKGROUND_OFFSET = 10;
const wrapAnsi16 = (offset = 0) => code => `\u001B[${code + offset}m`;
const ANSI_BACKGROUND_OFFSET = 10;
const wrapAnsi256 = (offset = 0) => code => `\u001B[${38 + offset};5;${code}m`; const wrapAnsi256 = (offset = 0) => code => `\u001B[${38 + offset};5;${code}m`;
@ -5881,10 +5901,8 @@ function assembleStyles() {
styles.color.close = '\u001B[39m'; styles.color.close = '\u001B[39m';
styles.bgColor.close = '\u001B[49m'; styles.bgColor.close = '\u001B[49m';
styles.color.ansi = wrapAnsi16();
styles.color.ansi256 = wrapAnsi256(); styles.color.ansi256 = wrapAnsi256();
styles.color.ansi16m = wrapAnsi16m(); styles.color.ansi16m = wrapAnsi16m();
styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET); styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET); styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
@ -5939,67 +5957,17 @@ function assembleStyles() {
hexToAnsi256: { hexToAnsi256: {
value: hex => styles.rgbToAnsi256(...styles.hexToRgb(hex)), value: hex => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
enumerable: false enumerable: false
},
ansi256ToAnsi: {
value: code => {
if (code < 8) {
return 30 + code;
}
if (code < 16) {
return 90 + (code - 8);
}
let red;
let green;
let blue;
if (code >= 232) {
red = (((code - 232) * 10) + 8) / 255;
green = red;
blue = red;
} else {
code -= 16;
const remainder = code % 36;
red = Math.floor(code / 36) / 5;
green = Math.floor(remainder / 6) / 5;
blue = (remainder % 6) / 5;
}
const value = Math.max(red, green, blue) * 2;
if (value === 0) {
return 30;
}
let result = 30 + ((Math.round(blue) << 2) | (Math.round(green) << 1) | Math.round(red));
if (value === 2) {
result += 60;
}
return result;
},
enumerable: false
},
rgbToAnsi: {
value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
enumerable: false
},
hexToAnsi: {
value: hex => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
enumerable: false
} }
}); });
return styles; return styles;
} }
const ansiStyles = assembleStyles(); // Make the export immutable
Object.defineProperty(module, 'exports', {
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (ansiStyles); enumerable: true,
get: assembleStyles
});
/***/ }), /***/ }),
@ -8990,8 +8958,8 @@ module.exports = require("zlib");;
/******/ } /******/ }
/******/ // Create a new module (and put it into the cache) /******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = { /******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed /******/ id: moduleId,
/******/ // no module.loaded needed /******/ loaded: false,
/******/ exports: {} /******/ exports: {}
/******/ }; /******/ };
/******/ /******/
@ -9004,36 +8972,20 @@ module.exports = require("zlib");;
/******/ if(threw) delete __webpack_module_cache__[moduleId]; /******/ if(threw) delete __webpack_module_cache__[moduleId];
/******/ } /******/ }
/******/ /******/
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/
/******/ // Return the exports of the module /******/ // Return the exports of the module
/******/ return module.exports; /******/ return module.exports;
/******/ } /******/ }
/******/ /******/
/************************************************************************/ /************************************************************************/
/******/ /* webpack/runtime/define property getters */ /******/ /* webpack/runtime/node module decorator */
/******/ (() => { /******/ (() => {
/******/ // define getter functions for harmony exports /******/ __nccwpck_require__.nmd = (module) => {
/******/ __nccwpck_require__.d = (exports, definition) => { /******/ module.paths = [];
/******/ for(var key in definition) { /******/ if (!module.children) module.children = [];
/******/ if(__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key)) { /******/ return module;
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/ __nccwpck_require__.o = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop)
/******/ })();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ (() => {
/******/ // define __esModule on exports
/******/ __nccwpck_require__.r = (exports) => {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ }; /******/ };
/******/ })(); /******/ })();
/******/ /******/

View File

@ -8,6 +8,7 @@ import {isDateMoreRecentThan} from '../functions/dates/is-date-more-recent-than'
import {isValidDate} from '../functions/dates/is-valid-date'; import {isValidDate} from '../functions/dates/is-valid-date';
import {isBoolean} from '../functions/is-boolean'; import {isBoolean} from '../functions/is-boolean';
import {isLabeled} from '../functions/is-labeled'; import {isLabeled} from '../functions/is-labeled';
import { cleanLabel } from '../functions/clean-label';
import {shouldMarkWhenStale} from '../functions/should-mark-when-stale'; import {shouldMarkWhenStale} from '../functions/should-mark-when-stale';
import {wordsToList} from '../functions/words-to-list'; import {wordsToList} from '../functions/words-to-list';
import {IComment} from '../interfaces/comment'; import {IComment} from '../interfaces/comment';
@ -536,7 +537,7 @@ export class IssuesProcessor {
const reversedEvents = events.reverse(); const reversedEvents = events.reverse();
const staleLabeledEvent = reversedEvents.find( const staleLabeledEvent = reversedEvents.find(
event => event.event === 'labeled' && event.label.name === label event => event.event === 'labeled' && cleanLabel(event.label.name) === cleanLabel(label)
); );
if (!staleLabeledEvent) { if (!staleLabeledEvent) {

View File

@ -0,0 +1,14 @@
import deburr from 'lodash.deburr';
import { CleanLabel } from '../types/clean-label';
/**
* @description
* Clean a label by lowercasing it and deburring it for consistency
*
* @param {string} label A raw GitHub label
*
* @return {string} A lowercased, deburred version of the passed in label
*/
export function cleanLabel(label: Readonly<string>): CleanLabel {
return deburr(label.toLowerCase());
}

View File

@ -1,7 +1,6 @@
import deburr from 'lodash.deburr';
import {Issue} from '../classes/issue'; import {Issue} from '../classes/issue';
import {ILabel} from '../interfaces/label'; import {ILabel} from '../interfaces/label';
import {CleanLabel} from '../types/clean-label'; import {cleanLabel} from './clean-label';
/** /**
* @description * @description
@ -20,7 +19,3 @@ export function isLabeled(
return cleanLabel(label) === cleanLabel(issueLabel.name); return cleanLabel(label) === cleanLabel(issueLabel.name);
}); });
} }
function cleanLabel(label: Readonly<string>): CleanLabel {
return deburr(label.toLowerCase());
}