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

Allow full and abbreviated issue URL as well for required external repo. #1

Merged
merged 1 commit into from
Nov 7, 2024
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
2 changes: 1 addition & 1 deletion __mocks__/@actions/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = {
? "Lorem ipsum close https://github.com/orgone/repoone/issues/123, fixes https://github.com/orgtwo/repotwo/issues/456 and closes ext_org/ext_repo#1337"
: github.context.localRepo
? "Lorem ipsum close #12345 and fix #456"
: "Lorem ipsum close https://github.com/orgone/repoone/issues/123, fixes https://github.com/orgtwo/repotwo/issues/456 and resolves ext_org/ext_repo#1337 but also closes #12345 and fixed #67890",
: "Lorem ipsum close https://github.com/orgone/repoone/issues/123, fixes https://github.com/orgtwo/repotwo/issues/456 and resolves ext_org/ext_repo#1337 but also closes #12345 and fixed #67890. In addition, fix orgtwo/repotwo/issues/789 and resolved orgtwo/repotwo#123.",
closingIssuesReferences:
github.context.looseMatching ||
github.context.allowOnlyExternalIssues
Expand Down
6 changes: 4 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33834,6 +33834,8 @@ minimatch.unescape = unescape_unescape;
const GITHUB_KEYWORDS =
"close|closes|closed|fix|fixes|fixed|resolve|resolves|resolved";

const GITHUB_URL = "https?:\\/\\/github\\.com\\/";

function parseCSV(value) {
if (value.trim() === "") return [];
return value.split(",").map((p) => p.trim());
Expand Down Expand Up @@ -33942,12 +33944,12 @@ function extractExternalIssueCount(body) {

if (requiredExternalRepo?.length) {
regex = new RegExp(
`\\b(${GITHUB_KEYWORDS})\\s${requiredExternalRepo}#\\d+`,
`\\b(${GITHUB_KEYWORDS})\\s(${GITHUB_URL}${requiredExternalRepo}\\/issues\\/|${requiredExternalRepo}(\\/issues\\/|#))\\d+`,
"gim",
);
} else {
regex = new RegExp(
`\\b(${GITHUB_KEYWORDS})\\s(https?:\\/\\/github\\.com\\/)*(([^/]+)\\/([^/|#]+)(\\/issues\\/|#)(\\d+))`,
`\\b(${GITHUB_KEYWORDS})\\s(${GITHUB_URL})*(([^/]+)\\/([^/|#]+)(\\/issues\\/|#)(\\d+))`,
"gim",
);
}
Expand Down
30 changes: 28 additions & 2 deletions src/action.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ test("should return the number of linked issues using loose matching on local an

await run();

expect(core.setOutput).toHaveBeenNthCalledWith(1, "linked_issues_count", 5);
expect(core.setOutput).toHaveBeenNthCalledWith(1, "linked_issues_count", 7);
});

test("should return the number of linked issues on only external repository when only external issues are allowed", async () => {
Expand All @@ -140,7 +140,7 @@ test("should return the number of linked issues on only external repository when

await run();

expect(core.setOutput).toHaveBeenNthCalledWith(1, "linked_issues_count", 3);
expect(core.setOutput).toHaveBeenNthCalledWith(1, "linked_issues_count", 5);
});

test("filters by required-external-repo", async () => {
Expand Down Expand Up @@ -195,6 +195,32 @@ test("filters by both allow-only-external-issues and required-external-repo", as
expect(core.setOutput).toHaveBeenNthCalledWith(1, "linked_issues_count", 1);
});

test("matches full issue URLs against required-external-repo", async () => {
core.getInput.mockImplementation((a) =>
a === "required-external-repo" ? "orgtwo/repotwo" : "",
);

// eslint-disable-next-line
github.context = {
allowOnlyExternalIssues: true,
eventName: "pull_request",
payload: {
action: "opened",
number: 123,
repository: {
name: REPO_NAME,
owner: {
login: ORG_NAME,
},
},
},
};

await run();

expect(core.setOutput).toHaveBeenNthCalledWith(1, "linked_issues_count", 3);
});

test.each([["pull_request"], ["pull_request_target"]])(
"should succeed when [no-issue] is part of the PR body and also delete any comments",
async (eventName) => {
Expand Down
6 changes: 4 additions & 2 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
const GITHUB_KEYWORDS =
"close|closes|closed|fix|fixes|fixed|resolve|resolves|resolved";

const GITHUB_URL = "https?:\\/\\/github\\.com\\/";

function parseCSV(value) {
if (value.trim() === "") return [];
return value.split(",").map((p) => p.trim());
Expand Down Expand Up @@ -113,12 +115,12 @@

if (requiredExternalRepo?.length) {
regex = new RegExp(
`\\b(${GITHUB_KEYWORDS})\\s${requiredExternalRepo}#\\d+`,
`\\b(${GITHUB_KEYWORDS})\\s(${GITHUB_URL}${requiredExternalRepo}\\/issues\\/|${requiredExternalRepo}(\\/issues\\/|#))\\d+`,
"gim",
);
} else {
regex = new RegExp(
`\\b(${GITHUB_KEYWORDS})\\s(https?:\\/\\/github\\.com\\/)*(([^/]+)\\/([^/|#]+)(\\/issues\\/|#)(\\d+))`,
`\\b(${GITHUB_KEYWORDS})\\s(${GITHUB_URL})*(([^/]+)\\/([^/|#]+)(\\/issues\\/|#)(\\d+))`,
"gim",
);
}
Expand Down Expand Up @@ -146,9 +148,9 @@

export async function getBodyValidIssueCount({
body,
octokit,

Check failure on line 151 in src/util.js

View workflow job for this annotation

GitHub Actions / build

'octokit' is defined but never used
repoOwner,

Check failure on line 152 in src/util.js

View workflow job for this annotation

GitHub Actions / build

'repoOwner' is defined but never used
repoName,

Check failure on line 153 in src/util.js

View workflow job for this annotation

GitHub Actions / build

'repoName' is defined but never used
allowOnlyExternalIssues,
}) {
if (!body) {
Expand Down
Loading