Skip to content

Commit d5d9a41

Browse files
Merge branch 'master' of github.com:RocketSurgeonsGuild/actions
2 parents 937fd0d + 8acdb99 commit d5d9a41

File tree

7 files changed

+781
-386
lines changed

7 files changed

+781
-386
lines changed

auto-label/action.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
name: 'Auto Label'
22
description: 'Automatically labels a PR based on some prefix in the title.'
33
inputs:
4-
default-label:
5-
description: 'the default label to use for unlabeled pull requests'
6-
required: true
74
github-token:
85
description: 'Token for the repository. Can be passed in using {{ secrets.GITHUB_TOKEN }}'
96
required: true

auto-label/dist/index.js

Lines changed: 89 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ function whichSync (cmd, opt) {
536536
// We use any as a valid input type
537537
/* eslint-disable @typescript-eslint/no-explicit-any */
538538
Object.defineProperty(exports, "__esModule", { value: true });
539+
exports.toCommandValue = void 0;
539540
/**
540541
* Sanitizes an input into a string so it can be passed into issueCommand safely
541542
* @param input input to sanitize into a string
@@ -567,14 +568,27 @@ module.exports = require("os");
567568
"use strict";
568569

569570
// For internal use, subject to change.
571+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
572+
if (k2 === undefined) k2 = k;
573+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
574+
}) : (function(o, m, k, k2) {
575+
if (k2 === undefined) k2 = k;
576+
o[k2] = m[k];
577+
}));
578+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
579+
Object.defineProperty(o, "default", { enumerable: true, value: v });
580+
}) : function(o, v) {
581+
o["default"] = v;
582+
});
570583
var __importStar = (this && this.__importStar) || function (mod) {
571584
if (mod && mod.__esModule) return mod;
572585
var result = {};
573-
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
574-
result["default"] = mod;
586+
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
587+
__setModuleDefault(result, mod);
575588
return result;
576589
};
577590
Object.defineProperty(exports, "__esModule", { value: true });
591+
exports.issueCommand = void 0;
578592
// We use any as a valid input type
579593
/* eslint-disable @typescript-eslint/no-explicit-any */
580594
const fs = __importStar(__webpack_require__(747));
@@ -1158,7 +1172,7 @@ function run() {
11581172
const github = github_1.getOctokit(githubToken, {});
11591173
if (payload.pull_request) {
11601174
const pr = yield github.pulls.get(Object.assign(Object.assign({}, repo), { pull_number: payload.pull_request.number }));
1161-
if (payload.action === 'opened' && pr.data.merged) {
1175+
if (payload.action === 'opened' || payload.action === 'reopened') {
11621176
yield ensure_label_1.addPullRequestLabel(github, repo, pr.data);
11631177
}
11641178
}
@@ -1490,14 +1504,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
14901504
exports.addPullRequestLabel = void 0;
14911505
function addPullRequestLabel(github, request, pr) {
14921506
return __awaiter(this, void 0, void 0, function* () {
1507+
console.log(`pr title: ${pr.title}`);
14931508
const title = pr.title.split(':')[0].trim();
1494-
const titleLabel = pr.labels.filter(z => z.name.includes(title));
1509+
var labelsForRepository = yield github.issues.listLabelsForRepo(Object.assign({}, request));
1510+
const titleLabel = labelsForRepository.data.filter(z => z.name.includes(title)).map(x => x.name);
14951511
const hasLabel = titleLabel.length > 0;
14961512
console.log(`label ${hasLabel ? 'found' : 'not found'}`, pr.labels);
1497-
if (hasLabel)
1513+
if (!hasLabel)
14981514
return;
14991515
console.log('adding title label', titleLabel);
1500-
yield github.issues.addLabels(Object.assign(Object.assign({}, request), { issue_number: pr.number, labels: titleLabel.map(z => z.name) }));
1516+
yield github.issues.addLabels(Object.assign(Object.assign({}, request), { issue_number: pr.number, labels: titleLabel }));
15011517
});
15021518
}
15031519
exports.addPullRequestLabel = addPullRequestLabel;
@@ -1959,14 +1975,27 @@ function errname(uv, code) {
19591975

19601976
"use strict";
19611977

1978+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
1979+
if (k2 === undefined) k2 = k;
1980+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
1981+
}) : (function(o, m, k, k2) {
1982+
if (k2 === undefined) k2 = k;
1983+
o[k2] = m[k];
1984+
}));
1985+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
1986+
Object.defineProperty(o, "default", { enumerable: true, value: v });
1987+
}) : function(o, v) {
1988+
o["default"] = v;
1989+
});
19621990
var __importStar = (this && this.__importStar) || function (mod) {
19631991
if (mod && mod.__esModule) return mod;
19641992
var result = {};
1965-
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
1966-
result["default"] = mod;
1993+
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
1994+
__setModuleDefault(result, mod);
19671995
return result;
19681996
};
19691997
Object.defineProperty(exports, "__esModule", { value: true });
1998+
exports.issue = exports.issueCommand = void 0;
19701999
const os = __importStar(__webpack_require__(87));
19712000
const utils_1 = __webpack_require__(82);
19722001
/**
@@ -4081,6 +4110,25 @@ exports.getOctokit = getOctokit;
40814110

40824111
"use strict";
40834112

4113+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4114+
if (k2 === undefined) k2 = k;
4115+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4116+
}) : (function(o, m, k, k2) {
4117+
if (k2 === undefined) k2 = k;
4118+
o[k2] = m[k];
4119+
}));
4120+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
4121+
Object.defineProperty(o, "default", { enumerable: true, value: v });
4122+
}) : function(o, v) {
4123+
o["default"] = v;
4124+
});
4125+
var __importStar = (this && this.__importStar) || function (mod) {
4126+
if (mod && mod.__esModule) return mod;
4127+
var result = {};
4128+
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
4129+
__setModuleDefault(result, mod);
4130+
return result;
4131+
};
40844132
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
40854133
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
40864134
return new (P || (P = Promise))(function (resolve, reject) {
@@ -4090,14 +4138,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
40904138
step((generator = generator.apply(thisArg, _arguments || [])).next());
40914139
});
40924140
};
4093-
var __importStar = (this && this.__importStar) || function (mod) {
4094-
if (mod && mod.__esModule) return mod;
4095-
var result = {};
4096-
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
4097-
result["default"] = mod;
4098-
return result;
4099-
};
41004141
Object.defineProperty(exports, "__esModule", { value: true });
4142+
exports.getState = exports.saveState = exports.group = exports.endGroup = exports.startGroup = exports.info = exports.warning = exports.error = exports.debug = exports.isDebug = exports.setFailed = exports.setCommandEcho = exports.setOutput = exports.getBooleanInput = exports.getInput = exports.addPath = exports.setSecret = exports.exportVariable = exports.ExitCode = void 0;
41014143
const command_1 = __webpack_require__(431);
41024144
const file_command_1 = __webpack_require__(102);
41034145
const utils_1 = __webpack_require__(82);
@@ -4164,7 +4206,9 @@ function addPath(inputPath) {
41644206
}
41654207
exports.addPath = addPath;
41664208
/**
4167-
* Gets the value of an input. The value is also trimmed.
4209+
* Gets the value of an input.
4210+
* Unless trimWhitespace is set to false in InputOptions, the value is also trimmed.
4211+
* Returns an empty string if the value is not defined.
41684212
*
41694213
* @param name name of the input to get
41704214
* @param options optional. See InputOptions.
@@ -4175,9 +4219,34 @@ function getInput(name, options) {
41754219
if (options && options.required && !val) {
41764220
throw new Error(`Input required and not supplied: ${name}`);
41774221
}
4222+
if (options && options.trimWhitespace === false) {
4223+
return val;
4224+
}
41784225
return val.trim();
41794226
}
41804227
exports.getInput = getInput;
4228+
/**
4229+
* Gets the input value of the boolean type in the YAML 1.2 "core schema" specification.
4230+
* Support boolean input list: `true | True | TRUE | false | False | FALSE` .
4231+
* The return value is also in boolean type.
4232+
* ref: https://yaml.org/spec/1.2/spec.html#id2804923
4233+
*
4234+
* @param name name of the input to get
4235+
* @param options optional. See InputOptions.
4236+
* @returns boolean
4237+
*/
4238+
function getBooleanInput(name, options) {
4239+
const trueValue = ['true', 'True', 'TRUE'];
4240+
const falseValue = ['false', 'False', 'FALSE'];
4241+
const val = getInput(name, options);
4242+
if (trueValue.includes(val))
4243+
return true;
4244+
if (falseValue.includes(val))
4245+
return false;
4246+
throw new TypeError(`Input does not meet YAML 1.2 "Core Schema" specification: ${name}\n` +
4247+
`Support boolean input list: \`true | True | TRUE | false | False | FALSE\``);
4248+
}
4249+
exports.getBooleanInput = getBooleanInput;
41814250
/**
41824251
* Sets the value of an output.
41834252
*
@@ -4186,6 +4255,7 @@ exports.getInput = getInput;
41864255
*/
41874256
// eslint-disable-next-line @typescript-eslint/no-explicit-any
41884257
function setOutput(name, value) {
4258+
process.stdout.write(os.EOL);
41894259
command_1.issueCommand('set-output', { name }, value);
41904260
}
41914261
exports.setOutput = setOutput;
@@ -5112,7 +5182,9 @@ class HttpClient {
51125182
maxSockets: maxSockets,
51135183
keepAlive: this._keepAlive,
51145184
proxy: {
5115-
proxyAuth: `${proxyUrl.username}:${proxyUrl.password}`,
5185+
...((proxyUrl.username || proxyUrl.password) && {
5186+
proxyAuth: `${proxyUrl.username}:${proxyUrl.password}`
5187+
}),
51165188
host: proxyUrl.hostname,
51175189
port: proxyUrl.port
51185190
}

auto-label/src/ensure-label.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@ export async function addPullRequestLabel(
88
request: { owner: string; repo: string },
99
pr: import('@octokit/types/dist-types/generated/Endpoints').PullsGetResponseData,
1010
) {
11+
console.log(`pr title: ${pr.title}`);
1112
const title = pr.title.split(':')[0].trim();
12-
const titleLabel = pr.labels.filter(z => z.name.includes(title));
13+
var labelsForRepository = await github.issues.listLabelsForRepo({ ...request });
14+
const titleLabel = labelsForRepository.data.filter(z => z.name.includes(title)).map(x => x.name);
1315
const hasLabel = titleLabel.length > 0;
1416

1517
console.log(`label ${hasLabel ? 'found' : 'not found'}`, pr.labels);
16-
if (hasLabel) return;
18+
if (!hasLabel) return;
1719

1820
console.log('adding title label', titleLabel);
1921
await github.issues.addLabels({
2022
...request,
2123
issue_number: pr.number,
22-
labels: titleLabel.map(z => z.name),
24+
labels: titleLabel,
2325
});
2426
}

auto-label/src/main.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ async function run(): Promise<void> {
1414
pull_number: payload.pull_request.number,
1515
});
1616

17-
if (payload.action === 'opened' && pr.data.merged) {
17+
if (payload.action === 'opened' || payload.action === 'reopened') {
1818
await addPullRequestLabel(github, repo, pr.data);
19-
}
19+
}
2020
}
2121
} catch (error) {
22-
setFailed(error.message);
22+
setFailed((error ).message);
2323
}
2424
}
2525

0 commit comments

Comments
 (0)