Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow the use of custom issue numbers #66

Merged
merged 1 commit into from
May 15, 2023
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
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ inputs:
description: 'Remove the label from the issue if the label regex does not match'
required: false
default: "0"
issue_number:
description: 'The number of the issue/PR to label'
required: false
default: ${{ github.event.issue.number || github.event.pull_request.number }}

runs:
using: 'node16'
main: 'lib/index.js'
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js

Large diffs are not rendered by default.

35 changes: 13 additions & 22 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,7 @@ async function run() {
const includeTitle = parseInt(getInput("include-title", { required: false }));
const syncLabels = parseInt(getInput("sync-labels", { required: false }));

const issue_number = getIssueOrPRNumber();
if (issue_number === undefined) {
console.log("Could not get issue or PR number from context, exiting");
return;
}

const issue_body = getIssueOrPRBody();
if (issue_body === undefined) {
console.log("Could not get issue or PR body from context, exiting");
return;
}

const issue_title = getIssueOrPRTitle();
if (!issue_title) {
console.log("Could not get issue or PR title from context, exiting");
return;
}
const issue_number = parseInt(getInput("issue-number", { required: true }))

// A client to load data from GitHub
const { rest: client } = getOctokit(token);
Expand All @@ -54,6 +38,18 @@ async function run() {
issue_number,
});

const issue_body = issue.data.body ?? getIssueOrPRBody();
if (issue_body === undefined) {
console.log("Could not get issue or PR body from API or context, exiting");
return;
}

const issue_title = issue.data.title ?? getIssueOrPRTitle();
if (!issue_title) {
console.log("Could not get issue or PR title from API or context, exiting");
return;
}

const labels: String[] = []
issue.data.labels.forEach((label) => {
if (typeof label === 'string') {
Expand Down Expand Up @@ -125,11 +121,6 @@ async function run() {
}
}

function getIssueOrPRNumber() {
const { issue, pull_request } = context.payload;
return issue?.number ?? pull_request?.number;
}

function getIssueOrPRBody() {
const { issue, pull_request } = context.payload;
if (issue?.body === null || pull_request?.body === null) {
Expand Down