@ffflorian/gh-open 3.11.0 → 3.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -35,13 +35,13 @@
|
|
|
35
35
|
"name": "@ffflorian/gh-open",
|
|
36
36
|
"repository": "https://github.com/ffflorian/node-packages/tree/main/packages/gh-open",
|
|
37
37
|
"scripts": {
|
|
38
|
-
"build": "tsc -p tsconfig.json",
|
|
38
|
+
"build": "tsc -p tsconfig.build.json",
|
|
39
39
|
"clean": "rimraf dist",
|
|
40
40
|
"dist": "yarn clean && yarn build",
|
|
41
41
|
"start": "tsx src/cli.ts -d",
|
|
42
42
|
"test": "vitest run"
|
|
43
43
|
},
|
|
44
44
|
"type": "module",
|
|
45
|
-
"version": "3.11.
|
|
46
|
-
"gitHead": "
|
|
45
|
+
"version": "3.11.1",
|
|
46
|
+
"gitHead": "624bfac36e769ed7157fe9a9ada1c3e5443745ff"
|
|
47
47
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { assert, expect, describe, test } from 'vitest';
|
|
2
|
-
import nock from 'nock';
|
|
3
|
-
import { StatusCodes as HTTP_STATUS } from 'http-status-codes';
|
|
4
|
-
import { GitHubClient } from './GitHubClient.js';
|
|
5
|
-
const TEN_SECONDS_IN_MILLIS = 10000;
|
|
6
|
-
const HALF_SECOND_IN_MILLIS = 500;
|
|
7
|
-
describe('GitHubClient', () => {
|
|
8
|
-
describe('getPullRequests', () => {
|
|
9
|
-
test('cancels the request after a given time', async () => {
|
|
10
|
-
nock('https://api.github.com')
|
|
11
|
-
.get(/repos\/.*\/.*\/pulls/)
|
|
12
|
-
.query(true)
|
|
13
|
-
.delay(TEN_SECONDS_IN_MILLIS)
|
|
14
|
-
.reply(HTTP_STATUS.OK);
|
|
15
|
-
const gitHubClient = new GitHubClient(HALF_SECOND_IN_MILLIS);
|
|
16
|
-
try {
|
|
17
|
-
await gitHubClient.getPullRequests('user', 'repository');
|
|
18
|
-
assert.fail('Should not have resolved');
|
|
19
|
-
}
|
|
20
|
-
catch (error) {
|
|
21
|
-
expect(error.message).toBe('The operation was aborted due to timeout');
|
|
22
|
-
}
|
|
23
|
-
finally {
|
|
24
|
-
nock.cleanAll();
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
describe('getPullRequestsByBranch', () => {
|
|
29
|
-
test('correctly parses pull requests', async () => {
|
|
30
|
-
const exampleData = [
|
|
31
|
-
{
|
|
32
|
-
_links: {
|
|
33
|
-
html: {
|
|
34
|
-
href: 'https://github.com/user/repo/pull/1234',
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
head: {
|
|
38
|
-
ref: 'branch-name',
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
];
|
|
42
|
-
nock('https://api.github.com')
|
|
43
|
-
.get(/repos\/.*\/.*\/pulls/)
|
|
44
|
-
.query(true)
|
|
45
|
-
.reply(HTTP_STATUS.OK, exampleData);
|
|
46
|
-
const gitHubClient = new GitHubClient();
|
|
47
|
-
const result = await gitHubClient.getPullRequestByBranch('user', 'repository', 'branch-name');
|
|
48
|
-
expect(result).toEqual(exampleData[0]);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { expect, describe, test } from 'vitest';
|
|
2
|
-
import { RepositoryService } from './RepositoryService.js';
|
|
3
|
-
describe('RepositoryService', () => {
|
|
4
|
-
const repositoryService = new RepositoryService();
|
|
5
|
-
describe('getFullUrl', () => {
|
|
6
|
-
const normalizedUrl = 'https://github.com/ffflorian/gh-open';
|
|
7
|
-
const testRegex = (str) => {
|
|
8
|
-
const match = repositoryService['parser'].fullUrl.exec(str);
|
|
9
|
-
expect(match[0]).toEqual(expect.any(String));
|
|
10
|
-
const replaced = str.replace(repositoryService['parser'].fullUrl, 'https://$1/$2');
|
|
11
|
-
expect(replaced).toBe(normalizedUrl);
|
|
12
|
-
};
|
|
13
|
-
test('converts complete git URLs', () => {
|
|
14
|
-
const gitUrl = 'git@github.com:ffflorian/gh-open.git';
|
|
15
|
-
testRegex(gitUrl);
|
|
16
|
-
});
|
|
17
|
-
test('converts git URLs without a suffix', () => {
|
|
18
|
-
const gitUrl = 'git@github.com:ffflorian/gh-open';
|
|
19
|
-
testRegex(gitUrl);
|
|
20
|
-
});
|
|
21
|
-
test('converts git URLs without a user', () => {
|
|
22
|
-
const gitUrl = 'github.com:ffflorian/gh-open.git';
|
|
23
|
-
testRegex(gitUrl);
|
|
24
|
-
});
|
|
25
|
-
test('converts complete https URLs', () => {
|
|
26
|
-
const gitUrl = 'https://github.com/ffflorian/gh-open.git';
|
|
27
|
-
testRegex(gitUrl);
|
|
28
|
-
});
|
|
29
|
-
test('converts https URLs without suffix', () => {
|
|
30
|
-
const gitUrl = 'https://github.com/ffflorian/gh-open';
|
|
31
|
-
testRegex(gitUrl);
|
|
32
|
-
});
|
|
33
|
-
test('converts https URLs with a username', () => {
|
|
34
|
-
const gitUrl = 'https://git@github.com/ffflorian/gh-open.git';
|
|
35
|
-
testRegex(gitUrl);
|
|
36
|
-
});
|
|
37
|
-
test('converts https URLs with a username and password', () => {
|
|
38
|
-
const gitUrl = 'https://git:password@github.com/ffflorian/gh-open.git';
|
|
39
|
-
testRegex(gitUrl);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
describe('parseGitConfig', () => {
|
|
43
|
-
const rawUrl = 'git@github.com:ffflorian/gh-open.git';
|
|
44
|
-
const testRegex = (str) => {
|
|
45
|
-
const match = repositoryService['parser'].rawUrl.exec(str);
|
|
46
|
-
expect(match.groups.rawUrl).toBe(rawUrl);
|
|
47
|
-
};
|
|
48
|
-
test('converts a normal git config', () => {
|
|
49
|
-
const gitConfig = `[remote "origin"]
|
|
50
|
-
url = git@github.com:ffflorian/gh-open.git
|
|
51
|
-
fetch = +refs/heads/*:refs/remotes/origin/*
|
|
52
|
-
[branch "main"]
|
|
53
|
-
remote = origin
|
|
54
|
-
merge = refs/heads/main`;
|
|
55
|
-
testRegex(gitConfig);
|
|
56
|
-
});
|
|
57
|
-
describe('parseGitBranch', () => {
|
|
58
|
-
const testRegex = (str, result) => {
|
|
59
|
-
const match = repositoryService['parser'].gitBranch.exec(str);
|
|
60
|
-
expect(match.groups.branch).toBe(result);
|
|
61
|
-
};
|
|
62
|
-
test('detects the main branch', () => {
|
|
63
|
-
const rawBranch = 'main';
|
|
64
|
-
const gitHead = 'ref: refs/heads/main\n';
|
|
65
|
-
testRegex(gitHead, rawBranch);
|
|
66
|
-
});
|
|
67
|
-
test('detects a branch with a slash', () => {
|
|
68
|
-
const rawBranch = 'fix/regex';
|
|
69
|
-
const gitHead = 'ref: refs/heads/fix/regex\n';
|
|
70
|
-
testRegex(gitHead, rawBranch);
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
});
|