Skip to content

Commit 95a6d64

Browse files
authored
fix: origins without extensions (#38)
if you do `git clone git@github.com:chdsbd/kodiak`, your origin won't end with `.git`, which vscode-githubinator expected. This change allows origins for GitHub without trailing `.git`.
1 parent 57cbb22 commit 95a6d64

File tree

7 files changed

+198
-1309
lines changed

7 files changed

+198
-1309
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
"out": true // set this to false to include "out" folder in search results
88
},
99
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
10-
"typescript.tsc.autoDetect": "off"
10+
"typescript.tsc.autoDetect": "off",
11+
"editor.formatOnSave": true
1112
}

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## 0.3.1 - 2021-04-17
11+
12+
### Fixed
13+
14+
- allow origin urls not ending in `.git` for GitHub.
15+
1016
## 0.3.0 - 2020-08-15
1117

1218
### Added

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ With `vsce` installed from NPM (`yarn global add vsce`), clone [this repo](https
6565

6666
## Release Notes
6767

68+
## 0.3.1
69+
70+
- allow origin urls not ending in `.git` for GitHub.
71+
6872
## 0.3.0
6973

7074
- Support calling Githubinator without an open file.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "githubinator",
33
"displayName": "Githubinator",
44
"description": "Quickly open files on Github and other providers. View blame information, copy permalinks and more. See the \"commands\" section of the README for more details.",
5-
"version": "0.3.0",
5+
"version": "0.3.1",
66
"publisher": "chdsbd",
77
"license": "SEE LICENSE IN LICENSE",
88
"icon": "images/logo256.png",
@@ -293,7 +293,7 @@
293293
"prettier": "^1.16.4",
294294
"tslint": "^5.12.1",
295295
"typescript": "^3.3.1",
296-
"vscode": "^1.1.28"
296+
"vscode": "^1.1.37"
297297
},
298298
"dependencies": {
299299
"gitconfiglocal": "^2.1.0",

src/providers.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ abstract class BaseProvider {
9494
if (org == null || repo == null) {
9595
continue
9696
}
97+
;[repo] = repo.split(/\.git$/)
9798
return { org, repo, hostname }
9899
}
99100
return null
@@ -105,8 +106,8 @@ export class Github extends BaseProvider {
105106
DEFAULT_HOSTNAMES = ["github.com"]
106107
PROVIDER_NAME = "github"
107108
MATCHERS = [
108-
(hostname: string) => RegExp(`^git@${hostname}:(.*)\/(.*)\.git$`),
109-
(hostname: string) => RegExp(`^https:\/\/${hostname}\/(.*)\/(.*)\.git$`),
109+
(hostname: string) => RegExp(`^git@${hostname}:(.*)\/(.*)(\.git)?$`),
110+
(hostname: string) => RegExp(`^https:\/\/${hostname}\/(.*)\/(.*)(\.git)?$`),
110111
]
111112
async getUrls({
112113
selection,

src/test/providers.test.ts

Lines changed: 60 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,59 +10,70 @@ import * as assert from "assert"
1010

1111
suite("Github", async () => {
1212
test("ssh", async () => {
13-
async function findRemote(hostname: string) {
14-
return "git@github.com:recipeyak/recipeyak.git"
13+
for (let url of [
14+
"git@github.com:recipeyak/recipeyak.git",
15+
"git@github.com:recipeyak/recipeyak",
16+
]) {
17+
async function findRemote(hostname: string) {
18+
return url
19+
}
20+
const gh = new Github({}, "origin", findRemote)
21+
const result = await gh.getUrls({
22+
selection: [17, 24],
23+
head: createSha("db99a912f5c4bffe11d91e163cd78ed96589611b"),
24+
relativeFilePath: "frontend/src/components/App.tsx",
25+
})
26+
const expected = {
27+
blobUrl:
28+
"https://github.com/recipeyak/recipeyak/blob/db99a912f5c4bffe11d91e163cd78ed96589611b/frontend/src/components/App.tsx#L18-L25",
29+
blameUrl:
30+
"https://github.com/recipeyak/recipeyak/blame/db99a912f5c4bffe11d91e163cd78ed96589611b/frontend/src/components/App.tsx#L18-L25",
31+
compareUrl:
32+
"https://github.com/recipeyak/recipeyak/compare/db99a912f5c4bffe11d91e163cd78ed96589611b",
33+
historyUrl:
34+
"https://github.com/recipeyak/recipeyak/commits/db99a912f5c4bffe11d91e163cd78ed96589611b/frontend/src/components/App.tsx",
35+
prUrl:
36+
"https://github.com/recipeyak/recipeyak/pull/new/db99a912f5c4bffe11d91e163cd78ed96589611b",
37+
repoUrl: "https://github.com/recipeyak/recipeyak",
38+
}
39+
assert.deepEqual(result, expected)
1540
}
16-
const gh = new Github({}, "origin", findRemote)
17-
const result = await gh.getUrls({
18-
selection: [17, 24],
19-
head: createSha("db99a912f5c4bffe11d91e163cd78ed96589611b"),
20-
relativeFilePath: "frontend/src/components/App.tsx",
21-
})
22-
const expected = {
23-
blobUrl:
24-
"https://github.com/recipeyak/recipeyak/blob/db99a912f5c4bffe11d91e163cd78ed96589611b/frontend/src/components/App.tsx#L18-L25",
25-
blameUrl:
26-
"https://github.com/recipeyak/recipeyak/blame/db99a912f5c4bffe11d91e163cd78ed96589611b/frontend/src/components/App.tsx#L18-L25",
27-
compareUrl:
28-
"https://github.com/recipeyak/recipeyak/compare/db99a912f5c4bffe11d91e163cd78ed96589611b",
29-
historyUrl:
30-
"https://github.com/recipeyak/recipeyak/commits/db99a912f5c4bffe11d91e163cd78ed96589611b/frontend/src/components/App.tsx",
31-
prUrl:
32-
"https://github.com/recipeyak/recipeyak/pull/new/db99a912f5c4bffe11d91e163cd78ed96589611b",
33-
repoUrl: "https://github.com/recipeyak/recipeyak",
34-
}
35-
assert.deepEqual(result, expected)
3641
})
3742
test("https", async () => {
38-
async function findRemote(hostname: string) {
39-
return "https://github.mycompany.com/recipeyak/recipeyak.git"
43+
for (let url of [
44+
"git@github.mycompany.com:recipeyak/recipeyak.git",
45+
"git@github.mycompany.com:recipeyak/recipeyak",
46+
]) {
47+
async function findRemote(hostname: string) {
48+
return url
49+
}
50+
const gh = new Github(
51+
{
52+
github: { hostnames: ["github.mycompany.com"] },
53+
},
54+
"origin",
55+
findRemote,
56+
)
57+
const result = await gh.getUrls({
58+
selection: [17, 24],
59+
head: createBranch("master"),
60+
relativeFilePath: "frontend/src/components/App.tsx",
61+
})
62+
const expected = {
63+
blobUrl:
64+
"https://github.mycompany.com/recipeyak/recipeyak/blob/master/frontend/src/components/App.tsx#L18-L25",
65+
blameUrl:
66+
"https://github.mycompany.com/recipeyak/recipeyak/blame/master/frontend/src/components/App.tsx#L18-L25",
67+
compareUrl:
68+
"https://github.mycompany.com/recipeyak/recipeyak/compare/master",
69+
historyUrl:
70+
"https://github.mycompany.com/recipeyak/recipeyak/commits/master/frontend/src/components/App.tsx",
71+
prUrl:
72+
"https://github.mycompany.com/recipeyak/recipeyak/pull/new/master",
73+
repoUrl: "https://github.mycompany.com/recipeyak/recipeyak",
74+
}
75+
assert.deepEqual(result, expected)
4076
}
41-
const gh = new Github(
42-
{
43-
github: { hostnames: ["github.mycompany.com"] },
44-
},
45-
"origin",
46-
findRemote,
47-
)
48-
const result = await gh.getUrls({
49-
selection: [17, 24],
50-
head: createBranch("master"),
51-
relativeFilePath: "frontend/src/components/App.tsx",
52-
})
53-
const expected = {
54-
blobUrl:
55-
"https://github.mycompany.com/recipeyak/recipeyak/blob/master/frontend/src/components/App.tsx#L18-L25",
56-
blameUrl:
57-
"https://github.mycompany.com/recipeyak/recipeyak/blame/master/frontend/src/components/App.tsx#L18-L25",
58-
compareUrl:
59-
"https://github.mycompany.com/recipeyak/recipeyak/compare/master",
60-
historyUrl:
61-
"https://github.mycompany.com/recipeyak/recipeyak/commits/master/frontend/src/components/App.tsx",
62-
prUrl: "https://github.mycompany.com/recipeyak/recipeyak/pull/new/master",
63-
repoUrl: "https://github.mycompany.com/recipeyak/recipeyak",
64-
}
65-
assert.deepEqual(result, expected)
6677
})
6778
})
6879

0 commit comments

Comments
 (0)