-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
247 lines (226 loc) · 9.31 KB
/
Copy pathtest.js
File metadata and controls
247 lines (226 loc) · 9.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
import test from "ava";
import { parseGitHubUrl } from "./index.js";
test("parses GitHub repo URL", (t) => {
t.deepEqual(parseGitHubUrl("https://github.com/AlightSoulmate/github-url-parser"), {
owner: "AlightSoulmate",
repo: "github-url-parser",
domain: "github.com",
type: "github",
kind: "repo",
committish: null,
repoUrl: "https://github.com/AlightSoulmate/github-url-parser",
browseUrl: "https://github.com/AlightSoulmate/github-url-parser",
apiUrl: "https://api.github.com/repos/AlightSoulmate/github-url-parser",
httpsUrl: "https://github.com/AlightSoulmate/github-url-parser.git",
sshUrl: "git@github.com:AlightSoulmate/github-url-parser.git",
});
});
test("parses GitHub SSH URL", (t) => {
t.deepEqual(parseGitHubUrl("git@github.com:AlightSoulmate/github-url-parser.git"), {
owner: "AlightSoulmate",
repo: "github-url-parser",
domain: "github.com",
type: "github",
kind: "repo",
committish: null,
repoUrl: "https://github.com/AlightSoulmate/github-url-parser",
browseUrl: "https://github.com/AlightSoulmate/github-url-parser",
apiUrl: "https://api.github.com/repos/AlightSoulmate/github-url-parser",
httpsUrl: "https://github.com/AlightSoulmate/github-url-parser.git",
sshUrl: "git@github.com:AlightSoulmate/github-url-parser.git",
});
});
test("parses GitHub URL with .git suffix", (t) => {
t.deepEqual(parseGitHubUrl("https://github.com/AlightSoulmate/github-url-parser.git"), {
owner: "AlightSoulmate",
repo: "github-url-parser",
domain: "github.com",
type: "github",
kind: "repo",
committish: null,
repoUrl: "https://github.com/AlightSoulmate/github-url-parser",
browseUrl: "https://github.com/AlightSoulmate/github-url-parser",
apiUrl: "https://api.github.com/repos/AlightSoulmate/github-url-parser",
httpsUrl: "https://github.com/AlightSoulmate/github-url-parser.git",
sshUrl: "git@github.com:AlightSoulmate/github-url-parser.git",
});
});
test("parses GitHub shortcut URL", (t) => {
t.like(parseGitHubUrl("github:AlightSoulmate/github-url-parser#v0.1.0"), {
owner: "AlightSoulmate",
repo: "github-url-parser",
kind: "repo",
committish: "v0.1.0",
browseUrl: "https://github.com/AlightSoulmate/github-url-parser/tree/v0.1.0",
apiUrl: "https://api.github.com/repos/AlightSoulmate/github-url-parser",
httpsUrl: "https://github.com/AlightSoulmate/github-url-parser.git#v0.1.0",
});
});
test("parses GitHub blob URL", (t) => {
t.deepEqual(parseGitHubUrl("https://github.com/AlightSoulmate/github-url-parser/blob/main/package.json"), {
owner: "AlightSoulmate",
repo: "github-url-parser",
domain: "github.com",
type: "github",
kind: "blob",
committish: "main",
repoUrl: "https://github.com/AlightSoulmate/github-url-parser",
browseUrl: "https://github.com/AlightSoulmate/github-url-parser/blob/main/package.json",
apiUrl: "https://api.github.com/repos/AlightSoulmate/github-url-parser/contents/package.json?ref=main",
httpsUrl: "https://github.com/AlightSoulmate/github-url-parser.git",
sshUrl: "git@github.com:AlightSoulmate/github-url-parser.git",
ref: "main",
path: "package.json",
rawUrl: "https://raw.githubusercontent.com/AlightSoulmate/github-url-parser/main/package.json",
});
});
test("parses GitHub tree URL", (t) => {
t.like(parseGitHubUrl("https://github.com/AlightSoulmate/github-url-parser/tree/main/src"), {
owner: "AlightSoulmate",
repo: "github-url-parser",
kind: "tree",
ref: "main",
path: "src",
rawUrl: null,
browseUrl: "https://github.com/AlightSoulmate/github-url-parser/tree/main/src",
apiUrl: "https://api.github.com/repos/AlightSoulmate/github-url-parser/contents/src?ref=main",
});
});
test("parses GitHub issue URL", (t) => {
t.like(parseGitHubUrl("https://github.com/AlightSoulmate/github-url-parser/issues/123"), {
owner: "AlightSoulmate",
repo: "github-url-parser",
kind: "issue",
number: 123,
browseUrl: "https://github.com/AlightSoulmate/github-url-parser/issues/123",
apiUrl: "https://api.github.com/repos/AlightSoulmate/github-url-parser/issues/123",
});
});
test("parses GitHub pull request URL", (t) => {
t.like(parseGitHubUrl("https://github.com/AlightSoulmate/github-url-parser/pull/456"), {
owner: "AlightSoulmate",
repo: "github-url-parser",
kind: "pull",
number: 456,
browseUrl: "https://github.com/AlightSoulmate/github-url-parser/pull/456",
apiUrl: "https://api.github.com/repos/AlightSoulmate/github-url-parser/pulls/456",
});
});
test("parses GitHub commit URL", (t) => {
t.like(parseGitHubUrl("https://github.com/AlightSoulmate/github-url-parser/commit/abc123"), {
owner: "AlightSoulmate",
repo: "github-url-parser",
kind: "commit",
sha: "abc123",
committish: "abc123",
browseUrl: "https://github.com/AlightSoulmate/github-url-parser/commit/abc123",
apiUrl: "https://api.github.com/repos/AlightSoulmate/github-url-parser/commits/abc123",
});
});
test("parses GitHub release tag URL", (t) => {
t.like(parseGitHubUrl("https://github.com/AlightSoulmate/github-url-parser/releases/tag/v0.1.0"), {
owner: "AlightSoulmate",
repo: "github-url-parser",
kind: "release",
tag: "v0.1.0",
committish: "v0.1.0",
browseUrl: "https://github.com/AlightSoulmate/github-url-parser/releases/tag/v0.1.0",
apiUrl: "https://api.github.com/repos/AlightSoulmate/github-url-parser/releases/tags/v0.1.0",
});
});
test("parses GitHub releases URL", (t) => {
t.like(parseGitHubUrl("https://github.com/AlightSoulmate/github-url-parser/releases"), {
owner: "AlightSoulmate",
repo: "github-url-parser",
kind: "releases",
collection: "releases",
browseUrl: "https://github.com/AlightSoulmate/github-url-parser/releases",
apiUrl: "https://api.github.com/repos/AlightSoulmate/github-url-parser/releases",
});
});
test("parses GitHub latest release URL", (t) => {
t.like(parseGitHubUrl("https://github.com/AlightSoulmate/github-url-parser/releases/latest"), {
owner: "AlightSoulmate",
repo: "github-url-parser",
kind: "latest-release",
selector: "latest",
browseUrl: "https://github.com/AlightSoulmate/github-url-parser/releases/latest",
apiUrl: "https://api.github.com/repos/AlightSoulmate/github-url-parser/releases/latest",
});
});
test("parses GitHub compare URL", (t) => {
t.like(parseGitHubUrl("https://github.com/AlightSoulmate/github-url-parser/compare/main...dev"), {
owner: "AlightSoulmate",
repo: "github-url-parser",
kind: "compare",
range: "main...dev",
baseRef: "main",
headRef: "dev",
browseUrl: "https://github.com/AlightSoulmate/github-url-parser/compare/main...dev",
apiUrl: "https://api.github.com/repos/AlightSoulmate/github-url-parser/compare/main...dev",
});
});
test("parses GitHub tags URL", (t) => {
t.like(parseGitHubUrl("https://github.com/AlightSoulmate/github-url-parser/tags"), {
owner: "AlightSoulmate",
repo: "github-url-parser",
kind: "tags",
collection: "tags",
browseUrl: "https://github.com/AlightSoulmate/github-url-parser/tags",
apiUrl: "https://api.github.com/repos/AlightSoulmate/github-url-parser/tags",
});
});
test("parses GitHub branches URL", (t) => {
t.like(parseGitHubUrl("https://github.com/AlightSoulmate/github-url-parser/branches"), {
owner: "AlightSoulmate",
repo: "github-url-parser",
kind: "branches",
collection: "branches",
browseUrl: "https://github.com/AlightSoulmate/github-url-parser/branches",
apiUrl: "https://api.github.com/repos/AlightSoulmate/github-url-parser/branches",
});
});
test("parses GitHub discussions URL", (t) => {
t.like(parseGitHubUrl("https://github.com/AlightSoulmate/github-url-parser/discussions"), {
owner: "AlightSoulmate",
repo: "github-url-parser",
kind: "discussions",
collection: "discussions",
browseUrl: "https://github.com/AlightSoulmate/github-url-parser/discussions",
});
});
test("parses GitHub discussion URL", (t) => {
t.like(parseGitHubUrl("https://github.com/AlightSoulmate/github-url-parser/discussions/789"), {
owner: "AlightSoulmate",
repo: "github-url-parser",
kind: "discussion",
number: 789,
browseUrl: "https://github.com/AlightSoulmate/github-url-parser/discussions/789",
});
});
test("parses GitHub actions URL", (t) => {
t.like(parseGitHubUrl("https://github.com/AlightSoulmate/github-url-parser/actions"), {
owner: "AlightSoulmate",
repo: "github-url-parser",
kind: "actions",
collection: "actions",
browseUrl: "https://github.com/AlightSoulmate/github-url-parser/actions",
apiUrl: "https://api.github.com/repos/AlightSoulmate/github-url-parser/actions",
});
});
test("parses GitHub workflow run URL", (t) => {
t.like(parseGitHubUrl("https://github.com/AlightSoulmate/github-url-parser/actions/runs/123456789"), {
owner: "AlightSoulmate",
repo: "github-url-parser",
kind: "workflow-run",
runId: 123456789,
browseUrl: "https://github.com/AlightSoulmate/github-url-parser/actions/runs/123456789",
apiUrl: "https://api.github.com/repos/AlightSoulmate/github-url-parser/actions/runs/123456789",
});
});
test("returns null for non-GitHub URL", (t) => {
t.is(parseGitHubUrl("https://example.com/foo/bar"), null);
});
test("returns null for non-GitHub hosted git URL", (t) => {
t.is(parseGitHubUrl("https://gitlab.com/user/repo"), null);
});