Compare commits

..

19 Commits

Author SHA1 Message Date
2455e15969 Merge pull request #704 from jonico/support-ghes
Support GitHub Enterprise Server
2021-01-26 11:17:38 +09:00
05bc46786e Support GitHub Server API URL
* pass GitHub Server API in Octokkit constructor
2021-01-25 19:16:19 +01:00
adc6552966 Support GitHub Enterprise Server
* parse GITHUB_SERVER_URL if present
* accept proper server remotes as well
2021-01-25 18:25:20 +01:00
171fc6cce4 Merge pull request #701 from peter-evans/update-distribution
Update distribution
2021-01-25 14:22:27 +09:00
3fb765f674 build: update distribution 2021-01-25 05:19:37 +00:00
d95c81ee98 Merge pull request #686 from peter-evans/update-dependencies
Update dependencies
2021-01-25 14:16:59 +09:00
8d5ed6557f chore: update dependencies 2021-01-21 02:46:33 +00:00
7b1819c092 Merge pull request #683 from peter-evans/update-distribution
Update distribution
2020-12-28 10:22:06 +09:00
be0a8c9666 build: update distribution 2020-12-28 01:20:44 +00:00
a0a6157bf1 Merge pull request #594 from peter-evans/update-dependencies
Update dependencies
2020-12-28 10:18:18 +09:00
9c5ec2e07d chore: update dependencies 2020-12-24 02:04:52 +00:00
45c510e1f6 Merge pull request #672 from peter-evans/reset-perf
perf: git reset instead of fetch
2020-12-23 14:28:23 +09:00
249b80db6b perf: git reset instead of fetch 2020-12-23 14:10:40 +09:00
6c2b44c6ac Merge pull request #666 from peter-evans/dependabot/npm_and_yarn/node-notifier-8.0.1
build(deps): bump node-notifier from 8.0.0 to 8.0.1
2020-12-23 09:48:12 +09:00
76c58cf6a9 build(deps): bump node-notifier from 8.0.0 to 8.0.1
Bumps [node-notifier](https://github.com/mikaelbr/node-notifier) from 8.0.0 to 8.0.1.
- [Release notes](https://github.com/mikaelbr/node-notifier/releases)
- [Changelog](https://github.com/mikaelbr/node-notifier/blob/v8.0.1/CHANGELOG.md)
- [Commits](https://github.com/mikaelbr/node-notifier/compare/v8.0.0...v8.0.1)

Signed-off-by: dependabot[bot] <support@github.com>
2020-12-22 13:17:50 +00:00
8c603dbb04 Merge pull request #653 from peter-evans/fix-error-handling
fix: change or->and to catch all errors
2020-12-09 09:56:23 +09:00
d01e0807ef fix: change or->and to catch all errors 2020-12-09 09:38:10 +09:00
ce699aa2d1 Merge pull request #637 from peter-evans/prune-remote
fix: prune stale remote ref for self-hosted runners
2020-11-25 12:40:23 +09:00
9984f611a7 fix: prune stale remote ref for self-hosted runners 2020-11-24 12:34:57 +09:00
7 changed files with 1331 additions and 2444 deletions

697
dist/index.js vendored

File diff suppressed because it is too large Load Diff

3000
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -31,24 +31,24 @@
"dependencies": { "dependencies": {
"@actions/core": "1.2.6", "@actions/core": "1.2.6",
"@actions/exec": "1.0.4", "@actions/exec": "1.0.4",
"@octokit/core": "3.1.2", "@octokit/core": "3.2.4",
"@octokit/plugin-paginate-rest": "2.4.0", "@octokit/plugin-paginate-rest": "2.8.0",
"@octokit/plugin-rest-endpoint-methods": "4.2.0", "@octokit/plugin-rest-endpoint-methods": "4.5.2",
"uuid": "8.3.0" "uuid": "8.3.2"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "26.0.14", "@types/jest": "26.0.20",
"@types/node": "14.10.3", "@types/node": "14.14.22",
"@typescript-eslint/parser": "4.1.1", "@typescript-eslint/parser": "4.14.0",
"@vercel/ncc": "0.24.1", "@vercel/ncc": "0.27.0",
"eslint": "7.9.0", "eslint": "7.18.0",
"eslint-plugin-github": "4.1.1", "eslint-plugin-github": "4.1.1",
"eslint-plugin-jest": "24.0.1", "eslint-plugin-jest": "24.1.3",
"jest": "26.4.2", "jest": "26.6.3",
"jest-circus": "26.4.2", "jest-circus": "26.6.3",
"js-yaml": "3.14.0", "js-yaml": "4.0.0",
"prettier": "2.1.2", "prettier": "2.2.1",
"ts-jest": "26.3.0", "ts-jest": "26.4.4",
"typescript": "4.0.2" "typescript": "4.1.3"
} }
} }

View File

@ -130,8 +130,18 @@ export async function createOrUpdateBranch(
// Perform fetch and reset the working base // Perform fetch and reset the working base
// Commits made during the workflow will be removed // Commits made during the workflow will be removed
if (workingBaseType == WorkingBaseType.Branch) { if (workingBaseType == WorkingBaseType.Branch) {
core.info(`Resetting working base branch '${workingBase}' to its remote`) core.info(`Resetting working base branch '${workingBase}'`)
await git.fetch([`${workingBase}:${workingBase}`], baseRemote, ['--force']) if (branchRemoteName == 'fork') {
// If pushing to a fork we must fetch with 'unshallow' to avoid the following error on git push
// ! [remote rejected] HEAD -> tests/push-branch-to-fork (shallow update not allowed)
await git.fetch([`${workingBase}:${workingBase}`], baseRemote, [
'--force'
])
} else {
// If the remote is 'origin' we can git reset
await git.checkout(workingBase)
await git.exec(['reset', '--hard', `${baseRemote}/${workingBase}`])
}
} }
// If the working base is not the base, rebase the temp branch commits // If the working base is not the base, rebase the temp branch commits
@ -168,7 +178,7 @@ export async function createOrUpdateBranch(
// The pull request branch does not exist // The pull request branch does not exist
core.info(`Pull request branch '${branch}' does not exist yet.`) core.info(`Pull request branch '${branch}' does not exist yet.`)
// Create the pull request branch // Create the pull request branch
await git.checkout(branch, 'HEAD') await git.checkout(branch, tempBranch)
// Check if the pull request branch is ahead of the base // Check if the pull request branch is ahead of the base
result.hasDiffWithBase = await isAhead(git, base, branch) result.hasDiffWithBase = await isAhead(git, base, branch)
if (result.hasDiffWithBase) { if (result.hasDiffWithBase) {

View File

@ -106,6 +106,12 @@ export async function createPullRequest(inputs: Inputs): Promise<void> {
`The 'base' and 'branch' for a pull request must be different branches. Unable to continue.` `The 'base' and 'branch' for a pull request must be different branches. Unable to continue.`
) )
} }
// For self-hosted runners the repository state persists between runs.
// This command prunes the stale remote ref when the pull request branch was
// deleted after being merged or closed. Without this the push using
// '--force-with-lease' fails due to "stale info."
// https://github.com/peter-evans/create-pull-request/issues/633
await git.exec(['remote', 'prune', branchRemoteName])
core.endGroup() core.endGroup()
// Apply the branch suffix if set // Apply the branch suffix if set

View File

@ -23,6 +23,7 @@ export class GitHubHelper {
if (token) { if (token) {
options.auth = `${token}` options.auth = `${token}`
} }
options.baseUrl = process.env['GITHUB_API_URL'] || 'https://api.github.com'
this.octokit = new Octokit(options) this.octokit = new Octokit(options)
} }
@ -58,9 +59,11 @@ export class GitHubHelper {
} }
} catch (e) { } catch (e) {
if ( if (
!e.message || e.message &&
!e.message.includes(`A pull request already exists for ${headBranch}`) e.message.includes(`A pull request already exists for ${headBranch}`)
) { ) {
core.info(`A pull request already exists for ${headBranch}`)
} else {
throw e throw e
} }
} }

View File

@ -39,8 +39,21 @@ interface RemoteDetail {
export function getRemoteDetail(remoteUrl: string): RemoteDetail { export function getRemoteDetail(remoteUrl: string): RemoteDetail {
// Parse the protocol and github repository from a URL // Parse the protocol and github repository from a URL
// e.g. HTTPS, peter-evans/create-pull-request // e.g. HTTPS, peter-evans/create-pull-request
const httpsUrlPattern = /^https:\/\/.*@?github.com\/(.+\/.+)$/i const githubUrl = process.env['GITHUB_SERVER_URL'] || 'https://github.com'
const sshUrlPattern = /^git@github.com:(.+\/.+).git$/i
const githubServerMatch = githubUrl.match(/^https?:\/\/(.+)$/i)
if (!githubServerMatch) {
throw new Error('Could not parse GitHub Server name')
}
const httpsUrlPattern = new RegExp(
'^https?://.*@?' + githubServerMatch[1] + '/(.+/.+)$',
'i'
)
const sshUrlPattern = new RegExp(
'^git@' + githubServerMatch[1] + ':(.+/.+).git$',
'i'
)
const httpsMatch = remoteUrl.match(httpsUrlPattern) const httpsMatch = remoteUrl.match(httpsUrlPattern)
if (httpsMatch) { if (httpsMatch) {