mirror of
https://github.com/kiegroup/git-backporting.git
synced 2025-07-06 17:43:48 +00:00
feat(issue-54): backport pr commits without squash (#55)
* feat(issue-54): backport pr commits without squash fix https://github.com/kiegroup/git-backporting/issues/54 * feat(issue-54): fixed readme
This commit is contained in:
parent
a737aa7c4c
commit
c4dbb26c1d
29 changed files with 990 additions and 145 deletions
|
@ -31,20 +31,36 @@ export default class GitHubClient implements GitClient {
|
|||
return "noreply@github.com";
|
||||
}
|
||||
|
||||
async getPullRequest(owner: string, repo: string, prNumber: number): Promise<GitPullRequest> {
|
||||
async getPullRequest(owner: string, repo: string, prNumber: number, squash = true): Promise<GitPullRequest> {
|
||||
this.logger.info(`Getting pull request ${owner}/${repo}/${prNumber}.`);
|
||||
const { data } = await this.octokit.rest.pulls.get({
|
||||
owner: owner,
|
||||
repo: repo,
|
||||
pull_number: prNumber
|
||||
pull_number: prNumber,
|
||||
});
|
||||
|
||||
return this.mapper.mapPullRequest(data as PullRequest);
|
||||
const commits: string[] = [];
|
||||
if (!squash) {
|
||||
// fetch all commits
|
||||
try {
|
||||
const { data } = await this.octokit.rest.pulls.listCommits({
|
||||
owner: owner,
|
||||
repo: repo,
|
||||
pull_number: prNumber,
|
||||
});
|
||||
|
||||
commits.push(...data.map(c => c.sha));
|
||||
} catch(error) {
|
||||
throw new Error(`Failed to retrieve commits for pull request n. ${prNumber}`);
|
||||
}
|
||||
}
|
||||
|
||||
return this.mapper.mapPullRequest(data as PullRequest, commits);
|
||||
}
|
||||
|
||||
async getPullRequestFromUrl(prUrl: string): Promise<GitPullRequest> {
|
||||
async getPullRequestFromUrl(prUrl: string, squash = true): Promise<GitPullRequest> {
|
||||
const { owner, project, id } = this.extractPullRequestData(prUrl);
|
||||
return this.getPullRequest(owner, project, id);
|
||||
return this.getPullRequest(owner, project, id, squash);
|
||||
}
|
||||
|
||||
// WRITE
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue