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

fix(createGHA): remove non-github remote check #665

Merged
merged 2 commits into from
Nov 11, 2022
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
9 changes: 6 additions & 3 deletions __tests__/lib/createGHA.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ describe('#createGHA', () => {
return expect(createGHA('success!', cmd, command.args, opts)).resolves.toBe('success!');
});

it('should not run if a repo with no remote', () => {
git.remote = getGitRemoteMock('', '', '');

return expect(createGHA('success!', cmd, command.args, opts)).resolves.toBe('success!');
});

it('should not run if user previously declined to set up GHA for current directory + pkg version', async () => {
const repoRoot = process.cwd();

Expand Down Expand Up @@ -209,7 +215,6 @@ describe('#createGHA', () => {

return expect(getGitData()).resolves.toStrictEqual({
containsGitHubRemote: true,
containsNonGitHubRemote: false,
defaultBranch: 'main',
isRepo: true,
repoRoot,
Expand All @@ -223,7 +228,6 @@ describe('#createGHA', () => {

return expect(getGitData()).resolves.toStrictEqual({
containsGitHubRemote: true,
containsNonGitHubRemote: false,
defaultBranch: 'main',
isRepo: true,
repoRoot: '',
Expand All @@ -243,7 +247,6 @@ describe('#createGHA', () => {

return expect(getGitData()).resolves.toStrictEqual({
containsGitHubRemote: undefined,
containsNonGitHubRemote: undefined,
defaultBranch: undefined,
isRepo: false,
repoRoot: '',
Expand Down
11 changes: 4 additions & 7 deletions src/lib/createGHA/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ export async function getGitData() {
debug(`[getGitData] isRepo result: ${isRepo}`);

let containsGitHubRemote;
let containsNonGitHubRemote;
let defaultBranch;
const rawRemotes = await git.remote([]).catch(e => {
debug(`[getGitData] error grabbing git remotes: ${e.message}`);
Expand All @@ -133,11 +132,9 @@ export async function getGitData() {
// This is a bit hairy but we want to keep it fairly general here
// in case of GitHub Enterprise, etc.
containsGitHubRemote = /github/.test(remotesList);
containsNonGitHubRemote = /gitlab/.test(remotesList) || /bitbucket/.test(remotesList);
}

debug(`[getGitData] containsGitHubRemote result: ${containsGitHubRemote}`);
debug(`[getGitData] containsNonGitHubRemote result: ${containsNonGitHubRemote}`);
debug(`[getGitData] defaultBranch result: ${defaultBranch}`);

const repoRoot = await git.revparse(['--show-toplevel']).catch(e => {
Expand All @@ -147,7 +144,7 @@ export async function getGitData() {

debug(`[getGitData] repoRoot result: ${repoRoot}`);

return { containsGitHubRemote, containsNonGitHubRemote, defaultBranch, isRepo, repoRoot };
return { containsGitHubRemote, defaultBranch, isRepo, repoRoot };
}

/**
Expand All @@ -169,7 +166,7 @@ export default async function createGHA(
return msg;
}

const { containsGitHubRemote, containsNonGitHubRemote, defaultBranch, isRepo, repoRoot } = await getGitData();
const { containsGitHubRemote, defaultBranch, isRepo, repoRoot } = await getGitData();

const configVal = configstore.get(getConfigStoreKey(repoRoot));
debug(`repo value in config: ${configVal}`);
Expand All @@ -183,8 +180,8 @@ export default async function createGHA(
!isRepo ||
// user has previously declined to set up GHA for current repo and `rdme` package version
configVal === majorPkgVersion ||
// is a repo, but only contains non-GitHub remotes
(isRepo && containsNonGitHubRemote && !containsGitHubRemote) ||
// is a repo, but does not contain a GitHub remote
(isRepo && !containsGitHubRemote) ||
// not testing this function
(isTest() && !process.env.TEST_RDME_CREATEGHA)
) {
Expand Down