Skip to content

Commit

Permalink
Added suggestion provided in code review. Added ReadMe. Fixed action.…
Browse files Browse the repository at this point in the history
…yml default value.
  • Loading branch information
AlexVermette-Eaton committed May 10, 2024
1 parent 1614d7d commit daf4986
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 36 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,19 @@ Default:
Configure experimental features by passing a JSON object.
The following properties can be specified:

#### `conflict_resolution`

Default: `fail`

Specifies how the action will handle a conflict occuring during the cherry-pick.
In all cases, the action will stop the cherry-pick at the first conflict encountered.

Behavior is defined by the option selected.
- When set to `fail` the backport fails when the cherry-pick encounters a conflict.
- When set to `draft_commit_conflicts` the backport will always create a draft pull request with the first conflict encountered committed.

Instructions are provided on the original pull request on how to resolve the conflict and continue the cherry-pick.

#### `detect_merge_method`

Default: `false`
Expand Down
12 changes: 6 additions & 6 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,10 +655,10 @@ class Git {
return null;
}
else {
let uncommitedShas = [...commitShas];
let uncommittedShas = [...commitShas];
// Cherry-pick commit one by one.
for (const sha of commitShas) {
const { exitCode } = yield this.git("cherry-pick", ["-x", sha], pwd);
while (uncommittedShas.length > 0) {
const { exitCode } = yield this.git("cherry-pick", ["-x", uncommittedShas[0]], pwd);
if (exitCode !== 0) {
if (exitCode === 1) {
// conflict encountered
Expand All @@ -669,19 +669,19 @@ class Git {
if (exitCode !== 0) {
yield abortCherryPickAndThrow(commitShas, exitCode);
}
return uncommitedShas;
return uncommittedShas;
}
else {
throw new Error(`'Unsupported conflict_resolution method ${conflictResolution}`);
}
}
else {
// other fail reasons
yield abortCherryPickAndThrow([sha], exitCode);
yield abortCherryPickAndThrow([uncommittedShas[0]], exitCode);
}
}
// pop sha
uncommitedShas.shift();
uncommittedShas.shift();
}
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

41 changes: 21 additions & 20 deletions dist/licenses.txt
Original file line number Diff line number Diff line change
Expand Up @@ -473,26 +473,27 @@ THE SOFTWARE.

dedent
MIT
# MIT License

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The MIT License (MIT)

Copyright (c) 2015 Desmond Brand ([email protected])

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


deprecation
Expand Down
8 changes: 5 additions & 3 deletions src/backport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,11 @@ export class Backport {
uncommitedShas,
this.config.experimental.conflict_resolution,
)
: this.composeMessageForSuccess(new_pr.number,
target,
this.shouldUseDownstreamRepo() ? `${owner}/${repo}` : "",);
: this.composeMessageForSuccess(
new_pr.number,
target,
this.shouldUseDownstreamRepo() ? `${owner}/${repo}` : "",
);

successByTarget.set(target, true);
createdPullRequestNumbers.push(new_pr.number);
Expand Down
16 changes: 10 additions & 6 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,15 @@ export class Git {

return null;
} else {
let uncommitedShas: string[] = [...commitShas];
let uncommittedShas: string[] = [...commitShas];

// Cherry-pick commit one by one.
for (const sha of commitShas) {
const { exitCode } = await this.git("cherry-pick", ["-x", sha], pwd);
while (uncommittedShas.length > 0) {
const { exitCode } = await this.git(
"cherry-pick",
["-x", uncommittedShas[0]],
pwd,
);

if (exitCode !== 0) {
if (exitCode === 1) {
Expand All @@ -194,20 +198,20 @@ export class Git {
await abortCherryPickAndThrow(commitShas, exitCode);
}

return uncommitedShas;
return uncommittedShas;
} else {
throw new Error(
`'Unsupported conflict_resolution method ${conflictResolution}`,
);
}
} else {
// other fail reasons
await abortCherryPickAndThrow([sha], exitCode);
await abortCherryPickAndThrow([uncommittedShas[0]], exitCode);
}
}

// pop sha
uncommitedShas.shift();
uncommittedShas.shift();
}

return null;
Expand Down

0 comments on commit daf4986

Please sign in to comment.