@@ -13,7 +13,8 @@ export interface Project extends Github.ProjectsListForRepoResponseItem {}
1313export interface Column extends Github . ProjectsListColumnsResponseItem { }
1414export interface Card extends Github . ProjectsListCardsResponseItem { }
1515export interface Pull extends Github . PullsGetResponse {
16- approved ?: boolean ;
16+ approvedByMe ?: boolean ;
17+ approvedByAll ?: boolean ;
1718}
1819
1920export interface GetPullSuccessResult {
@@ -124,9 +125,9 @@ export class ProjectService<K extends string = "Check and Merge" | "Review"> {
124125 ...this . _ownerAndRepo ,
125126 pull_number : pull . number
126127 } ) ;
127- const review = reviews . data ?. find ( review => review . user . id === id ) ;
128- const approved = review ?. state === "APPROVED" ;
129- return { error : false , pull : { ...pull , approved } , labels } ;
128+ const approvedByAll = ( reviews . data ?. length > 0 && reviews . data . every ( review => review . state === "APPROVED" ) ) ?? false ;
129+ const approvedByMe = reviews . data ?. some ( review => review . user . id === id && review . state === "APPROVED" ) ?? false ;
130+ return { error : false , pull : { ...pull , approvedByMe , approvedByAll } , labels } ;
130131 }
131132
132133 async whoAmiI ( ) : Promise < number | undefined > {
@@ -140,19 +141,39 @@ export class ProjectService<K extends string = "Check and Merge" | "Review"> {
140141 return this . _userId ;
141142 }
142143
143- async approvePull ( pull : Pull ) : Promise < void > {
144- const auth = await this . _github . users . getAuthenticated ( ) ;
145- if ( ! auth . data ) {
146- return ;
144+ async isApprovedByAll ( pull : Pull ) : Promise < boolean > {
145+ const reviews = await this . _github . pulls . listReviews ( { ...this . _ownerAndRepo , pull_number : pull . number } ) ;
146+ let wasApproved = false ;
147+ if ( reviews . data ) {
148+ for ( const review of reviews . data ) {
149+ if ( review . state === "APPROVED" ) {
150+ wasApproved = true ;
151+ }
152+ else {
153+ return false ;
154+ }
155+ }
147156 }
157+ return wasApproved ;
158+ }
148159
149- const id = auth . data . id ;
160+ async isApprovedByMe ( pull : Pull ) : Promise < boolean > {
161+ const id = await this . whoAmiI ( ) ;
150162 const reviews = await this . _github . pulls . listReviews ( { ...this . _ownerAndRepo , pull_number : pull . number } ) ;
151163 if ( reviews . data ) {
152164 for ( const review of reviews . data ) {
153- if ( review . user . id === id && review . state === "APPROVED" ) return ;
165+ if ( review . state === "APPROVED" && review . user . id === id ) {
166+ return true ;
167+ }
154168 }
155169 }
170+ return false ;
171+ }
172+
173+ async approvePull ( pull : Pull ) : Promise < void > {
174+ if ( await this . isApprovedByMe ( pull ) ) {
175+ return ;
176+ }
156177
157178 const review = await this . _github . pulls . createReview ( {
158179 ...this . _ownerAndRepo ,
@@ -167,7 +188,8 @@ export class ProjectService<K extends string = "Check and Merge" | "Review"> {
167188 review_id : review . data . id
168189 } ) ;
169190
170- pull . approved = true ;
191+ pull . approvedByMe = await this . isApprovedByMe ( pull ) ;
192+ pull . approvedByAll = await this . isApprovedByAll ( pull ) ;
171193 }
172194
173195 async mergePull ( pull : Pull , method ?: "merge" | "squash" | "rebase" ) : Promise < void > {
0 commit comments