File tree Expand file tree Collapse file tree 4 files changed +43
-0
lines changed
Expand file tree Collapse file tree 4 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ module.exports = function createReleasePR (config) {
1313 var template = fs . readFileSync ( templatePath , 'utf8' )
1414 var message = releaseMessage ( template , prs )
1515
16+ client . assignReviewers ( releasePR , prs )
1617 return client . updatePR ( releasePR , message )
1718 } )
1819 } )
Original file line number Diff line number Diff line change @@ -172,6 +172,17 @@ GithubClient.prototype.collectReleasePRs = function (releasePR) {
172172 } )
173173}
174174
175+ GithubClient . prototype . assignReviewers = function ( pr , prs ) {
176+ var reviewers = prs
177+ . map ( pr => pr . assignee ? pr . assignee : pr . user )
178+ . filter ( user => user . type === 'User' )
179+ . map ( user => user . login )
180+
181+ return this . post ( this . pullRequestEndpoint ( ) + '/' + pr . number + '/requested_reviewers' , { reviewers } ) . then ( function ( res ) {
182+ return res . body
183+ } )
184+ }
185+
175186GithubClient . prototype . updatePR = function ( pr , data ) {
176187 return this . patch ( this . pullRequestEndpoint ( ) + '/' + pr . number , data ) . then ( function ( res ) {
177188 return res . body
Original file line number Diff line number Diff line change @@ -163,6 +163,34 @@ describe('GithubClient', function () {
163163 } )
164164 } )
165165
166+ describe ( '#assignReviewers()' , function ( ) {
167+ const USER1 = 'pr1-owner'
168+ const USER2 = 'pr2-owner'
169+ const BOT = 'bot'
170+ nock ( 'https://api.github.com' )
171+ . post ( '/repos/uiureo/awesome-app/pulls/42/requested_reviewers' )
172+ . query ( true )
173+ . reply ( 200 , ( _ , requestBody ) => ( {
174+ requested_reviewers : requestBody . reviewers . map ( login => ( { login } ) )
175+ } ) )
176+
177+ it ( 'returns pr that has reviewers' , function ( done ) {
178+ const prs = [
179+ { assignee : { login : USER1 , type : 'User' } } ,
180+ { user : { login : USER2 , type : 'User' } } ,
181+ { user : { login : BOT , type : 'Bot' } }
182+ ]
183+ this . client . assignReviewers ( { number : 42 } , prs )
184+ . then ( function ( pr ) {
185+ assert ( pr . requested_reviewers . length === 2 )
186+ assert ( pr . requested_reviewers [ 0 ] . login === USER1 )
187+ assert ( pr . requested_reviewers [ 1 ] . login === USER2 )
188+
189+ done ( )
190+ } ) . catch ( done )
191+ } )
192+ } )
193+
166194 describe ( '#updatePR()' , function ( ) {
167195 nock ( 'https://api.github.com/' )
168196 . patch ( '/repos/uiureo/awesome-app/pulls/42' )
Original file line number Diff line number Diff line change @@ -16,6 +16,9 @@ function MockGithubClient () {
1616 } ,
1717 updatePR : function ( releasePR , message ) {
1818 return Promise . resolve ( { pr : releasePR , message : message } )
19+ } ,
20+ assignReviewers : function ( releasePR , prs ) {
21+ return Promise . resolve ( { requested_reviewers : [ ] } )
1922 }
2023 }
2124}
You can’t perform that action at this time.
0 commit comments