mirror of
https://github.com/actions/add-to-project.git
synced 2025-12-10 20:21:17 +00:00
Add basic labeled filter
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
{
|
||||
"printWidth": 80,
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"semi": false,
|
||||
|
||||
@@ -8,6 +8,9 @@ inputs:
|
||||
github-token:
|
||||
required: true
|
||||
description: A GitHub personal access token with write access to the project
|
||||
labeled:
|
||||
required: false
|
||||
description: A comma-separated list of labels to use as a filter for issue to be added
|
||||
runs:
|
||||
using: 'node12'
|
||||
main: 'dist/index.js'
|
||||
|
||||
23
dist/index.js
generated
vendored
23
dist/index.js
generated
vendored
@@ -42,19 +42,30 @@ const github = __importStar(__nccwpck_require__(5438));
|
||||
// https://github.com/orgs|users/<ownerName>/projects/<projectNumber>
|
||||
const urlParse = /^(?:https:\/\/)?github\.com\/(?<ownerType>orgs|users)\/(?<ownerName>[^/]+)\/projects\/(?<projectNumber>\d+)/;
|
||||
function run() {
|
||||
var _a, _b, _c, _d, _e, _f, _g, _h;
|
||||
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const projectUrl = core.getInput('project-url', { required: true });
|
||||
const ghToken = core.getInput('github-token', { required: true });
|
||||
const labeled = (_b = (_a = core.getInput('labeled')) === null || _a === void 0 ? void 0 : _a.split(',')) !== null && _b !== void 0 ? _b : [];
|
||||
const octokit = github.getOctokit(ghToken);
|
||||
const urlMatch = projectUrl.match(urlParse);
|
||||
const issue = (_c = github.context.payload.issue) !== null && _c !== void 0 ? _c : github.context.payload.pull_request;
|
||||
const issueLabels = ((_d = issue === null || issue === void 0 ? void 0 : issue.labels) !== null && _d !== void 0 ? _d : []).map((l) => l.name);
|
||||
// Ensure the issue matches our `labeled` filter, if provided.
|
||||
if (labeled.length > 0) {
|
||||
const hasLabel = issueLabels.some(l => labeled.includes(l));
|
||||
if (!hasLabel) {
|
||||
core.info(`Skipping issue ${issue === null || issue === void 0 ? void 0 : issue.number} because it does not have one of the labels: ${labeled.join(', ')}`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
core.debug(`Project URL: ${projectUrl}`);
|
||||
if (!urlMatch) {
|
||||
throw new Error(`Invalid project URL: ${projectUrl}. Project URL should match the format https://github.com/<orgs-or-users>/<ownerName>/projects/<projectNumber>`);
|
||||
}
|
||||
const ownerName = (_a = urlMatch.groups) === null || _a === void 0 ? void 0 : _a.ownerName;
|
||||
const projectNumber = parseInt((_c = (_b = urlMatch.groups) === null || _b === void 0 ? void 0 : _b.projectNumber) !== null && _c !== void 0 ? _c : '', 10);
|
||||
const ownerType = (_d = urlMatch.groups) === null || _d === void 0 ? void 0 : _d.ownerType;
|
||||
const ownerName = (_e = urlMatch.groups) === null || _e === void 0 ? void 0 : _e.ownerName;
|
||||
const projectNumber = parseInt((_g = (_f = urlMatch.groups) === null || _f === void 0 ? void 0 : _f.projectNumber) !== null && _g !== void 0 ? _g : '', 10);
|
||||
const ownerType = (_h = urlMatch.groups) === null || _h === void 0 ? void 0 : _h.ownerType;
|
||||
const ownerTypeQuery = mustGetOwnerTypeQuery(ownerType);
|
||||
core.debug(`Org name: ${ownerName}`);
|
||||
core.debug(`Project number: ${projectNumber}`);
|
||||
@@ -70,8 +81,8 @@ function run() {
|
||||
ownerName,
|
||||
projectNumber
|
||||
});
|
||||
const projectId = (_e = idResp[ownerTypeQuery]) === null || _e === void 0 ? void 0 : _e.projectNext.id;
|
||||
const contentId = (_g = (_f = github.context.payload.issue) === null || _f === void 0 ? void 0 : _f.node_id) !== null && _g !== void 0 ? _g : (_h = github.context.payload.pull_request) === null || _h === void 0 ? void 0 : _h.node_id;
|
||||
const projectId = (_j = idResp[ownerTypeQuery]) === null || _j === void 0 ? void 0 : _j.projectNext.id;
|
||||
const contentId = issue === null || issue === void 0 ? void 0 : issue.node_id;
|
||||
core.debug(`Project node ID: ${projectId}`);
|
||||
core.debug(`Content ID: ${contentId}`);
|
||||
// Next, use the GraphQL API to add the issue to the project.
|
||||
|
||||
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
25
src/main.ts
25
src/main.ts
@@ -33,8 +33,29 @@ interface ProjectAddItemResponse {
|
||||
async function run(): Promise<void> {
|
||||
const projectUrl = core.getInput('project-url', {required: true})
|
||||
const ghToken = core.getInput('github-token', {required: true})
|
||||
const labeled = core.getInput('labeled')?.split(',') ?? []
|
||||
const octokit = github.getOctokit(ghToken)
|
||||
const urlMatch = projectUrl.match(urlParse)
|
||||
const issue =
|
||||
github.context.payload.issue ?? github.context.payload.pull_request
|
||||
const issueLabels: string[] = (issue?.labels ?? []).map(
|
||||
(l: {name: string}) => l.name
|
||||
)
|
||||
|
||||
// Ensure the issue matches our `labeled` filter, if provided.
|
||||
if (labeled.length > 0) {
|
||||
const hasLabel = issueLabels.some(l => labeled.includes(l))
|
||||
|
||||
if (!hasLabel) {
|
||||
core.info(
|
||||
`Skipping issue ${
|
||||
issue?.number
|
||||
} because it does not have one of the labels: ${labeled.join(', ')}`
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
core.debug(`Project URL: ${projectUrl}`)
|
||||
|
||||
@@ -69,9 +90,7 @@ async function run(): Promise<void> {
|
||||
)
|
||||
|
||||
const projectId = idResp[ownerTypeQuery]?.projectNext.id
|
||||
const contentId =
|
||||
github.context.payload.issue?.node_id ??
|
||||
github.context.payload.pull_request?.node_id
|
||||
const contentId = issue?.node_id
|
||||
|
||||
core.debug(`Project node ID: ${projectId}`)
|
||||
core.debug(`Content ID: ${contentId}`)
|
||||
|
||||
Reference in New Issue
Block a user