1
0
Fork 0
mirror of https://code.forgejo.org/actions/checkout.git synced 2025-08-15 01:40:50 +00:00
This commit is contained in:
Nicolas Schweitzer 2025-08-13 09:00:27 -05:00 committed by GitHub
commit 79d27f71d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 87 additions and 20 deletions

View file

@ -274,6 +274,23 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
settings.commit,
settings.githubServerUrl
)
if (settings.gitUser) {
if (!(await git.configExists('user.name', true))) {
await git.config('user.name', settings.gitUser, true)
}
if (!(await git.configExists('user.email', true))) {
const userId = await githubApiHelper.getUserId(
settings.gitUser,
settings.authToken,
settings.githubServerUrl
)
await git.config(
'user.email',
`${userId}+${settings.gitUser}@users.noreply.github.com`,
true
)
}
}
} finally {
// Remove auth
if (authHelper) {

View file

@ -79,6 +79,11 @@ export interface IGitSourceSettings {
*/
authToken: string
/**
* A github user slug to set a default user name and email in the local git config
*/
gitUser: string
/**
* The SSH key to configure
*/

View file

@ -143,3 +143,15 @@ async function downloadArchive(
})
return Buffer.from(response.data as ArrayBuffer) // response.data is ArrayBuffer
}
export async function getUserId(
username: string,
authToken: string,
baseUrl?: string
): Promise<number> {
const octokit = github.getOctokit(authToken, {
baseUrl: getServerApiUrl(baseUrl)
})
const user = await octokit.rest.users.getByUsername({username})
return user.data.id
}

View file

@ -138,6 +138,9 @@ export async function getInputs(): Promise<IGitSourceSettings> {
// Auth token
result.authToken = core.getInput('token', {required: true})
// Git user
result.gitUser = core.getInput('git-user') || 'github-action[bot]'
// SSH
result.sshKey = core.getInput('ssh-key')
result.sshKnownHosts = core.getInput('ssh-known-hosts')