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

Commit

Permalink
Adds PR, Issue or Card # as an input parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
bijujoseph committed Jul 8, 2021
1 parent 3d4bc1d commit c186788
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ inputs:
ignore-if-labeled:
description: "True/False value to indicate if no labels should be added or removed if the issue already has labels."
required: false
issue-number:
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`"
required: false
branding:
icon: zap-off
color: orange
Expand Down
41 changes: 29 additions & 12 deletions label.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,34 @@ var labelsToRemove = core
.split(",")
.map(x => x.trim());

/**
* Obtain the issue number either from input or from the context
* @param core - the core object
* @param context - the context object
* @returns {*|number} - issue/card/pr number if not provided by user.
*/
function getIssueNumber(core, context) {
let issueNumber = core.getInput("issue-number");

// return what is provided
if (issueNumber) return issueNumber;

// return the one found in issue
issueNumber = context.payload.issue && context.payload.issue.number;
if (issueNumber) return issueNumber;

// return the one found in PR
issueNumber =
context.payload.pull_request && context.payload.issue.pull_request;
if (issueNumber) return issueNumber;

let card_url =
context.payload.project_card && context.payload.project_card.content_url;
issueNumber = card_url && card_url.split("/").pop();

return issueNumber;
}

async function label() {
const myToken = core.getInput("repo-token");
const ignoreIfAssigned = core.getInput("ignore-if-assigned");
Expand All @@ -19,18 +47,7 @@ async function label() {
const context = github.context;
const repoName = context.payload.repository.name;
const ownerName = context.payload.repository.owner.login;
var issueNumber;

if (context.payload.issue !== undefined) {
issueNumber = context.payload.issue.number;
} else if (context.payload.pull_request !== undefined) {
issueNumber = context.payload.pull_request.number;
} else if (
context.payload.project_card !== undefined &&
context.payload.project_card.content_url
) {
issueNumber = context.payload.project_card.content_url.split("/").pop();
}
let issueNumber = getIssueNumber(core, context);

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

0 comments on commit c186788

Please sign in to comment.