forked from refined-github/refined-github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub-url.ts
81 lines (74 loc) · 3.78 KB
/
github-url.ts
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
import test from 'ava';
import './fixtures/globals';
import GitHubURL from '../source/github-helpers/github-url';
test('branch', t => {
const url = new GitHubURL('https://github.com/microsoft/TypeScript/tree/master');
t.is(url.user, 'microsoft');
t.is(url.repository, 'TypeScript');
t.is(url.route, 'tree');
t.is(url.branch, 'master');
t.is(url.filePath, '');
t.is(url.pathname, '/microsoft/TypeScript/tree/master');
t.is(url.href, 'https://github.com/microsoft/TypeScript/tree/master');
t.is(String(url), 'https://github.com/microsoft/TypeScript/tree/master');
});
test('object', t => {
const url = new GitHubURL('https://github.com/microsoft/TypeScript/tree/master/src');
t.is(url.user, 'microsoft');
t.is(url.repository, 'TypeScript');
t.is(url.route, 'tree');
t.is(url.branch, 'master');
t.is(url.filePath, 'src');
t.is(url.pathname, '/microsoft/TypeScript/tree/master/src');
t.is(url.href, 'https://github.com/microsoft/TypeScript/tree/master/src');
t.is(String(url), 'https://github.com/microsoft/TypeScript/tree/master/src');
});
test('nested object', t => {
const url = new GitHubURL('https://github.com/microsoft/TypeScript/tree/master/src/index.js');
t.is(url.user, 'microsoft');
t.is(url.repository, 'TypeScript');
t.is(url.route, 'tree');
t.is(url.branch, 'master');
t.is(url.filePath, 'src/index.js');
t.is(url.pathname, '/microsoft/TypeScript/tree/master/src/index.js');
t.is(url.href, 'https://github.com/microsoft/TypeScript/tree/master/src/index.js');
t.is(String(url), 'https://github.com/microsoft/TypeScript/tree/master/src/index.js');
});
test('change branch', t => {
const url = new GitHubURL('https://github.com/microsoft/TypeScript/tree/master/src/index.js').assign({
branch: 'dev',
});
t.is(url.user, 'microsoft');
t.is(url.repository, 'TypeScript');
t.is(url.route, 'tree');
t.is(url.branch, 'dev');
t.is(url.filePath, 'src/index.js');
t.is(url.pathname, '/microsoft/TypeScript/tree/dev/src/index.js');
t.is(url.href, 'https://github.com/microsoft/TypeScript/tree/dev/src/index.js');
t.is(String(url), 'https://github.com/microsoft/TypeScript/tree/dev/src/index.js');
});
test('change filePath', t => {
const url = new GitHubURL('https://github.com/microsoft/TypeScript/tree/master/src/index.js').assign({
filePath: 'package.json',
});
t.is(url.user, 'microsoft');
t.is(url.repository, 'TypeScript');
t.is(url.route, 'tree');
t.is(url.branch, 'master');
t.is(url.filePath, 'package.json');
t.is(url.pathname, '/microsoft/TypeScript/tree/master/package.json');
t.is(url.href, 'https://github.com/microsoft/TypeScript/tree/master/package.json');
t.is(String(url), 'https://github.com/microsoft/TypeScript/tree/master/package.json');
});
test('get filePath from search', t => {
const url = new GitHubURL('https://github.com/yakov116/refined-github/commits/f23b687b3b89aa95a76193722cdfeff740646670?after=f23b687b3b89aa95a76193722cdfeff740646670+34&path%5B%5D=source&path%5B%5D=features&path%5B%5D=release-download-count.tsx');
t.is(url.user, 'yakov116');
t.is(url.repository, 'refined-github');
t.is(url.route, 'commits');
t.is(url.branch, 'f23b687b3b89aa95a76193722cdfeff740646670');
t.is(url.filePath, 'source/features/release-download-count.tsx');
t.is(url.pathname, '/yakov116/refined-github/commits/f23b687b3b89aa95a76193722cdfeff740646670/source/features/release-download-count.tsx');
t.is(url.href, 'https://github.com/yakov116/refined-github/commits/f23b687b3b89aa95a76193722cdfeff740646670/source/features/release-download-count.tsx?after=f23b687b3b89aa95a76193722cdfeff740646670+34');
t.is(url.search, '?after=f23b687b3b89aa95a76193722cdfeff740646670+34');
t.is(String(url), 'https://github.com/yakov116/refined-github/commits/f23b687b3b89aa95a76193722cdfeff740646670/source/features/release-download-count.tsx?after=f23b687b3b89aa95a76193722cdfeff740646670+34');
});