@@ -25,11 +25,11 @@ module.exports = class Pull {
2525 if ( base . toLowerCase ( ) === upstream . toLowerCase ( ) . replace ( `${ this . config . owner . toLowerCase ( ) } :` , '' ) ) {
2626 this . logger . debug ( `[${ this . config . repoPath } ] ${ base } is same as ${ upstream } ` )
2727 } else if ( ! ( await this . hasDiff ( base , upstream ) ) ) {
28- this . logger . info ( `[${ this . config . repoPath } ] ${ base } is in sync with ${ upstream } ` )
28+ this . logger . debug ( `[${ this . config . repoPath } ] ${ base } is in sync with ${ upstream } ` )
2929 } else {
3030 const openPR = await this . getOpenPR ( base ) // Get one PR opened by app/pull
3131 if ( openPR ) {
32- this . logger . info ( `[${ this . config . repoPath } ] Found a PR from ${ upstream } to ${ base } ` )
32+ this . logger . debug ( `[${ this . config . repoPath } ] Found a PR from ${ upstream } to ${ base } ` )
3333 await this . checkAutoMerge ( openPR )
3434 } else {
3535 this . logger . info ( `[${ this . config . repoPath } ] Creating PR from ${ upstream } to ${ base } ` )
@@ -60,8 +60,8 @@ module.exports = class Pull {
6060 await this . hardResetCommit ( incomingPR . base . ref , incomingPR . head . sha )
6161 this . logger . info ( `[${ this . config . repoPath } ]#${ prNumber } Hard reset successful` )
6262 return true
63- } catch ( _ ) {
64- this . logger . debug ( `[${ this . config . repoPath } ]#${ prNumber } Hard reset failed` )
63+ } catch ( error ) {
64+ this . logger . warn ( { error } , `[${ this . config . repoPath } ]#${ prNumber } Hard reset failed` )
6565 }
6666 } else {
6767 const mergable = incomingPR . mergeable_state === 'clean' ||
@@ -80,20 +80,39 @@ module.exports = class Pull {
8080 }
8181
8282 async hasDiff ( base , upstream ) {
83- const comparison = await this . github . repos . compareCommits ( {
84- owner : this . config . owner ,
85- repo : this . config . repo ,
86- head : upstream ,
87- base
88- } )
89- return comparison . data . total_commits > 0
83+ try {
84+ const comparison = await this . github . repos . compareCommits ( {
85+ owner : this . config . owner ,
86+ repo : this . config . repo ,
87+ head : upstream ,
88+ base
89+ } )
90+ return comparison . data . total_commits > 0
91+ } catch ( ex ) {
92+ if ( ex . message . match ( / t h i s d i f f i s t a k i n g t o o l o n g t o g e n e r a t e / i) ) {
93+ return true
94+ } else if ( ex . message . match ( / n o t f o u n d / i) ) {
95+ this . logger . debug ( `[${ this . config . repoPath } ] ${ this . config . owner } :${ this . config . base } ...${ upstream } Not found` )
96+ return false
97+ } else if ( ex . message . match ( / n o c o m m o n a n c e s t o r / i) ) {
98+ this . logger . debug ( `[${ this . config . repoPath } ] ${ this . config . owner } :${ this . config . base } ...${ upstream } No common ancestor` )
99+ return false
100+ } else {
101+ this . logger . warn ( {
102+ err : ex ,
103+ owner : this . config . owner ,
104+ repo : this . config . repo ,
105+ head : upstream
106+ } , `[${ this . config . repoPath } ] Unable to fetch diff` )
107+ return false
108+ }
109+ }
90110 }
91111
92112 async getOpenPR ( base ) {
93113 const res = await this . github . search . issues ( {
94114 q : `repo:${ this . config . repoPath } type:pr is:open base:${ base } author:app/pull` ,
95- per_page : 1 ,
96- page : 1
115+ per_page : 1
97116 } )
98117 if ( res . data . total_count > 0 ) {
99118 const pr = await this . github . pullRequests . get ( {
@@ -132,7 +151,7 @@ module.exports = class Pull {
132151
133152 await this . addReviewers ( prNumber , reviewers )
134153
135- this . logger . info ( `[${ this . config . repoPath } ]#${ prNumber } Updated pull request` )
154+ this . logger . debug ( `[${ this . config . repoPath } ]#${ prNumber } Updated pull request` )
136155 }
137156
138157 async isMergeable ( number , config = { } ) {
0 commit comments