Skip to content
Merged
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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,13 @@ When you reach a point where you'd like to update your labels and regular expres
Set `versioned-regex` to any valid regular expression that should be used to capture the version number from the issue. The first match will be used should multiple be found.

Set `body-missing-regex-label` to the name of the label that should be added to an issue where the specified `version-regex` can't be found. This is useful for when your users accidentally delete this value. Leave this blank if you don't want to use this functionality.

### Pull request support

The labeler action is also available for pull requests. Make sure the workflow is triggered by pull requests.

```
on:
pull_requests:
types: [opened, edited]
```
72 changes: 48 additions & 24 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
Expand All @@ -8,13 +27,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core"));
const github = __importStar(require("@actions/github"));
Expand All @@ -28,11 +40,15 @@ function run() {
const enableVersionedRegex = parseInt(core.getInput('enable-versioned-regex', { required: true }));
const versionedRegex = new RegExp(core.getInput('versioned-regex', { required: false }));
const notBefore = Date.parse(core.getInput('not-before', { required: false }));
const bodyMissingRexexLabel = core.getInput('body-missing-regex-label', { required: false });
const issue_number = getIssueNumber();
const issue_body = getIssueBody();
if (!issue_number || !issue_body) {
console.log('Could not get issue number or issue body from context, exiting');
const bodyMissingRegexLabel = core.getInput('body-missing-regex-label', { required: false });
const issue_number = getIssueOrPullRequestNumber();
if (issue_number === undefined) {
console.log('Could not get issue or pull request number from context, exiting');
return;
}
const issue_body = getIssueOrPullRequestBody();
if (issue_body === undefined) {
console.log('Could not get issue or pull request body from context, exiting');
return;
}
// A client to load data from GitHub
Expand All @@ -42,15 +58,15 @@ function run() {
if (enableVersionedRegex == 1) {
const regexVersion = versionedRegex.exec(issue_body);
if (!regexVersion || !regexVersion[1]) {
if (bodyMissingRexexLabel) {
addLabels(client, issue_number, [bodyMissingRexexLabel]);
if (bodyMissingRegexLabel) {
addLabels(client, issue_number, [bodyMissingRegexLabel]);
}
console.log(`Issue #${issue_number} does not contain regex version in the body of the issue, exiting.`);
return 0;
}
else {
if (bodyMissingRexexLabel) {
removeLabelItems.push(bodyMissingRexexLabel);
if (bodyMissingRegexLabel) {
removeLabelItems.push(bodyMissingRegexLabel);
}
}
configPath = regexifyConfigPath(configPath, regexVersion[1]);
Expand Down Expand Up @@ -93,19 +109,27 @@ function run() {
}
});
}
function getIssueNumber() {
function getIssueOrPullRequestNumber() {
const issue = github.context.payload.issue;
if (!issue) {
return;
if (issue) {
return issue.number;
}
const pull_request = github.context.payload.pull_request;
if (pull_request) {
return pull_request.number;
}
return issue.number;
return;
}
function getIssueBody() {
function getIssueOrPullRequestBody() {
const issue = github.context.payload.issue;
if (!issue) {
return;
if (issue) {
return issue.body;
}
const pull_request = github.context.payload.pull_request;
if (pull_request) {
return pull_request.body;
}
return issue.body;
return;
}
function regexifyConfigPath(configPath, version) {
var lastIndex = configPath.lastIndexOf('.');
Expand Down
38 changes: 26 additions & 12 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ async function run() {
const versionedRegex = new RegExp(core.getInput('versioned-regex', { required: false }));
const notBefore = Date.parse(core.getInput('not-before', { required: false }));
const bodyMissingRegexLabel = core.getInput('body-missing-regex-label', { required: false });
const issue_number = getIssueNumber();
const issue_body = getIssueBody();
const issue_number = getIssueOrPullRequestNumber();
if (issue_number === undefined) {
console.log('Could not get issue or pull request number from context, exiting');
return;
}

if (issue_number === undefined || issue_body === undefined) {
console.log('Could not get issue number or issue body from context, exiting');
const issue_body = getIssueOrPullRequestBody();
if (issue_body === undefined) {
console.log('Could not get issue or pull request body from context, exiting');
return;
}

Expand Down Expand Up @@ -86,22 +90,32 @@ async function run() {
}
}

function getIssueNumber(): number | undefined {
function getIssueOrPullRequestNumber(): number | undefined {
const issue = github.context.payload.issue;
if (!issue) {
return;
if (issue) {
return issue.number;
}

const pull_request = github.context.payload.pull_request;
if (pull_request) {
return pull_request.number;
}

return issue.number;
return;
}

function getIssueBody(): string | undefined {
function getIssueOrPullRequestBody(): string | undefined {
const issue = github.context.payload.issue;
if (!issue) {
return;
if (issue) {
return issue.body;
}

const pull_request = github.context.payload.pull_request;
if (pull_request) {
return pull_request.body;
}

return issue.body;
return;
}

function regexifyConfigPath(configPath: string, version: string) {
Expand Down