@@ -114,7 +114,7 @@ function isConfig(config: any): config is Config {
114114
115115 if ( RUN_ALL ) {
116116
117- /*
117+ /*
118118 * There are a few different ways in which we may determine which queries
119119 * are currently interesting to the user, in decreasing usefulness:
120120 *
@@ -134,6 +134,22 @@ function isConfig(config: any): config is Config {
134134 * unableToGetChangedQueries to true.
135135 */
136136
137+ /*
138+ * Before we can run `git fetch` in the CWD,
139+ * we need to add a new remote that we're authenticated with
140+ */
141+ /**
142+ * The name we'll use for our new remote,
143+ * something that's reasonably unique.
144+ * Though we will delete this remote later.
145+ */
146+ const remoteName = event . after ;
147+ console . log ( `Adding remote ${ remoteName } ` ) ;
148+ await execFile ( 'git' , [
149+ 'remote' , 'add' , remoteName ,
150+ `https://x-access-token:${ GITHUB_TOKEN } @github.com/${ event . repository . full_name } .git`
151+ ] ) ;
152+
137153 /**
138154 * The output from a successful call to `git diff --name-only`
139155 */
@@ -160,11 +176,14 @@ function isConfig(config: any): config is Config {
160176 const pr = pulls . data [ 0 ] ;
161177 const baseBranch = pr . base . ref ;
162178 // Ensure we have the commits from that ref
163- await execFile ( 'git' , [ 'fetch' , 'origin' , baseBranch ] ) ;
179+ await execFile ( 'git' , [ 'fetch' , remoteName , baseBranch ] ) ;
180+ const baseSha = await ( await execFile (
181+ 'git' , [ 'rev-parse' , `refs/remotes/${ remoteName } /${ baseBranch } ` ]
182+ ) ) . stdout . trim ( ) ;
164183 diff = {
165- baseSha : baseBranch ,
184+ baseSha,
166185 filesChangedRaw : ( await execFile (
167- 'git' , [ 'diff' , '--name-only' , `origin/ ${ baseBranch } ..${ event . after } ` ]
186+ 'git' , [ 'diff' , '--name-only' , `${ baseSha } ..${ event . after } ` ]
168187 ) ) . stdout
169188 }
170189 } else {
@@ -202,8 +221,9 @@ function isConfig(config: any): config is Config {
202221
203222 if ( ! diff ) {
204223 try {
224+ await execFile ( 'git' , [ 'fetch' , remoteName , 'HEAD' ] ) ;
205225 const defaultBranchSha = await ( await execFile (
206- 'git' , [ 'rev-parse' , ' refs/remotes/origin /HEAD' ]
226+ 'git' , [ 'rev-parse' , ` refs/remotes/${ remoteName } /HEAD` ]
207227 ) ) . stdout . trim ( ) ;
208228 const result = await execFile (
209229 'git' , [ 'diff' , '--name-only' , `${ defaultBranchSha } ..${ event . after } ` ]
@@ -219,6 +239,9 @@ function isConfig(config: any): config is Config {
219239 }
220240 }
221241
242+ console . log ( `Removing remote ${ remoteName } ` ) ;
243+ await execFile ( 'git' , [ 'remote' , 'remove' , remoteName ] ) ;
244+
222245 if ( ! diff ) {
223246 unableToGetChangedQueries = true ;
224247 } else {
0 commit comments