Skip to content

Commit

Permalink
Merge pull request #26 from zanerock/work-liquid-labs/github-toolkit/25
Browse files Browse the repository at this point in the history
Change 'getGitHubOrgAndProject' to 'getGitHubOrgAndProjectBasename'
  • Loading branch information
zanerock authored Oct 26, 2023
2 parents 6b713b2 + 728b2c4 commit 4e90bd4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
const urlRegEx = /github.com[/:]([^/]+)\/([^.]+)/

const getGitHubOrgAndProject = ({ packageJSON, require }) => {
const getGitHubOrgAndProjectBasename = ({ packageJSON, require }) => {
const { repository } = packageJSON

const url = typeof repository === 'string' ? repository : repository.url

const [, org, project] = url.match(urlRegEx) || []
const [, org, projectBasename] = url.match(urlRegEx) || []

if (org === undefined && require === true) {
throw new Error(`Could not extract GitHub org and project from url '${url}'; this may not be a GitHub project.`)
}

return { org, project }
// TODO: 'project' is depricated
return { org, projectBasename }
}

export { getGitHubOrgAndProject }
export { getGitHubOrgAndProjectBasename }
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from './access-lib'
export * from './branch-lib'
export * from './determine-current-release'
export * from './get-github-org-and-project'
export * from './get-github-org-and-project-basename'
export * from './issues-lib'
export * from './labels-lib'
export * from './milestones-lib'
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
/* global describe expect test */

import { getGitHubOrgAndProject } from '../get-github-org-and-project'
import { getGitHubOrgAndProjectBasename } from '../get-github-org-and-project-basename'

// requires user to have API access
describe('getGitHubOrgAndProject', () => {
describe('getGitHubOrgAndProjectBasename', () => {
test('works with string repositories', () => {
const packageJSON = { repository : 'git+ssh://[email protected]/acme/foo-bar.git' }
expect(getGitHubOrgAndProject({ packageJSON })).toEqual({ org : 'acme', project : 'foo-bar' })
expect(getGitHubOrgAndProjectBasename({ packageJSON })).toEqual({ org : 'acme', projectBasename : 'foo-bar' })
})

test('works with object repositories', () => {
const packageJSON = { repository : { url : 'git+ssh://[email protected]/acme/foo-bar.git' } }
expect(getGitHubOrgAndProject({ packageJSON })).toEqual({ org : 'acme', project : 'foo-bar' })
expect(getGitHubOrgAndProjectBasename({ packageJSON })).toEqual({ org : 'acme', projectBasename : 'foo-bar' })
})

test('returns undefined values when no match', () => {
const packageJSON = { repository : 'git+ssh://[email protected]/acme/foo-bar.git' }
expect(getGitHubOrgAndProject({ packageJSON })).toEqual({ org : undefined, project : undefined })
expect(getGitHubOrgAndProjectBasename({ packageJSON })).toEqual({ org : undefined, projectBasename : undefined })
})

test('throws error when no match and required', () => {
const packageJSON = { repository : 'git+ssh://[email protected]/acme/foo-bar.git' }
expect(() => getGitHubOrgAndProject({ packageJSON, require : true })).toThrow()
expect(() => getGitHubOrgAndProjectBasename({ packageJSON, require : true })).toThrow()
})
})

0 comments on commit 4e90bd4

Please sign in to comment.