Skip to content

Commit

Permalink
Accept options for the rebase command (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
keichan34 authored Oct 15, 2024
1 parent 8631587 commit ebee9ea
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ inputs:
exclude-drafts:
description: 'Exclude draft pull requests'
default: false
rebase-options:
description: >
Additional options to pass to the git rebase command.
For example, to always prefer "their" code, use "-Xtheirs" ("--strategy-option=theirs").
Pass multiple options as a single string separated by commas or newlines.
runs:
using: 'node20'
main: 'dist/index.js'
Expand Down
14 changes: 10 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,8 @@ function run() {
base: core.getInput('base'),
includeLabels: utils.getInputAsArray('include-labels'),
excludeLabels: utils.getInputAsArray('exclude-labels'),
excludeDrafts: core.getInput('exclude-drafts') === 'true'
excludeDrafts: core.getInput('exclude-drafts') === 'true',
rebaseOptions: utils.getInputAsArray('rebase-options')
};
core.debug(`Inputs: ${(0, util_1.inspect)(inputs)}`);
const [headOwner, head] = inputValidator.parseHead(inputs.head);
Expand All @@ -418,7 +419,7 @@ function run() {
// Rebase
// Create a git command manager
const git = yield git_command_manager_1.GitCommandManager.create(sourceSettings.repositoryPath);
const rebaseHelper = new rebase_helper_1.RebaseHelper(git);
const rebaseHelper = new rebase_helper_1.RebaseHelper(git, inputs.rebaseOptions);
let rebasedCount = 0;
for (const pull of pulls) {
const result = yield rebaseHelper.rebase(pull);
Expand Down Expand Up @@ -625,8 +626,9 @@ exports.RebaseHelper = void 0;
const core = __importStar(__nccwpck_require__(2186));
const uuid_1 = __nccwpck_require__(5840);
class RebaseHelper {
constructor(git) {
constructor(git, options) {
this.git = git;
this.extraOptions = options;
}
rebase(pull) {
return __awaiter(this, void 0, void 0, function* () {
Expand Down Expand Up @@ -688,7 +690,11 @@ class RebaseHelper {
tryRebase(remoteName, ref) {
return __awaiter(this, void 0, void 0, function* () {
try {
const result = yield this.git.exec(['rebase', `${remoteName}/${ref}`]);
const result = yield this.git.exec([
'rebase',
...this.extraOptions,
`${remoteName}/${ref}`
]);
return result ? RebaseResult.Rebased : RebaseResult.AlreadyUpToDate;
}
catch (_a) {
Expand Down
5 changes: 3 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ async function run(): Promise<void> {
base: core.getInput('base'),
includeLabels: utils.getInputAsArray('include-labels'),
excludeLabels: utils.getInputAsArray('exclude-labels'),
excludeDrafts: core.getInput('exclude-drafts') === 'true'
excludeDrafts: core.getInput('exclude-drafts') === 'true',
rebaseOptions: utils.getInputAsArray('rebase-options')
}
core.debug(`Inputs: ${inspect(inputs)}`)

Expand Down Expand Up @@ -51,7 +52,7 @@ async function run(): Promise<void> {
// Rebase
// Create a git command manager
const git = await GitCommandManager.create(sourceSettings.repositoryPath)
const rebaseHelper = new RebaseHelper(git)
const rebaseHelper = new RebaseHelper(git, inputs.rebaseOptions)
let rebasedCount = 0
for (const pull of pulls) {
const result = await rebaseHelper.rebase(pull)
Expand Down
10 changes: 8 additions & 2 deletions src/rebase-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import {v4 as uuidv4} from 'uuid'

export class RebaseHelper {
private git: GitCommandManager
private extraOptions: string[]

constructor(git: GitCommandManager) {
constructor(git: GitCommandManager, options: string[]) {
this.git = git
this.extraOptions = options
}

async rebase(pull: Pull): Promise<boolean> {
Expand Down Expand Up @@ -86,7 +88,11 @@ export class RebaseHelper {
ref: string
): Promise<RebaseResult> {
try {
const result = await this.git.exec(['rebase', `${remoteName}/${ref}`])
const result = await this.git.exec([
'rebase',
...this.extraOptions,
`${remoteName}/${ref}`
])
return result ? RebaseResult.Rebased : RebaseResult.AlreadyUpToDate
} catch {
return RebaseResult.Failed
Expand Down

0 comments on commit ebee9ea

Please sign in to comment.