mirror of
https://code.forgejo.org/actions/checkout.git
synced 2025-04-21 09:10:16 +03:00
codereview: define a git-user slug instead of a true/false config
This commit is contained in:
parent
f3b199b7ed
commit
5fba9eb899
7 changed files with 32 additions and 14 deletions
|
@ -274,12 +274,14 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
|
|||
settings.commit,
|
||||
settings.githubServerUrl
|
||||
)
|
||||
if (settings.configureUser) {
|
||||
if (settings.gitUser) {
|
||||
if (!await git.configExists('user.name', true)) {
|
||||
await git.config('user.name', 'github-action[bot]', true)
|
||||
await git.config('user.name', settings.gitUser, true)
|
||||
}
|
||||
if (!await git.configExists('user.email', true)) {
|
||||
await git.config('user.email', '41898282+github-actions[bot]@users.noreply.github.com', 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 {
|
||||
|
|
|
@ -80,9 +80,9 @@ export interface IGitSourceSettings {
|
|||
authToken: string
|
||||
|
||||
/**
|
||||
* Indicates whether to set a default user name and email in the local git config
|
||||
* A github user slug to set a default user name and email in the local git config
|
||||
*/
|
||||
configureUser: boolean
|
||||
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,9 +138,8 @@ export async function getInputs(): Promise<IGitSourceSettings> {
|
|||
// Auth token
|
||||
result.authToken = core.getInput('token', {required: true})
|
||||
|
||||
// Configure user
|
||||
result.configureUser =
|
||||
(core.getInput('configure-user') || 'true').toUpperCase() === 'TRUE'
|
||||
// Git user
|
||||
result.gitUser = core.getInput('git-user') || 'github-action[bot]'
|
||||
|
||||
// SSH
|
||||
result.sshKey = core.getInput('ssh-key')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue