forked from backnotprop/plannotator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpr-provider.test.ts
More file actions
143 lines (127 loc) · 4.05 KB
/
pr-provider.test.ts
File metadata and controls
143 lines (127 loc) · 4.05 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
import { describe, expect, test } from "bun:test";
import {
getCliInstallUrl,
getCliName,
getDisplayRepo,
getMRLabel,
getMRNumberLabel,
getPlatformLabel,
parsePRUrl,
prRefFromMetadata,
type PRMetadata,
} from "./pr-provider";
describe("pr-provider platform helpers", () => {
test("parses GitHub PR URLs including nested suffixes", () => {
const ref = parsePRUrl("https://github.com/backnotprop/plannotator/pull/364/files");
expect(ref).toEqual({
platform: "github",
owner: "backnotprop",
repo: "plannotator",
number: 364,
});
});
test("parses GitLab.com MR URLs", () => {
const ref = parsePRUrl("https://gitlab.com/group/project/-/merge_requests/42/diffs");
expect(ref).toEqual({
platform: "gitlab",
host: "gitlab.com",
projectPath: "group/project",
iid: 42,
});
});
test("parses self-hosted GitLab MR URLs with nested groups", () => {
const ref = parsePRUrl("https://gitlab.example.com/group/subgroup/project/-/merge_requests/7");
expect(ref).toEqual({
platform: "gitlab",
host: "gitlab.example.com",
projectPath: "group/subgroup/project",
iid: 7,
});
});
test("returns null for unsupported URLs", () => {
expect(parsePRUrl("https://example.com/not-a-pr/123")).toBeNull();
expect(parsePRUrl("")).toBeNull();
});
test("formats platform-aware labels for GitHub and GitLab", () => {
const githubMeta: PRMetadata = {
platform: "github",
owner: "backnotprop",
repo: "plannotator",
number: 364,
title: "GitHub PR",
author: "backnotprop",
baseBranch: "main",
headBranch: "feature/github",
baseSha: "base",
headSha: "head",
url: "https://github.com/backnotprop/plannotator/pull/364",
};
const gitlabMeta: PRMetadata = {
platform: "gitlab",
host: "gitlab.example.com",
projectPath: "group/project",
iid: 42,
title: "GitLab MR",
author: "alice",
baseBranch: "main",
headBranch: "feature/gitlab",
baseSha: "base",
headSha: "head",
url: "https://gitlab.example.com/group/project/-/merge_requests/42",
};
expect(getPlatformLabel(githubMeta)).toBe("GitHub");
expect(getMRLabel(githubMeta)).toBe("PR");
expect(getMRNumberLabel(githubMeta)).toBe("#364");
expect(getDisplayRepo(githubMeta)).toBe("backnotprop/plannotator");
expect(getPlatformLabel(gitlabMeta)).toBe("GitLab");
expect(getMRLabel(gitlabMeta)).toBe("MR");
expect(getMRNumberLabel(gitlabMeta)).toBe("!42");
expect(getDisplayRepo(gitlabMeta)).toBe("group/project");
});
test("reconstructs refs and CLI metadata for each platform", () => {
const githubMeta: PRMetadata = {
platform: "github",
owner: "backnotprop",
repo: "plannotator",
number: 1,
title: "GitHub PR",
author: "backnotprop",
baseBranch: "main",
headBranch: "feature/github",
baseSha: "base",
headSha: "head",
url: "https://github.com/backnotprop/plannotator/pull/1",
};
const gitlabMeta: PRMetadata = {
platform: "gitlab",
host: "gitlab.example.com",
projectPath: "group/project",
iid: 2,
title: "GitLab MR",
author: "alice",
baseBranch: "main",
headBranch: "feature/gitlab",
baseSha: "base",
headSha: "head",
url: "https://gitlab.example.com/group/project/-/merge_requests/2",
};
const githubRef = prRefFromMetadata(githubMeta);
const gitlabRef = prRefFromMetadata(gitlabMeta);
expect(githubRef).toEqual({
platform: "github",
owner: "backnotprop",
repo: "plannotator",
number: 1,
});
expect(gitlabRef).toEqual({
platform: "gitlab",
host: "gitlab.example.com",
projectPath: "group/project",
iid: 2,
});
expect(getCliName(githubRef)).toBe("gh");
expect(getCliInstallUrl(githubRef)).toBe("https://cli.github.com");
expect(getCliName(gitlabRef)).toBe("glab");
expect(getCliInstallUrl(gitlabRef)).toBe("https://gitlab.com/gitlab-org/cli");
});
});