Repository: codecov/uploader (ts)

Issue:
Slug Parser doesn't parse ssh:// urls
**Describe the bug**
Our git remote is of the form `ssh://git@<host:port>/repo.git`
When using the uploader, the remote url parser doesn't match the http matcher but matches the git matcher.
However the cleaning splits on a `:` and only strips the scheme.
This causes the slug to start with `//` and then the uploader fails with the following:

```
[2022-06-03T15:17:49.918Z] ['error'] There was an error running the uploader: Error uploading to https://codecov.io: Error: There was an error fetching the storage URL during POST: 400 - Invalid request parameters
[2022-06-03T15:17:49.919Z] ['verbose'] The error stack is: Error: Error uploading to https://codecov.io: Error: There was an error fetching the storage URL during POST: 400 - Invalid request parameters
    at main (/snapshot/repo/dist/src/index.js)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
[2022-06-03T15:17:49.919Z] ['verbose'] End of uploader: 3102 milliseconds
```

**To Reproduce**
Steps to reproduce the behavior:
1. Create a git repo.
2. Set the remote to be of the form `ssh://git@<host:port>/repo.git`
3. Collect coverage data and try to upload it

**Expected behavior**
Coverage upload should succeed.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Additional context**
Add any other context about the problem here.


Pull request description:
fix: parse both versions of ssh urls for remotes
Fixes #792
Signed-off-by: Vihang Mehta <vihang@pixielabs.ai>

Patch:
diff --git a/src/helpers/git.ts b/src/helpers/git.ts
index 8ee9db4..4f38526 100644
--- a/src/helpers/git.ts
+++ b/src/helpers/git.ts
@@ -7,11 +7,11 @@ export function parseSlug(slug: string): string {
     return ''
   }
 
-  if (slug.match('http')) {
-    // Type is http(s)
+  if (slug.match('http:') || slug.match('https:') || slug.match('ssh:')) {
+    // Type is http(s) or ssh
     const phaseOne = slug.split('//')[1]?.replace('.git', '') || ''
     const phaseTwo = phaseOne?.split('/') || ''
-    const cleanSlug = `${phaseTwo[1]}/${phaseTwo[2]}`
+    const cleanSlug = phaseTwo.length > 2 ? `${phaseTwo[1]}/${phaseTwo[2]}` : ''
     return cleanSlug
   } else if (slug.match('@')) {
     // Type is git


Test patch:
diff --git a/test/helpers/git.test.ts b/test/helpers/git.test.ts
new file mode 100644
index 0000000..76364a1
--- /dev/null
+++ b/test/helpers/git.test.ts
@@ -0,0 +1,37 @@
+import { parseSlug } from '../../src/helpers/git'
+
+describe('Git Helper', () => {
+  it('should be able to parse http urls', () => {
+    const remoteAddr = 'http://github.com/codecov/uploader.git'
+    expect(parseSlug(remoteAddr)).toBe('codecov/uploader')
+  })
+
+  it('should be able to parse https urls', () => {
+    const remoteAddr = 'https://github.com/codecov/uploader.git'
+    expect(parseSlug(remoteAddr)).toBe('codecov/uploader')
+  })
+
+  it('should be able to parse ssh urls', () => {
+    const remoteAddr = 'ssh://git@github.com/codecov/uploader.git'
+    expect(parseSlug(remoteAddr)).toBe('codecov/uploader')
+  })
+
+  it('should be able to parse short form ssh urls', () => {
+    const remoteAddr = 'git@github.com:codecov/uploader.git'
+    expect(parseSlug(remoteAddr)).toBe('codecov/uploader')
+  })
+
+  it('doesn\'t error with malformed http urls', () => {
+    const remoteAddr = 'http://github.com/codecov'
+    expect(parseSlug(remoteAddr)).toBe('')
+  })
+
+  it('doesn\'t error with malformed short ssh urls', () => {
+    const remoteAddr = 'git@github.com/abcd'
+    expect(parseSlug(remoteAddr)).toBe('')
+  })
+
+  it('errors with unexpected addr', () => {
+    expect(() => { parseSlug('test non remoteAddr') }).toThrowError(/Unable to parse slug URL/)
+  })
+})