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:
Andrea Lamparelli 2023-07-11 11:22:01 +02:00 committed by GitHub
parent a737aa7c4c
commit c4dbb26c1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 990 additions and 145 deletions

View file

@ -24,7 +24,7 @@ export default class GitLabMapper implements GitResponseMapper<MergeRequestSchem
}
}
async mapPullRequest(mr: MergeRequestSchema): Promise<GitPullRequest> {
async mapPullRequest(mr: MergeRequestSchema, commits?: string[]): Promise<GitPullRequest> {
return {
number: mr.iid,
author: mr.author.username,
@ -40,12 +40,17 @@ export default class GitLabMapper implements GitResponseMapper<MergeRequestSchem
labels: mr.labels ?? [],
sourceRepo: await this.mapSourceRepo(mr),
targetRepo: await this.mapTargetRepo(mr),
nCommits: 1, // info not present on mr
// if mr is merged, use merge_commit_sha otherwise use sha
// what is the difference between sha and diff_refs.head_sha?
commits: this.isMerged(mr) ? [mr.squash_commit_sha ? mr.squash_commit_sha : mr.merge_commit_sha as string] : [mr.sha]
// if commits list is provided use that as source
nCommits: (commits && commits.length > 1) ? commits.length : 1,
commits: (commits && commits.length > 1) ? commits : this.getSha(mr)
};
}
private getSha(mr: MergeRequestSchema) {
// if mr is merged, use merge_commit_sha otherwise use sha
// what is the difference between sha and diff_refs.head_sha?
return this.isMerged(mr) ? [mr.squash_commit_sha ? mr.squash_commit_sha : mr.merge_commit_sha as string] : [mr.sha];
}
async mapSourceRepo(mr: MergeRequestSchema): Promise<GitRepository> {
const project: ProjectSchema = await this.getProject(mr.source_project_id);