-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathpull-request-handler.test.ts
More file actions
127 lines (112 loc) · 3.45 KB
/
pull-request-handler.test.ts
File metadata and controls
127 lines (112 loc) · 3.45 KB
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
import { resolvePullRequestCheckoutRef } from '@/lib/integrations/platforms/github/webhook-handlers/pull-request-checkout-ref';
import { shouldSkipSynchronizeForMergeCommit } from '@/lib/integrations/platforms/github/webhook-handlers/pull-request-handler';
describe('resolvePullRequestCheckoutRef', () => {
it('uses head.ref for same-repo PRs', () => {
const result = resolvePullRequestCheckoutRef({
pull_request: {
number: 123,
head: {
ref: 'feature/same-repo',
repo: { full_name: 'acme/widgets' },
},
},
repository: {
full_name: 'acme/widgets',
},
});
expect(result).toEqual({
checkoutRef: 'feature/same-repo',
isForkPr: false,
headRepoFullName: 'acme/widgets',
});
});
it('uses refs/pull/<number>/head for fork PRs', () => {
const result = resolvePullRequestCheckoutRef({
pull_request: {
number: 456,
head: {
ref: 'feature/fork-branch',
repo: { full_name: 'external/widgets-fork' },
},
},
repository: {
full_name: 'acme/widgets',
},
});
expect(result).toEqual({
checkoutRef: 'refs/pull/456/head',
isForkPr: true,
headRepoFullName: 'external/widgets-fork',
});
});
it('falls back to head.ref when head.repo is missing', () => {
const result = resolvePullRequestCheckoutRef({
pull_request: {
number: 789,
head: {
ref: 'feature/missing-head-repo',
},
},
repository: {
full_name: 'acme/widgets',
},
});
expect(result).toEqual({
checkoutRef: 'feature/missing-head-repo',
isForkPr: false,
headRepoFullName: null,
});
});
});
describe('shouldSkipSynchronizeForMergeCommit', () => {
const baseArgs = {
installationId: 'inst-1',
headOwner: 'acme',
headRepoName: 'widgets',
headSha: 'deadbeef',
appType: 'standard' as const,
};
it('returns false for non-synchronize actions without calling the check', async () => {
for (const action of ['opened', 'reopened', 'ready_for_review']) {
let called = false;
const result = await shouldSkipSynchronizeForMergeCommit({
...baseArgs,
action,
isMergeCommitFn: async () => {
called = true;
return true;
},
});
expect(result).toBe(false);
expect(called).toBe(false);
}
});
it('returns true when synchronize head is a merge commit', async () => {
const result = await shouldSkipSynchronizeForMergeCommit({
...baseArgs,
action: 'synchronize',
isMergeCommitFn: async () => true,
});
expect(result).toBe(true);
});
it('returns false when synchronize head is not a merge commit', async () => {
const result = await shouldSkipSynchronizeForMergeCommit({
...baseArgs,
action: 'synchronize',
isMergeCommitFn: async () => false,
});
expect(result).toBe(false);
});
it('passes the expected arguments to the check function', async () => {
const calls: Array<[string, string, string, string, string]> = [];
await shouldSkipSynchronizeForMergeCommit({
...baseArgs,
action: 'synchronize',
isMergeCommitFn: async (installationId, owner, repo, sha, appType) => {
calls.push([installationId, owner, repo, sha, appType]);
return false;
},
});
expect(calls).toEqual([['inst-1', 'acme', 'widgets', 'deadbeef', 'standard']]);
});
});