forked from pascalgn/automerge-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmerge.test.js
111 lines (94 loc) · 2.61 KB
/
merge.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
const { merge } = require("../lib/merge");
const { createConfig } = require("../lib/common");
const { pullRequest } = require("./common");
let octokit;
beforeEach(() => {
octokit = {
pulls: {
merge: jest.fn()
}
};
});
test("MERGE_COMMIT_MESSAGE_REGEX can be used to cut PR body", async () => {
// GIVEN
const pr = pullRequest();
pr.body = [
"PSA: This is the meaty part of the PR body.",
"It also matches newlines.",
"",
"----",
"",
"Here is a silly license agreement."
].join("\n");
const config = createConfig({
MERGE_COMMIT_MESSAGE: "pull-request-title-and-description",
MERGE_COMMIT_MESSAGE_REGEX: "PSA:(.*)^----"
});
// WHEN
expect(await merge({ config, octokit }, pr)).toEqual(true);
// THEN
expect(octokit.pulls.merge).toHaveBeenCalledWith(
expect.objectContaining({
commit_title:
"Update README\n\nThis is the meaty part of the PR body.\nIt also matches newlines.",
commit_message: "",
pull_number: 1,
repo: "repository",
sha: "2c3b4d5"
})
);
});
test("Throw if MERGE_COMMIT_MESSAGE_REGEX is invalid", async () => {
// GIVEN
const pr = pullRequest();
const config = createConfig({
MERGE_COMMIT_MESSAGE: "pull-request-title-and-description",
MERGE_COMMIT_MESSAGE_REGEX: ".*"
});
// WHEN
expect(merge({ config, octokit }, pr)).rejects.toThrow("capturing subgroup");
});
test("MERGE_FILTER_AUTHOR can be used to auto merge based on author", async () => {
// GIVEN
const pr = pullRequest();
const author = "minime";
const user = {
login: author
};
pr.user = user;
const config = createConfig({
MERGE_COMMIT_MESSAGE: "pull-request-title-and-description",
MERGE_FILTER_AUTHOR: author
});
// WHEN
expect(await merge({ config, octokit }, pr)).toEqual(true);
});
test("MERGE_FILTER_AUTHOR when not set should not affect anything", async () => {
// GIVEN
const pr = pullRequest();
const author = "minime";
const user = {
login: author
};
pr.user = user;
const config = createConfig({
MERGE_COMMIT_MESSAGE: "pull-request-title-and-description"
});
// WHEN
expect(await merge({ config, octokit }, pr)).toEqual(true);
});
test("MERGE_FILTER_AUTHOR when set but do not match current author should not merge", async () => {
// GIVEN
const pr = pullRequest();
const author = "notminime";
const user = {
login: author
};
pr.user = user;
const config = createConfig({
MERGE_COMMIT_MESSAGE: "pull-request-title-and-description",
MERGE_FILTER_AUTHOR: "minime"
});
// WHEN
expect(await merge({ config, octokit }, pr)).toEqual(false);
});