Skip to content

Commit

Permalink
fix(vcs-host): return github instead of github.com to match previ…
Browse files Browse the repository at this point in the history
…ous behavior

at least until the behavior change can be released as a breaking change

fixes #1167
  • Loading branch information
travi committed Feb 4, 2024
1 parent 965f3b7 commit f8e266d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/vcs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export async function determineExistingHostDetails({projectRoot}) {
const remoteOrigin = await git.remote(['get-url', 'origin']);
const {owner, name, host} = parseGitUrl(remoteOrigin.trimEnd());

return {owner, name, host};
return {owner, name, host: 'github.com' === host ? 'github' : host};
}
31 changes: 23 additions & 8 deletions src/vcs.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as simpleGit from 'simple-git';
import GitUrlParse from 'git-url-parse';

import {afterEach, describe, expect, it, vi} from 'vitest';
import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
import any from '@travi/any';
import {when} from 'jest-when';

Expand All @@ -11,21 +11,36 @@ vi.mock('simple-git');
vi.mock('git-url-parse');

describe('vcs', () => {
const projectRoot = any.string();
const owner = any.word();
const name = any.word();
const remoteUrl = any.url();

beforeEach(() => {
const remote = vi.fn();

when(simpleGit.simpleGit).calledWith({baseDir: projectRoot}).mockReturnValue({remote});
when(remote).calledWith(['get-url', 'origin']).mockResolvedValue(`${remoteUrl}\n`);
});

afterEach(() => {
vi.clearAllMocks();
});

it('should determine the existing details from the remote origin', async () => {
const owner = any.word();
const name = any.word();
const host = any.word();
const remoteUrl = any.url();
const projectRoot = any.string();
const remote = vi.fn();
when(simpleGit.simpleGit).calledWith({baseDir: projectRoot}).mockReturnValue({remote});
when(remote).calledWith(['get-url', 'origin']).mockResolvedValue(`${remoteUrl}\n`);
when(GitUrlParse).calledWith(remoteUrl).mockReturnValue({owner, name, host});

expect(await determineExistingHostDetails({projectRoot})).toEqual({owner, name, host});
});

it(
'should return `github` when the host is determined to be `github.com` until that can be a breaking change',
async () => {
const host = 'github.com';
when(GitUrlParse).calledWith(remoteUrl).mockReturnValue({owner, name, host});

expect(await determineExistingHostDetails({projectRoot})).toEqual({owner, name, host: 'github'});
}
);
});
6 changes: 5 additions & 1 deletion test/integration/features/step_definitions/vcs-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ Given('the repository hosted on {string}', async function (vcsHost) {
});

Then('vcs details are provided to the enhancers', async function () {
const expectedVcsDetails = {owner: this.gitHostAccount, name: this.repositoryName, host: this.vcsHost};
const expectedVcsDetails = {
owner: this.gitHostAccount,
name: this.repositoryName,
host: 'github.com' === this.vcsHost ? 'github' : this.vcsHost
};

assert.deepEqual(this.vcsDetailsProvidedToEnhancer, expectedVcsDetails);
});

0 comments on commit f8e266d

Please sign in to comment.