Skip to content

Commit 87a4b98

Browse files
committed
ci: added changesets
1 parent f1e79f0 commit 87a4b98

11 files changed

+1464
-636
lines changed

.changeset/changelog-github-custom.js

Lines changed: 380 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,380 @@
1+
'use strict';
2+
var __assign =
3+
(this && this.__assign) ||
4+
function () {
5+
__assign =
6+
Object.assign ||
7+
function (t) {
8+
for (var s, i = 1, n = arguments.length; i < n; i++) {
9+
s = arguments[i];
10+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
11+
}
12+
return t;
13+
};
14+
return __assign.apply(this, arguments);
15+
};
16+
var __awaiter =
17+
(this && this.__awaiter) ||
18+
function (thisArg, _arguments, P, generator) {
19+
function adopt(value) {
20+
return value instanceof P
21+
? value
22+
: new P(function (resolve) {
23+
resolve(value);
24+
});
25+
}
26+
return new (P || (P = Promise))(function (resolve, reject) {
27+
function fulfilled(value) {
28+
try {
29+
step(generator.next(value));
30+
} catch (e) {
31+
reject(e);
32+
}
33+
}
34+
function rejected(value) {
35+
try {
36+
step(generator['throw'](value));
37+
} catch (e) {
38+
reject(e);
39+
}
40+
}
41+
function step(result) {
42+
result.done
43+
? resolve(result.value)
44+
: adopt(result.value).then(fulfilled, rejected);
45+
}
46+
step((generator = generator.apply(thisArg, _arguments || [])).next());
47+
});
48+
};
49+
var __generator =
50+
(this && this.__generator) ||
51+
function (thisArg, body) {
52+
var _ = {
53+
label: 0,
54+
sent: function () {
55+
if (t[0] & 1) throw t[1];
56+
return t[1];
57+
},
58+
trys: [],
59+
ops: [],
60+
},
61+
f,
62+
y,
63+
t,
64+
g;
65+
return (
66+
(g = { next: verb(0), throw: verb(1), return: verb(2) }),
67+
typeof Symbol === 'function' &&
68+
(g[Symbol.iterator] = function () {
69+
return this;
70+
}),
71+
g
72+
);
73+
function verb(n) {
74+
return function (v) {
75+
return step([n, v]);
76+
};
77+
}
78+
function step(op) {
79+
if (f) throw new TypeError('Generator is already executing.');
80+
while ((g && ((g = 0), op[0] && (_ = 0)), _))
81+
try {
82+
if (
83+
((f = 1),
84+
y &&
85+
(t =
86+
op[0] & 2
87+
? y['return']
88+
: op[0]
89+
? y['throw'] || ((t = y['return']) && t.call(y), 0)
90+
: y.next) &&
91+
!(t = t.call(y, op[1])).done)
92+
)
93+
return t;
94+
if (((y = 0), t)) op = [op[0] & 2, t.value];
95+
switch (op[0]) {
96+
case 0:
97+
case 1:
98+
t = op;
99+
break;
100+
case 4:
101+
_.label++;
102+
return { value: op[1], done: false };
103+
case 5:
104+
_.label++;
105+
y = op[1];
106+
op = [0];
107+
continue;
108+
case 7:
109+
op = _.ops.pop();
110+
_.trys.pop();
111+
continue;
112+
default:
113+
if (
114+
!((t = _.trys), (t = t.length > 0 && t[t.length - 1])) &&
115+
(op[0] === 6 || op[0] === 2)
116+
) {
117+
_ = 0;
118+
continue;
119+
}
120+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
121+
_.label = op[1];
122+
break;
123+
}
124+
if (op[0] === 6 && _.label < t[1]) {
125+
_.label = t[1];
126+
t = op;
127+
break;
128+
}
129+
if (t && _.label < t[2]) {
130+
_.label = t[2];
131+
_.ops.push(op);
132+
break;
133+
}
134+
if (t[2]) _.ops.pop();
135+
_.trys.pop();
136+
continue;
137+
}
138+
op = body.call(thisArg, _);
139+
} catch (e) {
140+
op = [6, e];
141+
y = 0;
142+
} finally {
143+
f = t = 0;
144+
}
145+
if (op[0] & 5) throw op[1];
146+
return { value: op[0] ? op[1] : void 0, done: true };
147+
}
148+
};
149+
var __spreadArray =
150+
(this && this.__spreadArray) ||
151+
function (to, from, pack) {
152+
if (pack || arguments.length === 2)
153+
for (var i = 0, l = from.length, ar; i < l; i++) {
154+
if (ar || !(i in from)) {
155+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
156+
ar[i] = from[i];
157+
}
158+
}
159+
return to.concat(ar || Array.prototype.slice.call(from));
160+
};
161+
Object.defineProperty(exports, '__esModule', { value: true });
162+
// @ts-ignore
163+
var get_github_info_1 = require('@changesets/get-github-info');
164+
var dotenv_1 = require('dotenv');
165+
(0, dotenv_1.config)();
166+
var changelogFunctions = {
167+
getDependencyReleaseLine: function (changesets, dependenciesUpdated, options) {
168+
return __awaiter(void 0, void 0, void 0, function () {
169+
var changesetLink, _a, updatedDepenenciesList;
170+
return __generator(this, function (_b) {
171+
switch (_b.label) {
172+
case 0:
173+
if (!options.repo) {
174+
throw new Error(
175+
'Please provide a repo to this changelog generator like this:\n"changelog": ["@changesets/changelog-github", { "repo": "org/repo" }]',
176+
);
177+
}
178+
if (dependenciesUpdated.length === 0) return [2 /*return*/, ''];
179+
_a = '- Updated dependencies ['.concat;
180+
return [
181+
4 /*yield*/,
182+
Promise.all(
183+
changesets.map(function (cs) {
184+
return __awaiter(void 0, void 0, void 0, function () {
185+
var links;
186+
return __generator(this, function (_a) {
187+
switch (_a.label) {
188+
case 0:
189+
if (!cs.commit) return [3 /*break*/, 2];
190+
return [
191+
4 /*yield*/,
192+
(0, get_github_info_1.getInfo)({
193+
repo: options.repo,
194+
commit: cs.commit,
195+
}),
196+
];
197+
case 1:
198+
links = _a.sent().links;
199+
return [2 /*return*/, links.commit];
200+
case 2:
201+
return [2 /*return*/];
202+
}
203+
});
204+
});
205+
}),
206+
),
207+
];
208+
case 1:
209+
changesetLink = _a.apply('- Updated dependencies [', [
210+
_b
211+
.sent()
212+
.filter(function (_) {
213+
return _;
214+
})
215+
.join(', '),
216+
']:',
217+
]);
218+
updatedDepenenciesList = dependenciesUpdated.map(function (dependency) {
219+
return ' - '.concat(dependency.name, '@').concat(dependency.newVersion);
220+
});
221+
return [
222+
2 /*return*/,
223+
__spreadArray([changesetLink], updatedDepenenciesList, true).join('\n'),
224+
];
225+
}
226+
});
227+
});
228+
},
229+
getReleaseLine: function (changeset, type, options) {
230+
return __awaiter(void 0, void 0, void 0, function () {
231+
var prFromSummary,
232+
commitFromSummary,
233+
usersFromSummary,
234+
replacedChangelog,
235+
linkifyIssueHints,
236+
_a,
237+
firstLine,
238+
futureLines,
239+
links,
240+
users,
241+
suffix,
242+
emojiFirstline;
243+
return __generator(this, function (_b) {
244+
switch (_b.label) {
245+
case 0:
246+
if (!options || !options.repo) {
247+
throw new Error(
248+
'Please provide a repo to this changelog generator like this:\n"changelog": ["@changesets/changelog-github", { "repo": "org/repo" }]',
249+
);
250+
}
251+
usersFromSummary = [];
252+
replacedChangelog = changeset.summary
253+
.replace(/^\s*(?:pr|pull|pull\s+request):\s*#?(\d+)/im, function (_, pr) {
254+
var num = Number(pr);
255+
if (!isNaN(num)) prFromSummary = num;
256+
return '';
257+
})
258+
.replace(/^\s*commit:\s*([^\s]+)/im, function (_, commit) {
259+
commitFromSummary = commit;
260+
return '';
261+
})
262+
.replace(/^\s*(?:author|user):\s*@?([^\s]+)/gim, function (_, user) {
263+
usersFromSummary.push(user);
264+
return '';
265+
})
266+
.trim();
267+
linkifyIssueHints = function (line) {
268+
return line.replace(
269+
/(?<=\( ?(?:fix|fixes|see) )(#\d+)(?= ?\))/g,
270+
function (issueHash) {
271+
return '['
272+
.concat(issueHash, '](https://github.com/')
273+
.concat(options.repo, '/issues/')
274+
.concat(issueHash.substring(1), ')');
275+
},
276+
);
277+
};
278+
(_a = replacedChangelog.split('\n').map(function (l) {
279+
return linkifyIssueHints(l.trimEnd());
280+
})),
281+
(firstLine = _a[0]),
282+
(futureLines = _a.slice(1));
283+
return [
284+
4 /*yield*/,
285+
(function () {
286+
return __awaiter(void 0, void 0, void 0, function () {
287+
var links_1, shortCommitId, commitToFetchFrom, links_2;
288+
return __generator(this, function (_a) {
289+
switch (_a.label) {
290+
case 0:
291+
if (!(prFromSummary !== undefined)) return [3 /*break*/, 2];
292+
return [
293+
4 /*yield*/,
294+
(0, get_github_info_1.getInfoFromPullRequest)({
295+
repo: options.repo,
296+
pull: prFromSummary,
297+
}),
298+
];
299+
case 1:
300+
links_1 = _a.sent().links;
301+
if (commitFromSummary) {
302+
shortCommitId = commitFromSummary.slice(0, 7);
303+
links_1 = __assign(__assign({}, links_1), {
304+
commit: '[`'
305+
.concat(shortCommitId, '`](https://github.com/')
306+
.concat(options.repo, '/commit/')
307+
.concat(commitFromSummary, ')'),
308+
});
309+
}
310+
return [2 /*return*/, links_1];
311+
case 2:
312+
commitToFetchFrom = commitFromSummary || changeset.commit;
313+
if (!commitToFetchFrom) return [3 /*break*/, 4];
314+
return [
315+
4 /*yield*/,
316+
(0, get_github_info_1.getInfo)({
317+
repo: options.repo,
318+
commit: commitToFetchFrom,
319+
}),
320+
];
321+
case 3:
322+
links_2 = _a.sent().links;
323+
return [2 /*return*/, links_2];
324+
case 4:
325+
return [
326+
2 /*return*/,
327+
{
328+
commit: null,
329+
pull: null,
330+
user: null,
331+
},
332+
];
333+
}
334+
});
335+
});
336+
})(),
337+
];
338+
case 1:
339+
links = _b.sent();
340+
users = usersFromSummary.length
341+
? usersFromSummary
342+
.map(function (userFromSummary) {
343+
return '[@'
344+
.concat(userFromSummary, '](https://github.com/')
345+
.concat(userFromSummary, ')');
346+
})
347+
.join(', ')
348+
: links.user;
349+
suffix = '';
350+
if (links.pull || links.commit || users) {
351+
suffix = '('
352+
.concat(users ? 'by '.concat(users, ' ') : '', 'in ')
353+
.concat(links.pull || links.commit, ')');
354+
}
355+
emojiFirstline = firstLine
356+
.replace('FEAT:', '✨ ')
357+
.replace('feat:', '✨ ')
358+
.replace('fix:', '🐞🩹')
359+
.replace('FIX:', '🐞🩹')
360+
.replace('DOCS:', '📃')
361+
.replace('docs:', '📃');
362+
return [
363+
2 /*return*/,
364+
'\n\n- '
365+
.concat(emojiFirstline, ' ')
366+
.concat(suffix, '\n')
367+
.concat(
368+
futureLines
369+
.map(function (l) {
370+
return ' '.concat(l);
371+
})
372+
.join('\n'),
373+
),
374+
];
375+
}
376+
});
377+
});
378+
},
379+
};
380+
exports.default = changelogFunctions;

0 commit comments

Comments
 (0)