Merge pull request #338 from saravanan30erd/fix-url-match
Allow projects outside github.com
This commit is contained in:
@@ -572,24 +572,19 @@ describe('addToProject', () => {
|
|||||||
const infoSpy = jest.spyOn(core, 'info')
|
const infoSpy = jest.spyOn(core, 'info')
|
||||||
const gqlMock = mockGraphQL()
|
const gqlMock = mockGraphQL()
|
||||||
await expect(addToProject()).rejects.toThrow(
|
await expect(addToProject()).rejects.toThrow(
|
||||||
'https://github.com/orgs/github/repositories. Project URL should match the format https://github.com/<orgs-or-users>/<ownerName>/projects/<projectNumber>',
|
'Invalid project URL: https://github.com/orgs/github/repositories. Project URL should match the format <GitHub server domain name>/<orgs-or-users>/<ownerName>/projects/<projectNumber>',
|
||||||
)
|
)
|
||||||
expect(infoSpy).not.toHaveBeenCalled()
|
expect(infoSpy).not.toHaveBeenCalled()
|
||||||
expect(gqlMock).not.toHaveBeenCalled()
|
expect(gqlMock).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
test(`throws an error when url isn't under the github.com domain`, async () => {
|
test(`works with URLs that are not under the github.com domain`, async () => {
|
||||||
mockGetInput({
|
|
||||||
'project-url': 'https://notgithub.com/orgs/github/projects/1',
|
|
||||||
'github-token': 'gh_token',
|
|
||||||
})
|
|
||||||
|
|
||||||
github.context.payload = {
|
github.context.payload = {
|
||||||
issue: {
|
issue: {
|
||||||
number: 1,
|
number: 1,
|
||||||
labels: [],
|
labels: [{name: 'bug'}],
|
||||||
// eslint-disable-next-line camelcase
|
// eslint-disable-next-line camelcase
|
||||||
html_url: 'https://github.com/actions/add-to-project/issues/74',
|
html_url: 'https://notgithub.com/actions/add-to-project/issues/74',
|
||||||
},
|
},
|
||||||
repository: {
|
repository: {
|
||||||
name: 'add-to-project',
|
name: 'add-to-project',
|
||||||
@@ -599,13 +594,32 @@ describe('addToProject', () => {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
const infoSpy = jest.spyOn(core, 'info')
|
mockGraphQL(
|
||||||
const gqlMock = mockGraphQL()
|
{
|
||||||
await expect(addToProject()).rejects.toThrow(
|
test: /getProject/,
|
||||||
'https://notgithub.com/orgs/github/projects/1. Project URL should match the format https://github.com/<orgs-or-users>/<ownerName>/projects/<projectNumber>',
|
return: {
|
||||||
|
organization: {
|
||||||
|
projectV2: {
|
||||||
|
id: 'project-id',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
test: /addProjectV2ItemById/,
|
||||||
|
return: {
|
||||||
|
addProjectV2ItemById: {
|
||||||
|
item: {
|
||||||
|
id: 'project-item-id',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
)
|
)
|
||||||
expect(infoSpy).not.toHaveBeenCalled()
|
|
||||||
expect(gqlMock).not.toHaveBeenCalled()
|
await addToProject()
|
||||||
|
|
||||||
|
expect(outputs.itemId).toEqual('project-item-id')
|
||||||
})
|
})
|
||||||
|
|
||||||
test('constructs the correct graphQL query given an organization owner', async () => {
|
test('constructs the correct graphQL query given an organization owner', async () => {
|
||||||
|
|||||||
+2
-4
@@ -42,9 +42,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|||||||
exports.mustGetOwnerTypeQuery = exports.addToProject = void 0;
|
exports.mustGetOwnerTypeQuery = exports.addToProject = void 0;
|
||||||
const core = __importStar(__nccwpck_require__(2186));
|
const core = __importStar(__nccwpck_require__(2186));
|
||||||
const github = __importStar(__nccwpck_require__(5438));
|
const github = __importStar(__nccwpck_require__(5438));
|
||||||
// TODO: Ensure this (and the Octokit client) works for non-github.com URLs, as well.
|
const urlParse = /\/(?<ownerType>orgs|users)\/(?<ownerName>[^/]+)\/projects\/(?<projectNumber>\d+)/;
|
||||||
// https://github.com/orgs|users/<ownerName>/projects/<projectNumber>
|
|
||||||
const urlParse = /^(?:https:\/\/)?github\.com\/(?<ownerType>orgs|users)\/(?<ownerName>[^/]+)\/projects\/(?<projectNumber>\d+)/;
|
|
||||||
function addToProject() {
|
function addToProject() {
|
||||||
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
@@ -84,7 +82,7 @@ function addToProject() {
|
|||||||
core.debug(`Project URL: ${projectUrl}`);
|
core.debug(`Project URL: ${projectUrl}`);
|
||||||
const urlMatch = projectUrl.match(urlParse);
|
const urlMatch = projectUrl.match(urlParse);
|
||||||
if (!urlMatch) {
|
if (!urlMatch) {
|
||||||
throw new Error(`Invalid project URL: ${projectUrl}. Project URL should match the format https://github.com/<orgs-or-users>/<ownerName>/projects/<projectNumber>`);
|
throw new Error(`Invalid project URL: ${projectUrl}. Project URL should match the format <GitHub server domain name>/<orgs-or-users>/<ownerName>/projects/<projectNumber>`);
|
||||||
}
|
}
|
||||||
const projectOwnerName = (_e = urlMatch.groups) === null || _e === void 0 ? void 0 : _e.ownerName;
|
const projectOwnerName = (_e = urlMatch.groups) === null || _e === void 0 ? void 0 : _e.ownerName;
|
||||||
const projectNumber = parseInt((_g = (_f = urlMatch.groups) === null || _f === void 0 ? void 0 : _f.projectNumber) !== null && _g !== void 0 ? _g : '', 10);
|
const projectNumber = parseInt((_g = (_f = urlMatch.groups) === null || _f === void 0 ? void 0 : _f.projectNumber) !== null && _g !== void 0 ? _g : '', 10);
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
@@ -1,10 +1,7 @@
|
|||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import * as github from '@actions/github'
|
import * as github from '@actions/github'
|
||||||
|
|
||||||
// TODO: Ensure this (and the Octokit client) works for non-github.com URLs, as well.
|
const urlParse = /\/(?<ownerType>orgs|users)\/(?<ownerName>[^/]+)\/projects\/(?<projectNumber>\d+)/
|
||||||
// https://github.com/orgs|users/<ownerName>/projects/<projectNumber>
|
|
||||||
const urlParse =
|
|
||||||
/^(?:https:\/\/)?github\.com\/(?<ownerType>orgs|users)\/(?<ownerName>[^/]+)\/projects\/(?<projectNumber>\d+)/
|
|
||||||
|
|
||||||
interface ProjectNodeIDResponse {
|
interface ProjectNodeIDResponse {
|
||||||
organization?: {
|
organization?: {
|
||||||
@@ -80,7 +77,7 @@ export async function addToProject(): Promise<void> {
|
|||||||
|
|
||||||
if (!urlMatch) {
|
if (!urlMatch) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Invalid project URL: ${projectUrl}. Project URL should match the format https://github.com/<orgs-or-users>/<ownerName>/projects/<projectNumber>`,
|
`Invalid project URL: ${projectUrl}. Project URL should match the format <GitHub server domain name>/<orgs-or-users>/<ownerName>/projects/<projectNumber>`,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user