Skip to content

Commit 31b3f3c

Browse files
authored
Merge pull request #338 from saravanan30erd/fix-url-match
Allow projects outside github.com
2 parents 5b64707 + 039f00e commit 31b3f3c

File tree

4 files changed

+34
-25
lines changed

4 files changed

+34
-25
lines changed

__tests__/add-to-project.test.ts

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -572,24 +572,19 @@ describe('addToProject', () => {
572572
const infoSpy = jest.spyOn(core, 'info')
573573
const gqlMock = mockGraphQL()
574574
await expect(addToProject()).rejects.toThrow(
575-
'https://github.com/orgs/github/repositories. Project URL should match the format https://github.com/<orgs-or-users>/<ownerName>/projects/<projectNumber>',
575+
'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>',
576576
)
577577
expect(infoSpy).not.toHaveBeenCalled()
578578
expect(gqlMock).not.toHaveBeenCalled()
579579
})
580580

581-
test(`throws an error when url isn't under the github.com domain`, async () => {
582-
mockGetInput({
583-
'project-url': 'https://notgithub.com/orgs/github/projects/1',
584-
'github-token': 'gh_token',
585-
})
586-
581+
test(`works with URLs that are not under the github.com domain`, async () => {
587582
github.context.payload = {
588583
issue: {
589584
number: 1,
590-
labels: [],
585+
labels: [{name: 'bug'}],
591586
// eslint-disable-next-line camelcase
592-
html_url: 'https://github.com/actions/add-to-project/issues/74',
587+
html_url: 'https://notgithub.com/actions/add-to-project/issues/74',
593588
},
594589
repository: {
595590
name: 'add-to-project',
@@ -599,13 +594,32 @@ describe('addToProject', () => {
599594
},
600595
}
601596

602-
const infoSpy = jest.spyOn(core, 'info')
603-
const gqlMock = mockGraphQL()
604-
await expect(addToProject()).rejects.toThrow(
605-
'https://notgithub.com/orgs/github/projects/1. Project URL should match the format https://github.com/<orgs-or-users>/<ownerName>/projects/<projectNumber>',
597+
mockGraphQL(
598+
{
599+
test: /getProject/,
600+
return: {
601+
organization: {
602+
projectV2: {
603+
id: 'project-id',
604+
},
605+
},
606+
},
607+
},
608+
{
609+
test: /addProjectV2ItemById/,
610+
return: {
611+
addProjectV2ItemById: {
612+
item: {
613+
id: 'project-item-id',
614+
},
615+
},
616+
},
617+
},
606618
)
607-
expect(infoSpy).not.toHaveBeenCalled()
608-
expect(gqlMock).not.toHaveBeenCalled()
619+
620+
await addToProject()
621+
622+
expect(outputs.itemId).toEqual('project-item-id')
609623
})
610624

611625
test('constructs the correct graphQL query given an organization owner', async () => {

dist/index.js

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/add-to-project.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import * as core from '@actions/core'
22
import * as github from '@actions/github'
33

4-
// TODO: Ensure this (and the Octokit client) works for non-github.com URLs, as well.
5-
// https://github.com/orgs|users/<ownerName>/projects/<projectNumber>
6-
const urlParse =
7-
/^(?:https:\/\/)?github\.com\/(?<ownerType>orgs|users)\/(?<ownerName>[^/]+)\/projects\/(?<projectNumber>\d+)/
4+
const urlParse = /\/(?<ownerType>orgs|users)\/(?<ownerName>[^/]+)\/projects\/(?<projectNumber>\d+)/
85

96
interface ProjectNodeIDResponse {
107
organization?: {
@@ -80,7 +77,7 @@ export async function addToProject(): Promise<void> {
8077

8178
if (!urlMatch) {
8279
throw new Error(
83-
`Invalid project URL: ${projectUrl}. Project URL should match the format https://github.com/<orgs-or-users>/<ownerName>/projects/<projectNumber>`,
80+
`Invalid project URL: ${projectUrl}. Project URL should match the format <GitHub server domain name>/<orgs-or-users>/<ownerName>/projects/<projectNumber>`,
8481
)
8582
}
8683

0 commit comments

Comments
 (0)