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