/
fail.test.js
186 lines (150 loc) · 7.52 KB
/
fail.test.js
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
const test = require('ava');
const nock = require('nock');
const {stub} = require('sinon');
const fail = require('../lib/fail');
const authenticate = require('./helpers/mock-gitlab');
/* eslint camelcase: ["error", {properties: "never"}] */
test.beforeEach(t => {
// Mock logger
t.context.log = stub();
t.context.error = stub();
t.context.logger = {log: t.context.log, error: t.context.error};
});
test.afterEach.always(() => {
// Clear nock
nock.cleanAll();
});
test.serial('Post new issue if none exists yet', async t => {
const owner = 'test_user';
const repo = 'test_repo';
const env = {GITLAB_TOKEN: 'gitlab_token'};
const pluginConfig = {};
const branch = {name: 'main'};
const options = {repositoryUrl: `https://gitlab.com/${owner}/${repo}.git`};
const errors = [{message: 'An error occured'}];
const encodedRepoId = encodeURIComponent(`${owner}/${repo}`);
const encodedFailTitle = encodeURIComponent('The automated release is failing 🚨');
const gitlab = authenticate(env)
.get(`/projects/${encodedRepoId}/issues?state=opened&&search=${encodedFailTitle}`)
.reply(200, [
{
id: 2,
iid: 2,
project_id: 1,
web_url: 'https://gitlab.com/test_user/test_repo/issues/2',
title: 'API should implemented authentication',
},
])
.post(`/projects/${encodedRepoId}/issues`, {
id: 'test_user%2Ftest_repo',
description: `## :rotating_light: The automated release from the \`main\` branch failed. :rotating_light:
I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.
You can find below the list of errors reported by **semantic-release**. Each one of them has to be resolved in order to automatically publish your package. I'm sure you can fix this 💪.
Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.
Once all the errors are resolved, **semantic-release** will release your package the next time you push a commit to the \`main\` branch. You can also manually restart the failed CI job that runs **semantic-release**.
If you are not sure how to resolve this, here are some links that can help you:
- [Usage documentation](https://github.com/semantic-release/semantic-release/blob/master/docs/usage/README.md)
- [Frequently Asked Questions](https://github.com/semantic-release/semantic-release/blob/master/docs/support/FAQ.md)
- [Support channels](https://github.com/semantic-release/semantic-release#get-help)
If those don't help, or if this issue is reporting something you think isn't right, you can always ask the humans behind **[semantic-release](https://github.com/semantic-release/semantic-release/issues/new)**.
---
### An error occured
Unfortunately this error doesn't have any additional information.
---
Good luck with your project ✨
Your **[semantic-release](https://github.com/semantic-release/semantic-release)** bot :package: :rocket:`,
labels: 'semantic-release',
title: 'The automated release is failing 🚨',
})
.reply(200);
await fail(pluginConfig, {env, options, branch, errors, logger: t.context.logger});
t.true(gitlab.isDone());
});
test.serial('Post comments to existing issue', async t => {
const owner = 'test_user';
const repo = 'test_repo';
const env = {GITLAB_TOKEN: 'gitlab_token'};
const pluginConfig = {};
const branch = {name: 'main'};
const options = {repositoryUrl: `https://gitlab.com/${owner}/${repo}.git`};
const errors = [{message: 'An error occured'}];
const encodedRepoId = encodeURIComponent(`${owner}/${repo}`);
const encodedFailTitle = encodeURIComponent('The automated release is failing 🚨');
const gitlab = authenticate(env)
.get(`/projects/${encodedRepoId}/issues?state=opened&search=${encodedFailTitle}`)
.reply(200, [
{
id: 1,
iid: 1,
project_id: 1,
web_url: 'https://gitlab.com/test_user%2Ftest_repo/issues/1',
title: 'The automated release is failing 🚨',
},
{
id: 2,
iid: 2,
project_id: 1,
web_url: 'https://gitlab.com/test_user%2Ftest_repo/issues/2',
title: 'API should implemented authentication',
},
])
.post(`/projects/1/issues/1/notes`, {
body: `## :rotating_light: The automated release from the \`main\` branch failed. :rotating_light:
I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.
You can find below the list of errors reported by **semantic-release**. Each one of them has to be resolved in order to automatically publish your package. I'm sure you can fix this 💪.
Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.
Once all the errors are resolved, **semantic-release** will release your package the next time you push a commit to the \`main\` branch. You can also manually restart the failed CI job that runs **semantic-release**.
If you are not sure how to resolve this, here are some links that can help you:
- [Usage documentation](https://github.com/semantic-release/semantic-release/blob/master/docs/usage/README.md)
- [Frequently Asked Questions](https://github.com/semantic-release/semantic-release/blob/master/docs/support/FAQ.md)
- [Support channels](https://github.com/semantic-release/semantic-release#get-help)
If those don't help, or if this issue is reporting something you think isn't right, you can always ask the humans behind **[semantic-release](https://github.com/semantic-release/semantic-release/issues/new)**.
---
### An error occured
Unfortunately this error doesn't have any additional information.
---
Good luck with your project ✨
Your **[semantic-release](https://github.com/semantic-release/semantic-release)** bot :package: :rocket:`,
})
.reply(200);
await fail(pluginConfig, {env, options, branch, errors, logger: t.context.logger});
t.true(gitlab.isDone());
});
test.serial('Post comments to existing issue with custom template', async t => {
const owner = 'test_user';
const repo = 'test_repo';
const env = {GITLAB_TOKEN: 'gitlab_token'};
const pluginConfig = {
failComment: `Error: Release for branch \${branch.name} failed with error: \${errors.map(error => error.message).join(';')}`,
failTitle: 'Semantic Release Failure',
};
const branch = {name: 'main'};
const options = {repositoryUrl: `https://gitlab.com/${owner}/${repo}.git`};
const errors = [{message: 'An error occured'}];
const encodedRepoId = encodeURIComponent(`${owner}/${repo}`);
const encodedFailTitle = encodeURIComponent('Semantic Release Failure');
const gitlab = authenticate(env)
.get(`/projects/${encodedRepoId}/issues?state=opened&search=${encodedFailTitle}`)
.reply(200, [
{
id: 1,
iid: 1,
project_id: 1,
web_url: 'https://gitlab.com/test_user%2Ftest_repo/issues/1',
title: 'Semantic Release Failure',
},
{
id: 2,
iid: 2,
project_id: 1,
web_url: 'https://gitlab.com/test_user%2Ftest_repo/issues/2',
title: 'API should implemented authentication',
},
])
.post(`/projects/1/issues/1/notes`, {
body: `Error: Release for branch main failed with error: An error occured`,
})
.reply(200);
await fail(pluginConfig, {env, options, branch, errors, logger: t.context.logger});
t.true(gitlab.isDone());
});