feat: add flag to skip unstaged files

This commit is contained in:
Tomás Mayr 2021-03-10 15:29:25 -03:00
parent 09b9ac155b
commit 10f2c452a5
6 changed files with 28 additions and 12 deletions

View file

@ -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). | | | `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. | | | `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` | | `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 ### Action outputs
The following outputs can be used by subsequent workflow steps. The following outputs can be used by subsequent workflow steps.

View file

@ -64,6 +64,9 @@ inputs:
draft: draft:
description: 'Create a draft pull request' description: 'Create a draft pull request'
default: false default: false
skinUnstagedFiles:
description: 'Skips any unstaged files when creating a pull request.'
default: false
outputs: outputs:
pull-request-number: pull-request-number:
description: 'The pull request number' description: 'The pull request number'

23
dist/index.js vendored
View file

@ -99,7 +99,7 @@ function splitLines(multilineString) {
.map(s => s.trim()) .map(s => s.trim())
.filter(x => x !== ''); .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* () { return __awaiter(this, void 0, void 0, function* () {
// Get the working base. // Get the working base.
// When a ref, it may or may not be the actual 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(); const tempBranch = uuid_1.v4();
yield git.checkout(tempBranch, 'HEAD'); yield git.checkout(tempBranch, 'HEAD');
// Commit any uncommitted changes // Commit any uncommitted changes
if (yield git.isDirty(true)) { if (skipUnstagedFiles === false && (yield git.isDirty(true))) {
core.info('Uncommitted changes found. Adding a commit.'); core.info('Uncommitted changes found. Adding a commit.');
yield git.exec(['add', '-A']); yield git.exec(['add', '-A']);
const params = ['-m', commitMessage]; const params = ['-m', commitMessage];
@ -375,7 +375,7 @@ function createPullRequest(inputs) {
core.endGroup(); core.endGroup();
// Create or update the pull request branch // Create or update the pull request branch
core.startGroup('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(); core.endGroup();
if (['created', 'updated'].includes(result.action)) { if (['created', 'updated'].includes(result.action)) {
// The branch was created or updated // The branch was created or updated
@ -1082,7 +1082,8 @@ function run() {
reviewers: utils.getInputAsArray('reviewers'), reviewers: utils.getInputAsArray('reviewers'),
teamReviewers: utils.getInputAsArray('team-reviewers'), teamReviewers: utils.getInputAsArray('team-reviewers'),
milestone: Number(core.getInput('milestone')), 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)}`); core.debug(`Inputs: ${util_1.inspect(inputs)}`);
yield create_pull_request_1.createPullRequest(inputs); yield create_pull_request_1.createPullRequest(inputs);
@ -3497,7 +3498,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
var request = __nccwpck_require__(234); var request = __nccwpck_require__(234);
var universalUserAgent = __nccwpck_require__(30); var universalUserAgent = __nccwpck_require__(30);
const VERSION = "4.6.0"; const VERSION = "4.6.1";
class GraphqlError extends Error { class GraphqlError extends Error {
constructor(request, response) { constructor(request, response) {
@ -3520,10 +3521,18 @@ class GraphqlError extends Error {
} }
const NON_VARIABLE_OPTIONS = ["method", "baseUrl", "url", "headers", "request", "query", "mediaType"]; 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\/?$/; const GHES_V3_SUFFIX_REGEX = /\/api\/v3\/?$/;
function graphql(request, query, options) { function graphql(request, query, options) {
if (typeof query === "string" && options && "query" in options) { if (options) {
return Promise.reject(new Error(`[@octokit/graphql] "query" cannot be used as variable name`)); 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({ const parsedOptions = typeof query === "string" ? Object.assign({

View file

@ -91,7 +91,8 @@ export async function createOrUpdateBranch(
base: string, base: string,
branch: string, branch: string,
branchRemoteName: string, branchRemoteName: string,
signoff: boolean signoff: boolean,
skipUnstagedFiles: boolean
): Promise<CreateOrUpdateBranchResult> { ): Promise<CreateOrUpdateBranchResult> {
// Get the working base. // Get the working base.
// When a ref, it may or may not be the actual base. // When a ref, it may or may not be the actual base.
@ -117,7 +118,7 @@ export async function createOrUpdateBranch(
const tempBranch = uuidv4() const tempBranch = uuidv4()
await git.checkout(tempBranch, 'HEAD') await git.checkout(tempBranch, 'HEAD')
// Commit any uncommitted changes // Commit any uncommitted changes
if (await git.isDirty(true)) { if (skipUnstagedFiles === false && (await git.isDirty(true))) {
core.info('Uncommitted changes found. Adding a commit.') core.info('Uncommitted changes found. Adding a commit.')
await git.exec(['add', '-A']) await git.exec(['add', '-A'])
const params = ['-m', commitMessage] const params = ['-m', commitMessage]

View file

@ -29,6 +29,7 @@ export interface Inputs {
teamReviewers: string[] teamReviewers: string[]
milestone: number milestone: number
draft: boolean draft: boolean
skipUnstagedFiles: boolean
} }
export async function createPullRequest(inputs: Inputs): Promise<void> { export async function createPullRequest(inputs: Inputs): Promise<void> {
@ -173,7 +174,8 @@ export async function createPullRequest(inputs: Inputs): Promise<void> {
inputs.base, inputs.base,
inputs.branch, inputs.branch,
branchRemoteName, branchRemoteName,
inputs.signoff inputs.signoff,
inputs.skipUnstagedFiles
) )
core.endGroup() core.endGroup()

View file

@ -24,7 +24,8 @@ async function run(): Promise<void> {
reviewers: utils.getInputAsArray('reviewers'), reviewers: utils.getInputAsArray('reviewers'),
teamReviewers: utils.getInputAsArray('team-reviewers'), teamReviewers: utils.getInputAsArray('team-reviewers'),
milestone: Number(core.getInput('milestone')), 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)}`) core.debug(`Inputs: ${inspect(inputs)}`)