diff --git a/github-actions/commit-message-based-labels/lib/BUILD.bazel b/github-actions/commit-message-based-labels/lib/BUILD.bazel index e09dfd43c..3519efb4b 100644 --- a/github-actions/commit-message-based-labels/lib/BUILD.bazel +++ b/github-actions/commit-message-based-labels/lib/BUILD.bazel @@ -15,7 +15,7 @@ ts_library( deps = [ "//github-actions:utils", "//ng-dev/commit-message", - "//ng-dev/pr/config", + "//ng-dev/pr/common", "@npm//@actions/core", "@npm//@actions/github", "@npm//@octokit/rest", diff --git a/github-actions/commit-message-based-labels/lib/main.ts b/github-actions/commit-message-based-labels/lib/main.ts index 198c5ee36..7edac0a89 100644 --- a/github-actions/commit-message-based-labels/lib/main.ts +++ b/github-actions/commit-message-based-labels/lib/main.ts @@ -2,19 +2,9 @@ import * as core from '@actions/core'; import {context} from '@actions/github'; import {Octokit} from '@octokit/rest'; import {Commit, parseCommitMessage} from '../../../ng-dev/commit-message/parse.js'; -import {COMMIT_TYPES} from '../../../ng-dev/commit-message/config.js'; -import {breakingChangeLabel, deprecationLabel} from '../../../ng-dev/pr/config/index.js'; +import {ToolingPullRequestLabels} from '../../../ng-dev/pr/common/labels.js'; import {ANGULAR_ROBOT, getAuthTokenFor, revokeActiveInstallationToken} from '../../utils.js'; -/** List of supported label and commit message attribute combinations. */ -const supportedLabels = [ - [breakingChangeLabel, 'breakingChanges'], - [deprecationLabel, 'deprecations'], -] as const; - -/** Label for docs changes. */ -const compDocsLabel = 'comp: docs'; - class CommitMessageBasedLabelManager { /** Run the commit message based labelling process. */ static run = async () => { @@ -30,8 +20,8 @@ class CommitMessageBasedLabelManager { /** Labels currently applied to the PR. */ labels = new Set(); - /** Parsed commit message for every commit on the PR. */ - commits = new Set(); + /** All commits in the PR */ + commits: Commit[] = []; private constructor(private git: Octokit) {} @@ -43,10 +33,14 @@ class CommitMessageBasedLabelManager { // Add or Remove label as appropriate for each of the supported label and commit messaage // combinations. - for (const [label, commitProperty] of supportedLabels) { - const hasCommit = [...this.commits].some((commit) => commit[commitProperty].length > 0); + for (const {commitCheck, label} of Object.values(ToolingPullRequestLabels)) { + // If the commit check is set to false, no labeling is applied automatically. + if (commitCheck === false) { + continue; + } + const hasCommit = this.commits.some(commitCheck); const hasLabel = this.labels.has(label); - core.info(`${commitProperty} | hasLabel: ${hasLabel} | hasCommit: ${hasCommit}`); + core.info(`${label} | hasLabel: ${hasLabel} | hasCommit: ${hasCommit}`); if (hasCommit && !hasLabel) { await this.addLabel(label); @@ -55,16 +49,6 @@ class CommitMessageBasedLabelManager { await this.removeLabel(label); } } - - // Add 'comp: docs' label for changes which contain a docs commit. - if (!this.labels.has(compDocsLabel)) { - for (const commit of this.commits) { - if (commit.type === COMMIT_TYPES['docs'].name) { - await this.addLabel(compDocsLabel); - break; - } - } - } } /** Add the provided label to the pull request. */ @@ -99,8 +83,8 @@ class CommitMessageBasedLabelManager { await this.git .paginate(this.git.pulls.listCommits, {owner, pull_number: number, repo}) - .then((commits) => - commits.forEach(({commit}) => this.commits.add(parseCommitMessage(commit.message))), + .then( + (commits) => (this.commits = commits.map(({commit}) => parseCommitMessage(commit.message))), ); await this.git.issues diff --git a/github-actions/commit-message-based-labels/main.js b/github-actions/commit-message-based-labels/main.js index e40179f1b..9c5666d17 100644 --- a/github-actions/commit-message-based-labels/main.js +++ b/github-actions/commit-message-based-labels/main.js @@ -97,11 +97,11 @@ var require_command = __commonJS({ }; Object.defineProperty(exports, "__esModule", { value: true }); exports.issue = exports.issueCommand = void 0; - var os3 = __importStar(__require("os")); + var os = __importStar(__require("os")); var utils_1 = require_utils(); function issueCommand(command, properties, message) { const cmd = new Command(command, properties, message); - process.stdout.write(cmd.toString() + os3.EOL); + process.stdout.write(cmd.toString() + os.EOL); } exports.issueCommand = issueCommand; function issue(name, message = "") { @@ -185,7 +185,7 @@ var require_file_command = __commonJS({ Object.defineProperty(exports, "__esModule", { value: true }); exports.issueCommand = void 0; var fs = __importStar(__require("fs")); - var os3 = __importStar(__require("os")); + var os = __importStar(__require("os")); var utils_1 = require_utils(); function issueCommand(command, message) { const filePath = process.env[`GITHUB_${command}`]; @@ -195,7 +195,7 @@ var require_file_command = __commonJS({ if (!fs.existsSync(filePath)) { throw new Error(`Missing file at path: ${filePath}`); } - fs.appendFileSync(filePath, `${utils_1.toCommandValue(message)}${os3.EOL}`, { + fs.appendFileSync(filePath, `${utils_1.toCommandValue(message)}${os.EOL}`, { encoding: "utf8" }); } @@ -2013,7 +2013,7 @@ var require_core = __commonJS({ var command_1 = require_command(); var file_command_1 = require_file_command(); var utils_1 = require_utils(); - var os3 = __importStar(__require("os")); + var os = __importStar(__require("os")); var path = __importStar(__require("path")); var uuid_1 = require_dist(); var oidc_utils_1 = require_oidc_utils(); @@ -2034,7 +2034,7 @@ var require_core = __commonJS({ if (convertedVal.includes(delimiter)) { throw new Error(`Unexpected input: value should not contain the delimiter "${delimiter}"`); } - const commandValue = `${name}<<${delimiter}${os3.EOL}${convertedVal}${os3.EOL}${delimiter}`; + const commandValue = `${name}<<${delimiter}${os.EOL}${convertedVal}${os.EOL}${delimiter}`; file_command_1.issueCommand("ENV", commandValue); } else { command_1.issueCommand("set-env", { name }, convertedVal); @@ -2084,7 +2084,7 @@ Support boolean input list: \`true | True | TRUE | false | False | FALSE\``); } exports.getBooleanInput = getBooleanInput; function setOutput(name, value) { - process.stdout.write(os3.EOL); + process.stdout.write(os.EOL); command_1.issueCommand("set-output", { name }, value); } exports.setOutput = setOutput; @@ -2118,7 +2118,7 @@ Support boolean input list: \`true | True | TRUE | false | False | FALSE\``); } exports.notice = notice; function info3(message) { - process.stdout.write(message + os3.EOL); + process.stdout.write(message + os.EOL); } exports.info = info3; function startGroup(name) { @@ -8402,11 +8402,11 @@ var require_lib4 = __commonJS({ json: { enumerable: true }, text: { enumerable: true } }); - Body.mixIn = function(proto2) { + Body.mixIn = function(proto) { for (const name of Object.getOwnPropertyNames(Body.prototype)) { - if (!(name in proto2)) { + if (!(name in proto)) { const desc = Object.getOwnPropertyDescriptor(Body.prototype, name); - Object.defineProperty(proto2, name, desc); + Object.defineProperty(proto, name, desc); } } }; @@ -8909,8 +8909,8 @@ var require_lib4 = __commonJS({ return typeof input === "object" && typeof input[INTERNALS$2] === "object"; } function isAbortSignal(signal) { - const proto2 = signal && typeof signal === "object" && Object.getPrototypeOf(signal); - return !!(proto2 && proto2.constructor.name === "AbortSignal"); + const proto = signal && typeof signal === "object" && Object.getPrototypeOf(signal); + return !!(proto && proto.constructor.name === "AbortSignal"); } var Request = class { constructor(input) { @@ -13295,11 +13295,11 @@ var require_lib6 = __commonJS({ json: { enumerable: true }, text: { enumerable: true } }); - Body.mixIn = function(proto2) { + Body.mixIn = function(proto) { for (const name of Object.getOwnPropertyNames(Body.prototype)) { - if (!(name in proto2)) { + if (!(name in proto)) { const desc = Object.getOwnPropertyDescriptor(Body.prototype, name); - Object.defineProperty(proto2, name, desc); + Object.defineProperty(proto, name, desc); } } }; @@ -13802,8 +13802,8 @@ var require_lib6 = __commonJS({ return typeof input === "object" && typeof input[INTERNALS$2] === "object"; } function isAbortSignal(signal) { - const proto2 = signal && typeof signal === "object" && Object.getPrototypeOf(signal); - return !!(proto2 && proto2.constructor.name === "AbortSignal"); + const proto = signal && typeof signal === "object" && Object.getPrototypeOf(signal); + return !!(proto && proto.constructor.name === "AbortSignal"); } var Request = class { constructor(input) { @@ -16543,14 +16543,14 @@ var require_lodash = __commonJS({ var baseCreate = function() { function object() { } - return function(proto2) { - if (!isObject(proto2)) { + return function(proto) { + if (!isObject(proto)) { return {}; } if (objectCreate) { - return objectCreate(proto2); + return objectCreate(proto); } - object.prototype = proto2; + object.prototype = proto; var result2 = new object(); object.prototype = undefined2; return result2; @@ -18704,8 +18704,8 @@ var require_lodash = __commonJS({ } var isMaskable = coreJsData ? isFunction : stubFalse; function isPrototype(value) { - var Ctor = value && value.constructor, proto2 = typeof Ctor == "function" && Ctor.prototype || objectProto; - return value === proto2; + var Ctor = value && value.constructor, proto = typeof Ctor == "function" && Ctor.prototype || objectProto; + return value === proto; } function isStrictComparable(value) { return value === value && !isObject(value); @@ -19917,11 +19917,11 @@ var require_lodash = __commonJS({ if (!isObjectLike(value) || baseGetTag(value) != objectTag) { return false; } - var proto2 = getPrototype(value); - if (proto2 === null) { + var proto = getPrototype(value); + if (proto === null) { return true; } - var Ctor = hasOwnProperty.call(proto2, "constructor") && proto2.constructor; + var Ctor = hasOwnProperty.call(proto, "constructor") && proto.constructor; return typeof Ctor == "function" && Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString; } var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp; @@ -26374,11 +26374,11 @@ var require_lib8 = __commonJS({ json: { enumerable: true }, text: { enumerable: true } }); - Body.mixIn = function(proto2) { + Body.mixIn = function(proto) { for (const name of Object.getOwnPropertyNames(Body.prototype)) { - if (!(name in proto2)) { + if (!(name in proto)) { const desc = Object.getOwnPropertyDescriptor(Body.prototype, name); - Object.defineProperty(proto2, name, desc); + Object.defineProperty(proto, name, desc); } } }; @@ -26881,8 +26881,8 @@ var require_lib8 = __commonJS({ return typeof input === "object" && typeof input[INTERNALS$2] === "object"; } function isAbortSignal(signal) { - const proto2 = signal && typeof signal === "object" && Object.getPrototypeOf(signal); - return !!(proto2 && proto2.constructor.name === "AbortSignal"); + const proto = signal && typeof signal === "object" && Object.getPrototypeOf(signal); + return !!(proto && proto.constructor.name === "AbortSignal"); } var Request = class { constructor(input) { @@ -30404,8 +30404,8 @@ var require_lodash2 = __commonJS({ return !!length && (typeof value == "number" || reIsUint.test(value)) && (value > -1 && value % 1 == 0 && value < length); } function isPrototype(value) { - var Ctor = value && value.constructor, proto2 = typeof Ctor == "function" && Ctor.prototype || objectProto; - return value === proto2; + var Ctor = value && value.constructor, proto = typeof Ctor == "function" && Ctor.prototype || objectProto; + return value === proto; } function includes(collection, value, fromIndex, guard) { collection = isArrayLike(collection) ? collection : values(collection); @@ -30618,11 +30618,11 @@ var require_lodash6 = __commonJS({ if (!isObjectLike(value) || objectToString.call(value) != objectTag || isHostObject(value)) { return false; } - var proto2 = getPrototype(value); - if (proto2 === null) { + var proto = getPrototype(value); + if (proto === null) { return true; } - var Ctor = hasOwnProperty.call(proto2, "constructor") && proto2.constructor; + var Ctor = hasOwnProperty.call(proto, "constructor") && proto.constructor; return typeof Ctor == "function" && Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString; } module.exports = isPlainObject; @@ -32059,726 +32059,25 @@ function parseInternal(fullText) { } // -var ANSI_BACKGROUND_OFFSET = 10; -var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`; -var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`; -var wrapAnsi16m = (offset = 0) => (red2, green2, blue2) => `\x1B[${38 + offset};2;${red2};${green2};${blue2}m`; -function assembleStyles() { - const codes = /* @__PURE__ */ new Map(); - const styles2 = { - modifier: { - reset: [0, 0], - bold: [1, 22], - dim: [2, 22], - italic: [3, 23], - underline: [4, 24], - overline: [53, 55], - inverse: [7, 27], - hidden: [8, 28], - strikethrough: [9, 29] - }, - color: { - black: [30, 39], - red: [31, 39], - green: [32, 39], - yellow: [33, 39], - blue: [34, 39], - magenta: [35, 39], - cyan: [36, 39], - white: [37, 39], - blackBright: [90, 39], - redBright: [91, 39], - greenBright: [92, 39], - yellowBright: [93, 39], - blueBright: [94, 39], - magentaBright: [95, 39], - cyanBright: [96, 39], - whiteBright: [97, 39] - }, - bgColor: { - bgBlack: [40, 49], - bgRed: [41, 49], - bgGreen: [42, 49], - bgYellow: [43, 49], - bgBlue: [44, 49], - bgMagenta: [45, 49], - bgCyan: [46, 49], - bgWhite: [47, 49], - bgBlackBright: [100, 49], - bgRedBright: [101, 49], - bgGreenBright: [102, 49], - bgYellowBright: [103, 49], - bgBlueBright: [104, 49], - bgMagentaBright: [105, 49], - bgCyanBright: [106, 49], - bgWhiteBright: [107, 49] - } - }; - styles2.color.gray = styles2.color.blackBright; - styles2.bgColor.bgGray = styles2.bgColor.bgBlackBright; - styles2.color.grey = styles2.color.blackBright; - styles2.bgColor.bgGrey = styles2.bgColor.bgBlackBright; - for (const [groupName, group] of Object.entries(styles2)) { - for (const [styleName, style] of Object.entries(group)) { - styles2[styleName] = { - open: `\x1B[${style[0]}m`, - close: `\x1B[${style[1]}m` - }; - group[styleName] = styles2[styleName]; - codes.set(style[0], style[1]); - } - Object.defineProperty(styles2, groupName, { - value: group, - enumerable: false - }); - } - Object.defineProperty(styles2, "codes", { - value: codes, - enumerable: false - }); - styles2.color.close = "\x1B[39m"; - styles2.bgColor.close = "\x1B[49m"; - styles2.color.ansi = wrapAnsi16(); - styles2.color.ansi256 = wrapAnsi256(); - styles2.color.ansi16m = wrapAnsi16m(); - styles2.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET); - styles2.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET); - styles2.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET); - Object.defineProperties(styles2, { - rgbToAnsi256: { - value: (red2, green2, blue2) => { - if (red2 === green2 && green2 === blue2) { - if (red2 < 8) { - return 16; - } - if (red2 > 248) { - return 231; - } - return Math.round((red2 - 8) / 247 * 24) + 232; - } - return 16 + 36 * Math.round(red2 / 255 * 5) + 6 * Math.round(green2 / 255 * 5) + Math.round(blue2 / 255 * 5); - }, - enumerable: false - }, - hexToRgb: { - value: (hex) => { - const matches = /(?[a-f\d]{6}|[a-f\d]{3})/i.exec(hex.toString(16)); - if (!matches) { - return [0, 0, 0]; - } - let { colorString } = matches.groups; - if (colorString.length === 3) { - colorString = [...colorString].map((character) => character + character).join(""); - } - const integer = Number.parseInt(colorString, 16); - return [ - integer >> 16 & 255, - integer >> 8 & 255, - integer & 255 - ]; - }, - enumerable: false - }, - hexToAnsi256: { - value: (hex) => styles2.rgbToAnsi256(...styles2.hexToRgb(hex)), - enumerable: false - }, - ansi256ToAnsi: { - value: (code) => { - if (code < 8) { - return 30 + code; - } - if (code < 16) { - return 90 + (code - 8); - } - let red2; - let green2; - let blue2; - if (code >= 232) { - red2 = ((code - 232) * 10 + 8) / 255; - green2 = red2; - blue2 = red2; - } else { - code -= 16; - const remainder = code % 36; - red2 = Math.floor(code / 36) / 5; - green2 = Math.floor(remainder / 6) / 5; - blue2 = remainder % 6 / 5; - } - const value = Math.max(red2, green2, blue2) * 2; - if (value === 0) { - return 30; - } - let result = 30 + (Math.round(blue2) << 2 | Math.round(green2) << 1 | Math.round(red2)); - if (value === 2) { - result += 60; - } - return result; - }, - enumerable: false - }, - rgbToAnsi: { - value: (red2, green2, blue2) => styles2.ansi256ToAnsi(styles2.rgbToAnsi256(red2, green2, blue2)), - enumerable: false - }, - hexToAnsi: { - value: (hex) => styles2.ansi256ToAnsi(styles2.hexToAnsi256(hex)), - enumerable: false - } - }); - return styles2; -} -var ansiStyles = assembleStyles(); -var ansi_styles_default = ansiStyles; - -// -import process2 from "node:process"; -import os from "node:os"; -import tty from "node:tty"; -function hasFlag(flag, argv = process2.argv) { - const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--"; - const position = argv.indexOf(prefix + flag); - const terminatorPosition = argv.indexOf("--"); - return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition); -} -var { env } = process2; -var flagForceColor; -if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) { - flagForceColor = 0; -} else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) { - flagForceColor = 1; -} -function envForceColor() { - if ("FORCE_COLOR" in env) { - if (env.FORCE_COLOR === "true") { - return 1; - } - if (env.FORCE_COLOR === "false") { - return 0; - } - return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3); - } -} -function translateLevel(level) { - if (level === 0) { - return false; - } - return { - level, - hasBasic: true, - has256: level >= 2, - has16m: level >= 3 - }; -} -function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) { - const noFlagForceColor = envForceColor(); - if (noFlagForceColor !== void 0) { - flagForceColor = noFlagForceColor; - } - const forceColor = sniffFlags ? flagForceColor : noFlagForceColor; - if (forceColor === 0) { - return 0; - } - if (sniffFlags) { - if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) { - return 3; - } - if (hasFlag("color=256")) { - return 2; - } - } - if (haveStream && !streamIsTTY && forceColor === void 0) { - return 0; - } - const min = forceColor || 0; - if (env.TERM === "dumb") { - return min; - } - if (process2.platform === "win32") { - const osRelease = os.release().split("."); - if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) { - return Number(osRelease[2]) >= 14931 ? 3 : 2; - } - return 1; - } - if ("CI" in env) { - if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") { - return 1; - } - return min; - } - if ("TEAMCITY_VERSION" in env) { - return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0; - } - if ("TF_BUILD" in env && "AGENT_NAME" in env) { - return 1; - } - if (env.COLORTERM === "truecolor") { - return 3; - } - if ("TERM_PROGRAM" in env) { - const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10); - switch (env.TERM_PROGRAM) { - case "iTerm.app": - return version >= 3 ? 3 : 2; - case "Apple_Terminal": - return 2; - } - } - if (/-256(color)?$/i.test(env.TERM)) { - return 2; - } - if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) { - return 1; - } - if ("COLORTERM" in env) { - return 1; - } - return min; -} -function createSupportsColor(stream, options = {}) { - const level = _supportsColor(stream, { - streamIsTTY: stream && stream.isTTY, - ...options - }); - return translateLevel(level); -} -var supportsColor = { - stdout: createSupportsColor({ isTTY: tty.isatty(1) }), - stderr: createSupportsColor({ isTTY: tty.isatty(2) }) -}; -var supports_color_default = supportsColor; - -// -function stringReplaceAll(string, substring, replacer) { - let index = string.indexOf(substring); - if (index === -1) { - return string; - } - const substringLength = substring.length; - let endIndex = 0; - let returnValue = ""; - do { - returnValue += string.substr(endIndex, index - endIndex) + substring + replacer; - endIndex = index + substringLength; - index = string.indexOf(substring, endIndex); - } while (index !== -1); - returnValue += string.slice(endIndex); - return returnValue; -} -function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) { - let endIndex = 0; - let returnValue = ""; - do { - const gotCR = string[index - 1] === "\r"; - returnValue += string.substr(endIndex, (gotCR ? index - 1 : index) - endIndex) + prefix + (gotCR ? "\r\n" : "\n") + postfix; - endIndex = index + 1; - index = string.indexOf("\n", endIndex); - } while (index !== -1); - returnValue += string.slice(endIndex); - return returnValue; -} - -// -var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default; -var GENERATOR = Symbol("GENERATOR"); -var STYLER = Symbol("STYLER"); -var IS_EMPTY = Symbol("IS_EMPTY"); -var levelMapping = [ - "ansi", - "ansi", - "ansi256", - "ansi16m" -]; -var styles = /* @__PURE__ */ Object.create(null); -var applyOptions = (object, options = {}) => { - if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) { - throw new Error("The `level` option should be an integer from 0 to 3"); - } - const colorLevel = stdoutColor ? stdoutColor.level : 0; - object.level = options.level === void 0 ? colorLevel : options.level; -}; -var chalkFactory = (options) => { - const chalk2 = (...strings) => strings.join(" "); - applyOptions(chalk2, options); - Object.setPrototypeOf(chalk2, createChalk.prototype); - return chalk2; -}; -function createChalk(options) { - return chalkFactory(options); -} -Object.setPrototypeOf(createChalk.prototype, Function.prototype); -for (const [styleName, style] of Object.entries(ansi_styles_default)) { - styles[styleName] = { - get() { - const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]); - Object.defineProperty(this, styleName, { value: builder }); - return builder; - } - }; -} -styles.visible = { - get() { - const builder = createBuilder(this, this[STYLER], true); - Object.defineProperty(this, "visible", { value: builder }); - return builder; - } -}; -var getModelAnsi = (model, level, type, ...arguments_) => { - if (model === "rgb") { - if (level === "ansi16m") { - return ansi_styles_default[type].ansi16m(...arguments_); - } - if (level === "ansi256") { - return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_)); - } - return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_)); - } - if (model === "hex") { - return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_)); - } - return ansi_styles_default[type][model](...arguments_); -}; -var usedModels = ["rgb", "hex", "ansi256"]; -for (const model of usedModels) { - styles[model] = { - get() { - const { level } = this; - return function(...arguments_) { - const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]); - return createBuilder(this, styler, this[IS_EMPTY]); - }; - } - }; - const bgModel = "bg" + model[0].toUpperCase() + model.slice(1); - styles[bgModel] = { - get() { - const { level } = this; - return function(...arguments_) { - const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]); - return createBuilder(this, styler, this[IS_EMPTY]); - }; - } - }; -} -var proto = Object.defineProperties(() => { -}, { - ...styles, - level: { - enumerable: true, - get() { - return this[GENERATOR].level; - }, - set(level) { - this[GENERATOR].level = level; - } - } -}); -var createStyler = (open, close, parent) => { - let openAll; - let closeAll; - if (parent === void 0) { - openAll = open; - closeAll = close; - } else { - openAll = parent.openAll + open; - closeAll = close + parent.closeAll; - } - return { - open, - close, - openAll, - closeAll, - parent - }; -}; -var createBuilder = (self2, _styler, _isEmpty) => { - const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" ")); - Object.setPrototypeOf(builder, proto); - builder[GENERATOR] = self2; - builder[STYLER] = _styler; - builder[IS_EMPTY] = _isEmpty; - return builder; -}; -var applyStyle = (self2, string) => { - if (self2.level <= 0 || !string) { - return self2[IS_EMPTY] ? "" : string; - } - let styler = self2[STYLER]; - if (styler === void 0) { - return string; - } - const { openAll, closeAll } = styler; - if (string.includes("\x1B")) { - while (styler !== void 0) { - string = stringReplaceAll(string, styler.close, styler.open); - styler = styler.parent; - } - } - const lfIndex = string.indexOf("\n"); - if (lfIndex !== -1) { - string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex); - } - return openAll + string + closeAll; -}; -Object.defineProperties(createChalk.prototype, styles); -var chalk = createChalk(); -var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 }); -var source_default = chalk; - -// -import process3 from "node:process"; -import os2 from "node:os"; -import tty2 from "node:tty"; -function hasFlag2(flag, argv = process3.argv) { - const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--"; - const position = argv.indexOf(prefix + flag); - const terminatorPosition = argv.indexOf("--"); - return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition); -} -var { env: env2 } = process3; -var flagForceColor2; -if (hasFlag2("no-color") || hasFlag2("no-colors") || hasFlag2("color=false") || hasFlag2("color=never")) { - flagForceColor2 = 0; -} else if (hasFlag2("color") || hasFlag2("colors") || hasFlag2("color=true") || hasFlag2("color=always")) { - flagForceColor2 = 1; -} -function envForceColor2() { - if ("FORCE_COLOR" in env2) { - if (env2.FORCE_COLOR === "true") { - return 1; - } - if (env2.FORCE_COLOR === "false") { - return 0; - } - return env2.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env2.FORCE_COLOR, 10), 3); - } -} -function translateLevel2(level) { - if (level === 0) { - return false; - } - return { - level, - hasBasic: true, - has256: level >= 2, - has16m: level >= 3 - }; -} -function _supportsColor2(haveStream, { streamIsTTY, sniffFlags = true } = {}) { - const noFlagForceColor = envForceColor2(); - if (noFlagForceColor !== void 0) { - flagForceColor2 = noFlagForceColor; - } - const forceColor = sniffFlags ? flagForceColor2 : noFlagForceColor; - if (forceColor === 0) { - return 0; - } - if (sniffFlags) { - if (hasFlag2("color=16m") || hasFlag2("color=full") || hasFlag2("color=truecolor")) { - return 3; - } - if (hasFlag2("color=256")) { - return 2; - } - } - if (haveStream && !streamIsTTY && forceColor === void 0) { - return 0; - } - const min = forceColor || 0; - if (env2.TERM === "dumb") { - return min; - } - if (process3.platform === "win32") { - const osRelease = os2.release().split("."); - if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) { - return Number(osRelease[2]) >= 14931 ? 3 : 2; - } - return 1; - } - if ("CI" in env2) { - if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE", "DRONE"].some((sign) => sign in env2) || env2.CI_NAME === "codeship") { - return 1; - } - return min; - } - if ("TEAMCITY_VERSION" in env2) { - return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env2.TEAMCITY_VERSION) ? 1 : 0; - } - if ("TF_BUILD" in env2 && "AGENT_NAME" in env2) { - return 1; - } - if (env2.COLORTERM === "truecolor") { - return 3; - } - if ("TERM_PROGRAM" in env2) { - const version = Number.parseInt((env2.TERM_PROGRAM_VERSION || "").split(".")[0], 10); - switch (env2.TERM_PROGRAM) { - case "iTerm.app": - return version >= 3 ? 3 : 2; - case "Apple_Terminal": - return 2; - } - } - if (/-256(color)?$/i.test(env2.TERM)) { - return 2; - } - if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env2.TERM)) { - return 1; - } - if ("COLORTERM" in env2) { - return 1; - } - return min; -} -function createSupportsColor2(stream, options = {}) { - const level = _supportsColor2(stream, { - streamIsTTY: stream && stream.isTTY, - ...options - }); - return translateLevel2(level); -} -var supportsColor2 = { - stdout: createSupportsColor2({ isTTY: tty2.isatty(1) }), - stderr: createSupportsColor2({ isTTY: tty2.isatty(2) }) -}; - -// -var LogLevel; -(function(LogLevel2) { - LogLevel2[LogLevel2["SILENT"] = 0] = "SILENT"; - LogLevel2[LogLevel2["ERROR"] = 1] = "ERROR"; - LogLevel2[LogLevel2["WARN"] = 2] = "WARN"; - LogLevel2[LogLevel2["LOG"] = 3] = "LOG"; - LogLevel2[LogLevel2["INFO"] = 4] = "INFO"; - LogLevel2[LogLevel2["DEBUG"] = 5] = "DEBUG"; -})(LogLevel || (LogLevel = {})); -var DEFAULT_LOG_LEVEL = LogLevel.INFO; -var red = source_default.red; -var reset = source_default.reset; -var green = source_default.green; -var yellow = source_default.yellow; -var bold = source_default.bold; -var blue = source_default.blue; -var Log = class { -}; -Log.info = buildLogLevelFunction(() => console.info, LogLevel.INFO, null); -Log.error = buildLogLevelFunction(() => console.error, LogLevel.ERROR, source_default.red); -Log.debug = buildLogLevelFunction(() => console.debug, LogLevel.DEBUG, null); -Log.log = buildLogLevelFunction(() => console.log, LogLevel.LOG, null); -Log.warn = buildLogLevelFunction(() => console.warn, LogLevel.WARN, source_default.yellow); -function buildLogLevelFunction(loadCommand, level, defaultColor) { - const loggingFunction = (...values) => { - runConsoleCommand( - loadCommand, - level, - ...values.map((v) => typeof v === "string" && defaultColor ? defaultColor(v) : v) - ); - }; - loggingFunction.group = (label, collapsed = false) => { - const command = collapsed ? console.groupCollapsed : console.group; - runConsoleCommand(() => command, level, defaultColor ? defaultColor(label) : label); - }; - loggingFunction.groupEnd = () => { - runConsoleCommand(() => console.groupEnd, level); - }; - return loggingFunction; -} -function runConsoleCommand(loadCommand, logLevel, ...text) { - if (getLogLevel() >= logLevel) { - loadCommand()(...text); - } - printToLogFile(logLevel, ...text); -} -function getLogLevel() { - const logLevelEnvValue = (process.env[`LOG_LEVEL`] || "").toUpperCase(); - const logLevel = LogLevel[logLevelEnvValue]; - if (logLevel === void 0) { - return DEFAULT_LOG_LEVEL; - } - return logLevel; -} -var LOGGED_TEXT = ""; -var LOG_LEVEL_COLUMNS = 7; -function printToLogFile(logLevel, ...text) { - const logLevelText = `${LogLevel[logLevel]}:`.padEnd(LOG_LEVEL_COLUMNS); - LOGGED_TEXT += text.join(" ").split("\n").map((l) => `${logLevelText} ${l} -`).join(""); -} - -// -var ScopeRequirement; -(function(ScopeRequirement2) { - ScopeRequirement2[ScopeRequirement2["Required"] = 0] = "Required"; - ScopeRequirement2[ScopeRequirement2["Optional"] = 1] = "Optional"; - ScopeRequirement2[ScopeRequirement2["Forbidden"] = 2] = "Forbidden"; -})(ScopeRequirement || (ScopeRequirement = {})); -var ReleaseNotesLevel; -(function(ReleaseNotesLevel2) { - ReleaseNotesLevel2[ReleaseNotesLevel2["Hidden"] = 0] = "Hidden"; - ReleaseNotesLevel2[ReleaseNotesLevel2["Visible"] = 1] = "Visible"; -})(ReleaseNotesLevel || (ReleaseNotesLevel = {})); -var COMMIT_TYPES = { - build: { - name: "build", - description: "Changes to local repository build system and tooling", - scope: ScopeRequirement.Optional, - releaseNotesLevel: ReleaseNotesLevel.Hidden - }, - ci: { - name: "ci", - description: "Changes to CI configuration and CI specific tooling", - scope: ScopeRequirement.Forbidden, - releaseNotesLevel: ReleaseNotesLevel.Hidden - }, - docs: { - name: "docs", - description: "Changes which exclusively affects documentation.", - scope: ScopeRequirement.Optional, - releaseNotesLevel: ReleaseNotesLevel.Hidden - }, - feat: { - name: "feat", - description: "Creates a new feature", - scope: ScopeRequirement.Required, - releaseNotesLevel: ReleaseNotesLevel.Visible +var ToolingPullRequestLabels = { + BREAKING_CHANGE: { + label: "flag: breaking change", + commitCheck: (c) => c.breakingChanges.length !== 0 }, - fix: { - name: "fix", - description: "Fixes a previously discovered failure/bug", - scope: ScopeRequirement.Required, - releaseNotesLevel: ReleaseNotesLevel.Visible + DEPRECATION: { + label: "flag: deprecation", + commitCheck: (c) => c.deprecations.length !== 0 }, - perf: { - name: "perf", - description: "Improves performance without any change in functionality or API", - scope: ScopeRequirement.Required, - releaseNotesLevel: ReleaseNotesLevel.Visible + FEATURE: { + label: "feature", + commitCheck: (c) => c.type === "feat" }, - refactor: { - name: "refactor", - description: "Refactor without any change in functionality or API (includes style changes)", - scope: ScopeRequirement.Optional, - releaseNotesLevel: ReleaseNotesLevel.Hidden - }, - release: { - name: "release", - description: "A release point in the repository", - scope: ScopeRequirement.Forbidden, - releaseNotesLevel: ReleaseNotesLevel.Hidden - }, - test: { - name: "test", - description: "Improvements or corrections made to the project's test suite", - scope: ScopeRequirement.Optional, - releaseNotesLevel: ReleaseNotesLevel.Hidden + DOCS_CHANGE: { + label: "comp: docs", + commitCheck: (c) => c.type === "docs" } }; -// -var breakingChangeLabel = "flag: breaking change"; -var deprecationLabel = "flag: deprecation"; - // var import_core = __toESM(require_core()); var import_rest = __toESM(require_dist_node20()); @@ -32813,24 +32112,22 @@ async function revokeActiveInstallationToken(githubOrToken) { // var _a; -var supportedLabels = [ - [breakingChangeLabel, "breakingChanges"], - [deprecationLabel, "deprecations"] -]; -var compDocsLabel = "comp: docs"; var CommitMessageBasedLabelManager = class { constructor(git) { this.git = git; this.labels = /* @__PURE__ */ new Set(); - this.commits = /* @__PURE__ */ new Set(); + this.commits = []; } async run() { await this.initialize(); core.info(`PR #${import_github2.context.issue.number}`); - for (const [label, commitProperty] of supportedLabels) { - const hasCommit = [...this.commits].some((commit) => commit[commitProperty].length > 0); + for (const { commitCheck, label } of Object.values(ToolingPullRequestLabels)) { + if (commitCheck === false) { + continue; + } + const hasCommit = this.commits.some(commitCheck); const hasLabel = this.labels.has(label); - core.info(`${commitProperty} | hasLabel: ${hasLabel} | hasCommit: ${hasCommit}`); + core.info(`${label} | hasLabel: ${hasLabel} | hasCommit: ${hasCommit}`); if (hasCommit && !hasLabel) { await this.addLabel(label); } @@ -32838,14 +32135,6 @@ var CommitMessageBasedLabelManager = class { await this.removeLabel(label); } } - if (!this.labels.has(compDocsLabel)) { - for (const commit of this.commits) { - if (commit.type === COMMIT_TYPES["docs"].name) { - await this.addLabel(compDocsLabel); - break; - } - } - } } async addLabel(label) { const { number: issue_number, owner, repo } = import_github2.context.issue; @@ -32871,7 +32160,7 @@ var CommitMessageBasedLabelManager = class { } async initialize() { const { number, owner, repo } = import_github2.context.issue; - await this.git.paginate(this.git.pulls.listCommits, { owner, pull_number: number, repo }).then((commits) => commits.forEach(({ commit }) => this.commits.add(parseCommitMessage(commit.message)))); + await this.git.paginate(this.git.pulls.listCommits, { owner, pull_number: number, repo }).then((commits) => this.commits = commits.map(({ commit }) => parseCommitMessage(commit.message))); await this.git.issues.listLabelsOnIssue({ issue_number: number, owner, repo }).then((resp) => resp.data.forEach(({ name }) => this.labels.add(name))); } }; diff --git a/ng-dev/pr/common/BUILD.bazel b/ng-dev/pr/common/BUILD.bazel index 065bb5371..af73a9acb 100644 --- a/ng-dev/pr/common/BUILD.bazel +++ b/ng-dev/pr/common/BUILD.bazel @@ -3,7 +3,10 @@ load("//tools:defaults.bzl", "ts_library") ts_library( name = "common", srcs = glob(["**/*.ts"]), - visibility = ["//ng-dev:__subpackages__"], + visibility = [ + "//github-actions/commit-message-based-labels:__subpackages__", + "//ng-dev:__subpackages__", + ], deps = [ "//ng-dev/commit-message", "//ng-dev/pr/config", diff --git a/ng-dev/pr/common/labels.ts b/ng-dev/pr/common/labels.ts new file mode 100644 index 000000000..1a11c9f98 --- /dev/null +++ b/ng-dev/pr/common/labels.ts @@ -0,0 +1,28 @@ +import {Commit} from '../../commit-message/parse.js'; + +interface Label { + /* The label string. */ + label: string; + /** A matching function, if the label is automatically applied by our github action, otherwise false. */ + commitCheck: ((c: Commit) => boolean) | false; +} + +/** Set of labels which are known to tooling, and in some cases are managed by tooling. */ +export const ToolingPullRequestLabels = { + BREAKING_CHANGE: