mirror of
https://forgejo.stefka.eu/jiriks74/create-pull-request.git
synced 2025-01-18 16:01:06 +01:00
feat: add flag to skip unstaged files
This commit is contained in:
parent
09b9ac155b
commit
10f2c452a5
6 changed files with 28 additions and 12 deletions
|
@ -63,7 +63,7 @@ All inputs are **optional**. If not set, sensible defaults will be used.
|
|||
| `team-reviewers` | A comma or newline-separated list of GitHub teams to request a review from. Note that a `repo` scoped [PAT](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) may be required. See [this issue](https://github.com/peter-evans/create-pull-request/issues/155). | |
|
||||
| `milestone` | The number of the milestone to associate this pull request with. | |
|
||||
| `draft` | Create a [draft pull request](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests#draft-pull-requests). | `false` |
|
||||
|
||||
| `skip-unstaged-files` | Skips adding any unstaged files when creating the pull request | `false` |
|
||||
### Action outputs
|
||||
|
||||
The following outputs can be used by subsequent workflow steps.
|
||||
|
|
|
@ -64,6 +64,9 @@ inputs:
|
|||
draft:
|
||||
description: 'Create a draft pull request'
|
||||
default: false
|
||||
skinUnstagedFiles:
|
||||
description: 'Skips any unstaged files when creating a pull request.'
|
||||
default: false
|
||||
outputs:
|
||||
pull-request-number:
|
||||
description: 'The pull request number'
|
||||
|
|
21
dist/index.js
vendored
21
dist/index.js
vendored
|
@ -99,7 +99,7 @@ function splitLines(multilineString) {
|
|||
.map(s => s.trim())
|
||||
.filter(x => x !== '');
|
||||
}
|
||||
function createOrUpdateBranch(git, commitMessage, base, branch, branchRemoteName, signoff) {
|
||||
function createOrUpdateBranch(git, commitMessage, base, branch, branchRemoteName, signoff, skipUnstagedFiles) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
// Get the working base.
|
||||
// When a ref, it may or may not be the actual base.
|
||||
|
@ -122,7 +122,7 @@ function createOrUpdateBranch(git, commitMessage, base, branch, branchRemoteName
|
|||
const tempBranch = uuid_1.v4();
|
||||
yield git.checkout(tempBranch, 'HEAD');
|
||||
// Commit any uncommitted changes
|
||||
if (yield git.isDirty(true)) {
|
||||
if (skipUnstagedFiles === false && (yield git.isDirty(true))) {
|
||||
core.info('Uncommitted changes found. Adding a commit.');
|
||||
yield git.exec(['add', '-A']);
|
||||
const params = ['-m', commitMessage];
|
||||
|
@ -375,7 +375,7 @@ function createPullRequest(inputs) {
|
|||
core.endGroup();
|
||||
// Create or update the pull request branch
|
||||
core.startGroup('Create or update the pull request branch');
|
||||
const result = yield create_or_update_branch_1.createOrUpdateBranch(git, inputs.commitMessage, inputs.base, inputs.branch, branchRemoteName, inputs.signoff);
|
||||
const result = yield create_or_update_branch_1.createOrUpdateBranch(git, inputs.commitMessage, inputs.base, inputs.branch, branchRemoteName, inputs.signoff, inputs.skipUnstagedFiles);
|
||||
core.endGroup();
|
||||
if (['created', 'updated'].includes(result.action)) {
|
||||
// The branch was created or updated
|
||||
|
@ -1082,7 +1082,8 @@ function run() {
|
|||
reviewers: utils.getInputAsArray('reviewers'),
|
||||
teamReviewers: utils.getInputAsArray('team-reviewers'),
|
||||
milestone: Number(core.getInput('milestone')),
|
||||
draft: core.getInput('draft') === 'true'
|
||||
draft: core.getInput('draft') === 'true',
|
||||
skipUnstagedFiles: core.getInput('skip-unstaged-files') === 'true'
|
||||
};
|
||||
core.debug(`Inputs: ${util_1.inspect(inputs)}`);
|
||||
yield create_pull_request_1.createPullRequest(inputs);
|
||||
|
@ -3497,7 +3498,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|||
var request = __nccwpck_require__(234);
|
||||
var universalUserAgent = __nccwpck_require__(30);
|
||||
|
||||
const VERSION = "4.6.0";
|
||||
const VERSION = "4.6.1";
|
||||
|
||||
class GraphqlError extends Error {
|
||||
constructor(request, response) {
|
||||
|
@ -3520,12 +3521,20 @@ class GraphqlError extends Error {
|
|||
}
|
||||
|
||||
const NON_VARIABLE_OPTIONS = ["method", "baseUrl", "url", "headers", "request", "query", "mediaType"];
|
||||
const FORBIDDEN_VARIABLE_OPTIONS = ["query", "method", "url"];
|
||||
const GHES_V3_SUFFIX_REGEX = /\/api\/v3\/?$/;
|
||||
function graphql(request, query, options) {
|
||||
if (typeof query === "string" && options && "query" in options) {
|
||||
if (options) {
|
||||
if (typeof query === "string" && "query" in options) {
|
||||
return Promise.reject(new Error(`[@octokit/graphql] "query" cannot be used as variable name`));
|
||||
}
|
||||
|
||||
for (const key in options) {
|
||||
if (!FORBIDDEN_VARIABLE_OPTIONS.includes(key)) continue;
|
||||
return Promise.reject(new Error(`[@octokit/graphql] "${key}" cannot be used as variable name`));
|
||||
}
|
||||
}
|
||||
|
||||
const parsedOptions = typeof query === "string" ? Object.assign({
|
||||
query
|
||||
}, options) : query;
|
||||
|
|
|
@ -91,7 +91,8 @@ export async function createOrUpdateBranch(
|
|||
base: string,
|
||||
branch: string,
|
||||
branchRemoteName: string,
|
||||
signoff: boolean
|
||||
signoff: boolean,
|
||||
skipUnstagedFiles: boolean
|
||||
): Promise<CreateOrUpdateBranchResult> {
|
||||
// Get the working base.
|
||||
// When a ref, it may or may not be the actual base.
|
||||
|
@ -117,7 +118,7 @@ export async function createOrUpdateBranch(
|
|||
const tempBranch = uuidv4()
|
||||
await git.checkout(tempBranch, 'HEAD')
|
||||
// Commit any uncommitted changes
|
||||
if (await git.isDirty(true)) {
|
||||
if (skipUnstagedFiles === false && (await git.isDirty(true))) {
|
||||
core.info('Uncommitted changes found. Adding a commit.')
|
||||
await git.exec(['add', '-A'])
|
||||
const params = ['-m', commitMessage]
|
||||
|
|
|
@ -29,6 +29,7 @@ export interface Inputs {
|
|||
teamReviewers: string[]
|
||||
milestone: number
|
||||
draft: boolean
|
||||
skipUnstagedFiles: boolean
|
||||
}
|
||||
|
||||
export async function createPullRequest(inputs: Inputs): Promise<void> {
|
||||
|
@ -173,7 +174,8 @@ export async function createPullRequest(inputs: Inputs): Promise<void> {
|
|||
inputs.base,
|
||||
inputs.branch,
|
||||
branchRemoteName,
|
||||
inputs.signoff
|
||||
inputs.signoff,
|
||||
inputs.skipUnstagedFiles
|
||||
)
|
||||
core.endGroup()
|
||||
|
||||
|
|
|
@ -24,7 +24,8 @@ async function run(): Promise<void> {
|
|||
reviewers: utils.getInputAsArray('reviewers'),
|
||||
teamReviewers: utils.getInputAsArray('team-reviewers'),
|
||||
milestone: Number(core.getInput('milestone')),
|
||||
draft: core.getInput('draft') === 'true'
|
||||
draft: core.getInput('draft') === 'true',
|
||||
skipUnstagedFiles: core.getInput('skip-unstaged-files') === 'true'
|
||||
}
|
||||
core.debug(`Inputs: ${inspect(inputs)}`)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue