@lbdudc/linea-git 0.0.0-stage → 0.1.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/README.md +47 -2
- package/dist/access.d.ts +18 -0
- package/dist/access.js +18 -0
- package/dist/access.js.map +1 -0
- package/dist/auth.d.ts +11 -0
- package/dist/auth.js +16 -0
- package/dist/auth.js.map +1 -0
- package/dist/changelog/generate.d.ts +18 -0
- package/dist/changelog/generate.js +166 -0
- package/dist/changelog/generate.js.map +1 -0
- package/dist/changelog/index.d.ts +5 -0
- package/dist/changelog/index.js +3 -0
- package/dist/changelog/index.js.map +1 -0
- package/dist/changelog/parse.d.ts +43 -0
- package/dist/changelog/parse.js +91 -0
- package/dist/changelog/parse.js.map +1 -0
- package/dist/changelog/types.d.ts +85 -0
- package/dist/changelog/types.js +2 -0
- package/dist/changelog/types.js.map +1 -0
- package/dist/checkout/credential.d.ts +14 -0
- package/dist/checkout/credential.js +29 -0
- package/dist/checkout/credential.js.map +1 -0
- package/dist/checkout/git.d.ts +78 -0
- package/dist/checkout/git.js +191 -0
- package/dist/checkout/git.js.map +1 -0
- package/dist/checkout/index.d.ts +3 -0
- package/dist/checkout/index.js +4 -0
- package/dist/checkout/index.js.map +1 -0
- package/dist/checkout/sync.d.ts +156 -0
- package/dist/checkout/sync.js +211 -0
- package/dist/checkout/sync.js.map +1 -0
- package/dist/closing.d.ts +1 -0
- package/dist/closing.js +14 -0
- package/dist/closing.js.map +1 -0
- package/dist/config.d.ts +53 -0
- package/dist/config.js +40 -0
- package/dist/config.js.map +1 -0
- package/dist/deletion.d.ts +19 -0
- package/dist/deletion.js +27 -0
- package/dist/deletion.js.map +1 -0
- package/dist/errors.d.ts +26 -0
- package/dist/errors.js +47 -0
- package/dist/errors.js.map +1 -0
- package/dist/factory.d.ts +20 -0
- package/dist/factory.js +46 -0
- package/dist/factory.js.map +1 -0
- package/dist/github/client.d.ts +44 -0
- package/dist/github/client.js +145 -0
- package/dist/github/client.js.map +1 -0
- package/dist/github/config.d.ts +24 -0
- package/dist/github/config.js +11 -0
- package/dist/github/config.js.map +1 -0
- package/dist/github/provider.d.ts +510 -0
- package/dist/github/provider.js +1009 -0
- package/dist/github/provider.js.map +1 -0
- package/dist/gitlab/client.d.ts +50 -0
- package/dist/gitlab/client.js +228 -0
- package/dist/gitlab/client.js.map +1 -0
- package/dist/gitlab/provider.d.ts +487 -0
- package/dist/gitlab/provider.js +719 -0
- package/dist/gitlab/provider.js.map +1 -0
- package/dist/host.d.ts +27 -0
- package/dist/host.js +45 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/local/diff.d.ts +3 -0
- package/dist/local/diff.js +43 -0
- package/dist/local/diff.js.map +1 -0
- package/dist/local/git.d.ts +24 -0
- package/dist/local/git.js +51 -0
- package/dist/local/git.js.map +1 -0
- package/dist/local/health.d.ts +36 -0
- package/dist/local/health.js +57 -0
- package/dist/local/health.js.map +1 -0
- package/dist/local/hooks.d.ts +2 -0
- package/dist/local/hooks.js +44 -0
- package/dist/local/hooks.js.map +1 -0
- package/dist/local/http.d.ts +35 -0
- package/dist/local/http.js +160 -0
- package/dist/local/http.js.map +1 -0
- package/dist/local/provider.d.ts +571 -0
- package/dist/local/provider.js +1237 -0
- package/dist/local/provider.js.map +1 -0
- package/dist/local/store.d.ts +136 -0
- package/dist/local/store.js +171 -0
- package/dist/local/store.js.map +1 -0
- package/dist/packages/github-source.d.ts +69 -0
- package/dist/packages/github-source.js +133 -0
- package/dist/packages/github-source.js.map +1 -0
- package/dist/packages/gitlab-source.d.ts +59 -0
- package/dist/packages/gitlab-source.js +214 -0
- package/dist/packages/gitlab-source.js.map +1 -0
- package/dist/packages/index.d.ts +30 -0
- package/dist/packages/index.js +45 -0
- package/dist/packages/index.js.map +1 -0
- package/dist/packages/provider-source.d.ts +34 -0
- package/dist/packages/provider-source.js +57 -0
- package/dist/packages/provider-source.js.map +1 -0
- package/dist/packages/repository-files.d.ts +12 -0
- package/dist/packages/repository-files.js +16 -0
- package/dist/packages/repository-files.js.map +1 -0
- package/dist/provider.d.ts +888 -0
- package/dist/provider.js +29 -0
- package/dist/provider.js.map +1 -0
- package/dist/read-cache.d.ts +5 -0
- package/dist/read-cache.js +101 -0
- package/dist/read-cache.js.map +1 -0
- package/dist/registry/catalog.d.ts +55 -0
- package/dist/registry/catalog.js +143 -0
- package/dist/registry/catalog.js.map +1 -0
- package/dist/registry/kinds.d.ts +21 -0
- package/dist/registry/kinds.js +43 -0
- package/dist/registry/kinds.js.map +1 -0
- package/dist/registry/packages.d.ts +165 -0
- package/dist/registry/packages.js +290 -0
- package/dist/registry/packages.js.map +1 -0
- package/dist/registry/publish.d.ts +35 -0
- package/dist/registry/publish.js +155 -0
- package/dist/registry/publish.js.map +1 -0
- package/dist/registry/release.d.ts +63 -0
- package/dist/registry/release.js +79 -0
- package/dist/registry/release.js.map +1 -0
- package/dist/restoration.d.ts +14 -0
- package/dist/restoration.js +33 -0
- package/dist/restoration.js.map +1 -0
- package/dist/templates.d.ts +8 -0
- package/dist/templates.js +39 -0
- package/dist/templates.js.map +1 -0
- package/dist/testing/contract.d.ts +43 -0
- package/dist/testing/contract.js +713 -0
- package/dist/testing/contract.js.map +1 -0
- package/dist/testing/diff.d.ts +1 -0
- package/dist/testing/diff.js +65 -0
- package/dist/testing/diff.js.map +1 -0
- package/dist/testing/git-http.d.ts +12 -0
- package/dist/testing/git-http.js +308 -0
- package/dist/testing/git-http.js.map +1 -0
- package/dist/testing/github-double.d.ts +151 -0
- package/dist/testing/github-double.js +1129 -0
- package/dist/testing/github-double.js.map +1 -0
- package/dist/testing/gitlab-double.d.ts +161 -0
- package/dist/testing/gitlab-double.js +1554 -0
- package/dist/testing/gitlab-double.js.map +1 -0
- package/dist/testing/index.d.ts +7 -0
- package/dist/testing/index.js +8 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +12 -0
- package/dist/version.js.map +1 -0
- package/package.json +66 -4
|
@@ -0,0 +1,713 @@
|
|
|
1
|
+
// @ts-nocheck: written as plain JavaScript (it is the suite the server tests used); only its shape matters to a caller
|
|
2
|
+
import { describe, it, expect } from 'vitest';
|
|
3
|
+
import { GIT_PROVIDER_METHODS } from '../provider.js';
|
|
4
|
+
import { deleteEmptyLineNamespace, deleteLineOnHost, deleteProductOnHost } from '../deletion.js';
|
|
5
|
+
/**
|
|
6
|
+
* What every `GitProvider` has to do, whatever host is behind it. A host passes `makeProvider` (a new provider on a clean host each call)
|
|
7
|
+
* and the contract runs against it: if a new provider (GitHub...) passes this, the services work on it, because the services only use
|
|
8
|
+
* what is checked here.
|
|
9
|
+
*
|
|
10
|
+
* `status` of an error is what the services look at (404: not there, 400/409: a change made from a stale revision).
|
|
11
|
+
*/
|
|
12
|
+
export const describeGitProviderContract = ({ name, makeProvider, addMember, signWebhook, pushEvent, addMilestone }) => {
|
|
13
|
+
const token = 'fake-token';
|
|
14
|
+
// in LINEA a namespace and the repository in it have the same name
|
|
15
|
+
const repoIn = async (git, { topics = ['product'], repoName = 'Shop', namespaceName = repoName } = {}) => {
|
|
16
|
+
const namespace = await git.createNamespace({ token, name: namespaceName });
|
|
17
|
+
const repository = await git.createRepository({ token, name: repoName, namespaceId: namespace.id, topics });
|
|
18
|
+
return { namespace, repository };
|
|
19
|
+
};
|
|
20
|
+
describe(`GitProvider contract: ${name}`, () => {
|
|
21
|
+
it('has every method of the contract', () => {
|
|
22
|
+
const git = makeProvider();
|
|
23
|
+
for (const method of GIT_PROVIDER_METHODS)
|
|
24
|
+
expect(typeof git[method], method).toBe('function');
|
|
25
|
+
expect(['local', 'gitlab', 'github']).toContain(git.kind);
|
|
26
|
+
});
|
|
27
|
+
it('creates a namespace and a repository in it, and describes them in the neutral shapes', async () => {
|
|
28
|
+
const git = makeProvider();
|
|
29
|
+
const { namespace, repository } = await repoIn(git);
|
|
30
|
+
expect(namespace).toMatchObject({ name: 'Shop' });
|
|
31
|
+
expect(namespace.id).toBeDefined();
|
|
32
|
+
expect(repository).toMatchObject({ name: 'Shop', topics: ['product'] });
|
|
33
|
+
expect(repository.namespaceId).toBeDefined();
|
|
34
|
+
expect(repository.id).toBeDefined();
|
|
35
|
+
expect(repository.path).toMatch(/Acme.*Shop|Shop/);
|
|
36
|
+
expect(repository.webUrl).toMatch(/^https?:\/\//);
|
|
37
|
+
expect(typeof repository.webIdeUrl).toBe('string');
|
|
38
|
+
expect((await git.getRepository({ token, id: repository.id })).path).toBe(repository.path);
|
|
39
|
+
});
|
|
40
|
+
it('finds a repository and a namespace by their path, and says there is none when there is none', async () => {
|
|
41
|
+
const git = makeProvider();
|
|
42
|
+
const { namespace, repository } = await repoIn(git, { repoName: 'Findable' });
|
|
43
|
+
expect((await git.findRepository({ token, path: repository.path }))?.id).toBe(repository.id);
|
|
44
|
+
expect(await git.findRepository({ token, path: 'nobody/nothing' })).toBeNull();
|
|
45
|
+
const [place] = await git.listNamespaces({ token });
|
|
46
|
+
expect((await git.findNamespace({ token, fullPath: place.fullPath }))?.fullPath).toBe(place.fullPath);
|
|
47
|
+
expect(await git.findNamespace({ token, fullPath: 'no-such-namespace' })).toBeNull();
|
|
48
|
+
expect(namespace.name).toBe('Findable');
|
|
49
|
+
});
|
|
50
|
+
it('adds a topic once', async () => {
|
|
51
|
+
const git = makeProvider();
|
|
52
|
+
const { repository } = await repoIn(git, { topics: ['product'] });
|
|
53
|
+
await git.addTopic({ token, id: repository.id, topic: 'extra' });
|
|
54
|
+
await git.addTopic({ token, id: repository.id, topic: 'extra' });
|
|
55
|
+
expect((await git.getRepository({ token, id: repository.id })).topics.sort()).toEqual(['extra', 'product']);
|
|
56
|
+
});
|
|
57
|
+
it('lists the repositories that have a topic, and only those', async () => {
|
|
58
|
+
const git = makeProvider();
|
|
59
|
+
await repoIn(git, { topics: ['product'], repoName: 'A' });
|
|
60
|
+
await repoIn(git, { topics: ['spl'], repoName: 'B' });
|
|
61
|
+
expect((await git.listRepositories({ token, topic: 'product' })).map((r) => r.name)).toEqual(['A']);
|
|
62
|
+
expect((await git.listRepositories({ token, topic: 'spl' })).map((r) => r.name)).toEqual(['B']);
|
|
63
|
+
});
|
|
64
|
+
it('lists the namespaces the user can create things in, and a listed one can be the parent of a new one', async () => {
|
|
65
|
+
const git = makeProvider();
|
|
66
|
+
await git.createNamespace({ token, name: 'Visible' });
|
|
67
|
+
const namespaces = await git.listNamespaces({ token });
|
|
68
|
+
expect(namespaces.length).toBeGreaterThan(0);
|
|
69
|
+
for (const namespace of namespaces) {
|
|
70
|
+
expect(namespace.id).toBeDefined();
|
|
71
|
+
expect(typeof namespace.fullPath).toBe('string');
|
|
72
|
+
}
|
|
73
|
+
const child = await git.createNamespace({ token, name: 'Child', parentId: namespaces[0].id });
|
|
74
|
+
const repository = await git.createRepository({ token, name: 'Child', namespaceId: child.id, topics: ['product'] });
|
|
75
|
+
expect(repository.name).toBe('Child');
|
|
76
|
+
});
|
|
77
|
+
it('keeps a line and its products together: a product knows its line, renames with it, and goes when the line goes', async () => {
|
|
78
|
+
const git = makeProvider();
|
|
79
|
+
const lineNs = await git.createNamespace({ token, name: 'Line1' });
|
|
80
|
+
const line = await git.createRepository({ token, name: 'Line1', namespaceId: lineNs.id, topics: ['spl'] });
|
|
81
|
+
const productNs = await git.createNamespace({ token, name: 'Prod1', parentId: line.namespaceId });
|
|
82
|
+
const product = await git.createRepository({ token, name: 'Prod1', namespaceId: productNs.id, topics: ['product'] });
|
|
83
|
+
expect(product.name).toBe('Prod1');
|
|
84
|
+
expect(product.parentNamespaceId).toBe(line.namespaceId);
|
|
85
|
+
const listed = await git.listRepositories({ token, topic: 'product' });
|
|
86
|
+
expect(listed.map((r) => [r.name, r.parentNamespaceId])).toEqual([['Prod1', line.namespaceId]]);
|
|
87
|
+
expect(listed[0].topics).toEqual(['product']);
|
|
88
|
+
await git.renameNamespace({ token, id: product.namespaceId, name: 'Prod2' });
|
|
89
|
+
const renamed = await git.renameRepository({ token, id: product.id, name: 'Prod2' });
|
|
90
|
+
expect(renamed.name).toBe('Prod2');
|
|
91
|
+
expect(renamed.parentNamespaceId).toBe(line.namespaceId);
|
|
92
|
+
expect((await git.getRepository({ token, id: product.id })).name).toBe('Prod2');
|
|
93
|
+
await git.deleteNamespace({ token, id: line.namespaceId });
|
|
94
|
+
expect(await git.listRepositories({ token, topic: 'product' })).toEqual([]);
|
|
95
|
+
expect(await git.listRepositories({ token, topic: 'spl' })).toEqual([]);
|
|
96
|
+
});
|
|
97
|
+
it('deletes a line with the products chosen, and what is kept stays until it goes too', async () => {
|
|
98
|
+
const git = makeProvider();
|
|
99
|
+
const lineSpace = await git.createNamespace({ token, name: 'Del' });
|
|
100
|
+
const line = await git.createRepository({ token, name: 'Del', namespaceId: lineSpace.id, topics: ['spl'] });
|
|
101
|
+
const makeProduct = async (name) => {
|
|
102
|
+
const space = await git.createNamespace({ token, name, parentId: line.namespaceId });
|
|
103
|
+
const repository = await git.createRepository({ token, name, namespaceId: space.id, topics: ['product'] });
|
|
104
|
+
return { id: name, repositoryId: repository.id, namespaceId: repository.namespaceId };
|
|
105
|
+
};
|
|
106
|
+
const gone = await makeProduct('DelGone');
|
|
107
|
+
const kept = await makeProduct('DelKept');
|
|
108
|
+
const plan = await deleteLineOnHost({
|
|
109
|
+
provider: git, token, line: { repositoryId: line.id, namespaceId: line.namespaceId }, products: [gone, kept], keepProductIds: ['DelKept'],
|
|
110
|
+
});
|
|
111
|
+
expect(plan.lineSurvives).toBe(true);
|
|
112
|
+
expect((await git.listRepositories({ token, topic: 'spl' })).map((r) => r.name)).not.toContain('Del');
|
|
113
|
+
expect((await git.listRepositories({ token, topic: 'product' })).map((r) => r.id)).toEqual([kept.repositoryId]);
|
|
114
|
+
await deleteProductOnHost({ provider: git, token, product: kept });
|
|
115
|
+
await deleteEmptyLineNamespace({ provider: git, token, namespaceId: line.namespaceId });
|
|
116
|
+
expect(await git.listRepositories({ token, topic: 'product' })).toEqual([]);
|
|
117
|
+
});
|
|
118
|
+
it('deletes a line and every product of it at once', async () => {
|
|
119
|
+
const git = makeProvider();
|
|
120
|
+
const lineSpace = await git.createNamespace({ token, name: 'DelAll' });
|
|
121
|
+
const line = await git.createRepository({ token, name: 'DelAll', namespaceId: lineSpace.id, topics: ['spl'] });
|
|
122
|
+
const space = await git.createNamespace({ token, name: 'DelAllProduct', parentId: line.namespaceId });
|
|
123
|
+
const repository = await git.createRepository({ token, name: 'DelAllProduct', namespaceId: space.id, topics: ['product'] });
|
|
124
|
+
await deleteLineOnHost({
|
|
125
|
+
provider: git, token, line: { repositoryId: line.id, namespaceId: line.namespaceId },
|
|
126
|
+
products: [{ id: 'p', repositoryId: repository.id, namespaceId: repository.namespaceId }],
|
|
127
|
+
});
|
|
128
|
+
expect(await git.listRepositories({ token, topic: 'spl' })).toEqual([]);
|
|
129
|
+
expect(await git.listRepositories({ token, topic: 'product' })).toEqual([]);
|
|
130
|
+
});
|
|
131
|
+
it('a host that deletes at once has nothing to restore, and says so', async () => {
|
|
132
|
+
const git = makeProvider();
|
|
133
|
+
if (git.capabilities().deletion.delayed)
|
|
134
|
+
return;
|
|
135
|
+
await expect(git.restoreRepository({ token, id: 1 })).rejects.toMatchObject({ status: 400 });
|
|
136
|
+
await expect(git.restoreNamespace({ token, id: 1 })).rejects.toMatchObject({ status: 400 });
|
|
137
|
+
});
|
|
138
|
+
it('says how the host deletes', () => {
|
|
139
|
+
const { deletion } = makeProvider().capabilities();
|
|
140
|
+
expect(typeof deletion.namespaceIsRepository).toBe('boolean');
|
|
141
|
+
expect(typeof deletion.delayed).toBe('boolean');
|
|
142
|
+
});
|
|
143
|
+
it('makes the base branch the first one of a product, and then lets another be the default', async () => {
|
|
144
|
+
const git = makeProvider();
|
|
145
|
+
const namespace = await git.createNamespace({ token, name: 'Gen' });
|
|
146
|
+
const repository = await git.createRepository({ token, name: 'Gen', namespaceId: namespace.id, topics: ['product'], defaultBranch: 'bigbang' });
|
|
147
|
+
expect(repository.defaultBranch).toBe('bigbang');
|
|
148
|
+
await git.createBranch({ token, id: repository.id, branch: 'main', ref: 'bigbang' });
|
|
149
|
+
await git.setDefaultBranch({ token, id: repository.id, branch: 'main' });
|
|
150
|
+
expect((await git.getRepository({ token, id: repository.id })).defaultBranch).toBe('main');
|
|
151
|
+
expect((await git.getBranch({ token, id: repository.id, branch: 'bigbang' })).name).toBe('bigbang');
|
|
152
|
+
});
|
|
153
|
+
it('reads and writes files: base64 content that round-trips UTF-8, and a revision to quote later', async () => {
|
|
154
|
+
const git = makeProvider();
|
|
155
|
+
const { repository } = await repoIn(git);
|
|
156
|
+
const text = 'features\n\tConfiguración\n';
|
|
157
|
+
await git.createFile({ token, id: repository.id, path: 'src/model.uvl', branch: 'main', content: text });
|
|
158
|
+
const file = await git.getFile({ token, id: repository.id, path: 'src/model.uvl', ref: 'main' });
|
|
159
|
+
expect(file.encoding).toBe('base64');
|
|
160
|
+
expect(Buffer.from(file.content, 'base64').toString('utf8')).toBe(text);
|
|
161
|
+
expect(file.revision).toBeTruthy();
|
|
162
|
+
expect(file.path).toBe('src/model.uvl');
|
|
163
|
+
await git.saveFile({ token, id: repository.id, path: 'src/model.uvl', branch: 'main', content: 'features\n\tOther\n' });
|
|
164
|
+
const raw = await git.readFile({ token, id: repository.id, path: 'src/model.uvl', ref: 'main' });
|
|
165
|
+
expect(raw.toString('utf8')).toBe('features\n\tOther\n');
|
|
166
|
+
expect(await git.readFile({ token, id: repository.id, path: 'nothing.txt', ref: 'main' })).toBeNull();
|
|
167
|
+
expect(await git.listFiles({ token, id: repository.id, ref: 'main' })).toContain('src/model.uvl');
|
|
168
|
+
});
|
|
169
|
+
it('says a file is not there with status 404', async () => {
|
|
170
|
+
const git = makeProvider();
|
|
171
|
+
const { repository } = await repoIn(git);
|
|
172
|
+
await expect(git.getFileRevision({ token, id: repository.id, path: 'missing.json', ref: 'main' })).rejects.toMatchObject({ status: 404 });
|
|
173
|
+
});
|
|
174
|
+
it('commits several changes at once, and refuses one made from a stale revision', async () => {
|
|
175
|
+
const git = makeProvider();
|
|
176
|
+
const { repository } = await repoIn(git);
|
|
177
|
+
await git.commit({ token, id: repository.id, branch: 'main', message: 'two files', actions: [
|
|
178
|
+
{ action: 'create', path: 'a.txt', content: 'a' },
|
|
179
|
+
{ action: 'create', path: 'b.txt', content: 'b' },
|
|
180
|
+
] });
|
|
181
|
+
const files = await git.listFiles({ token, id: repository.id, ref: 'main' });
|
|
182
|
+
expect(files).toEqual(expect.arrayContaining(['a.txt', 'b.txt']));
|
|
183
|
+
const before = await git.getFileRevision({ token, id: repository.id, path: 'a.txt', ref: 'main' });
|
|
184
|
+
await git.commit({ token, id: repository.id, branch: 'main', message: 'update', track: false, actions: [
|
|
185
|
+
{ action: 'update', path: 'a.txt', content: 'a2', expectedRevision: before.revision },
|
|
186
|
+
] });
|
|
187
|
+
const stale = await git.commit({ token, id: repository.id, branch: 'main', message: 'stale', track: false, actions: [
|
|
188
|
+
{ action: 'update', path: 'a.txt', content: 'a3', expectedRevision: before.revision },
|
|
189
|
+
] }).catch((error) => error);
|
|
190
|
+
expect([400, 409]).toContain(stale?.status);
|
|
191
|
+
await git.commit({ token, id: repository.id, branch: 'main', message: 'delete', actions: [{ action: 'delete', path: 'b.txt' }] });
|
|
192
|
+
expect(await git.listFiles({ token, id: repository.id, ref: 'main' })).not.toContain('b.txt');
|
|
193
|
+
});
|
|
194
|
+
it('creates branches and tags, and finds them', async () => {
|
|
195
|
+
const git = makeProvider();
|
|
196
|
+
const { repository } = await repoIn(git);
|
|
197
|
+
await git.createBranch({ token, id: repository.id, branch: 'work', ref: 'main' });
|
|
198
|
+
const branch = await git.getBranch({ token, id: repository.id, branch: 'work' });
|
|
199
|
+
expect(branch.name).toBe('work');
|
|
200
|
+
await expect(git.createBranch({ token, id: repository.id, branch: 'work', ref: 'main', track: false }))
|
|
201
|
+
.rejects.toSatisfy((error) => git.isAlreadyExistsError(error));
|
|
202
|
+
await git.createTag({ token, id: repository.id, tag: 'v1.0.0', ref: 'main', message: 'Release' });
|
|
203
|
+
expect((await git.getTag({ token, id: repository.id, tag: 'v1.0.0' }))?.name).toBe('v1.0.0');
|
|
204
|
+
// the annotation comes back as it was written, and a tag without one has none
|
|
205
|
+
expect((await git.getTag({ token, id: repository.id, tag: 'v1.0.0' }))?.message?.trim()).toBe('Release');
|
|
206
|
+
await git.createTag({ token, id: repository.id, tag: 'v1.0.1', ref: 'main' });
|
|
207
|
+
expect((await git.getTag({ token, id: repository.id, tag: 'v1.0.1' }))?.message ?? null).toBeNull();
|
|
208
|
+
expect(await git.getTag({ token, id: repository.id, tag: 'v9.9.9' })).toBeNull();
|
|
209
|
+
expect((await git.listTags({ token, id: repository.id })).map((t) => t.name)).toContain('v1.0.0');
|
|
210
|
+
});
|
|
211
|
+
it('compares two refs: the commits and the files `to` brought', async () => {
|
|
212
|
+
const git = makeProvider();
|
|
213
|
+
const { repository } = await repoIn(git);
|
|
214
|
+
await git.createBranch({ token, id: repository.id, branch: 'feature', ref: 'main' });
|
|
215
|
+
await git.commit({ token, id: repository.id, branch: 'feature', message: 'add compare', actions: [{ action: 'create', path: 'cmp.txt', content: 'x\n' }] });
|
|
216
|
+
const result = await git.compare({ token, id: repository.id, from: 'main', to: 'feature' });
|
|
217
|
+
expect(result.commits.map((c) => c.title)).toContain('add compare');
|
|
218
|
+
expect(result.files.map((f) => f.newPath)).toContain('cmp.txt');
|
|
219
|
+
expect(result.files.find((f) => f.newPath === 'cmp.txt')).toMatchObject({ status: 'added' });
|
|
220
|
+
const none = await git.compare({ token, id: repository.id, from: 'feature', to: 'main' });
|
|
221
|
+
expect(none.files).toEqual([]);
|
|
222
|
+
});
|
|
223
|
+
it('opens a change request, merges it, and finds it among the merged ones', async () => {
|
|
224
|
+
const git = makeProvider();
|
|
225
|
+
const { repository } = await repoIn(git);
|
|
226
|
+
await git.createBranch({ token, id: repository.id, branch: 'feature', ref: 'main' });
|
|
227
|
+
await git.commit({ token, id: repository.id, branch: 'feature', message: 'add', actions: [{ action: 'create', path: 'new.txt', content: 'x' }] });
|
|
228
|
+
const request = await git.createChangeRequest({ token, id: repository.id, title: 'Add new', sourceBranch: 'feature', targetBranch: 'main' });
|
|
229
|
+
expect(request).toMatchObject({ title: 'Add new', sourceBranch: 'feature', targetBranch: 'main' });
|
|
230
|
+
expect(typeof request.number).toBe('number');
|
|
231
|
+
const opened = await git.listChangeRequests({ token, id: repository.id, state: 'opened', targetBranch: 'main' });
|
|
232
|
+
expect(opened.map((r) => r.number)).toContain(request.number);
|
|
233
|
+
const conflicts = await git.mergeChangeRequest({ token, id: repository.id, number: request.number });
|
|
234
|
+
expect(conflicts).toBe(false);
|
|
235
|
+
expect(await git.listFiles({ token, id: repository.id, ref: 'main' })).toContain('new.txt');
|
|
236
|
+
const merged = await git.listChangeRequests({ token, id: repository.id, state: 'merged', targetBranch: 'main' });
|
|
237
|
+
expect(merged.map((r) => r.sourceBranch)).toContain('feature');
|
|
238
|
+
});
|
|
239
|
+
it('says a change request has conflicts, and leaves the target as it was', async () => {
|
|
240
|
+
const git = makeProvider();
|
|
241
|
+
const { repository } = await repoIn(git);
|
|
242
|
+
await git.createFile({ token, id: repository.id, path: 'c.txt', branch: 'main', content: 'base' });
|
|
243
|
+
await git.createBranch({ token, id: repository.id, branch: 'other', ref: 'main' });
|
|
244
|
+
await git.commit({ token, id: repository.id, branch: 'other', message: 'theirs', actions: [{ action: 'update', path: 'c.txt', content: 'theirs' }] });
|
|
245
|
+
await git.commit({ token, id: repository.id, branch: 'main', message: 'ours', actions: [{ action: 'update', path: 'c.txt', content: 'ours' }] });
|
|
246
|
+
const request = await git.createChangeRequest({ token, id: repository.id, title: 'Clash', sourceBranch: 'other', targetBranch: 'main' });
|
|
247
|
+
expect(await git.mergeChangeRequest({ token, id: repository.id, number: request.number })).toBe(true);
|
|
248
|
+
expect((await git.readFile({ token, id: repository.id, path: 'c.txt', ref: 'main' })).toString('utf8')).toBe('ours');
|
|
249
|
+
const [open] = await git.listChangeRequests({ token, id: repository.id, state: 'opened', targetBranch: 'main' });
|
|
250
|
+
expect(open.hasConflicts).toBe(true);
|
|
251
|
+
});
|
|
252
|
+
it('renames a standing change request instead of opening a second one', async () => {
|
|
253
|
+
const git = makeProvider();
|
|
254
|
+
const { repository } = await repoIn(git);
|
|
255
|
+
await git.createBranch({ token, id: repository.id, branch: 'bigbang', ref: 'main' });
|
|
256
|
+
await git.commit({ token, id: repository.id, branch: 'bigbang', message: 'v1', actions: [{ action: 'create', path: 'v.txt', content: '1' }] });
|
|
257
|
+
const first = await git.createOrRenameChangeRequest({ token, id: repository.id, title: 'Update to 1', sourceBranch: 'bigbang' });
|
|
258
|
+
const second = await git.createOrRenameChangeRequest({ token, id: repository.id, title: 'Update to 2', sourceBranch: 'bigbang' });
|
|
259
|
+
expect(second.number).toBe(first.number);
|
|
260
|
+
const open = await git.listChangeRequests({ token, id: repository.id, state: 'opened' });
|
|
261
|
+
expect(open.map((request) => request.title)).toEqual(['Update to 2']);
|
|
262
|
+
});
|
|
263
|
+
it('keeps or deletes the branch of a merged change request, as asked', async () => {
|
|
264
|
+
const git = makeProvider();
|
|
265
|
+
const { repository } = await repoIn(git);
|
|
266
|
+
for (const [branch, deleteSourceBranch] of [['keep-me', false], ['delete-me', true]]) {
|
|
267
|
+
await git.createBranch({ token, id: repository.id, branch, ref: 'main' });
|
|
268
|
+
await git.commit({ token, id: repository.id, branch, message: branch, actions: [{ action: 'create', path: `${branch}.txt`, content: branch }] });
|
|
269
|
+
const request = await git.createChangeRequest({ token, id: repository.id, title: branch, sourceBranch: branch, targetBranch: 'main' });
|
|
270
|
+
expect(await git.mergeChangeRequest({ token, id: repository.id, number: request.number, deleteSourceBranch })).toBe(false);
|
|
271
|
+
}
|
|
272
|
+
expect((await git.getBranch({ token, id: repository.id, branch: 'keep-me' })).name).toBe('keep-me');
|
|
273
|
+
await expect(git.getBranch({ token, id: repository.id, branch: 'delete-me' })).rejects.toMatchObject({ status: 404 });
|
|
274
|
+
});
|
|
275
|
+
it('has no pipeline for a branch that never ran one', async () => {
|
|
276
|
+
const git = makeProvider();
|
|
277
|
+
const { repository } = await repoIn(git);
|
|
278
|
+
expect(await git.getLatestPipeline({ token, id: repository.id, ref: 'main' })).toBeNull();
|
|
279
|
+
});
|
|
280
|
+
it('lists the members with a numeric access level', async () => {
|
|
281
|
+
const git = makeProvider();
|
|
282
|
+
const { repository } = await repoIn(git);
|
|
283
|
+
await addMember({ repository, username: 'dev', accessLevel: 40 });
|
|
284
|
+
const members = await git.getMembers({ token, id: repository.id });
|
|
285
|
+
expect(members).toContainEqual(expect.objectContaining({ username: 'dev', accessLevel: 40 }));
|
|
286
|
+
for (const member of members) {
|
|
287
|
+
expect(typeof member.username).toBe('string');
|
|
288
|
+
expect(typeof member.accessLevel).toBe('number');
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
it('knows a webhook delivery from its host by the secret, and reads which branch was pushed', async () => {
|
|
292
|
+
const git = makeProvider();
|
|
293
|
+
const delivery = signWebhook({ body: { ref: 'refs/heads/bigbang' }, secret: 's3cret' });
|
|
294
|
+
expect(git.verifyWebhook({ headers: delivery.headers, rawBody: delivery.rawBody, secret: 's3cret' })).toBe(true);
|
|
295
|
+
expect(git.verifyWebhook({ headers: delivery.headers, rawBody: delivery.rawBody, secret: 'wrong' })).toBe(false);
|
|
296
|
+
expect(git.verifyWebhook({ headers: {}, rawBody: delivery.rawBody, secret: 's3cret' })).toBe(false);
|
|
297
|
+
expect(git.parsePushEvent(pushEvent({ repositoryId: 7, branch: 'bigbang' }))).toEqual({ repositoryId: 7, branch: 'bigbang' });
|
|
298
|
+
expect(git.parsePushEvent({ headers: {}, body: {} })).toBeNull();
|
|
299
|
+
});
|
|
300
|
+
it('registers a webhook once', async () => {
|
|
301
|
+
const git = makeProvider();
|
|
302
|
+
const { repository } = await repoIn(git);
|
|
303
|
+
const args = { token, id: repository.id, url: 'https://linea.example/api/webhooks/x', secret: 's3cret' };
|
|
304
|
+
expect((await git.ensureWebhook(args)).status).toBe('created');
|
|
305
|
+
expect((await git.ensureWebhook(args)).status).toBe('already_exists');
|
|
306
|
+
});
|
|
307
|
+
it('downloads a zip of the repository', async () => {
|
|
308
|
+
const git = makeProvider();
|
|
309
|
+
const { repository } = await repoIn(git);
|
|
310
|
+
const { buffer } = await import('node:stream/consumers');
|
|
311
|
+
const bytes = await buffer(await git.downloadArchive({ token, id: repository.id, ref: 'main' }));
|
|
312
|
+
expect(bytes.subarray(0, 2).toString('latin1')).toBe('PK');
|
|
313
|
+
});
|
|
314
|
+
describe('releases', () => {
|
|
315
|
+
// a repository with a tag to make releases of
|
|
316
|
+
const tagIn = async (git, tag = 'v1.0.0') => {
|
|
317
|
+
const { repository } = await repoIn(git);
|
|
318
|
+
await git.createTag({ token, id: repository.id, tag, ref: 'main', message: '{}' });
|
|
319
|
+
return repository;
|
|
320
|
+
};
|
|
321
|
+
it('says what it can do', () => {
|
|
322
|
+
expect(typeof makeProvider().capabilities().releases.prerelease).toBe('boolean');
|
|
323
|
+
});
|
|
324
|
+
it('creates a release of a tag and describes it in the neutral shape', async () => {
|
|
325
|
+
const git = makeProvider();
|
|
326
|
+
const repository = await tagIn(git);
|
|
327
|
+
const made = await git.createRelease({ token, id: repository.id, tag: 'v1.0.0', name: 'First', description: '# Notes\n- one' });
|
|
328
|
+
expect(made).toMatchObject({ tag: 'v1.0.0', name: 'First', description: '# Notes\n- one', prerelease: false });
|
|
329
|
+
expect(typeof made.createdAt).toBe('string');
|
|
330
|
+
expect(typeof made.url).toBe('string');
|
|
331
|
+
});
|
|
332
|
+
it('names the release after the tag when it is given no name', async () => {
|
|
333
|
+
const git = makeProvider();
|
|
334
|
+
const repository = await tagIn(git);
|
|
335
|
+
expect(await git.createRelease({ token, id: repository.id, tag: 'v1.0.0' })).toMatchObject({ name: 'v1.0.0', description: '' });
|
|
336
|
+
});
|
|
337
|
+
it('reads a release, and says there is none when there is none', async () => {
|
|
338
|
+
const git = makeProvider();
|
|
339
|
+
const repository = await tagIn(git);
|
|
340
|
+
expect(await git.getRelease({ token, id: repository.id, tag: 'v1.0.0' })).toBeNull();
|
|
341
|
+
await git.createRelease({ token, id: repository.id, tag: 'v1.0.0', name: 'First' });
|
|
342
|
+
expect(await git.getRelease({ token, id: repository.id, tag: 'v1.0.0' })).toMatchObject({ tag: 'v1.0.0', name: 'First' });
|
|
343
|
+
});
|
|
344
|
+
it('lists the releases, newest first', async () => {
|
|
345
|
+
const git = makeProvider();
|
|
346
|
+
const repository = await tagIn(git);
|
|
347
|
+
expect(await git.listReleases({ token, id: repository.id })).toEqual([]);
|
|
348
|
+
await git.createTag({ token, id: repository.id, tag: 'v1.1.0', ref: 'main', message: '{}' });
|
|
349
|
+
await git.createRelease({ token, id: repository.id, tag: 'v1.0.0' });
|
|
350
|
+
await git.createRelease({ token, id: repository.id, tag: 'v1.1.0' });
|
|
351
|
+
expect((await git.listReleases({ token, id: repository.id })).map((release) => release.tag)).toEqual(['v1.1.0', 'v1.0.0']);
|
|
352
|
+
});
|
|
353
|
+
it('does not overwrite the release of a tag that has one', async () => {
|
|
354
|
+
const git = makeProvider();
|
|
355
|
+
const repository = await tagIn(git);
|
|
356
|
+
await git.createRelease({ token, id: repository.id, tag: 'v1.0.0', name: 'First', description: 'original' });
|
|
357
|
+
const error = await git.createRelease({ token, id: repository.id, tag: 'v1.0.0', name: 'Other', description: 'changed' }).catch((e) => e);
|
|
358
|
+
expect(error).toBeInstanceOf(Error);
|
|
359
|
+
expect(git.isAlreadyExistsError(error)).toBe(true);
|
|
360
|
+
expect(await git.getRelease({ token, id: repository.id, tag: 'v1.0.0' })).toMatchObject({ name: 'First', description: 'original' });
|
|
361
|
+
});
|
|
362
|
+
it('updates a release, touching only what changes holds', async () => {
|
|
363
|
+
const git = makeProvider();
|
|
364
|
+
const repository = await tagIn(git);
|
|
365
|
+
await git.createRelease({ token, id: repository.id, tag: 'v1.0.0', name: 'First', description: 'old' });
|
|
366
|
+
const updated = await git.updateRelease({ token, id: repository.id, tag: 'v1.0.0', changes: { description: 'new' } });
|
|
367
|
+
expect(updated).toMatchObject({ tag: 'v1.0.0', name: 'First', description: 'new' });
|
|
368
|
+
expect(await git.getRelease({ token, id: repository.id, tag: 'v1.0.0' })).toMatchObject({ name: 'First', description: 'new' });
|
|
369
|
+
const renamed = await git.updateRelease({ token, id: repository.id, tag: 'v1.0.0', changes: { name: 'Renamed' } });
|
|
370
|
+
expect(renamed).toMatchObject({ name: 'Renamed', description: 'new' });
|
|
371
|
+
});
|
|
372
|
+
it('marks a prerelease where the host can', async () => {
|
|
373
|
+
const git = makeProvider();
|
|
374
|
+
const repository = await tagIn(git);
|
|
375
|
+
const made = await git.createRelease({ token, id: repository.id, tag: 'v1.0.0', prerelease: true });
|
|
376
|
+
expect(made.prerelease).toBe(git.capabilities().releases.prerelease);
|
|
377
|
+
if (git.capabilities().releases.prerelease) {
|
|
378
|
+
expect((await git.updateRelease({ token, id: repository.id, tag: 'v1.0.0', changes: { prerelease: false } })).prerelease).toBe(false);
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
it('refuses a release of a tag that does not exist, or the update of one that was never made', async () => {
|
|
382
|
+
const git = makeProvider();
|
|
383
|
+
const repository = await tagIn(git);
|
|
384
|
+
await expect(git.createRelease({ token, id: repository.id, tag: 'v9.9.9' })).rejects.toBeTruthy();
|
|
385
|
+
expect(await git.getRelease({ token, id: repository.id, tag: 'v9.9.9' })).toBeNull();
|
|
386
|
+
expect(await git.listReleases({ token, id: repository.id })).toEqual([]);
|
|
387
|
+
await expect(git.updateRelease({ token, id: repository.id, tag: 'v1.0.0', changes: { name: 'x' } })).rejects.toMatchObject({ status: 404 });
|
|
388
|
+
});
|
|
389
|
+
});
|
|
390
|
+
describe('issues', () => {
|
|
391
|
+
const issueIn = async (git, fields = {}) => {
|
|
392
|
+
const { repository } = await repoIn(git);
|
|
393
|
+
return { repository, issue: await git.createIssue({ token, id: repository.id, title: 'It breaks', ...fields }) };
|
|
394
|
+
};
|
|
395
|
+
it('says what it can do', () => {
|
|
396
|
+
const { issues } = makeProvider().capabilities();
|
|
397
|
+
expect(typeof issues.labels).toBe('boolean');
|
|
398
|
+
expect(typeof issues.milestones).toBe('boolean');
|
|
399
|
+
expect(typeof issues.assignees).toBe('boolean');
|
|
400
|
+
expect(typeof issues.closingWords).toBe('boolean');
|
|
401
|
+
});
|
|
402
|
+
it('closes the issues a merged request names with a closing word, when the provider does it (the other hosts do it themselves)', async () => {
|
|
403
|
+
const git = makeProvider();
|
|
404
|
+
if (!git.capabilities().issues.closingWords)
|
|
405
|
+
return;
|
|
406
|
+
const { repository } = await repoIn(git);
|
|
407
|
+
const id = repository.id;
|
|
408
|
+
const [first, second, third] = [1, 2, 3].map((n) => `Problem ${n}`);
|
|
409
|
+
for (const title of [first, second, third])
|
|
410
|
+
await git.createIssue({ token, id, title });
|
|
411
|
+
await git.createBranch({ token, id, branch: 'feature', ref: 'main' });
|
|
412
|
+
await git.commit({ token, id, branch: 'feature', message: 'work\n\nFixes #2', actions: [{ action: 'create', path: 'a.txt', content: 'a' }] });
|
|
413
|
+
const request = await git.createMergeRequest({ token, id, title: 'Add a', description: 'Closes #1 and mentions #3', sourceBranch: 'feature', targetBranch: 'main' });
|
|
414
|
+
expect((await git.getIssue({ token, id, number: 1 })).state).toBe('opened');
|
|
415
|
+
await git.mergeMergeRequest({ token, id, number: request.number });
|
|
416
|
+
expect((await git.getIssue({ token, id, number: 1 })).state).toBe('closed');
|
|
417
|
+
expect((await git.getIssue({ token, id, number: 2 })).state).toBe('closed');
|
|
418
|
+
expect((await git.getIssue({ token, id, number: 3 })).state).toBe('opened');
|
|
419
|
+
});
|
|
420
|
+
it('leaves the issues alone when the request merges into a branch that is not the default one', async () => {
|
|
421
|
+
const git = makeProvider();
|
|
422
|
+
if (!git.capabilities().issues.closingWords)
|
|
423
|
+
return;
|
|
424
|
+
const { repository } = await repoIn(git);
|
|
425
|
+
const id = repository.id;
|
|
426
|
+
await git.createIssue({ token, id, title: 'Problem' });
|
|
427
|
+
await git.createBranch({ token, id, branch: 'staging', ref: 'main' });
|
|
428
|
+
await git.createBranch({ token, id, branch: 'feature', ref: 'main' });
|
|
429
|
+
await git.commit({ token, id, branch: 'feature', message: 'work', actions: [{ action: 'create', path: 'a.txt', content: 'a' }] });
|
|
430
|
+
const request = await git.createMergeRequest({ token, id, title: 'Closes #1', sourceBranch: 'feature', targetBranch: 'staging' });
|
|
431
|
+
await git.mergeMergeRequest({ token, id, number: request.number });
|
|
432
|
+
expect((await git.getIssue({ token, id, number: 1 })).state).toBe('opened');
|
|
433
|
+
});
|
|
434
|
+
it('creates an issue and describes it in the neutral shape', async () => {
|
|
435
|
+
const git = makeProvider();
|
|
436
|
+
const { repository } = await repoIn(git);
|
|
437
|
+
await addMilestone?.({ repository, title: 'v1' });
|
|
438
|
+
const made = await git.createIssue({ token, id: repository.id, title: 'It breaks', description: '# Steps\n1. Click', labels: ['bug', 'ui'], assignees: ['maria'], milestone: 'v1' });
|
|
439
|
+
expect(made).toMatchObject({ number: 1, title: 'It breaks', description: '# Steps\n1. Click', state: 'opened', assignees: ['maria'], milestone: 'v1', closedAt: null, commentCount: 0 });
|
|
440
|
+
expect([...made.labels].sort()).toEqual(['bug', 'ui']);
|
|
441
|
+
expect(typeof made.author).toBe('string');
|
|
442
|
+
expect(typeof made.createdAt).toBe('string');
|
|
443
|
+
expect(typeof made.webUrl).toBe('string');
|
|
444
|
+
expect(await git.getIssue({ token, id: repository.id, number: made.number })).toMatchObject({ number: 1, title: 'It breaks' });
|
|
445
|
+
});
|
|
446
|
+
it('numbers the issues of a repository one after another', async () => {
|
|
447
|
+
const git = makeProvider();
|
|
448
|
+
const { repository, issue } = await issueIn(git);
|
|
449
|
+
const next = await git.createIssue({ token, id: repository.id, title: 'Another' });
|
|
450
|
+
expect(next.number).toBeGreaterThan(issue.number);
|
|
451
|
+
});
|
|
452
|
+
it('has no issue where there is none', async () => {
|
|
453
|
+
const git = makeProvider();
|
|
454
|
+
const { repository } = await repoIn(git);
|
|
455
|
+
await expect(git.getIssue({ token, id: repository.id, number: 99 })).rejects.toMatchObject({ status: 404 });
|
|
456
|
+
});
|
|
457
|
+
it('lists the open ones, newest first, and filters them', async () => {
|
|
458
|
+
const git = makeProvider();
|
|
459
|
+
const { repository } = await repoIn(git);
|
|
460
|
+
await addMilestone?.({ repository, title: 'v1' });
|
|
461
|
+
const id = repository.id;
|
|
462
|
+
const first = await git.createIssue({ token, id, title: 'Slow login', description: 'takes ages', labels: ['bug'], assignees: ['maria'], milestone: 'v1' });
|
|
463
|
+
const second = await git.createIssue({ token, id, title: 'Add dark mode', labels: ['feature'] });
|
|
464
|
+
const third = await git.createIssue({ token, id, title: 'Crash on save', labels: ['bug'] });
|
|
465
|
+
await git.updateIssue({ token, id, number: third.number, changes: { state: 'closed' } });
|
|
466
|
+
const numbers = async (filter) => (await git.listIssues({ token, id, filter })).items.map((i) => i.number);
|
|
467
|
+
expect(await numbers({})).toEqual([second.number, first.number]);
|
|
468
|
+
expect(await numbers({ state: 'closed' })).toEqual([third.number]);
|
|
469
|
+
expect(await numbers({ state: 'all' })).toEqual([third.number, second.number, first.number]);
|
|
470
|
+
expect(await numbers({ state: 'all', labels: ['bug'] })).toEqual([third.number, first.number]);
|
|
471
|
+
expect(await numbers({ assignee: 'maria' })).toEqual([first.number]);
|
|
472
|
+
expect(await numbers({ milestone: 'v1' })).toEqual([first.number]);
|
|
473
|
+
expect(await numbers({ author: 'nobody-wrote-this' })).toEqual([]);
|
|
474
|
+
expect(await numbers({ search: 'dark' })).toEqual([second.number]);
|
|
475
|
+
expect(await numbers({ search: 'ages' })).toEqual([first.number]);
|
|
476
|
+
});
|
|
477
|
+
it('pages a list', async () => {
|
|
478
|
+
const git = makeProvider();
|
|
479
|
+
const { repository } = await repoIn(git);
|
|
480
|
+
for (const title of ['a', 'b', 'c'])
|
|
481
|
+
await git.createIssue({ token, id: repository.id, title });
|
|
482
|
+
const one = await git.listIssues({ token, id: repository.id, filter: { perPage: 2 } });
|
|
483
|
+
expect(one.items.map((i) => i.title)).toEqual(['c', 'b']);
|
|
484
|
+
expect(one).toMatchObject({ page: 1, perPage: 2, hasMore: true });
|
|
485
|
+
const two = await git.listIssues({ token, id: repository.id, filter: { perPage: 2, page: 2 } });
|
|
486
|
+
expect(two.items.map((i) => i.title)).toEqual(['a']);
|
|
487
|
+
expect(two.hasMore).toBe(false);
|
|
488
|
+
});
|
|
489
|
+
it('edits an issue, closes it and opens it again, touching only what it is told', async () => {
|
|
490
|
+
const git = makeProvider();
|
|
491
|
+
const { repository, issue } = await issueIn(git, { description: 'before', labels: ['bug'] });
|
|
492
|
+
const id = repository.id;
|
|
493
|
+
const edited = await git.updateIssue({ token, id, number: issue.number, changes: { title: 'Renamed', labels: ['bug', 'urgent'], assignees: ['maria'] } });
|
|
494
|
+
expect(edited).toMatchObject({ title: 'Renamed', description: 'before', assignees: ['maria'] });
|
|
495
|
+
expect([...edited.labels].sort()).toEqual(['bug', 'urgent']);
|
|
496
|
+
const closed = await git.updateIssue({ token, id, number: issue.number, changes: { state: 'closed' } });
|
|
497
|
+
expect(closed.state).toBe('closed');
|
|
498
|
+
expect(closed.closedAt).not.toBeNull();
|
|
499
|
+
const reopened = await git.updateIssue({ token, id, number: issue.number, changes: { state: 'opened' } });
|
|
500
|
+
expect(reopened).toMatchObject({ state: 'opened', closedAt: null, title: 'Renamed' });
|
|
501
|
+
const cleared = await git.updateIssue({ token, id, number: issue.number, changes: { description: '', labels: [], assignees: [] } });
|
|
502
|
+
expect(cleared).toMatchObject({ description: '', labels: [], assignees: [] });
|
|
503
|
+
});
|
|
504
|
+
it('keeps the thread of an issue in order', async () => {
|
|
505
|
+
const git = makeProvider();
|
|
506
|
+
const { repository, issue } = await issueIn(git);
|
|
507
|
+
const id = repository.id;
|
|
508
|
+
expect(await git.listIssueComments({ token, id, number: issue.number })).toEqual([]);
|
|
509
|
+
const first = await git.addIssueComment({ token, id, number: issue.number, body: 'I can reproduce it' });
|
|
510
|
+
await git.addIssueComment({ token, id, number: issue.number, body: 'Fixed in the next version' });
|
|
511
|
+
expect(first).toMatchObject({ body: 'I can reproduce it' });
|
|
512
|
+
expect(typeof first.author).toBe('string');
|
|
513
|
+
const thread = await git.listIssueComments({ token, id, number: issue.number });
|
|
514
|
+
expect(thread.map((c) => c.body)).toEqual(['I can reproduce it', 'Fixed in the next version']);
|
|
515
|
+
expect((await git.getIssue({ token, id, number: issue.number })).commentCount).toBe(2);
|
|
516
|
+
});
|
|
517
|
+
it('lists the labels and the milestones to choose from', async () => {
|
|
518
|
+
const git = makeProvider();
|
|
519
|
+
const { repository } = await repoIn(git);
|
|
520
|
+
await addMilestone?.({ repository, title: 'v1' });
|
|
521
|
+
await git.createIssue({ token, id: repository.id, title: 'x', labels: ['bug'], milestone: 'v1' });
|
|
522
|
+
expect(Array.isArray(await git.listLabels({ token, id: repository.id }))).toBe(true);
|
|
523
|
+
expect((await git.listMilestones({ token, id: repository.id })).map((m) => m.title)).toContain('v1');
|
|
524
|
+
});
|
|
525
|
+
});
|
|
526
|
+
describe('templates', () => {
|
|
527
|
+
const place = {
|
|
528
|
+
gitlab: { issue: '.gitlab/issue_templates/bug.md', mergeRequest: '.gitlab/merge_request_templates/feature.md' },
|
|
529
|
+
github: { issue: '.github/ISSUE_TEMPLATE/bug.md', mergeRequest: '.github/pull_request_template.md' }
|
|
530
|
+
};
|
|
531
|
+
const withTemplates = async (git) => {
|
|
532
|
+
const { repository } = await repoIn(git);
|
|
533
|
+
const id = repository.id;
|
|
534
|
+
if (git.kind === 'local') {
|
|
535
|
+
await git.saveTemplate({ token, id, kind: 'issue', name: 'bug', content: '## Steps\n1.' });
|
|
536
|
+
await git.saveTemplate({ token, id, kind: 'mergeRequest', name: 'feature', content: '## What changes' });
|
|
537
|
+
}
|
|
538
|
+
else {
|
|
539
|
+
await git.createFile({ token, id, path: place[git.kind].issue, branch: 'main', content: '## Steps\n1.' });
|
|
540
|
+
await git.createFile({ token, id, path: place[git.kind].mergeRequest, branch: 'main', content: '## What changes' });
|
|
541
|
+
}
|
|
542
|
+
return id;
|
|
543
|
+
};
|
|
544
|
+
it('says whether they can be edited', () => {
|
|
545
|
+
expect(typeof makeProvider().capabilities().templates.editable).toBe('boolean');
|
|
546
|
+
});
|
|
547
|
+
it('has none where nobody wrote any', async () => {
|
|
548
|
+
const git = makeProvider();
|
|
549
|
+
const { repository } = await repoIn(git);
|
|
550
|
+
expect(await git.listTemplates({ token, id: repository.id, kind: 'issue' })).toEqual([]);
|
|
551
|
+
expect(await git.listTemplates({ token, id: repository.id, kind: 'mergeRequest' })).toEqual([]);
|
|
552
|
+
});
|
|
553
|
+
it('lists the ones of the issues and the ones of the merge requests apart', async () => {
|
|
554
|
+
const git = makeProvider();
|
|
555
|
+
const id = await withTemplates(git);
|
|
556
|
+
const [issue] = await git.listTemplates({ token, id, kind: 'issue' });
|
|
557
|
+
const [request] = await git.listTemplates({ token, id, kind: 'mergeRequest' });
|
|
558
|
+
expect(issue.content).toBe('## Steps\n1.');
|
|
559
|
+
expect(request.content).toBe('## What changes');
|
|
560
|
+
expect(typeof issue.name).toBe('string');
|
|
561
|
+
expect(issue.name).not.toBe(request.name);
|
|
562
|
+
});
|
|
563
|
+
it('is edited where the host keeps them in its own bookkeeping, and refused where they are files', async () => {
|
|
564
|
+
const git = makeProvider();
|
|
565
|
+
const { repository } = await repoIn(git);
|
|
566
|
+
const id = repository.id;
|
|
567
|
+
if (!git.capabilities().templates.editable) {
|
|
568
|
+
await expect(git.saveTemplate({ token, id, kind: 'issue', name: 'x', content: 'y' })).rejects.toMatchObject({ status: 400 });
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
await git.saveTemplate({ token, id, kind: 'issue', name: 'bug', content: 'one' });
|
|
572
|
+
await git.saveTemplate({ token, id, kind: 'issue', name: 'bug', content: 'two' });
|
|
573
|
+
await git.saveTemplate({ token, id, kind: 'issue', name: 'idea', content: 'three' });
|
|
574
|
+
expect(await git.listTemplates({ token, id, kind: 'issue' })).toEqual([{ name: 'bug', content: 'two' }, { name: 'idea', content: 'three' }]);
|
|
575
|
+
await git.deleteTemplate({ token, id, kind: 'issue', name: 'bug' });
|
|
576
|
+
expect((await git.listTemplates({ token, id, kind: 'issue' })).map((template) => template.name)).toEqual(['idea']);
|
|
577
|
+
await expect(git.deleteTemplate({ token, id, kind: 'issue', name: 'bug' })).rejects.toMatchObject({ status: 404 });
|
|
578
|
+
await expect(git.saveTemplate({ token, id, kind: 'issue', name: ' ', content: 'x' })).rejects.toMatchObject({ status: 400 });
|
|
579
|
+
});
|
|
580
|
+
});
|
|
581
|
+
describe('merge requests', () => {
|
|
582
|
+
// a repository with a branch that adds one file and changes another
|
|
583
|
+
const requestIn = async (git, fields = {}) => {
|
|
584
|
+
const { repository } = await repoIn(git);
|
|
585
|
+
const id = repository.id;
|
|
586
|
+
await git.createBranch({ token, id, branch: 'feature', ref: 'main' });
|
|
587
|
+
await git.commit({ token, id, branch: 'feature', message: 'work', actions: [{ action: 'create', path: 'docs/a.md', content: 'line one\nline two\n' }] });
|
|
588
|
+
const request = await git.createMergeRequest({ token, id, title: 'Add the docs', description: '# Why\nBecause.', sourceBranch: 'feature', targetBranch: 'main', ...fields });
|
|
589
|
+
return { id, request };
|
|
590
|
+
};
|
|
591
|
+
it('says what it can do', () => {
|
|
592
|
+
const { mergeRequests } = makeProvider().capabilities();
|
|
593
|
+
for (const key of ['labels', 'reviewers', 'approvals', 'resolvableThreads', 'squash'])
|
|
594
|
+
expect(typeof mergeRequests[key], key).toBe('boolean');
|
|
595
|
+
});
|
|
596
|
+
it('lists the branches of the repository', async () => {
|
|
597
|
+
const git = makeProvider();
|
|
598
|
+
const { id } = await requestIn(git);
|
|
599
|
+
const names = await git.listBranches({ token, id });
|
|
600
|
+
expect(names).toContain('main');
|
|
601
|
+
expect(names).toContain('feature');
|
|
602
|
+
});
|
|
603
|
+
it('opens one and describes it in the neutral shape', async () => {
|
|
604
|
+
const git = makeProvider();
|
|
605
|
+
const { id, request } = await requestIn(git, { labels: ['bug'] });
|
|
606
|
+
expect(request).toMatchObject({ title: 'Add the docs', description: '# Why\nBecause.', state: 'opened', sourceBranch: 'feature', targetBranch: 'main', hasConflicts: false, mergedAt: null });
|
|
607
|
+
expect(typeof request.number).toBe('number');
|
|
608
|
+
expect(typeof request.author).toBe('string');
|
|
609
|
+
expect(typeof request.createdAt).toBe('string');
|
|
610
|
+
expect(request.labels).toEqual(['bug']);
|
|
611
|
+
expect(await git.getMergeRequest({ token, id, number: request.number })).toMatchObject({ number: request.number, title: 'Add the docs' });
|
|
612
|
+
await expect(git.getMergeRequest({ token, id, number: 999 })).rejects.toMatchObject({ status: 404 });
|
|
613
|
+
});
|
|
614
|
+
it('lists them, newest first, narrowed by state, text, label and branches, a page at a time', async () => {
|
|
615
|
+
const git = makeProvider();
|
|
616
|
+
const { id, request } = await requestIn(git, { labels: ['bug'] });
|
|
617
|
+
await git.createBranch({ token, id, branch: 'other', ref: 'main' });
|
|
618
|
+
await git.commit({ token, id, branch: 'other', message: 'more', actions: [{ action: 'create', path: 'b.txt', content: 'b' }] });
|
|
619
|
+
const second = await git.createMergeRequest({ token, id, title: 'Another change', sourceBranch: 'other', targetBranch: 'main' });
|
|
620
|
+
const numbers = async (filter) => (await git.listMergeRequests({ token, id, filter })).items.map((r) => r.number);
|
|
621
|
+
expect(await numbers({})).toEqual([second.number, request.number]);
|
|
622
|
+
expect(await numbers({ state: 'merged' })).toEqual([]);
|
|
623
|
+
expect(await numbers({ search: 'docs' })).toEqual([request.number]);
|
|
624
|
+
expect(await numbers({ labels: ['bug'] })).toEqual([request.number]);
|
|
625
|
+
expect(await numbers({ sourceBranch: 'other' })).toEqual([second.number]);
|
|
626
|
+
expect(await numbers({ targetBranch: 'main' })).toEqual([second.number, request.number]);
|
|
627
|
+
const first = await git.listMergeRequests({ token, id, filter: { perPage: 1 } });
|
|
628
|
+
expect(first).toMatchObject({ page: 1, perPage: 1, hasMore: true });
|
|
629
|
+
expect((await git.listMergeRequests({ token, id, filter: { perPage: 1, page: 2 } })).items.map((r) => r.number)).toEqual([request.number]);
|
|
630
|
+
});
|
|
631
|
+
it('shows the code it proposes, file by file, with the lines it adds', async () => {
|
|
632
|
+
const git = makeProvider();
|
|
633
|
+
const { id, request } = await requestIn(git);
|
|
634
|
+
const files = await git.getMergeRequestDiff({ token, id, number: request.number });
|
|
635
|
+
const added = files.find((file) => file.newPath === 'docs/a.md');
|
|
636
|
+
expect(added).toMatchObject({ status: 'added', additions: 2, deletions: 0 });
|
|
637
|
+
expect(added.patch).toContain('+line one');
|
|
638
|
+
expect(added.patch).toContain('+line two');
|
|
639
|
+
});
|
|
640
|
+
it('keeps the conversations: a general message, one about a line, the answers, and resolving the ones about code', async () => {
|
|
641
|
+
const git = makeProvider();
|
|
642
|
+
const { id, request } = await requestIn(git);
|
|
643
|
+
const number = request.number;
|
|
644
|
+
const general = await git.addMergeRequestComment({ token, id, number, body: 'Looks fine overall' });
|
|
645
|
+
expect(general.position).toBeUndefined();
|
|
646
|
+
expect(general.comments.map((c) => c.body)).toEqual(['Looks fine overall']);
|
|
647
|
+
const online = await git.addMergeRequestComment({ token, id, number, body: 'Why this word?', position: { path: 'docs/a.md', line: 2, side: 'new' } });
|
|
648
|
+
expect(online.position).toEqual({ path: 'docs/a.md', line: 2, side: 'new' });
|
|
649
|
+
const answered = await git.addMergeRequestComment({ token, id, number, body: 'To be clearer', threadId: online.id });
|
|
650
|
+
expect(answered.comments.map((c) => c.body)).toEqual(['Why this word?', 'To be clearer']);
|
|
651
|
+
const threads = await git.listMergeRequestThreads({ token, id, number });
|
|
652
|
+
expect(threads).toHaveLength(2);
|
|
653
|
+
expect(threads.find((t) => t.position)?.comments).toHaveLength(2);
|
|
654
|
+
expect((await git.getMergeRequest({ token, id, number })).commentCount).toBeGreaterThanOrEqual(3);
|
|
655
|
+
if (git.capabilities().mergeRequests.resolvableThreads) {
|
|
656
|
+
expect(threads.find((t) => t.position)?.resolvable).toBe(true);
|
|
657
|
+
expect((await git.setThreadResolved({ token, id, number, threadId: online.id, resolved: true })).resolved).toBe(true);
|
|
658
|
+
expect((await git.listMergeRequestThreads({ token, id, number })).find((t) => t.position)?.resolved).toBe(true);
|
|
659
|
+
expect((await git.setThreadResolved({ token, id, number, threadId: online.id, resolved: false })).resolved).toBe(false);
|
|
660
|
+
}
|
|
661
|
+
else {
|
|
662
|
+
await expect(git.setThreadResolved({ token, id, number, threadId: online.id, resolved: true })).rejects.toMatchObject({ status: 400 });
|
|
663
|
+
}
|
|
664
|
+
});
|
|
665
|
+
it('edits one, closes it and opens it again, touching only what it is told', async () => {
|
|
666
|
+
const git = makeProvider();
|
|
667
|
+
const { id, request } = await requestIn(git);
|
|
668
|
+
const number = request.number;
|
|
669
|
+
const edited = await git.updateMergeRequest({ token, id, number, changes: { title: 'Renamed', description: 'New text' } });
|
|
670
|
+
expect(edited).toMatchObject({ title: 'Renamed', description: 'New text', state: 'opened' });
|
|
671
|
+
const labelled = await git.updateMergeRequest({ token, id, number, changes: { labels: ['bug', 'ui'], reviewers: ['maria'] } });
|
|
672
|
+
expect([...labelled.labels].sort()).toEqual(['bug', 'ui']);
|
|
673
|
+
expect(labelled.reviewers).toEqual(['maria']);
|
|
674
|
+
expect(labelled.title).toBe('Renamed');
|
|
675
|
+
expect((await git.updateMergeRequest({ token, id, number, changes: { state: 'closed' } })).state).toBe('closed');
|
|
676
|
+
expect((await git.listMergeRequests({ token, id, filter: { state: 'closed' } })).items.map((r) => r.number)).toEqual([number]);
|
|
677
|
+
expect((await git.updateMergeRequest({ token, id, number, changes: { state: 'opened' } })).state).toBe('opened');
|
|
678
|
+
});
|
|
679
|
+
it('takes an approval where the host has approvals, and says no where it has none', async () => {
|
|
680
|
+
const git = makeProvider();
|
|
681
|
+
const { id, request } = await requestIn(git);
|
|
682
|
+
if (git.capabilities().mergeRequests.approvals) {
|
|
683
|
+
await git.approveMergeRequest({ token, id, number: request.number });
|
|
684
|
+
expect((await git.getMergeRequest({ token, id, number: request.number })).approvals?.given).toHaveLength(1);
|
|
685
|
+
}
|
|
686
|
+
else {
|
|
687
|
+
await expect(git.approveMergeRequest({ token, id, number: request.number })).rejects.toMatchObject({ status: 400 });
|
|
688
|
+
}
|
|
689
|
+
});
|
|
690
|
+
it('merges it as one commit when asked to squash, and takes the branch away when asked to', async () => {
|
|
691
|
+
const git = makeProvider();
|
|
692
|
+
const { id, request } = await requestIn(git);
|
|
693
|
+
await git.commit({ token, id, branch: 'feature', message: 'second', actions: [{ action: 'create', path: 'docs/b.md', content: 'two' }] });
|
|
694
|
+
expect(await git.mergeMergeRequest({ token, id, number: request.number, options: { squash: true, deleteSourceBranch: true } })).toBe(false);
|
|
695
|
+
const files = await git.listFiles({ token, id, ref: 'main' });
|
|
696
|
+
expect(files).toContain('docs/a.md');
|
|
697
|
+
expect(files).toContain('docs/b.md');
|
|
698
|
+
expect((await git.getMergeRequest({ token, id, number: request.number })).state).toBe('merged');
|
|
699
|
+
expect((await git.listMergeRequests({ token, id, filter: { state: 'merged' } })).items.map((r) => r.number)).toEqual([request.number]);
|
|
700
|
+
await expect(git.getBranch({ token, id, branch: 'feature' })).rejects.toBeDefined();
|
|
701
|
+
});
|
|
702
|
+
});
|
|
703
|
+
it('undoes what it created on rollback, newest first', async () => {
|
|
704
|
+
const git = makeProvider();
|
|
705
|
+
const { repository } = await repoIn(git, { repoName: 'Gone' });
|
|
706
|
+
expect((await git.listRepositories({ token, topic: 'product' })).map((r) => r.id)).toContain(repository.id);
|
|
707
|
+
await git.rollback();
|
|
708
|
+
const left = await makeProvider().listRepositories({ token, topic: 'product' });
|
|
709
|
+
expect(left.map((r) => r.id)).not.toContain(repository.id);
|
|
710
|
+
});
|
|
711
|
+
});
|
|
712
|
+
};
|
|
713
|
+
//# sourceMappingURL=contract.js.map
|