@@ -114,7 +114,7 @@ function isConfig(config: any): config is Config {
114
114
115
115
if ( RUN_ALL ) {
116
116
117
- /*
117
+ /*
118
118
* There are a few different ways in which we may determine which queries
119
119
* are currently interesting to the user, in decreasing usefulness:
120
120
*
@@ -134,6 +134,22 @@ function isConfig(config: any): config is Config {
134
134
* unableToGetChangedQueries to true.
135
135
*/
136
136
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
+
137
153
/**
138
154
* The output from a successful call to `git diff --name-only`
139
155
*/
@@ -160,11 +176,14 @@ function isConfig(config: any): config is Config {
160
176
const pr = pulls . data [ 0 ] ;
161
177
const baseBranch = pr . base . ref ;
162
178
// 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 ( ) ;
164
183
diff = {
165
- baseSha : baseBranch ,
184
+ baseSha,
166
185
filesChangedRaw : ( await execFile (
167
- 'git' , [ 'diff' , '--name-only' , `origin/ ${ baseBranch } ..${ event . after } ` ]
186
+ 'git' , [ 'diff' , '--name-only' , `${ baseSha } ..${ event . after } ` ]
168
187
) ) . stdout
169
188
}
170
189
} else {
@@ -202,8 +221,9 @@ function isConfig(config: any): config is Config {
202
221
203
222
if ( ! diff ) {
204
223
try {
224
+ await execFile ( 'git' , [ 'fetch' , remoteName , 'HEAD' ] ) ;
205
225
const defaultBranchSha = await ( await execFile (
206
- 'git' , [ 'rev-parse' , ' refs/remotes/origin /HEAD' ]
226
+ 'git' , [ 'rev-parse' , ` refs/remotes/${ remoteName } /HEAD` ]
207
227
) ) . stdout . trim ( ) ;
208
228
const result = await execFile (
209
229
'git' , [ 'diff' , '--name-only' , `${ defaultBranchSha } ..${ event . after } ` ]
@@ -219,6 +239,9 @@ function isConfig(config: any): config is Config {
219
239
}
220
240
}
221
241
242
+ console . log ( `Removing remote ${ remoteName } ` ) ;
243
+ await execFile ( 'git' , [ 'remote' , 'remove' , remoteName ] ) ;
244
+
222
245
if ( ! diff ) {
223
246
unableToGetChangedQueries = true ;
224
247
} else {
0 commit comments