Skip to content

Commit

Permalink
Add SKIP_IF_NOT_IN_PROJECT flag
Browse files Browse the repository at this point in the history
  • Loading branch information
m7kvqbe1 committed Oct 18, 2024
1 parent 9951730 commit 3945b00
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 13 deletions.
14 changes: 9 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,27 @@ author: "m7kvqbe1"

inputs:
github-token:
description: "Personal Access Token to access the repository and projects board"
description: "Personal Access Token to access the repository and projects board."
required: true
project-url:
description: "The URL of the GitHub Project (V2)"
description: "The URL of the GitHub Project (V2)."
required: true
target-labels:
description: 'Comma-separated list of labels that should trigger the action (e.g., "Size: Small, Size: Medium")'
description: 'Comma-separated list of labels that should trigger the action (e.g., "Size: Small, Size: Medium").'
required: true
target-column:
description: 'The target column name to move the issue to when labeled (e.g., "Candidates for Ready")'
description: 'The target column name to move the issue to when labeled (e.g., "Candidates for Ready").'
required: true
ignored-columns:
description: 'Comma-separated list of column names to ignore (e.g., "Ready, In Progress, In Review, Done")'
description: 'Comma-separated list of column names to ignore (e.g., "Ready, In Progress, In Review, Done").'
required: true
default-column:
description: 'The column to move the issue to when a target label is removed. If not specified, no action will be taken on unlabeling.'
required: false
skip-if-not-in-project:
description: 'If set to "true", skip moving the issue if it is not already in the project.'
required: false
default: 'false'

runs:
using: "node20"
Expand Down
23 changes: 19 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34756,7 +34756,8 @@ const processIssueItem = async (
projectData,
issue,
TARGET_COLUMN,
IGNORED_COLUMNS
IGNORED_COLUMNS,
SKIP_IF_NOT_IN_PROJECT
) => {
const statusField = await getStatusField(octokit, projectData.id);
const targetStatusOption = getTargetStatusOption(statusField, TARGET_COLUMN);
Expand All @@ -34772,11 +34773,19 @@ const processIssueItem = async (
);

if (!issueItemData) {
if (SKIP_IF_NOT_IN_PROJECT) {
console.log(
`Issue #${issue.number} is not in the project. Skipping due to skip-if-not-in-project flag.`
);
return;
}

issueItemData = await addIssueToProject(
octokit,
projectData.id,
issue.node_id
);
console.log(`Added issue #${issue.number} to the project.`);
}

const currentStatus = getCurrentStatus(issueItemData);
Expand Down Expand Up @@ -34804,7 +34813,8 @@ const handleLabeledEvent = async (
projectData,
TARGET_COLUMN,
IGNORED_COLUMNS,
TARGET_LABELS
TARGET_LABELS,
SKIP_IF_NOT_IN_PROJECT
) => {
validateIssue(issue, TARGET_LABELS);

Expand All @@ -34813,7 +34823,8 @@ const handleLabeledEvent = async (
projectData,
issue,
TARGET_COLUMN,
IGNORED_COLUMNS
IGNORED_COLUMNS,
SKIP_IF_NOT_IN_PROJECT
);
};

Expand Down Expand Up @@ -34908,6 +34919,9 @@ const run = async () => {
const IGNORED_COLUMNS = parseCommaSeparatedInput(ignoredColumns);
const DEFAULT_COLUMN = defaultColumn ? defaultColumn.trim() : null;

const SKIP_IF_NOT_IN_PROJECT =
_actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput("skip-if-not-in-project") === "true";

const octokit = _actions_github__WEBPACK_IMPORTED_MODULE_1__.getOctokit(token);
const issue = _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.payload.issue;
const action = _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.payload.action;
Expand All @@ -34921,7 +34935,8 @@ const run = async () => {
projectData,
TARGET_COLUMN,
IGNORED_COLUMNS,
TARGET_LABELS
TARGET_LABELS,
SKIP_IF_NOT_IN_PROJECT
);
return;
}
Expand Down
23 changes: 19 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ const processIssueItem = async (
projectData,
issue,
TARGET_COLUMN,
IGNORED_COLUMNS
IGNORED_COLUMNS,
SKIP_IF_NOT_IN_PROJECT
) => {
const statusField = await getStatusField(octokit, projectData.id);
const targetStatusOption = getTargetStatusOption(statusField, TARGET_COLUMN);
Expand All @@ -250,11 +251,19 @@ const processIssueItem = async (
);

if (!issueItemData) {
if (SKIP_IF_NOT_IN_PROJECT) {
console.log(
`Issue #${issue.number} is not in the project. Skipping due to skip-if-not-in-project flag.`
);
return;
}

issueItemData = await addIssueToProject(
octokit,
projectData.id,
issue.node_id
);
console.log(`Added issue #${issue.number} to the project.`);
}

const currentStatus = getCurrentStatus(issueItemData);
Expand Down Expand Up @@ -282,7 +291,8 @@ const handleLabeledEvent = async (
projectData,
TARGET_COLUMN,
IGNORED_COLUMNS,
TARGET_LABELS
TARGET_LABELS,
SKIP_IF_NOT_IN_PROJECT
) => {
validateIssue(issue, TARGET_LABELS);

Expand All @@ -291,7 +301,8 @@ const handleLabeledEvent = async (
projectData,
issue,
TARGET_COLUMN,
IGNORED_COLUMNS
IGNORED_COLUMNS,
SKIP_IF_NOT_IN_PROJECT
);
};

Expand Down Expand Up @@ -386,6 +397,9 @@ const run = async () => {
const IGNORED_COLUMNS = parseCommaSeparatedInput(ignoredColumns);
const DEFAULT_COLUMN = defaultColumn ? defaultColumn.trim() : null;

const SKIP_IF_NOT_IN_PROJECT =
core.getInput("skip-if-not-in-project") === "true";

const octokit = github.getOctokit(token);
const issue = github.context.payload.issue;
const action = github.context.payload.action;
Expand All @@ -399,7 +413,8 @@ const run = async () => {
projectData,
TARGET_COLUMN,
IGNORED_COLUMNS,
TARGET_LABELS
TARGET_LABELS,
SKIP_IF_NOT_IN_PROJECT
);
return;
}
Expand Down

0 comments on commit 3945b00

Please sign in to comment.