add add-pattern-array argument

This commit is contained in:
avdim 2021-12-08 14:28:53 +03:00
parent 4b53b6fd1a
commit 76979c4272
6 changed files with 22 additions and 8 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@ lib/
node_modules/ node_modules/
.DS_Store .DS_Store
.idea

View file

@ -64,6 +64,10 @@ inputs:
draft: draft:
description: 'Create a draft pull request' description: 'Create a draft pull request'
default: false default: false
add-pattern-array:
description: 'git add [pattern]'
default: |
-A
outputs: outputs:
pull-request-number: pull-request-number:
description: 'The pull request number' description: 'The pull request number'

11
dist/index.js vendored
View file

@ -98,7 +98,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, filePatterns) {
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.
@ -124,7 +124,9 @@ function createOrUpdateBranch(git, commitMessage, base, branch, branchRemoteName
// Commit any uncommitted changes // Commit any uncommitted changes
if (yield git.isDirty(true)) { if (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']); for (const filePattern of filePatterns) {
yield git.exec(['add', filePattern]);
}
const params = ['-m', commitMessage]; const params = ['-m', commitMessage];
if (signoff) { if (signoff) {
params.push('--signoff'); params.push('--signoff');
@ -377,7 +379,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 (0, create_or_update_branch_1.createOrUpdateBranch)(git, inputs.commitMessage, inputs.base, inputs.branch, branchRemoteName, inputs.signoff); const result = yield (0, create_or_update_branch_1.createOrUpdateBranch)(git, inputs.commitMessage, inputs.base, inputs.branch, branchRemoteName, inputs.signoff, inputs.addPatternArray);
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
@ -1090,7 +1092,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',
addPatternArray: utils.getInputAsArray('add-pattern-array')
}; };
core.debug(`Inputs: ${(0, util_1.inspect)(inputs)}`); core.debug(`Inputs: ${(0, util_1.inspect)(inputs)}`);
yield (0, create_pull_request_1.createPullRequest)(inputs); yield (0, create_pull_request_1.createPullRequest)(inputs);

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,
filePatterns: string[]
): 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.
@ -120,7 +121,9 @@ export async function createOrUpdateBranch(
// Commit any uncommitted changes // Commit any uncommitted changes
if (await git.isDirty(true)) { if (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']) for (const filePattern of filePatterns) {
await git.exec(['add', filePattern])
}
const params = ['-m', commitMessage] const params = ['-m', commitMessage]
if (signoff) { if (signoff) {
params.push('--signoff') params.push('--signoff')

View file

@ -29,6 +29,7 @@ export interface Inputs {
teamReviewers: string[] teamReviewers: string[]
milestone: number milestone: number
draft: boolean draft: boolean
addPatternArray: string[]
} }
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.addPatternArray
) )
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',
addPatternArray: utils.getInputAsArray('add-pattern-array')
} }
core.debug(`Inputs: ${inspect(inputs)}`) core.debug(`Inputs: ${inspect(inputs)}`)