[cli] Fix vercel git connect command when passing a URL parameter (#9967)

Hey team,

I had an error this morning when trying to link my repo using the CLI 
![Screenshot 2023-05-17 at 11 38 01](https://github.com/vercel/vercel/assets/1637651/798d6e4f-8c9e-41b7-b712-0322001fca02)


Seems like a combination of `: any` and a recent refacto introduced an issue here.

~- Removed all `any` that were hiding the error~
- Correctly pass the URL already parsed

~- Removed the second useless parsing~
~- Added missing `--help` flag~
  ~I noticed you never specify them and Typescript screams because of that, not sure if on purpose and how you make the compilation pass with this error. Don't hesitate to tell me.~

The fix could be improved by using `arg.Result<THE_ACTUAL_TYPE>` but that would require to store the dictionnary of flags somewhere else and also create an external type. This is already better so...

--- 

NB: 
I had multiple issues while cloning this repo
- pnpm bootstrap does not work
- missing `constants.ts` file that is not explained in the Contributing guidelines
- maybe due to bootstrap not working, almost nothing else worked and the tests too.
This commit is contained in:
Samuel Bodin
2023-05-23 04:50:42 +02:00
committed by GitHub
parent 4fd593ac09
commit a19edc985b
3 changed files with 63 additions and 1 deletions

View File

@@ -65,6 +65,63 @@ describe('git', () => {
process.chdir(originalCwd);
}
});
it('connects an unlinked project with a remote url', async () => {
const cwd = fixture('unlinked');
try {
process.chdir(cwd);
await fs.rename(join(cwd, 'git'), join(cwd, '.git'));
useUser();
useTeams('team_dummy');
useProject({
...defaultProject,
id: 'unlinked',
name: 'unlinked',
});
client.setArgv('git', 'connect', 'https://github.com/user2/repo2');
const gitPromise = git(client);
await expect(client.stderr).toOutput('Set up');
client.stdin.write('y\n');
await expect(client.stderr).toOutput(
'Which scope should contain your project?'
);
client.stdin.write('\r');
await expect(client.stderr).toOutput('Found project');
client.stdin.write('y\n');
await expect(client.stderr).toOutput(
`Do you still want to connect https://github.com/user2/repo2?`
);
client.stdin.write('y\n');
await expect(client.stderr).toOutput(
`Connecting Git remote: https://github.com/user2/repo2`
);
const exitCode = await gitPromise;
await expect(client.stderr).toOutput(
'Connected GitHub repository user2/repo2!'
);
expect(exitCode).toEqual(0);
const project: Project = await client.fetch(`/v8/projects/unlinked`);
expect(project.link).toMatchObject({
type: 'github',
repo: 'user2/repo2',
repoId: 1010,
gitCredentialId: '',
sourceless: true,
createdAt: 1656109539791,
updatedAt: 1656109539791,
});
} finally {
await fs.rename(join(cwd, '.git'), join(cwd, 'git'));
process.chdir(originalCwd);
}
});
it('should fail when there is no git config', async () => {
const cwd = fixture('no-git-config');
try {