Skip to content
This repository was archived by the owner on Oct 8, 2022. It is now read-only.

Commit 1825c39

Browse files
author
Andy McKay
authored
Merge pull request #25 from bijujoseph/master
Ability to accept issue number as parameter
2 parents 3d4bc1d + c186788 commit 1825c39

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

action.yml

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ inputs:
1717
ignore-if-labeled:
1818
description: "True/False value to indicate if no labels should be added or removed if the issue already has labels."
1919
required: false
20+
issue-number:
21+
description: "An issue number or PR number or project card number. Optional, if not specified, will use the one available in github event `github.event.pull_request` or `github.event.issue`"
22+
required: false
2023
branding:
2124
icon: zap-off
2225
color: orange

label.js

+29-12
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,34 @@ var labelsToRemove = core
1111
.split(",")
1212
.map(x => x.trim());
1313

14+
/**
15+
* Obtain the issue number either from input or from the context
16+
* @param core - the core object
17+
* @param context - the context object
18+
* @returns {*|number} - issue/card/pr number if not provided by user.
19+
*/
20+
function getIssueNumber(core, context) {
21+
let issueNumber = core.getInput("issue-number");
22+
23+
// return what is provided
24+
if (issueNumber) return issueNumber;
25+
26+
// return the one found in issue
27+
issueNumber = context.payload.issue && context.payload.issue.number;
28+
if (issueNumber) return issueNumber;
29+
30+
// return the one found in PR
31+
issueNumber =
32+
context.payload.pull_request && context.payload.issue.pull_request;
33+
if (issueNumber) return issueNumber;
34+
35+
let card_url =
36+
context.payload.project_card && context.payload.project_card.content_url;
37+
issueNumber = card_url && card_url.split("/").pop();
38+
39+
return issueNumber;
40+
}
41+
1442
async function label() {
1543
const myToken = core.getInput("repo-token");
1644
const ignoreIfAssigned = core.getInput("ignore-if-assigned");
@@ -19,18 +47,7 @@ async function label() {
1947
const context = github.context;
2048
const repoName = context.payload.repository.name;
2149
const ownerName = context.payload.repository.owner.login;
22-
var issueNumber;
23-
24-
if (context.payload.issue !== undefined) {
25-
issueNumber = context.payload.issue.number;
26-
} else if (context.payload.pull_request !== undefined) {
27-
issueNumber = context.payload.pull_request.number;
28-
} else if (
29-
context.payload.project_card !== undefined &&
30-
context.payload.project_card.content_url
31-
) {
32-
issueNumber = context.payload.project_card.content_url.split("/").pop();
33-
}
50+
let issueNumber = getIssueNumber(core, context);
3451

3552
if (issueNumber === undefined) {
3653
return "No action being taken. Ignoring because issueNumber was not identified";

0 commit comments

Comments
 (0)