Compare commits

...

7 Commits

5 changed files with 57 additions and 11 deletions

View File

@ -36,6 +36,13 @@ Create Pull Request action will:
You can also pin to a [specific release](https://github.com/peter-evans/create-pull-request/releases) version in the format `@v4.x.x`
### Workflow permissions
For this action to work you must explicitly allow GitHub Actions to create pull requests.
This setting can be found in a repository's settings under Actions > General > Workflow permissions.
For repositories belonging to an organization, this setting can be managed by admins in organization settings under Actions > General > Workflow permissions.
### Action inputs
All inputs are **optional**. If not set, sensible defaults will be used.
@ -106,7 +113,7 @@ How the action behaves:
- If there are changes (i.e. a diff exists with the checked-out base branch), the changes will be pushed to a new `branch` and a pull request created.
- If there are no changes (i.e. no diff exists with the checked-out base branch), no pull request will be created and the action exits silently.
- If a pull request already exists and there are no further changes (i.e. no diff with the current pull request branch) then the action exits silently.
- If a pull request already exists it will be updated if necessary. Local changes in the Actions workspace, or changes on the base branch, can cause an update. If no update is required the action exits silently.
- If a pull request exists and new changes on the base branch make the pull request unnecessary (i.e. there is no longer a diff between the pull request branch and the base), the pull request is automatically closed. Additionally, if `delete-branch` is set to `true` the `branch` will be deleted.
For further details about how the action works and usage guidelines, see [Concepts, guidelines and advanced usage](docs/concepts-guidelines.md).

26
dist/index.js vendored
View File

@ -39,6 +39,7 @@ exports.createOrUpdateBranch = exports.tryFetch = exports.getWorkingBaseAndType
const core = __importStar(__nccwpck_require__(2186));
const uuid_1 = __nccwpck_require__(5840);
const CHERRYPICK_EMPTY = 'The previous cherry-pick is now empty, possibly due to conflict resolution.';
const NOTHING_TO_COMMIT = 'nothing to commit, working tree clean';
var WorkingBaseType;
(function (WorkingBaseType) {
WorkingBaseType["Branch"] = "branch";
@ -62,7 +63,9 @@ exports.getWorkingBaseAndType = getWorkingBaseAndType;
function tryFetch(git, remote, branch) {
return __awaiter(this, void 0, void 0, function* () {
try {
yield git.fetch([`${branch}:refs/remotes/${remote}/${branch}`], remote);
yield git.fetch([`${branch}:refs/remotes/${remote}/${branch}`], remote, [
'--force'
]);
return true;
}
catch (_a) {
@ -136,7 +139,12 @@ function createOrUpdateBranch(git, commitMessage, base, branch, branchRemoteName
if (signoff) {
popts.push('--signoff');
}
yield git.commit(popts);
const commitResult = yield git.commit(popts, true);
// 'nothing to commit' can occur when core.autocrlf is set to true
if (commitResult.exitCode != 0 &&
!commitResult.stdout.includes(NOTHING_TO_COMMIT)) {
throw new Error(`Unexpected error: ${commitResult.stderr}`);
}
}
// Remove uncommitted tracked and untracked changes
yield git.exec(['reset', '--hard']);
@ -672,7 +680,7 @@ class GitCommandManager {
return yield this.exec(args, allowAllExitCodes);
});
}
commit(options) {
commit(options, allowAllExitCodes = false) {
return __awaiter(this, void 0, void 0, function* () {
const args = ['commit'];
if (this.identityGitOptions) {
@ -681,7 +689,7 @@ class GitCommandManager {
if (options) {
args.push(...options);
}
yield this.exec(args);
return yield this.exec(args, allowAllExitCodes);
});
}
config(configKey, configValue, globalConfig) {
@ -1136,13 +1144,21 @@ const plugin_paginate_rest_1 = __nccwpck_require__(4193);
const plugin_rest_endpoint_methods_1 = __nccwpck_require__(3044);
const https_proxy_agent_1 = __nccwpck_require__(7219);
exports.Octokit = core_1.Octokit.plugin(plugin_paginate_rest_1.paginateRest, plugin_rest_endpoint_methods_1.restEndpointMethods, autoProxyAgent);
// Octokit plugin to support the https_proxy environment variable
// Octokit plugin to support the https_proxy and no_proxy environment variable
function autoProxyAgent(octokit) {
const proxy = process.env.https_proxy || process.env.HTTPS_PROXY;
const noProxy = process.env.no_proxy || process.env.NO_PROXY;
let noProxyArray = [];
if (noProxy) {
noProxyArray = noProxy.split(',');
}
if (!proxy)
return;
const agent = new https_proxy_agent_1.HttpsProxyAgent(proxy);
octokit.hook.before('request', options => {
if (noProxyArray.includes(options.request.hostname)) {
return;
}
options.request.agent = agent;
});
}

View File

@ -4,6 +4,7 @@ import {v4 as uuidv4} from 'uuid'
const CHERRYPICK_EMPTY =
'The previous cherry-pick is now empty, possibly due to conflict resolution.'
const NOTHING_TO_COMMIT = 'nothing to commit, working tree clean'
export enum WorkingBaseType {
Branch = 'branch',
@ -33,7 +34,9 @@ export async function tryFetch(
branch: string
): Promise<boolean> {
try {
await git.fetch([`${branch}:refs/remotes/${remote}/${branch}`], remote)
await git.fetch([`${branch}:refs/remotes/${remote}/${branch}`], remote, [
'--force'
])
return true
} catch {
return false
@ -132,7 +135,14 @@ export async function createOrUpdateBranch(
if (signoff) {
popts.push('--signoff')
}
await git.commit(popts)
const commitResult = await git.commit(popts, true)
// 'nothing to commit' can occur when core.autocrlf is set to true
if (
commitResult.exitCode != 0 &&
!commitResult.stdout.includes(NOTHING_TO_COMMIT)
) {
throw new Error(`Unexpected error: ${commitResult.stderr}`)
}
}
// Remove uncommitted tracked and untracked changes

View File

@ -53,7 +53,10 @@ export class GitCommandManager {
return await this.exec(args, allowAllExitCodes)
}
async commit(options?: string[]): Promise<void> {
async commit(
options?: string[],
allowAllExitCodes = false
): Promise<GitOutput> {
const args = ['commit']
if (this.identityGitOptions) {
args.unshift(...this.identityGitOptions)
@ -63,7 +66,7 @@ export class GitCommandManager {
args.push(...options)
}
await this.exec(args)
return await this.exec(args, allowAllExitCodes)
}
async config(

View File

@ -11,13 +11,23 @@ export const Octokit = Core.plugin(
autoProxyAgent
)
// Octokit plugin to support the https_proxy environment variable
// Octokit plugin to support the https_proxy and no_proxy environment variable
function autoProxyAgent(octokit: Core) {
const proxy = process.env.https_proxy || process.env.HTTPS_PROXY
const noProxy = process.env.no_proxy || process.env.NO_PROXY
let noProxyArray: string[] = []
if (noProxy) {
noProxyArray = noProxy.split(',')
}
if (!proxy) return
const agent = new HttpsProxyAgent(proxy)
octokit.hook.before('request', options => {
if (noProxyArray.includes(options.request.hostname)) {
return
}
options.request.agent = agent
})
}