mirror of
https://code.forgejo.org/actions/checkout.git
synced 2025-08-15 01:40:50 +00:00
Merge ab5d862ce8
into ff7abcd0c3
This commit is contained in:
commit
79d27f71d3
13 changed files with 87 additions and 20 deletions
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue