@@ -51,22 +51,21 @@ async function ssh() {
5151async function accessToken ( ) {
5252 let accessToken = core . getInput ( 'access-token' )
5353 let accessTokenUser = core . getInput ( 'access-token-user' )
54+ let tokenRepository = core . getInput ( 'access-token-repository' )
5455
55- if ( accessToken !== '' && accessTokenUser !== '' ) {
56- // Get git remote and convert to https
57- let { stdout} = execa . commandSync ( '/usr/bin/git config --get remote.origin.url' )
58- let remote = stdout . trim ( )
59- if ( remote . startsWith ( 'git@' ) ) {
56+ if ( accessToken !== '' && accessTokenUser !== '' && tokenRepository !== '' ) {
57+ // Convert to https if it's a git url
58+ if ( tokenRepository . startsWith ( 'git@' ) ) {
6059 // Example: git@github .com:owner/repo.git
61- remote = remote . replace ( / : / , '/' ) // Replace the colon with a slash
62- remote = remote . replace ( / ^ g i t @ / , 'https://' ) // Replace the git@ with https://
60+ tokenRepository = tokenRepository . replace ( / : / , '/' ) // Replace the colon with a slash
61+ tokenRepository = tokenRepository . replace ( / ^ g i t @ / , 'https://' ) // Replace the git@ with https://
6362 }
6463
6564 // Add access token to remote so https://user:token@github .com/owner/repo.git
66- remote = remote . replace ( / ^ h t t p s : \/ \/ / , `https://${ accessTokenUser } :${ accessToken } @` )
65+ tokenRepository = tokenRepository . replace ( / ^ h t t p s : \/ \/ / , `https://${ accessTokenUser } :${ accessToken } @` )
6766
68- // Set remote to new so it will use the token
69- execa . commandSync ( `/usr/bin/git remote set-url origin ${ remote } ` )
67+ // Set remote, so it will use the token, init is in case it isn't tracked
68+ execa . commandSync ( `/usr/bin/git init && /usr/bin/git remote set-url origin ${ tokenRepository } ` )
7069 }
7170}
7271
0 commit comments