* feat: restore working base branch and uncommitted changes

* docs: uncommitted changes are stashed and restored

* docs: add major version notes

* fix: update package version

* fix: update package-lock

* feat: revise proxy implementation

* docs: add notes for the revised proxy implementation

* feat: set and remove git safe directory

* docs: add notes for the git safe directory feature

* fix: use base url for proxy check

* feat: determine the git dir with rev-parse

* build: update package lock

* fix: remove support for ghes alpha

* feat: revise handling of team reviewers

* docs: update notes

* feat: body-path

* docs: update to v5

* docs: update to v5

* build: fix package lock
This commit is contained in:
Peter Evans 2023-04-05 08:41:18 +09:00 committed by GitHub
parent 1847e5d1d6
commit 5b4a9f6a9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 501 additions and 59041 deletions

View file

@ -7,7 +7,10 @@ import * as utils from './utils'
export class GitAuthHelper {
private git: GitCommandManager
private gitConfigPath: string
private gitConfigPath = ''
private workingDirectory: string
private safeDirectoryConfigKey = 'safe.directory'
private safeDirectoryAdded = false
private extraheaderConfigKey: string
private extraheaderConfigPlaceholderValue = 'AUTHORIZATION: basic ***'
private extraheaderConfigValueRegex = '^AUTHORIZATION:'
@ -15,15 +18,38 @@ export class GitAuthHelper {
constructor(git: GitCommandManager) {
this.git = git
this.gitConfigPath = path.join(
this.git.getWorkingDirectory(),
'.git',
'config'
)
this.workingDirectory = this.git.getWorkingDirectory()
const serverUrl = this.getServerUrl()
this.extraheaderConfigKey = `http.${serverUrl.origin}/.extraheader`
}
async addSafeDirectory(): Promise<void> {
const exists = await this.git.configExists(
this.safeDirectoryConfigKey,
this.workingDirectory,
true
)
if (!exists) {
await this.git.config(
this.safeDirectoryConfigKey,
this.workingDirectory,
true,
true
)
this.safeDirectoryAdded = true
}
}
async removeSafeDirectory(): Promise<void> {
if (this.safeDirectoryAdded) {
await this.git.tryConfigUnset(
this.safeDirectoryConfigKey,
this.workingDirectory,
true
)
}
}
async savePersistedAuth(): Promise<void> {
// Save and unset persisted extraheader credential in git config if it exists
this.persistedExtraheaderConfigValue = await this.getAndUnset()
@ -106,6 +132,10 @@ export class GitAuthHelper {
find: string,
replace: string
): Promise<void> {
if (this.gitConfigPath.length === 0) {
const gitDir = await this.git.getGitDirectory()
this.gitConfigPath = path.join(this.workingDirectory, gitDir, 'config')
}
let content = (await fs.promises.readFile(this.gitConfigPath)).toString()
const index = content.indexOf(find)
if (index < 0 || index != content.lastIndexOf(find)) {
@ -116,12 +146,6 @@ export class GitAuthHelper {
}
private getServerUrl(): URL {
// todo: remove GITHUB_URL after support for GHES Alpha is no longer needed
// See https://github.com/actions/checkout/blob/main/src/url-helper.ts#L22-L29
return new URL(
process.env['GITHUB_SERVER_URL'] ||
process.env['GITHUB_URL'] ||
'https://github.com'
)
return new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com')
}
}