Skip to content

Commit

Permalink
fix: return GitHub no-squash commits in order
Browse files Browse the repository at this point in the history
Fixes: #114
  • Loading branch information
earl-warren committed Apr 1, 2024
1 parent 53cc505 commit ccfcb8e
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 29 deletions.
5 changes: 3 additions & 2 deletions dist/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1460,7 +1460,7 @@ class Runner {
}
// 7. apply all changes to the new branch
this.logger.debug("Cherry picking commits..");
for (const sha of originalPR.commits) {
for (const sha of originalPR.commits.reverse()) {
await git.gitCli.cherryPick(configs.folder, sha, configs.mergeStrategy, configs.mergeStrategyOption);
}
if (!configs.dryRun) {
Expand Down Expand Up @@ -5930,6 +5930,7 @@ var preservedUrlFields = [
"protocol",
"query",
"search",
"hash",
];

// Create handlers that pass events from native requests
Expand Down Expand Up @@ -6363,7 +6364,7 @@ RedirectableRequest.prototype._processResponse = function (response) {
redirectUrl.protocol !== "https:" ||
redirectUrl.host !== currentHost &&
!isSubdomain(redirectUrl.host, currentHost)) {
removeMatchingHeaders(/^(?:authorization|cookie)$/i, this._options.headers);
removeMatchingHeaders(/^(?:(?:proxy-)?authorization|cookie)$/i, this._options.headers);
}

// Evaluate the beforeRedirect callback
Expand Down
5 changes: 3 additions & 2 deletions dist/gha/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1428,7 +1428,7 @@ class Runner {
}
// 7. apply all changes to the new branch
this.logger.debug("Cherry picking commits..");
for (const sha of originalPR.commits) {
for (const sha of originalPR.commits.reverse()) {
await git.gitCli.cherryPick(configs.folder, sha, configs.mergeStrategy, configs.mergeStrategyOption);
}
if (!configs.dryRun) {
Expand Down Expand Up @@ -7659,6 +7659,7 @@ var preservedUrlFields = [
"protocol",
"query",
"search",
"hash",
];

// Create handlers that pass events from native requests
Expand Down Expand Up @@ -8092,7 +8093,7 @@ RedirectableRequest.prototype._processResponse = function (response) {
redirectUrl.protocol !== "https:" ||
redirectUrl.host !== currentHost &&
!isSubdomain(redirectUrl.host, currentHost)) {
removeMatchingHeaders(/^(?:authorization|cookie)$/i, this._options.headers);
removeMatchingHeaders(/^(?:(?:proxy-)?authorization|cookie)$/i, this._options.headers);
}

// Evaluate the beforeRedirect callback
Expand Down
2 changes: 1 addition & 1 deletion src/service/git/github/github-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default class GitHubClient implements GitClient {
}
}

return this.mapper.mapPullRequest(data as PullRequest, commits);
return this.mapper.mapPullRequest(data as PullRequest, commits.reverse());
}

async getPullRequestFromUrl(prUrl: string, squash = true): Promise<GitPullRequest> {
Expand Down
2 changes: 1 addition & 1 deletion src/service/runner/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export default class Runner {

// 7. apply all changes to the new branch
this.logger.debug("Cherry picking commits..");
for (const sha of originalPR.commits!) {
for (const sha of originalPR.commits.reverse()!) {
await git.gitCli.cherryPick(configs.folder, sha, configs.mergeStrategy, configs.mergeStrategyOption);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ describe("github pull request config parser", () => {
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 8632, false);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), ["0404fb922ab75c3a8aecad5c97d9af388df04695", "11da4e38aa3e577ffde6d546f1c52e53b04d3151"]);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), ["11da4e38aa3e577ffde6d546f1c52e53b04d3151", "0404fb922ab75c3a8aecad5c97d9af388df04695"]);

expect(configs.dryRun).toEqual(false);
expect(configs.git).toEqual({
Expand All @@ -382,7 +382,7 @@ describe("github pull request config parser", () => {
{
owner: "owner",
repo: "reponame",
head: "bp-v4-0404fb9-11da4e3",
head: "bp-v4-11da4e3-0404fb9",
base: "v4",
title: "[v4] PR Title",
body: "**Backport:** https://github.com/owner/reponame/pull/8632\r\n\r\nPlease review and merge",
Expand All @@ -394,7 +394,7 @@ describe("github pull request config parser", () => {
{
owner: "owner",
repo: "reponame",
head: "bp-v5-0404fb9-11da4e3",
head: "bp-v5-11da4e3-0404fb9",
base: "v5",
title: "[v5] PR Title",
body: "**Backport:** https://github.com/owner/reponame/pull/8632\r\n\r\nPlease review and merge",
Expand All @@ -406,7 +406,7 @@ describe("github pull request config parser", () => {
{
owner: "owner",
repo: "reponame",
head: "bp-v6-0404fb9-11da4e3",
head: "bp-v6-11da4e3-0404fb9",
base: "v6",
title: "[v6] PR Title",
body: "**Backport:** https://github.com/owner/reponame/pull/8632\r\n\r\nPlease review and merge",
Expand Down Expand Up @@ -438,7 +438,7 @@ describe("github pull request config parser", () => {
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 8632, false);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), ["0404fb922ab75c3a8aecad5c97d9af388df04695", "11da4e38aa3e577ffde6d546f1c52e53b04d3151"]);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), ["11da4e38aa3e577ffde6d546f1c52e53b04d3151", "0404fb922ab75c3a8aecad5c97d9af388df04695"]);

expect(configs.dryRun).toEqual(false);
expect(configs.git).toEqual({
Expand All @@ -453,7 +453,7 @@ describe("github pull request config parser", () => {
{
owner: "owner",
repo: "reponame",
head: "bp-v1-0404fb9-11da4e3",
head: "bp-v1-11da4e3-0404fb9",
base: "v1",
title: "[v1] PR Title",
body: "**Backport:** https://github.com/owner/reponame/pull/8632\r\n\r\nPlease review and merge",
Expand All @@ -465,7 +465,7 @@ describe("github pull request config parser", () => {
{
owner: "owner",
repo: "reponame",
head: "bp-v2-0404fb9-11da4e3",
head: "bp-v2-11da4e3-0404fb9",
base: "v2",
title: "[v2] PR Title",
body: "**Backport:** https://github.com/owner/reponame/pull/8632\r\n\r\nPlease review and merge",
Expand All @@ -477,7 +477,7 @@ describe("github pull request config parser", () => {
{
owner: "owner",
repo: "reponame",
head: "bp-v3-0404fb9-11da4e3",
head: "bp-v3-11da4e3-0404fb9",
base: "v3",
title: "[v3] PR Title",
body: "**Backport:** https://github.com/owner/reponame/pull/8632\r\n\r\nPlease review and merge",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ describe("github pull request config parser", () => {
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 8632, false);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), ["0404fb922ab75c3a8aecad5c97d9af388df04695", "11da4e38aa3e577ffde6d546f1c52e53b04d3151"]);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), ["11da4e38aa3e577ffde6d546f1c52e53b04d3151", "0404fb922ab75c3a8aecad5c97d9af388df04695"]);

expect(configs.dryRun).toEqual(false);
expect(configs.git).toEqual({
Expand Down Expand Up @@ -752,13 +752,13 @@ describe("github pull request config parser", () => {
cloneUrl: "https://github.com/owner/reponame.git"
},
nCommits: 2,
commits: ["0404fb922ab75c3a8aecad5c97d9af388df04695", "11da4e38aa3e577ffde6d546f1c52e53b04d3151"]
commits: ["11da4e38aa3e577ffde6d546f1c52e53b04d3151", "0404fb922ab75c3a8aecad5c97d9af388df04695"]
});
expect(configs.backportPullRequests.length).toEqual(1);
expect(configs.backportPullRequests[0]).toEqual({
owner: "owner",
repo: "reponame",
head: "bp-prod-0404fb9-11da4e3",
head: "bp-prod-11da4e3-0404fb9",
base: "prod",
title: "[prod] PR Title",
body: "**Backport:** https://github.com/owner/reponame/pull/8632\r\n\r\nPlease review and merge",
Expand Down
16 changes: 8 additions & 8 deletions test/service/runner/cli-github-runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -676,22 +676,22 @@ describe("cli runner", () => {
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");

expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-0404fb9-11da4e3");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-11da4e3-0404fb9");

expect(GitCLIService.prototype.fetch).toBeCalledTimes(0);

expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(2);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "0404fb922ab75c3a8aecad5c97d9af388df04695", undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "11da4e38aa3e577ffde6d546f1c52e53b04d3151", undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "0404fb922ab75c3a8aecad5c97d9af388df04695", undefined, undefined);

expect(GitCLIService.prototype.push).toBeCalledTimes(1);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-0404fb9-11da4e3");
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-11da4e3-0404fb9");

expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1);
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
owner: "owner",
repo: "reponame",
head: "bp-target-0404fb9-11da4e3",
head: "bp-target-11da4e3-0404fb9",
base: "target",
title: "[target] PR Title",
body: "**Backport:** https://github.com/owner/reponame/pull/8632\r\n\r\nPlease review and merge",
Expand Down Expand Up @@ -782,22 +782,22 @@ describe("cli runner", () => {
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");

expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-0404fb9-11da4e3");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-11da4e3-0404fb9");

expect(GitCLIService.prototype.fetch).toBeCalledTimes(0);

expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(2);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "0404fb922ab75c3a8aecad5c97d9af388df04695", "ort", "find-renames");
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "11da4e38aa3e577ffde6d546f1c52e53b04d3151", "ort", "find-renames");
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "0404fb922ab75c3a8aecad5c97d9af388df04695", "ort", "find-renames");

expect(GitCLIService.prototype.push).toBeCalledTimes(1);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-0404fb9-11da4e3");
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-11da4e3-0404fb9");

expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1);
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
owner: "owner",
repo: "reponame",
head: "bp-target-0404fb9-11da4e3",
head: "bp-target-11da4e3-0404fb9",
base: "target",
title: "[target] PR Title",
body: "**Backport:** https://github.com/owner/reponame/pull/8632\r\n\r\nPlease review and merge",
Expand Down
8 changes: 4 additions & 4 deletions test/service/runner/gha-github-runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,22 +493,22 @@ describe("gha runner", () => {
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");

expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-0404fb9-11da4e3");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-11da4e3-0404fb9");

expect(GitCLIService.prototype.fetch).toBeCalledTimes(0);

expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(2);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "0404fb922ab75c3a8aecad5c97d9af388df04695", undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "11da4e38aa3e577ffde6d546f1c52e53b04d3151", undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "0404fb922ab75c3a8aecad5c97d9af388df04695", undefined, undefined);

expect(GitCLIService.prototype.push).toBeCalledTimes(1);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-0404fb9-11da4e3");
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-11da4e3-0404fb9");

expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1);
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
owner: "owner",
repo: "reponame",
head: "bp-target-0404fb9-11da4e3",
head: "bp-target-11da4e3-0404fb9",
base: "target",
title: "[target] PR Title",
body: "**Backport:** https://github.com/owner/reponame/pull/8632\r\n\r\nPlease review and merge",
Expand Down

0 comments on commit ccfcb8e

Please sign in to comment.