1
1
import * as child_process from 'child_process'
2
2
import * as fs from 'fs' ;
3
3
import * as path from 'path' ;
4
+ import { homedir } from 'os' ;
4
5
import { promisify } from 'util' ;
5
6
import * as core from '@actions/core' ;
6
7
import Octokit from '@octokit/rest' ;
@@ -14,6 +15,7 @@ const access = promisify(fs.access);
14
15
const execFile = promisify ( child_process . execFile ) ;
15
16
const mkdir = promisify ( fs . mkdir ) ;
16
17
const readFile = promisify ( fs . readFile ) ;
18
+ const writeFile = promisify ( fs . writeFile ) ;
17
19
18
20
/**
19
21
* Must be "true" if all queries should be run (and not just changed queries)
@@ -136,19 +138,13 @@ function isConfig(config: any): config is Config {
136
138
137
139
/*
138
140
* Before we can run `git fetch` in the CWD,
139
- * we need to add a new remote that we're authenticated with
141
+ * we need to add the authentication details for the remote for https
140
142
*/
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
- ] ) ;
143
+ await execFile ( 'git' , [ 'config' , '--global' , 'credential.helper' , 'store' ] ) ;
144
+ // Write the required information to ~/.git-credentials
145
+ const credentials = `https://x-access-token:${ GITHUB_TOKEN } @github.com` ;
146
+ const credentialsPath = path . join ( homedir ( ) , '.git-credentials' ) ;
147
+ await writeFile ( credentialsPath , credentials ) ;
152
148
153
149
/**
154
150
* The output from a successful call to `git diff --name-only`
@@ -176,9 +172,9 @@ function isConfig(config: any): config is Config {
176
172
const pr = pulls . data [ 0 ] ;
177
173
const baseBranch = pr . base . ref ;
178
174
// Ensure we have the commits from that ref
179
- await execFile ( 'git' , [ 'fetch' , remoteName , baseBranch ] ) ;
175
+ await execFile ( 'git' , [ 'fetch' , 'origin' , baseBranch ] ) ;
180
176
const baseSha = await ( await execFile (
181
- 'git' , [ 'rev-parse' , `refs/remotes/${ remoteName } /${ baseBranch } ` ]
177
+ 'git' , [ 'rev-parse' , `refs/remotes/origin /${ baseBranch } ` ]
182
178
) ) . stdout . trim ( ) ;
183
179
diff = {
184
180
baseSha,
@@ -221,9 +217,9 @@ function isConfig(config: any): config is Config {
221
217
222
218
if ( ! diff ) {
223
219
try {
224
- await execFile ( 'git' , [ 'fetch' , remoteName , 'HEAD' ] ) ;
220
+ await execFile ( 'git' , [ 'fetch' , 'origin' , 'HEAD' ] ) ;
225
221
const defaultBranchSha = await ( await execFile (
226
- 'git' , [ 'rev-parse' , `refs/remotes/${ remoteName } /HEAD` ]
222
+ 'git' , [ 'rev-parse' , `refs/remotes/origin /HEAD` ]
227
223
) ) . stdout . trim ( ) ;
228
224
const result = await execFile (
229
225
'git' , [ 'diff' , '--name-only' , `${ defaultBranchSha } ..${ event . after } ` ]
@@ -239,9 +235,6 @@ function isConfig(config: any): config is Config {
239
235
}
240
236
}
241
237
242
- console . log ( `Removing remote ${ remoteName } ` ) ;
243
- await execFile ( 'git' , [ 'remote' , 'remove' , remoteName ] ) ;
244
-
245
238
if ( ! diff ) {
246
239
unableToGetChangedQueries = true ;
247
240
} else {
0 commit comments