1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.parseSquashPR = exports.parsePR = void 0;
|
4 | const make_hooks_1 = require("./utils/make-hooks");
|
5 |
|
6 | function parsePR(commit) {
|
7 | const merge = /Merge pull request #(\d+) from (.+)\n([\S\s]+)/;
|
8 | const prMatch = commit.subject.match(merge);
|
9 | if (!prMatch) {
|
10 | return commit;
|
11 | }
|
12 | return Object.assign(Object.assign({}, commit), { pullRequest: {
|
13 | number: Number(prMatch[1]),
|
14 | base: prMatch[2],
|
15 | }, subject: prMatch[3].trim() });
|
16 | }
|
17 | exports.parsePR = parsePR;
|
18 |
|
19 | function parseSquashPR(commit) {
|
20 | const firstLine = commit.subject.split("\n")[0];
|
21 | const squashMerge = /\(#(\d+)\)$/;
|
22 | const squashMergeMatch = firstLine.match(squashMerge);
|
23 | if (!squashMergeMatch) {
|
24 | return commit;
|
25 | }
|
26 | return Object.assign(Object.assign({}, commit), { pullRequest: {
|
27 | number: Number(squashMergeMatch[1]),
|
28 | }, subject: firstLine
|
29 | .substr(0, firstLine.length - squashMergeMatch[0].length)
|
30 | .trim() });
|
31 | }
|
32 | exports.parseSquashPR = parseSquashPR;
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | class LogParse {
|
39 |
|
40 | constructor() {
|
41 | this.hooks = make_hooks_1.makeLogParseHooks();
|
42 | this.hooks.parseCommit.tap("Merge Commit", parsePR);
|
43 | this.hooks.parseCommit.tap("Squash Merge Commit", parseSquashPR);
|
44 | this.hooks.parseCommit.tap("Strip consecutive white-space in Titles", (commit) => {
|
45 | const [firstLine, ...lines] = commit.subject.split("\n");
|
46 | commit.subject = [
|
47 | firstLine.replace(/[^\S\r\n]{2,}/g, " "),
|
48 | ...lines,
|
49 | ].join("\n");
|
50 | return commit;
|
51 | });
|
52 | }
|
53 |
|
54 | async normalizeCommits(commits) {
|
55 | const eCommits = await Promise.all(commits.map(async (commit) => this.normalizeCommit(commit)));
|
56 | return eCommits.filter(Boolean);
|
57 | }
|
58 |
|
59 | async normalizeCommit(commit) {
|
60 | const extended = await this.hooks.parseCommit.promise(Object.assign(Object.assign({ labels: [] }, commit), { authors: [{ name: commit.authorName, email: commit.authorEmail }] }));
|
61 | const shouldOmit = await this.hooks.omitCommit.promise(extended);
|
62 | if (shouldOmit) {
|
63 | return;
|
64 | }
|
65 | return extended;
|
66 | }
|
67 | }
|
68 | exports.default = LogParse;
|
69 |
|
\ | No newline at end of file |