-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: auto-detect the value of the no-squash option
Fixes: #113
- Loading branch information
1 parent
0a07bf3
commit bb70a5b
Showing
15 changed files
with
99 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,7 +65,7 @@ class ArgsParser { | |
inheritReviewers: this.getOrDefault(args.inheritReviewers, true), | ||
labels: this.getOrDefault(args.labels, []), | ||
inheritLabels: this.getOrDefault(args.inheritLabels, false), | ||
squash: this.getOrDefault(args.squash, true), | ||
squash: this.getOrDefault(args.squash), | ||
strategy: this.getOrDefault(args.strategy), | ||
strategyOption: this.getOrDefault(args.strategyOption), | ||
cherryPickOptions: this.getOrDefault(args.cherryPickOptions), | ||
|
@@ -107,7 +107,7 @@ var __importStar = (this && this.__importStar) || function (mod) { | |
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", ({ value: true })); | ||
exports.getAsBooleanOrDefault = exports.getAsSemicolonSeparatedList = exports.getAsCommaSeparatedList = exports.getAsCleanedCommaSeparatedList = exports.getOrUndefined = exports.readConfigFile = exports.parseArgs = void 0; | ||
exports.getAsInvertedBooleanOrUndefined = exports.getAsBooleanOrDefault = exports.getAsSemicolonSeparatedList = exports.getAsCommaSeparatedList = exports.getAsCleanedCommaSeparatedList = exports.getOrUndefined = exports.readConfigFile = exports.parseArgs = void 0; | ||
const fs = __importStar(__nccwpck_require__(7147)); | ||
/** | ||
* Parse the input configuation string as json object and | ||
|
@@ -163,6 +163,11 @@ function getAsBooleanOrDefault(value) { | |
return trimmed !== "" ? trimmed.toLowerCase() === "true" : undefined; | ||
} | ||
exports.getAsBooleanOrDefault = getAsBooleanOrDefault; | ||
function getAsInvertedBooleanOrUndefined(value) { | ||
const trimmed = value.trim(); | ||
return trimmed !== "" ? !(trimmed.toLowerCase() === "true") : undefined; | ||
} | ||
exports.getAsInvertedBooleanOrUndefined = getAsInvertedBooleanOrUndefined; | ||
|
||
|
||
/***/ }), | ||
|
@@ -203,7 +208,7 @@ class CLIArgsParser extends args_parser_1.default { | |
.option("--no-inherit-reviewers", "if provided and reviewers option is empty then inherit them from original pull request") | ||
.option("--labels <labels>", "comma separated list of labels to be assigned to the backported pull request", args_utils_1.getAsCommaSeparatedList) | ||
.option("--inherit-labels", "if true the backported pull request will inherit labels from the original one") | ||
.option("--no-squash", "if provided the tool will backport all commits as part of the pull request") | ||
.option("--no-squash", "If false only cherry-pick the merged commit, if true cherry-pick all the commits from the pull request. Always true if the pull request has not been merged. Defaults to true if the pull request was merged, false if it was squashed", undefined) | ||
.option("--strategy <strategy>", "cherry-pick merge strategy, default to 'recursive'", undefined) | ||
.option("--strategy-option <strategy-option>", "cherry-pick merge strategy option, default to 'theirs'") | ||
.option("--cherry-pick-options <options>", "additional cherry-pick options") | ||
|
@@ -803,13 +808,24 @@ class GitHubClient { | |
getDefaultGitEmail() { | ||
return "[email protected]"; | ||
} | ||
async getPullRequest(owner, repo, prNumber, squash = true) { | ||
async getPullRequest(owner, repo, prNumber, squash) { | ||
this.logger.debug(`Fetching pull request ${owner}/${repo}/${prNumber}`); | ||
const { data } = await this.octokit.rest.pulls.get({ | ||
owner: owner, | ||
repo: repo, | ||
pull_number: prNumber, | ||
}); | ||
if (data.state == "open") { | ||
squash = false; | ||
} | ||
else if (squash === undefined) { | ||
let commit = await this.octokit.rest.git.getCommit({ | ||
owner: owner, | ||
repo: repo, | ||
commit_sha: data.head.sha, | ||
}); | ||
squash = commit.data.parents.length > 1; | ||
} | ||
const commits = []; | ||
if (!squash) { | ||
// fetch all commits | ||
|
@@ -827,7 +843,7 @@ class GitHubClient { | |
} | ||
return this.mapper.mapPullRequest(data, commits); | ||
} | ||
async getPullRequestFromUrl(prUrl, squash = true) { | ||
async getPullRequestFromUrl(prUrl, squash) { | ||
const { owner, project, id } = this.extractPullRequestData(prUrl); | ||
return this.getPullRequest(owner, project, id, squash); | ||
} | ||
|
@@ -1038,9 +1054,10 @@ class GitLabClient { | |
} | ||
// READ | ||
// example: <host>/api/v4/projects/<namespace>%2Fbackporting-example/merge_requests/1 | ||
async getPullRequest(namespace, repo, mrNumber, squash = true) { | ||
async getPullRequest(namespace, repo, mrNumber, squash) { | ||
const projectId = this.getProjectId(namespace, repo); | ||
const { data } = await this.client.get(`/projects/${projectId}/merge_requests/${mrNumber}`); | ||
// TBD ??? | ||
const commits = []; | ||
if (!squash) { | ||
// fetch all commits | ||
|
@@ -1055,7 +1072,7 @@ class GitLabClient { | |
} | ||
return this.mapper.mapPullRequest(data, commits); | ||
} | ||
getPullRequestFromUrl(mrUrl, squash = true) { | ||
getPullRequestFromUrl(mrUrl, squash) { | ||
const { namespace, project, id } = this.extractMergeRequestData(mrUrl); | ||
return this.getPullRequest(namespace, project, id, squash); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,7 +65,7 @@ class ArgsParser { | |
inheritReviewers: this.getOrDefault(args.inheritReviewers, true), | ||
labels: this.getOrDefault(args.labels, []), | ||
inheritLabels: this.getOrDefault(args.inheritLabels, false), | ||
squash: this.getOrDefault(args.squash, true), | ||
squash: this.getOrDefault(args.squash), | ||
strategy: this.getOrDefault(args.strategy), | ||
strategyOption: this.getOrDefault(args.strategyOption), | ||
cherryPickOptions: this.getOrDefault(args.cherryPickOptions), | ||
|
@@ -107,7 +107,7 @@ var __importStar = (this && this.__importStar) || function (mod) { | |
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", ({ value: true })); | ||
exports.getAsBooleanOrDefault = exports.getAsSemicolonSeparatedList = exports.getAsCommaSeparatedList = exports.getAsCleanedCommaSeparatedList = exports.getOrUndefined = exports.readConfigFile = exports.parseArgs = void 0; | ||
exports.getAsInvertedBooleanOrUndefined = exports.getAsBooleanOrDefault = exports.getAsSemicolonSeparatedList = exports.getAsCommaSeparatedList = exports.getAsCleanedCommaSeparatedList = exports.getOrUndefined = exports.readConfigFile = exports.parseArgs = void 0; | ||
const fs = __importStar(__nccwpck_require__(7147)); | ||
/** | ||
* Parse the input configuation string as json object and | ||
|
@@ -163,6 +163,11 @@ function getAsBooleanOrDefault(value) { | |
return trimmed !== "" ? trimmed.toLowerCase() === "true" : undefined; | ||
} | ||
exports.getAsBooleanOrDefault = getAsBooleanOrDefault; | ||
function getAsInvertedBooleanOrUndefined(value) { | ||
const trimmed = value.trim(); | ||
return trimmed !== "" ? !(trimmed.toLowerCase() === "true") : undefined; | ||
} | ||
exports.getAsInvertedBooleanOrUndefined = getAsInvertedBooleanOrUndefined; | ||
|
||
|
||
/***/ }), | ||
|
@@ -206,7 +211,7 @@ class GHAArgsParser extends args_parser_1.default { | |
inheritReviewers: !(0, args_utils_1.getAsBooleanOrDefault)((0, core_1.getInput)("no-inherit-reviewers")), | ||
labels: (0, args_utils_1.getAsCommaSeparatedList)((0, core_1.getInput)("labels")), | ||
inheritLabels: (0, args_utils_1.getAsBooleanOrDefault)((0, core_1.getInput)("inherit-labels")), | ||
squash: !(0, args_utils_1.getAsBooleanOrDefault)((0, core_1.getInput)("no-squash")), | ||
squash: (0, args_utils_1.getAsInvertedBooleanOrUndefined)((0, core_1.getInput)("no-squash")), | ||
strategy: (0, args_utils_1.getOrUndefined)((0, core_1.getInput)("strategy")), | ||
strategyOption: (0, args_utils_1.getOrUndefined)((0, core_1.getInput)("strategy-option")), | ||
cherryPickOptions: (0, args_utils_1.getOrUndefined)((0, core_1.getInput)("cherry-pick-options")), | ||
|
@@ -770,13 +775,24 @@ class GitHubClient { | |
getDefaultGitEmail() { | ||
return "[email protected]"; | ||
} | ||
async getPullRequest(owner, repo, prNumber, squash = true) { | ||
async getPullRequest(owner, repo, prNumber, squash) { | ||
this.logger.debug(`Fetching pull request ${owner}/${repo}/${prNumber}`); | ||
const { data } = await this.octokit.rest.pulls.get({ | ||
owner: owner, | ||
repo: repo, | ||
pull_number: prNumber, | ||
}); | ||
if (data.state == "open") { | ||
squash = false; | ||
} | ||
else if (squash === undefined) { | ||
let commit = await this.octokit.rest.git.getCommit({ | ||
owner: owner, | ||
repo: repo, | ||
commit_sha: data.head.sha, | ||
}); | ||
squash = commit.data.parents.length > 1; | ||
} | ||
const commits = []; | ||
if (!squash) { | ||
// fetch all commits | ||
|
@@ -794,7 +810,7 @@ class GitHubClient { | |
} | ||
return this.mapper.mapPullRequest(data, commits); | ||
} | ||
async getPullRequestFromUrl(prUrl, squash = true) { | ||
async getPullRequestFromUrl(prUrl, squash) { | ||
const { owner, project, id } = this.extractPullRequestData(prUrl); | ||
return this.getPullRequest(owner, project, id, squash); | ||
} | ||
|
@@ -1005,9 +1021,10 @@ class GitLabClient { | |
} | ||
// READ | ||
// example: <host>/api/v4/projects/<namespace>%2Fbackporting-example/merge_requests/1 | ||
async getPullRequest(namespace, repo, mrNumber, squash = true) { | ||
async getPullRequest(namespace, repo, mrNumber, squash) { | ||
const projectId = this.getProjectId(namespace, repo); | ||
const { data } = await this.client.get(`/projects/${projectId}/merge_requests/${mrNumber}`); | ||
// TBD ??? | ||
const commits = []; | ||
if (!squash) { | ||
// fetch all commits | ||
|
@@ -1022,7 +1039,7 @@ class GitLabClient { | |
} | ||
return this.mapper.mapPullRequest(data, commits); | ||
} | ||
getPullRequestFromUrl(mrUrl, squash = true) { | ||
getPullRequestFromUrl(mrUrl, squash) { | ||
const { namespace, project, id } = this.extractMergeRequestData(mrUrl); | ||
return this.getPullRequest(namespace, project, id, squash); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,14 +37,25 @@ export default class GitHubClient implements GitClient { | |
return "[email protected]"; | ||
} | ||
|
||
async getPullRequest(owner: string, repo: string, prNumber: number, squash = true): Promise<GitPullRequest> { | ||
async getPullRequest(owner: string, repo: string, prNumber: number, squash: boolean | undefined): Promise<GitPullRequest> { | ||
this.logger.debug(`Fetching pull request ${owner}/${repo}/${prNumber}`); | ||
const { data } = await this.octokit.rest.pulls.get({ | ||
owner: owner, | ||
repo: repo, | ||
pull_number: prNumber, | ||
}); | ||
|
||
if (data.state == "open") { | ||
squash = false | ||
} else if (squash === undefined) { | ||
let commit = await this.octokit.rest.git.getCommit({ | ||
owner: owner, | ||
repo: repo, | ||
commit_sha: data.head.sha, | ||
}) | ||
squash = commit.data.parents.length > 1; | ||
} | ||
|
||
const commits: string[] = []; | ||
if (!squash) { | ||
// fetch all commits | ||
|
@@ -64,7 +75,7 @@ export default class GitHubClient implements GitClient { | |
return this.mapper.mapPullRequest(data as PullRequest, commits); | ||
} | ||
|
||
async getPullRequestFromUrl(prUrl: string, squash = true): Promise<GitPullRequest> { | ||
async getPullRequestFromUrl(prUrl: string, squash: boolean | undefined): Promise<GitPullRequest> { | ||
const { owner, project, id } = this.extractPullRequestData(prUrl); | ||
return this.getPullRequest(owner, project, id, squash); | ||
} | ||
|
@@ -156,4 +167,4 @@ export default class GitHubClient implements GitClient { | |
id: parseInt(prUrl.substring(prUrl.lastIndexOf("/") + 1, prUrl.length)), | ||
}; | ||
} | ||
} | ||
} |
Oops, something went wrong.