Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/
# Default: true
ssh-strict: ''

# The user to use when connecting to the remote SSH host. By default 'git' is
# used.
ssh-user: ''

# Whether to configure the token or SSH key with the local git config
# Default: true
persist-credentials: ''
Expand Down
1 change: 1 addition & 0 deletions __test__/git-auth-helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,7 @@ async function setup(testName: string): Promise<void> {
sshKey: sshPath ? 'some ssh private key' : '',
sshKnownHosts: '',
sshStrict: true,
sshUser: '',
workflowOrganizationId: 123456,
setSafeDirectory: true,
githubServerUrl: githubServerUrl
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ inputs:
and `CheckHostIP=no` to the SSH command line. Use the input `ssh-known-hosts` to
configure additional hosts.
default: true
ssh-user:
description: >
The user to use when connecting to the remote SSH host. By default 'git' is used.
persist-credentials:
description: 'Whether to configure the token or SSH key with the local git config'
default: true
Expand Down
4 changes: 3 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1798,6 +1798,7 @@ function getInputs() {
result.sshKnownHosts = core.getInput('ssh-known-hosts');
result.sshStrict =
(core.getInput('ssh-strict') || 'true').toUpperCase() === 'TRUE';
result.sshUser = core.getInput('ssh-user');
// Persist credentials
result.persistCredentials =
(core.getInput('persist-credentials') || 'false').toUpperCase() === 'TRUE';
Expand Down Expand Up @@ -2400,7 +2401,8 @@ function getFetchUrl(settings) {
const encodedOwner = encodeURIComponent(settings.repositoryOwner);
const encodedName = encodeURIComponent(settings.repositoryName);
if (settings.sshKey) {
return `git@${serviceUrl.hostname}:${encodedOwner}/${encodedName}.git`;
let user = settings.sshUser.length > 0 ? settings.sshUser : 'git';
return `${user}@${serviceUrl.hostname}:${encodedOwner}/${encodedName}.git`;
}
// "origin" is SCHEME://HOSTNAME[:PORT]
return `${serviceUrl.origin}/${encodedOwner}/${encodedName}`;
Expand Down
5 changes: 5 additions & 0 deletions src/git-source-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ export interface IGitSourceSettings {
*/
sshStrict: boolean

/**
* The SSH user to login as
*/
sshUser: string

/**
* Indicates whether to persist the credentials on disk to enable scripting authenticated git commands
*/
Expand Down
1 change: 1 addition & 0 deletions src/input-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export async function getInputs(): Promise<IGitSourceSettings> {
result.sshKnownHosts = core.getInput('ssh-known-hosts')
result.sshStrict =
(core.getInput('ssh-strict') || 'true').toUpperCase() === 'TRUE'
result.sshUser = core.getInput('ssh-user')

// Persist credentials
result.persistCredentials =
Expand Down
3 changes: 2 additions & 1 deletion src/url-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export function getFetchUrl(settings: IGitSourceSettings): string {
const encodedOwner = encodeURIComponent(settings.repositoryOwner)
const encodedName = encodeURIComponent(settings.repositoryName)
if (settings.sshKey) {
return `git@${serviceUrl.hostname}:${encodedOwner}/${encodedName}.git`
let user = settings.sshUser.length > 0 ? settings.sshUser : 'git'
return `${user}@${serviceUrl.hostname}:${encodedOwner}/${encodedName}.git`
}

// "origin" is SCHEME://HOSTNAME[:PORT]
Expand Down