@@ -3,8 +3,12 @@ import * as fs from 'fs-extra';
3
3
import * as os from 'os' ;
4
4
import * as path from 'path' ;
5
5
import simpleGit from 'simple-git' ;
6
+
7
+ import { PRChange } from '../src/enums' ;
6
8
import { initRepo } from '../src/operations/init-repo' ;
7
9
import { setupRemotes } from '../src/operations/setup-remotes' ;
10
+ import { updateManualBackport } from '../src/operations/update-manual-backport' ;
11
+ import { tagBackportReviewers } from '../src/utils' ;
8
12
9
13
let dirObject : { dir ?: string } | null = null ;
10
14
@@ -13,6 +17,22 @@ const saveDir = (o: { dir: string }) => {
13
17
return o . dir ;
14
18
} ;
15
19
20
+ const backportPRClosedEvent = require ( './fixtures/backport_pull_request.closed.json' ) ;
21
+ const backportPRMergedEvent = require ( './fixtures/backport_pull_request.merged.json' ) ;
22
+ const backportPROpenedEvent = require ( './fixtures/backport_pull_request.opened.json' ) ;
23
+
24
+ jest . mock ( '../src/utils' , ( ) => ( {
25
+ tagBackportReviewers : jest . fn ( ) . mockReturnValue ( Promise . resolve ( ) ) ,
26
+ isSemverMinorPR : jest . fn ( ) . mockReturnValue ( false ) ,
27
+ } ) ) ;
28
+
29
+ jest . mock ( '../src/utils/label-utils' , ( ) => ( {
30
+ labelExistsOnPR : jest . fn ( ) . mockResolvedValue ( true ) ,
31
+ getSemverLabel : jest . fn ( ) . mockResolvedValue ( false ) ,
32
+ addLabels : jest . fn ( ) ,
33
+ removeLabel : jest . fn ( ) ,
34
+ } ) ) ;
35
+
16
36
describe ( 'runner' , ( ) => {
17
37
jest . setTimeout ( 30000 ) ;
18
38
console . error = jest . fn ( ) ;
@@ -101,4 +121,50 @@ describe('runner', () => {
101
121
}
102
122
} ) ;
103
123
} ) ;
124
+
125
+ describe ( 'updateManualBackport()' , ( ) => {
126
+ const octokit = {
127
+ pulls : {
128
+ get : jest . fn ( ) . mockReturnValue ( Promise . resolve ( { } ) ) ,
129
+ } ,
130
+ issues : {
131
+ createComment : jest . fn ( ) . mockReturnValue ( Promise . resolve ( { } ) ) ,
132
+ listComments : jest . fn ( ) . mockReturnValue ( Promise . resolve ( { data : [ ] } ) ) ,
133
+ } ,
134
+ } ;
135
+
136
+ it ( 'tags reviewers on manual backport creation' , async ( ) => {
137
+ const context = {
138
+ ...backportPROpenedEvent ,
139
+ octokit,
140
+ repo : jest . fn ( ) ,
141
+ } ;
142
+ await updateManualBackport ( context , PRChange . OPEN , 1234 ) ;
143
+ expect ( tagBackportReviewers ) . toHaveBeenCalled ( ) ;
144
+ expect ( tagBackportReviewers ) . toHaveBeenCalledWith ( {
145
+ context,
146
+ targetPrNumber : 7 ,
147
+ } ) ;
148
+ } ) ;
149
+
150
+ it ( 'does not tag reviewers on merged PRs' , async ( ) => {
151
+ const context = {
152
+ ...backportPRMergedEvent ,
153
+ octokit,
154
+ repo : jest . fn ( ) ,
155
+ } ;
156
+ await updateManualBackport ( context , PRChange . MERGE , 1234 ) ;
157
+ expect ( tagBackportReviewers ) . not . toHaveBeenCalled ( ) ;
158
+ } ) ;
159
+
160
+ it ( 'does not tag reviewers on closed PRs' , async ( ) => {
161
+ const context = {
162
+ ...backportPRClosedEvent ,
163
+ octokit,
164
+ repo : jest . fn ( ) ,
165
+ } ;
166
+ await updateManualBackport ( context , PRChange . CLOSE , 1234 ) ;
167
+ expect ( tagBackportReviewers ) . not . toHaveBeenCalled ( ) ;
168
+ } ) ;
169
+ } ) ;
104
170
} ) ;
0 commit comments