@@ -2,14 +2,14 @@ import * as React from 'react';
22import { PullRequest } from './cache' ;
33import PullRequestContext from './context' ;
44import { useContext , useReducer , useRef , useState , useEffect , useCallback } from 'react' ;
5- import { PullRequestStateEnum , MergeMethod } from '../src/github/interface' ;
5+ import { PullRequestStateEnum , MergeMethod , PullRequestMergeability } from '../src/github/interface' ;
66import { checkIcon , deleteIcon , pendingIcon , alertIcon } from './icon' ;
77import { Avatar , } from './user' ;
88import { nbsp } from './space' ;
99import { groupBy } from '../src/common/utils' ;
1010
1111export const StatusChecks = ( pr : PullRequest ) => {
12- const { state, status, mergeable } = pr ;
12+ const { state, status, mergeable : _mergeable } = pr ;
1313 const [ showDetails , toggleDetails ] = useReducer (
1414 show => ! show ,
1515 status . statuses . some ( s => s . state === 'failure' ) ) as [ boolean , ( ) => void ] ;
@@ -22,6 +22,18 @@ export const StatusChecks = (pr: PullRequest) => {
2222 }
2323 } , status . statuses ) ;
2424
25+ const [ mergeable , setMergeability ] = useState ( _mergeable ) ;
26+ const { checkMergeability } = useContext ( PullRequestContext ) ;
27+
28+ useEffect ( ( ) => {
29+ const handle = setInterval ( async ( ) => {
30+ if ( mergeable === PullRequestMergeability . Unknown ) {
31+ setMergeability ( await checkMergeability ( ) ) ;
32+ }
33+ } , 3000 ) ;
34+ return ( ) => clearInterval ( handle ) ;
35+ } ) ;
36+
2537 return < div id = 'status-checks' > {
2638 state === PullRequestStateEnum . Merged
2739 ?
@@ -56,22 +68,26 @@ export const StatusChecks = (pr: PullRequest) => {
5668 : null
5769 }
5870 < MergeStatus mergeable = { mergeable } />
59- < PrActions { ...pr } />
71+ < PrActions { ...{ ... pr , mergeable } } />
6072 </ >
6173 } </ div > ;
6274} ;
6375
6476export default StatusChecks ;
6577
66- export const MergeStatus = ( { mergeable } : Pick < PullRequest , 'mergeable' > ) =>
67- < div className = 'status-item status-section' >
68- { mergeable ? checkIcon : deleteIcon }
78+ export const MergeStatus = ( { mergeable } : Pick < PullRequest , 'mergeable' > ) => {
79+ return < div className = 'status-item status-section' >
80+ { mergeable === PullRequestMergeability . Mergeable ? checkIcon :
81+ mergeable === PullRequestMergeability . NotMergeable ? deleteIcon : pendingIcon }
6982 < div > {
70- mergeable
83+ mergeable === PullRequestMergeability . Mergeable
7184 ? 'This branch has no conflicts with the base branch'
72- : 'This branch has conflicts that must be resolved'
85+ : mergeable === PullRequestMergeability . NotMergeable
86+ ? 'This branch has conflicts that must be resolved'
87+ : 'Checking if this branch can be merged...'
7388 } </ div >
7489 </ div > ;
90+ } ;
7591
7692export const ReadyForReview = ( ) => {
7793 const [ isBusy , setBusy ] = useState ( false ) ;
@@ -120,7 +136,7 @@ export const PrActions = (pr: PullRequest) => {
120136 ? hasWritePermission || canEdit
121137 ? < ReadyForReview />
122138 : null
123- : mergeable && hasWritePermission
139+ : mergeable === PullRequestMergeability . Mergeable && hasWritePermission
124140 ? < Merge { ...pr } />
125141 : null ;
126142} ;
0 commit comments