45 Commits
v4.7.1 ... main

Author SHA1 Message Date
dependabot[bot]
617d051801 build(deps): bump axios from 1.12.0 to 1.13.5 (#184)
Bumps [axios](https://github.com/axios/axios) from 1.12.0 to 1.13.5.
- [Release notes](https://github.com/axios/axios/releases)
- [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md)
- [Commits](https://github.com/axios/axios/compare/v1.12.0...v1.13.5)

---
updated-dependencies:
- dependency-name: axios
  dependency-version: 1.13.5
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-02-14 13:16:07 +01:00
dependabot[bot]
84086ccb67 build(deps): bump qs and express (#180)
Bumps [qs](https://github.com/ljharb/qs) and [express](https://github.com/expressjs/express). These dependencies needed to be updated together.

Updates `qs` from 6.13.0 to 6.14.1
- [Changelog](https://github.com/ljharb/qs/blob/main/CHANGELOG.md)
- [Commits](https://github.com/ljharb/qs/compare/v6.13.0...v6.14.1)

Updates `express` from 4.21.2 to 4.22.1
- [Release notes](https://github.com/expressjs/express/releases)
- [Changelog](https://github.com/expressjs/express/blob/v4.22.1/History.md)
- [Commits](https://github.com/expressjs/express/compare/4.21.2...v4.22.1)

---
updated-dependencies:
- dependency-name: qs
  dependency-version: 6.14.1
  dependency-type: indirect
- dependency-name: express
  dependency-version: 4.22.1
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-25 18:48:22 +01:00
dependabot[bot]
c93b7d67ea build(deps): bump lodash from 4.17.21 to 4.17.23 (#183)
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.21 to 4.17.23.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.17.21...4.17.23)

---
updated-dependencies:
- dependency-name: lodash
  dependency-version: 4.17.23
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-25 18:45:06 +01:00
oliverpool
430523aefa feat(#181): reconstruct script in failure comment (#182)
* feat(#181): reconstruct script in failure comment

* test: ensure steps after failure are still present
2026-01-25 18:39:11 +01:00
github-actions[bot]
baae3fe1e3 chore: release v4.8.7 (#179)
* chore: release v4.8.7

* docs: remove reverts from changelog

Signed-off-by: Andrea Lamparelli <a.lamparelli95@gmail.com>

* docs: fix changelog links

Signed-off-by: Andrea Lamparelli <a.lamparelli95@gmail.com>

---------

Signed-off-by: Andrea Lamparelli <a.lamparelli95@gmail.com>
Co-authored-by: Create or Update Pull Request Action <create-or-update-pull-request@users.noreply.github.com>
Co-authored-by: Andrea Lamparelli <a.lamparelli95@gmail.com>
2025-12-11 17:57:58 +01:00
Andrea Lamparelli
42d5ca8288 fix: override conventional-changelog-conventionalcommits (#178)
Signed-off-by: Andrea Lamparelli <a.lamparelli95@gmail.com>
2025-12-11 17:42:17 +01:00
Andrea Lamparelli
39b6b1515b fix: throw error when trying to backport single undefined commit (#177)
Signed-off-by: Andrea Lamparelli <a.lamparelli95@gmail.com>
2025-12-08 16:54:50 +01:00
Andrea Lamparelli
1a106f1eb6 build(deps): bump @commintlint and release-it (#175)
Signed-off-by: Andrea Lamparelli <a.lamparelli95@gmail.com>
2025-11-28 11:39:49 +01:00
Andrea Lamparelli
89105bb7d3 build(deps): bump glob to 10.5.0 and fix commit parser (#174)
Signed-off-by: Andrea Lamparelli <a.lamparelli95@gmail.com>
2025-11-28 11:28:06 +01:00
Andrea Lamparelli
23049ae554 Revert "build(deps): downgrade @release-it/conventional-changelog to 10.0.1 (#170)" (#172)
This reverts commit 3a675f142c.
2025-11-26 10:40:08 +01:00
Andrea Lamparelli
3a675f142c build(deps): downgrade @release-it/conventional-changelog to 10.0.1 (#170)
Signed-off-by: Andrea Lamparelli <a.lamparelli95@gmail.com>
2025-11-26 10:34:20 +01:00
Andrea Lamparelli
3799908281 build(deps): bump jest to 30.2.0 (#167)
Signed-off-by: Andrea Lamparelli <noreply@github.com>
2025-11-17 18:18:26 +01:00
Andrea Lamparelli
d5c509d220 ci: remove node 16 and add 22 and 24 (#168)
Signed-off-by: Andrea Lamparelli <noreply@github.com>
Co-authored-by: Andrea Lamparelli <noreply@github.com>
2025-11-17 18:15:33 +01:00
Andrea Lamparelli
c639b193bb build(deps): audit fix (#164)
Signed-off-by: Andrea Lamparelli <noreply@github.com>
2025-11-17 17:49:17 +01:00
Andrea Lamparelli
a31f1f1976 build(deps): bump jest to 29.7.0 (#166)
Signed-off-by: Andrea Lamparelli <a.lamparelli95@gmail.com>
2025-11-17 17:45:43 +01:00
Andrea Lamparelli
179191633c build(deps): rebuild after bump axios to 1.12.0 (#165)
Signed-off-by: Andrea Lamparelli <a.lamparelli95@gmail.com>
2025-11-17 15:08:21 +01:00
dependabot[bot]
00e591a1e6 build(deps): bump axios from 1.8.4 to 1.12.0 (#163)
Bumps [axios](https://github.com/axios/axios) from 1.8.4 to 1.12.0.
- [Release notes](https://github.com/axios/axios/releases)
- [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md)
- [Commits](https://github.com/axios/axios/compare/v1.8.4...v1.12.0)

---
updated-dependencies:
- dependency-name: axios
  dependency-version: 1.12.0
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-09-15 09:19:36 +02:00
github-actions[bot]
7d895d030f chore: release v4.8.6 (#162)
Co-authored-by: Create or Update Pull Request Action <create-or-update-pull-request@users.noreply.github.com>
2025-09-04 09:36:41 +02:00
Andrea Lamparelli
c5ce1d4c07 ci: bump node version to 20 for ci workflows (#161)
Signed-off-by: Andrea Lamparelli <a.lamparelli95@gmail.com>
2025-09-04 09:34:02 +02:00
dependabot[bot]
8c412dcb1f build(deps): bump tmp and @inquirer/editor (#160)
Removes [tmp](https://github.com/raszi/node-tmp). It's no longer used after updating ancestor dependency [@inquirer/editor](https://github.com/SBoudrias/Inquirer.js). These dependencies need to be updated together.


Removes `tmp`

Updates `@inquirer/editor` from 4.2.11 to 4.2.18
- [Release notes](https://github.com/SBoudrias/Inquirer.js/releases)
- [Commits](https://github.com/SBoudrias/Inquirer.js/compare/@inquirer/editor@4.2.11...@inquirer/editor@4.2.18)

---
updated-dependencies:
- dependency-name: tmp
  dependency-version: 
  dependency-type: indirect
- dependency-name: "@inquirer/editor"
  dependency-version: 4.2.18
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-08-26 11:40:09 +02:00
Andrea Lamparelli
8f0df7b1a4 build: audit fix (#159)
Signed-off-by: Andrea Lamparelli <a.lamparelli95@gmail.com>
2025-07-31 10:49:55 +02:00
dependabot[bot]
83a65d88c4 build(deps): bump form-data from 4.0.0 to 4.0.4 (#158)
---
updated-dependencies:
- dependency-name: form-data
  dependency-version: 4.0.4
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-07-31 10:26:58 +02:00
dependabot[bot]
8625efa217 build(deps): bump undici, @release-it/conventional-changelog and release-it (#157)
Bumps [undici](https://github.com/nodejs/undici) to 6.21.2 and updates ancestor dependencies [undici](https://github.com/nodejs/undici), [@release-it/conventional-changelog](https://github.com/release-it/conventional-changelog) and [release-it](https://github.com/release-it/release-it). These dependencies need to be updated together.


Updates `undici` from 6.21.1 to 6.21.2
- [Release notes](https://github.com/nodejs/undici/releases)
- [Commits](https://github.com/nodejs/undici/compare/v6.21.1...v6.21.2)

Updates `@release-it/conventional-changelog` from 10.0.0 to 10.0.1
- [Release notes](https://github.com/release-it/conventional-changelog/releases)
- [Commits](https://github.com/release-it/conventional-changelog/compare/10.0.0...10.0.1)

Updates `release-it` from 18.1.2 to 19.0.2
- [Release notes](https://github.com/release-it/release-it/releases)
- [Changelog](https://github.com/release-it/release-it/blob/main/CHANGELOG.md)
- [Commits](https://github.com/release-it/release-it/compare/18.1.2...19.0.2)

---
updated-dependencies:
- dependency-name: undici
  dependency-version: 6.21.2
  dependency-type: indirect
- dependency-name: "@release-it/conventional-changelog"
  dependency-version: 10.0.1
  dependency-type: direct:development
- dependency-name: release-it
  dependency-version: 19.0.2
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-05-15 17:45:57 +02:00
github-actions[bot]
7ff4fce545 chore: release v4.8.5 (#156)
Co-authored-by: Create or Update Pull Request Action <create-or-update-pull-request@users.noreply.github.com>
2025-04-15 10:57:49 +02:00
Andrea Lamparelli
c9a7375bf9 build(deps): upgrade release-it to v18 (#153) 2025-04-15 10:42:44 +02:00
Andrea Lamparelli
d74a787035 fix(#151): fix gitlab post comments url (#152) 2025-04-14 17:48:09 +02:00
Andrea Lamparelli
3a9d367b48 build(deps): audit fix (#150) 2025-03-24 20:23:36 +01:00
github-actions[bot]
b9ed3ac959 chore: release v4.8.4 (#147)
Co-authored-by: Create or Update Pull Request Action <create-or-update-pull-request@users.noreply.github.com>
2024-11-02 13:31:20 +01:00
Andrea Lamparelli
3deee59d4c fix: abort conflicting cherry-pick before starting new one (#146)
Signed-off-by: Andrea Lamparelli <a.lamparelli95@gmail.com>
2024-10-28 11:51:36 +01:00
Andrea Lamparelli
2b4b429356 build(deps): audit run (#143)
Signed-off-by: Andrea Lamparelli <a.lamparelli95@gmail.com>
2024-10-10 11:16:48 +02:00
dependabot[bot]
31eabaf84a build(deps): bump cookie and express (#142)
Bumps [cookie](https://github.com/jshttp/cookie) and [express](https://github.com/expressjs/express). These dependencies needed to be updated together.

Updates `cookie` from 0.6.0 to 0.7.1
- [Release notes](https://github.com/jshttp/cookie/releases)
- [Commits](https://github.com/jshttp/cookie/compare/v0.6.0...v0.7.1)

Updates `express` from 4.21.0 to 4.21.1
- [Release notes](https://github.com/expressjs/express/releases)
- [Changelog](https://github.com/expressjs/express/blob/4.21.1/History.md)
- [Commits](https://github.com/expressjs/express/compare/4.21.0...4.21.1)

---
updated-dependencies:
- dependency-name: cookie
  dependency-type: indirect
- dependency-name: express
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-10-10 11:07:36 +02:00
github-actions[bot]
a14014e89e chore: release v4.8.3 (#141)
Co-authored-by: Create or Update Pull Request Action <create-or-update-pull-request@users.noreply.github.com>
2024-10-10 10:58:28 +02:00
Ratchanan Srirattanamet
b4d0481c56 fix: auto-no-squash inference for GitLab (#140)
When a GitLab MR is not squashed, `squash_commit_sha` will be `null`,
not `undefined`. Update `inferSquash()` to account for this.
2024-10-07 14:40:31 +02:00
github-actions[bot]
c3daf80306 chore: release v4.8.2 (#139)
Co-authored-by: Create or Update Pull Request Action <create-or-update-pull-request@users.noreply.github.com>
2024-10-07 11:21:34 +02:00
Andrea Lamparelli
6d6592f958 ci: upgrade github actions (#138)
Signed-off-by: Andrea Lamparelli <a.lamparelli95@gmail.com>
2024-10-03 20:04:40 +02:00
Ratchanan Srirattanamet
e2d73d050c fix: cherry-pick order on GitLab by reversing commmit list only once (#137)
GitLabClient already handle commit order reversing, so re-handle it in
Runner causes cherry-pick order on GitLab to be wrong.

Remove commit order handling from Runner, and instead handle difference
between GitHub and Codeberg inside GitHubClient.

Now, since the default of --bp-branch-name takes the commit list from
{GitHub,GitLab}Client directly, that means backporting branch name
on Codeberg will also be changed to have commits in the correct order
too (old to new, in line with GitHub and GitLab), which is IMO a nice
bonus.
2024-10-03 19:39:03 +02:00
Ratchanan Srirattanamet
1e8358bb2c fix: handle Codeberg returning null entry in requested_reviewers (#136)
Codeberg can return null as part of requested_reviewers (presumably
because that user has been deleted). Handle that case, and also for
assignees since we're at it.
2024-10-03 19:21:14 +02:00
dependabot[bot]
fe22142b85 build(deps): bump serve-static and express (#134)
Bumps [serve-static](https://github.com/expressjs/serve-static) and [express](https://github.com/expressjs/express). These dependencies needed to be updated together.

Updates `serve-static` from 1.15.0 to 1.16.2
- [Release notes](https://github.com/expressjs/serve-static/releases)
- [Changelog](https://github.com/expressjs/serve-static/blob/v1.16.2/HISTORY.md)
- [Commits](https://github.com/expressjs/serve-static/compare/v1.15.0...v1.16.2)

Updates `express` from 4.19.2 to 4.21.0
- [Release notes](https://github.com/expressjs/express/releases)
- [Changelog](https://github.com/expressjs/express/blob/4.21.0/History.md)
- [Commits](https://github.com/expressjs/express/compare/4.19.2...4.21.0)

---
updated-dependencies:
- dependency-name: serve-static
  dependency-type: indirect
- dependency-name: express
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-09-17 16:59:26 +02:00
dependabot[bot]
26a4c5dfd2 build(deps): bump axios from 1.6.0 to 1.7.4 (#133)
Bumps [axios](https://github.com/axios/axios) from 1.6.0 to 1.7.4.
- [Release notes](https://github.com/axios/axios/releases)
- [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md)
- [Commits](https://github.com/axios/axios/compare/v1.6.0...v1.7.4)

---
updated-dependencies:
- dependency-name: axios
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-08-27 09:53:44 +02:00
github-actions[bot]
c5d7f0ea56 chore: release v4.8.1 (#132)
Co-authored-by: Create or Update Pull Request Action <create-or-update-pull-request@users.noreply.github.com>
2024-07-16 19:27:31 +02:00
Andrea Lamparelli
cb3473d7c9 fix(gh130): apply commits in the correct order on github (#131) 2024-07-16 17:49:23 +02:00
dependabot[bot]
da6431b114 build(deps-dev): bump braces from 3.0.2 to 3.0.3 (#129)
Bumps [braces](https://github.com/micromatch/braces) from 3.0.2 to 3.0.3.
- [Changelog](https://github.com/micromatch/braces/blob/master/CHANGELOG.md)
- [Commits](https://github.com/micromatch/braces/compare/3.0.2...3.0.3)

---
updated-dependencies:
- dependency-name: braces
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-06-21 14:05:07 +02:00
github-actions[bot]
c22286f85e chore: release v4.8.0 (#128)
Co-authored-by: Create or Update Pull Request Action <create-or-update-pull-request@users.noreply.github.com>
2024-04-11 08:44:11 +02:00
Andrea Lamparelli
2bb7f73112 feat: implement error notification as pr comment (#124)
* feat: implement error notification as pr comment

* Update action.yml

Co-authored-by: Earl Warren <109468362+earl-warren@users.noreply.github.com>

* feat: implement gitlab client and surround with try catch

* docs: add error notification enablment in the doc

* feat: disable comment if dry-run

* feat: update the default comment on error

---------

Co-authored-by: Earl Warren <109468362+earl-warren@users.noreply.github.com>
2024-04-10 23:01:16 +02:00
Earl Warren
6042bcc40b feat: auto-detect the value of the no-squash option (#118)
The auto-no-squash option is added to:

* backport all the commits when the pull/merge request has been merged
* backport the squashed commit otherwise

It is equivalent to dynamically adjust the value of the no-squash
option, depending on the context.

The no-squash option is kept for backward compatibility for a single
use case: backporting the merged commit instead of backporting the
commits of the pull/merge request request.

Detecting if a pull/merge request was squashed or not depends on the
underlying forge:

* Forgejo / GitHub: use the API to count the number of parents
* GitLab: if the squash_commit_sha is set, the merge request was
  squashed

If the pull/merge request is open, always backport all the commits it
contains.

Fixes: https://github.com/kiegroup/git-backporting/issues/113

Co-authored-by: Andrea Lamparelli <a.lamparelli95@gmail.com>
2024-04-08 18:51:13 +02:00
54 changed files with 23768 additions and 12258 deletions

View File

@@ -13,15 +13,15 @@ jobs:
name: ${{ matrix.os }} - node ${{ matrix.node-version }}
strategy:
matrix:
node-version: [16, 18, 20]
node-version: [18, 20, 22, 24]
os: [ubuntu-latest]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup Node ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm ci

View File

@@ -16,7 +16,7 @@ jobs:
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ArtiomTr/jest-coverage-report-action@v2
with:
test-script: npm test

View File

@@ -19,13 +19,13 @@ jobs:
name: Prepare release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 18
node-version: 20
- name: Git config
run: |
git config user.name "${GITHUB_ACTOR}"

View File

@@ -18,15 +18,15 @@ jobs:
name: ${{ matrix.os }} - node ${{ matrix.node-version }}
strategy:
matrix:
node-version: [16, 18, 20]
node-version: [18, 20, 22, 24]
os: [ubuntu-latest]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup Node ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm ci

View File

@@ -17,13 +17,13 @@ jobs:
name: Release package
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 18
node-version: 20
- name: Git config
run: |
git config user.name "${GITHUB_ACTOR}"

View File

@@ -1,5 +1,63 @@
# Changelog
## [4.8.7](///compare/v4.8.6...v4.8.7) (2025-12-11)
### Bug Fixes
* override conventional-changelog-conventionalcommits ([#178](https://github.com/kiegroup/git-backporting/issues/178)) ([42d5ca8](https://github.com/kiegroup/git-backporting/commit/42d5ca8288b2af94b1d47f7fe5cb153ae2480822))
* throw error when trying to backport single undefined commit ([#177](https://github.com/kiegroup/git-backporting/issues/177)) ([39b6b15](https://github.com/kiegroup/git-backporting/commit/39b6b1515be29d0fc5b48f2a85342217e3c22ce8))
## <small>4.8.6 (2025-09-04)</small>
* ci: bump node version to 20 for ci workflows (#161) ([c5ce1d4](https://github.com/kiegroup/git-backporting/commit/c5ce1d4)), closes [#161](https://github.com/kiegroup/git-backporting/issues/161)
* build: audit fix (#159) ([8f0df7b](https://github.com/kiegroup/git-backporting/commit/8f0df7b)), closes [#159](https://github.com/kiegroup/git-backporting/issues/159)
* build(deps): bump form-data from 4.0.0 to 4.0.4 (#158) ([83a65d8](https://github.com/kiegroup/git-backporting/commit/83a65d8)), closes [#158](https://github.com/kiegroup/git-backporting/issues/158)
* build(deps): bump tmp and @inquirer/editor (#160) ([8c412dc](https://github.com/kiegroup/git-backporting/commit/8c412dc)), closes [#160](https://github.com/kiegroup/git-backporting/issues/160)
* build(deps): bump undici, @release-it/conventional-changelog and release-it (#157) ([8625efa](https://github.com/kiegroup/git-backporting/commit/8625efa)), closes [#157](https://github.com/kiegroup/git-backporting/issues/157)
## <small>4.8.5 (2025-04-15)</small>
* build(deps): audit fix (#150) ([3a9d367](https://github.com/kiegroup/git-backporting/commit/3a9d367)), closes [#150](https://github.com/kiegroup/git-backporting/issues/150)
* build(deps): upgrade release-it to v18 (#153) ([c9a7375](https://github.com/kiegroup/git-backporting/commit/c9a7375)), closes [#153](https://github.com/kiegroup/git-backporting/issues/153)
* fix(#151): fix gitlab post comments url (#152) ([d74a787](https://github.com/kiegroup/git-backporting/commit/d74a787)), closes [#152](https://github.com/kiegroup/git-backporting/issues/152)
## [4.8.4](https://github.com/kiegroup/git-backporting/compare/v4.8.3...v4.8.4) (2024-11-02)
### Bug Fixes
* abort conflicting cherry-pick before starting new one ([#146](https://github.com/kiegroup/git-backporting/issues/146)) ([3deee59](https://github.com/kiegroup/git-backporting/commit/3deee59d4c3b726ae131b5974af4618dd5e7d1d2))
## [4.8.3](https://github.com/kiegroup/git-backporting/compare/v4.8.2...v4.8.3) (2024-10-10)
### Bug Fixes
* auto-no-squash inference for GitLab ([#140](https://github.com/kiegroup/git-backporting/issues/140)) ([b4d0481](https://github.com/kiegroup/git-backporting/commit/b4d0481c5649115367f1ae0724d12d55b6b86e10))
## [4.8.2](https://github.com/kiegroup/git-backporting/compare/v4.8.1...v4.8.2) (2024-10-07)
### Bug Fixes
* cherry-pick order on GitLab by reversing commmit list only once ([#137](https://github.com/kiegroup/git-backporting/issues/137)) ([e2d73d0](https://github.com/kiegroup/git-backporting/commit/e2d73d050c8387c0858877ac3c56c565bacaf4f9))
* handle Codeberg returning null entry in requested_reviewers ([#136](https://github.com/kiegroup/git-backporting/issues/136)) ([1e8358b](https://github.com/kiegroup/git-backporting/commit/1e8358bb2c461c56cf86e82bec4d71284866b13b))
## [4.8.1](https://github.com/kiegroup/git-backporting/compare/v4.8.0...v4.8.1) (2024-07-16)
### Bug Fixes
* **gh130:** apply commits in the correct order on github ([#131](https://github.com/kiegroup/git-backporting/issues/131)) ([cb3473d](https://github.com/kiegroup/git-backporting/commit/cb3473d7c9de66cb7bec188f08538e134cdc4bc0))
## [4.8.0](https://github.com/kiegroup/git-backporting/compare/v4.7.1...v4.8.0) (2024-04-11)
### Features
* auto-detect the value of the no-squash option ([#118](https://github.com/kiegroup/git-backporting/issues/118)) ([6042bcc](https://github.com/kiegroup/git-backporting/commit/6042bcc40ba83593a23dfe4d92cf50655a05b1cd))
* implement error notification as pr comment ([#124](https://github.com/kiegroup/git-backporting/issues/124)) ([2bb7f73](https://github.com/kiegroup/git-backporting/commit/2bb7f731127e099d1f196e6785e992589f7c4940))
## [4.7.1](https://github.com/kiegroup/git-backporting/compare/v4.7.0...v4.7.1) (2024-04-03)
@@ -166,4 +224,4 @@ Project moved under @kiegroup organization.
### Features
* backport still open pull requests ([b3936e0](https://github.com/kiegroup/git-backporting/commit/b3936e019a19976281c5e2582904264e974b8b42))
* pull request backporting ([b3936e0](https://github.com/kiegroup/git-backporting/commit/b3936e019a19976281c5e2582904264e974b8b42))
* pull request backporting ([b3936e0](https://github.com/kiegroup/git-backporting/commit/b3936e019a19976281c5e2582904264e974b8b42))

View File

@@ -70,7 +70,13 @@ It works in this way: given the provided `pull/merge request` it infers the serv
After that it clones the corresponding git repository, check out in the provided `target branch` and create a new branch from that (name automatically generated if not provided as option).
By default the tool will try to cherry-pick the single squashed/merged commit into the newly created branch (please consider using `--no-squash` option if you want to cherry-pick all commits belonging to the provided pull request).
By default the tool will try to cherry-pick the single squashed/merged commit into the newly created branch. The `--no-squash` and `--auto-no-squash` options control this behavior according the following table.
| No squash | Auto no squash |Behavior|
|---|---|---|
| unset/false | unset/false | cherry-pick a single commit, squashed or merged |
| set/true | unset/false | cherry-pick all commits found in the the original pull/merge request|
| (ignored) | set/true | cherry-pick all commits if the original pull/merge request was merged, a single commit if it was squashed |
Based on the original pull request, creates a new one containing the backporting to the target branch. Note that most of these information can be overridden with appropriate CLI options or GHA inputs.
@@ -121,11 +127,13 @@ This tool comes with some inputs that allow users to override the default behavi
| Backport Branch Names | --bp-branch-name | N | Comma separated lists of the backporting pull request branch names, if they exceeds 250 chars they will be truncated | bp-{target-branch}-{sha1}...{shaN} |
| Labels | --labels | N | Provide custom labels to be added to the backporting pull request | [] |
| Inherit labels | --inherit-labels | N | If enabled inherit lables from the original pull request | false |
| No squash | --no-squash | N | If provided the backporting will try to backport all pull request commits without squashing | false |
| No squash | --no-squash | N | Backport all commits found in the pull request. The default behavior is to only backport the first commit that was merged in the base branch. | |
| Auto no squash | --auto-no-squash | N | If the pull request was merged or is open, backport all commits. If the pull request commits were squashed, backport the squashed commit. | |
| Strategy | --strategy | N | Cherry pick merging strategy, see [git-merge](https://git-scm.com/docs/git-merge#_merge_strategies) doc for all possible values | "recursive" |
| Strategy Option | --strategy-option | N | Cherry pick merging strategy option, see [git-merge](https://git-scm.com/docs/git-merge#_merge_strategies) doc for all possible values | "theirs" |
| Cherry-pick Options | --cherry-pick-options | N | Additional cherry-pick options, see [git-cherry-pick](https://git-scm.com/docs/git-cherry-pick) doc for all possible values | "theirs" |
| Additional comments | --comments | N | Semicolon separated list of additional comments to be posted to the backported pull request | [] |
| Enable error notification | --enable-err-notification | N | If true, enable the error notification as comment on the original pull request | false |
| Dry Run | -d, --dry-run | N | If enabled the tool does not push nor create anything remotely, use this to skip PR creation | false |
> **NOTE**: `pull request` and (`target branch` or `target branch pattern`) are *mandatory*, they must be provided as CLI options or as part of the configuration file (if used).

View File

@@ -85,10 +85,14 @@ inputs:
default: "false"
no-squash:
description: >
If set to true the tool will backport all commits as part of the pull request
instead of the suqashed one
Backport all commits found in the pull request.
The default behavior is to only backport the first commit that was merged in the base branch.
required: false
auto-no-squash:
description: >
If the pull request was merged or is open, backport all commits.
If the pull request commits were squashed, backport the squashed commit.
required: false
default: "false"
strategy:
description: Cherry-pick merge strategy
required: false
@@ -105,6 +109,11 @@ inputs:
description: >
Semicolon separated list of additional comments to be posted to the backported pull request
required: false
enable-err-notification:
description: >
If true, enable the error notification as comment on the original pull request
required: false
default: "false"
runs:
using: node20

3784
dist/cli/index.js vendored

File diff suppressed because it is too large Load Diff

3778
dist/gha/index.js vendored

File diff suppressed because it is too large Load Diff

View File

@@ -35,7 +35,7 @@ jobs:
fail-fast: true
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Backporting

View File

@@ -9,7 +9,8 @@ const jestConfig: Config.InitialOptions = {
"^@bp/(.*)$": "<rootDir>/src/$1",
},
clearMocks: true,
resetMocks: true,
restoreMocks: false,
resetMocks: false,
modulePathIgnorePatterns: ["<rootDir>/build/", "<rootDir>/dist/"],
coveragePathIgnorePatterns: ["<rootDir>/node_modules/", "<rootDir>/test/", "<rootDir>/build/", "<rootDir>/dist/"]
};

2
mise.toml Normal file
View File

@@ -0,0 +1,2 @@
[tools]
node = "20"

21366
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "@kie/git-backporting",
"version": "4.7.1",
"version": "4.8.7",
"description": "Git backporting is a tool to execute automatic pull request git backporting.",
"author": "",
"license": "MIT",
@@ -50,25 +50,26 @@
},
"homepage": "https://github.com/kiegroup/git-backporting#readme",
"devDependencies": {
"@commitlint/cli": "^17.4.0",
"@commitlint/config-conventional": "^17.4.0",
"@commitlint/cli": "^20.1.0",
"@commitlint/config-conventional": "^20.0.0",
"@gitbeaker/rest": "^39.1.0",
"@kie/mock-github": "^1.1.0",
"@octokit/webhooks-types": "^6.8.0",
"@release-it/conventional-changelog": "^7.0.0",
"@release-it/conventional-changelog": "^10.0.0",
"@types/fs-extra": "^9.0.13",
"@types/jest": "^29.2.4",
"@types/node": "^18.11.17",
"@typescript-eslint/eslint-plugin": "^5.47.0",
"@typescript-eslint/parser": "^5.47.0",
"@vercel/ncc": "^0.36.0",
"conventional-commits-parser": "^6.2.0",
"eslint": "^8.30.0",
"husky": "^8.0.2",
"jest": "^29.0.0",
"jest": "^30.0.0",
"jest-sonar-reporter": "^2.0.0",
"release-it": "^16.1.3",
"release-it": "^19.0.6",
"semver": "^7.3.8",
"ts-jest": "^29.0.0",
"ts-jest": "^29.4.5",
"ts-node": "^10.8.1",
"tsc-alias": "^1.8.2",
"tsconfig-paths": "^4.1.0",
@@ -82,5 +83,8 @@
"fs-extra": "^11.1.0",
"https": "^1.0.0",
"simple-git": "^3.15.1"
},
"overrides": {
"conventional-changelog-conventionalcommits": "^8.0.0"
}
}

View File

@@ -44,10 +44,12 @@ export default abstract class ArgsParser {
labels: this.getOrDefault(args.labels, []),
inheritLabels: this.getOrDefault(args.inheritLabels, false),
squash: this.getOrDefault(args.squash, true),
autoNoSquash: this.getOrDefault(args.autoNoSquash, false),
strategy: this.getOrDefault(args.strategy),
strategyOption: this.getOrDefault(args.strategyOption),
cherryPickOptions: this.getOrDefault(args.cherryPickOptions),
comments: this.getOrDefault(args.comments)
comments: this.getOrDefault(args.comments),
enableErrorNotification: this.getOrDefault(args.enableErrorNotification, false),
};
}
}

View File

@@ -50,7 +50,7 @@ export function getAsSemicolonSeparatedList(value: string): string[] | undefined
return trimmed !== "" ? trimmed.split(";").map(v => v.trim()) : undefined;
}
export function getAsBooleanOrDefault(value: string): boolean | undefined {
export function getAsBooleanOrUndefined(value: string): boolean | undefined {
const trimmed = value.trim();
return trimmed !== "" ? trimmed.toLowerCase() === "true" : undefined;
}

View File

@@ -22,9 +22,11 @@ export interface Args {
inheritReviewers?: boolean, // if true and reviewers == [] then inherit reviewers from original pr
labels?: string[], // backport pr labels
inheritLabels?: boolean, // if true inherit labels from original pr
squash?: boolean, // if false use squashed/merged commit otherwise backport all commits as part of the pr
squash?: boolean,
autoNoSquash?: boolean,
strategy?: string, // cherry-pick merge strategy
strategyOption?: string, // cherry-pick merge strategy option
cherryPickOptions?: string, // additional cherry-pick options
comments?: string[], // additional comments to be posted
enableErrorNotification?: boolean, // enable the error notification on original pull request
}

View File

@@ -28,11 +28,13 @@ export default class CLIArgsParser extends ArgsParser {
.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", 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", "backport all commits found in the pull request. The default behavior is to only backport the first commit that was merged in the base branch")
.option("--auto-no-squash", "if the pull request was merged or is open, backport all commits. If the pull request commits were squashed, backport the squashed commit.")
.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")
.option("--comments <comments>", "semicolon separated list of additional comments to be posted to the backported pull request", getAsSemicolonSeparatedList)
.option("--enable-err-notification", "if true, enable the error notification as comment on the original pull request")
.option("-cf, --config-file <config-file>", "configuration file containing all valid options, the json must match Args interface");
}
@@ -66,10 +68,12 @@ export default class CLIArgsParser extends ArgsParser {
labels: opts.labels,
inheritLabels: opts.inheritLabels,
squash: opts.squash,
autoNoSquash: opts.autoNoSquash,
strategy: opts.strategy,
strategyOption: opts.strategyOption,
cherryPickOptions: opts.cherryPickOptions,
comments: opts.comments,
enableErrorNotification: opts.enableErrNotification,
};
}

View File

@@ -1,7 +1,7 @@
import ArgsParser from "@bp/service/args/args-parser";
import { Args } from "@bp/service/args/args.types";
import { getInput } from "@actions/core";
import { getAsBooleanOrDefault, getAsCleanedCommaSeparatedList, getAsCommaSeparatedList, getAsSemicolonSeparatedList, getOrUndefined, readConfigFile } from "@bp/service/args/args-utils";
import { getAsBooleanOrUndefined, getAsCleanedCommaSeparatedList, getAsCommaSeparatedList, getAsSemicolonSeparatedList, getOrUndefined, readConfigFile } from "@bp/service/args/args-utils";
export default class GHAArgsParser extends ArgsParser {
@@ -13,7 +13,7 @@ export default class GHAArgsParser extends ArgsParser {
args = readConfigFile(configFile);
} else {
args = {
dryRun: getAsBooleanOrDefault(getInput("dry-run")),
dryRun: getAsBooleanOrUndefined(getInput("dry-run")),
auth: getOrUndefined(getInput("auth")),
pullRequest: getInput("pull-request"),
targetBranch: getOrUndefined(getInput("target-branch")),
@@ -28,14 +28,16 @@ export default class GHAArgsParser extends ArgsParser {
bpBranchName: getOrUndefined(getInput("bp-branch-name")),
reviewers: getAsCleanedCommaSeparatedList(getInput("reviewers")),
assignees: getAsCleanedCommaSeparatedList(getInput("assignees")),
inheritReviewers: !getAsBooleanOrDefault(getInput("no-inherit-reviewers")),
inheritReviewers: !getAsBooleanOrUndefined(getInput("no-inherit-reviewers")),
labels: getAsCommaSeparatedList(getInput("labels")),
inheritLabels: getAsBooleanOrDefault(getInput("inherit-labels")),
squash: !getAsBooleanOrDefault(getInput("no-squash")),
inheritLabels: getAsBooleanOrUndefined(getInput("inherit-labels")),
squash: !getAsBooleanOrUndefined(getInput("no-squash")),
autoNoSquash: getAsBooleanOrUndefined(getInput("auto-no-squash")),
strategy: getOrUndefined(getInput("strategy")),
strategyOption: getOrUndefined(getInput("strategy-option")),
cherryPickOptions: getOrUndefined(getInput("cherry-pick-options")),
comments: getAsSemicolonSeparatedList(getInput("comments")),
enableErrorNotification: getAsBooleanOrUndefined(getInput("enable-err-notification")),
};
}

View File

@@ -2,11 +2,19 @@
import { BackportPullRequest, GitPullRequest } from "@bp/service/git/git.types";
export const MESSAGE_ERROR_PLACEHOLDER = "{{error}}";
export const MESSAGE_TARGET_BRANCH_PLACEHOLDER = "{{target-branch}}";
export interface LocalGit {
user: string, // local git user
email: string, // local git email
}
export interface ErrorNotification {
enabled: boolean, // if the error notification is enabled
message: string, // notification message, placeholder {{error}} will be replaced with actual error
}
/**
* Internal configuration object
*/
@@ -20,6 +28,7 @@ export interface Configs {
cherryPickOptions?: string, // additional cherry-pick options
originalPullRequest: GitPullRequest,
backportPullRequests: BackportPullRequest[],
errorNotification: ErrorNotification,
}
export enum AuthTokenId {

View File

@@ -1,7 +1,7 @@
import { getAsCleanedCommaSeparatedList, getAsCommaSeparatedList } from "@bp/service/args/args-utils";
import { Args } from "@bp/service/args/args.types";
import ConfigsParser from "@bp/service/configs/configs-parser";
import { Configs } from "@bp/service/configs/configs.types";
import { Configs, MESSAGE_TARGET_BRANCH_PLACEHOLDER } from "@bp/service/configs/configs.types";
import GitClient from "@bp/service/git/git-client";
import GitClientFactory from "@bp/service/git/git-client-factory";
import { BackportPullRequest, GitPullRequest } from "@bp/service/git/git.types";
@@ -16,9 +16,12 @@ export default class PullRequestConfigsParser extends ConfigsParser {
}
public async parse(args: Args): Promise<Configs> {
let pr: GitPullRequest;
let pr: GitPullRequest;
if (args.autoNoSquash) {
args.squash = undefined;
}
try {
pr = await this.gitClient.getPullRequestFromUrl(args.pullRequest, args.squash!);
pr = await this.gitClient.getPullRequestFromUrl(args.pullRequest, args.squash);
} catch(error) {
this.logger.error("Something went wrong retrieving pull request");
throw error;
@@ -55,7 +58,11 @@ export default class PullRequestConfigsParser extends ConfigsParser {
git: {
user: args.gitUser ?? this.gitClient.getDefaultGitUser(),
email: args.gitEmail ?? this.gitClient.getDefaultGitEmail(),
}
},
errorNotification: {
enabled: args.enableErrorNotification ?? false,
message: this.getDefaultErrorComment(),
},
};
}
@@ -63,6 +70,11 @@ export default class PullRequestConfigsParser extends ConfigsParser {
return "bp";
}
private getDefaultErrorComment(): string {
// TODO: fetch from arg or set default with placeholder {{error}}
return `The backport to \`${MESSAGE_TARGET_BRANCH_PLACEHOLDER}\` failed. Check the latest run for more details.`;
}
/**
* Parse the provided labels and return a list of target branches
* obtained by applying the provided pattern as regular expression extractor
@@ -127,7 +139,10 @@ export default class PullRequestConfigsParser extends ConfigsParser {
let backportBranch = bpBranchNames.length > 1 ? bpBranchNames[idx] : bpBranchNames[0];
if (backportBranch === undefined || backportBranch.trim() === "") {
// for each commit takes the first 7 chars that are enough to uniquely identify them in most of the projects
const concatenatedCommits: string = originalPullRequest.commits!.map(c => c.slice(0, 7)).join("-");
const concatenatedCommits: string = originalPullRequest.commits!.filter(c => c).map(c => c.slice(0, 7)).join("-");
if (concatenatedCommits === "") {
throw new Error("Missing commits, stopping the backporting!");
}
backportBranch = `bp-${tb}-${concatenatedCommits}`;
} else if (bpBranchNames.length == 1 && targetBranches.length > 1) {
// multiple targets and single custom backport branch name we need to differentiate branch names

View File

@@ -68,6 +68,15 @@ export default class GitCLIService {
}
this.logger.info(`Folder ${to} already exist. Won't clone`);
// ensure the working tree is properly reset - no stale changes
// from previous (failed) backport
const ongoingCherryPick = await this.anyConflict(to);
if (ongoingCherryPick) {
this.logger.warn("Found previously failed cherry-pick, aborting it");
await this.git(to).raw(["cherry-pick", "--abort"]);
}
// checkout to the proper branch
this.logger.info(`Checking out branch ${branch}`);
await this.git(to).checkout(branch);
@@ -131,6 +140,21 @@ export default class GitCLIService {
}
}
/**
* Check whether there are some conflicts in the current working directory
* which means there is an ongoing cherry-pick that did not complete successfully
* @param cwd repository in which the check should be performed
* @return true if there is some conflict, false otherwise
*/
async anyConflict(cwd: string): Promise<boolean> {
const status = await this.git(cwd).status();
if (status.conflicted.length > 0) {
this.logger.debug(`Found conflicts in branch ${status.current}`);
return true;
}
return false;
}
/**
* Push a branch to a remote
* @param cwd repository in which the push should be performed

View File

@@ -25,7 +25,7 @@ import { BackportPullRequest, GitClientType, GitPullRequest } from "@bp/service/
* @param squash if true keep just one single commit, otherwise get the full list
* @returns {Promise<PullRequest>}
*/
getPullRequest(owner: string, repo: string, prNumber: number, squash: boolean): Promise<GitPullRequest>;
getPullRequest(owner: string, repo: string, prNumber: number, squash: boolean | undefined): Promise<GitPullRequest>;
/**
* Get a pull request object from the underneath git service
@@ -33,7 +33,7 @@ import { BackportPullRequest, GitClientType, GitPullRequest } from "@bp/service/
* @param squash if true keep just one single commit, otherwise get the full list
* @returns {Promise<PullRequest>}
*/
getPullRequestFromUrl(prUrl: string, squash: boolean): Promise<GitPullRequest>;
getPullRequestFromUrl(prUrl: string, squash: boolean | undefined): Promise<GitPullRequest>;
// WRITE
@@ -44,4 +44,11 @@ import { BackportPullRequest, GitClientType, GitPullRequest } from "@bp/service/
*/
createPullRequest(backport: BackportPullRequest): Promise<string>;
/**
* Create a new comment on the provided pull request
* @param prUrl pull request's URL
* @param comment comment body
*/
createPullRequestComment(prUrl: string, comment: string): Promise<string | undefined>;
}

View File

@@ -1,3 +1,4 @@
import LoggerServiceFactory from "@bp/service/logger/logger-service-factory";
import { GitClientType } from "@bp/service/git/git.types";
import { AuthTokenId } from "@bp/service/configs/configs.types";
@@ -41,6 +42,29 @@ export const inferGitApiUrl = (prUrl: string, apiVersion = "v4"): string => {
return `${baseUrl}/api/${apiVersion}`;
};
/**
* Infer the value of the squash option
* @param open true if the pull/merge request is still open
* @param squash_commit undefined or null if the pull/merge request was merged, the sha of the squashed commit if it was squashed
* @returns true if a single commit must be cherry-picked, false if all merged commits must be cherry-picked
*/
export const inferSquash = (open: boolean, squash_commit: string | undefined | null): boolean => {
const logger = LoggerServiceFactory.getLogger();
if (open) {
logger.debug("cherry-pick all commits because they have not been merged (or squashed) in the base branch yet");
return false;
} else {
if (squash_commit) {
logger.debug(`cherry-pick the squashed commit ${squash_commit}`);
return true;
} else {
logger.debug("cherry-pick the merged commit(s)");
return false;
}
}
};
/**
* Retrieve the git token from env variable, the default is taken from GIT_TOKEN env.
* All specific git env variable have precedence and override the default one.

View File

@@ -1,7 +1,7 @@
export interface GitPullRequest {
number?: number,
author: string,
url?: string,
url: string,
htmlUrl?: string,
state?: GitRepoState,
merged?: boolean,

View File

@@ -1,4 +1,5 @@
import GitClient from "@bp/service/git/git-client";
import { inferSquash } from "@bp/service/git/git-util";
import { BackportPullRequest, GitClientType, GitPullRequest } from "@bp/service/git/git.types";
import GitHubMapper from "@bp/service/git/github/github-mapper";
import OctokitFactory from "@bp/service/git/github/octokit-factory";
@@ -37,7 +38,7 @@ export default class GitHubClient implements GitClient {
return "noreply@github.com";
}
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,
@@ -45,6 +46,22 @@ export default class GitHubClient implements GitClient {
pull_number: prNumber,
});
if (squash === undefined) {
let commit_sha: string | undefined = undefined;
const open: boolean = data.state == "open";
if (!open) {
const commit = await this.octokit.rest.git.getCommit({
owner: owner,
repo: repo,
commit_sha: (data.merge_commit_sha as string),
});
if (commit.data.parents.length === 1) {
commit_sha = (data.merge_commit_sha as string);
}
}
squash = inferSquash(open, commit_sha);
}
const commits: string[] = [];
if (!squash) {
// fetch all commits
@@ -56,6 +73,11 @@ export default class GitHubClient implements GitClient {
});
commits.push(...data.map(c => c.sha));
if (this.isForCodeberg) {
// For some reason, even though Codeberg advertises API compatibility
// with GitHub, it returns commits in reversed order.
commits.reverse();
}
} catch(error) {
throw new Error(`Failed to retrieve commits for pull request n. ${prNumber}`);
}
@@ -64,7 +86,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);
}
@@ -141,6 +163,29 @@ export default class GitHubClient implements GitClient {
return data.html_url;
}
async createPullRequestComment(prUrl: string, comment: string): Promise<string | undefined> {
let commentUrl: string | undefined = undefined;
try {
const { owner, project, id } = this.extractPullRequestData(prUrl);
const { data } = await this.octokit.issues.createComment({
owner: owner,
repo: project,
issue_number: id,
body: comment
});
if (!data) {
throw new Error("Pull request comment creation failed");
}
commentUrl = data.url;
} catch (error) {
this.logger.error(`Error creating comment on pull request ${prUrl}: ${error}`);
}
return commentUrl;
}
// UTILS
/**

View File

@@ -24,8 +24,8 @@ export default class GitHubMapper implements GitResponseMapper<PullRequest, "ope
state: this.mapGitState(pr.state), // TODO fix using custom mapper
merged: pr.merged ?? false,
mergedBy: pr.merged_by?.login,
reviewers: pr.requested_reviewers?.filter(r => "login" in r).map((r => (r as User)?.login)) ?? [],
assignees: pr.assignees?.filter(r => "login" in r).map(r => r.login) ?? [],
reviewers: pr.requested_reviewers?.filter(r => r && "login" in r).map((r => (r as User)?.login)) ?? [],
assignees: pr.assignees?.filter(r => r && "login" in r).map(r => r.login) ?? [],
labels: pr.labels?.map(l => l.name) ?? [],
sourceRepo: await this.mapSourceRepo(pr),
targetRepo: await this.mapTargetRepo(pr),
@@ -37,7 +37,12 @@ export default class GitHubMapper implements GitResponseMapper<PullRequest, "ope
private getSha(pr: PullRequest) {
// if pr is open use latest commit sha otherwise use merge_commit_sha
return pr.state === "open" ? [pr.head.sha] : [pr.merge_commit_sha as string];
const sha = pr.state === "open" ? pr.head.sha : pr.merge_commit_sha as string;
if (!sha) {
throw new Error("Trying to backport a single squashed/merged commit that does not exist! Aborting...");
}
return [sha];
}
async mapSourceRepo(pr: PullRequest): Promise<GitRepository> {

View File

@@ -1,5 +1,6 @@
import LoggerService from "@bp/service/logger/logger-service";
import GitClient from "@bp/service/git/git-client";
import { inferSquash } from "@bp/service/git/git-util";
import { GitPullRequest, BackportPullRequest, GitClientType } from "@bp/service/git/git.types";
import LoggerServiceFactory from "@bp/service/logger/logger-service-factory";
import { CommitSchema, MergeRequestSchema, UserSchema } from "@gitbeaker/rest";
@@ -45,9 +46,15 @@ export default class GitLabClient implements GitClient {
// READ
// example: <host>/api/v4/projects/<namespace>%2Fbackporting-example/merge_requests/1
async getPullRequest(namespace: string, repo: string, mrNumber: number, squash = true): Promise<GitPullRequest> {
async getPullRequest(namespace: string, repo: string, mrNumber: number, squash: boolean | undefined): Promise<GitPullRequest> {
const projectId = this.getProjectId(namespace, repo);
const { data } = await this.client.get(`/projects/${projectId}/merge_requests/${mrNumber}`);
const url = `/projects/${projectId}/merge_requests/${mrNumber}`;
this.logger.debug(`Fetching pull request ${url}`);
const { data } = await this.client.get(`${url}`);
if (squash === undefined) {
squash = inferSquash(data.state === "opened", data.squash_commit_sha);
}
const commits: string[] = [];
if (!squash) {
@@ -65,7 +72,7 @@ export default class GitLabClient implements GitClient {
return this.mapper.mapPullRequest(data as MergeRequestSchema, commits);
}
getPullRequestFromUrl(mrUrl: string, squash = true): Promise<GitPullRequest> {
getPullRequestFromUrl(mrUrl: string, squash: boolean | undefined): Promise<GitPullRequest> {
const { namespace, project, id } = this.extractMergeRequestData(mrUrl);
return this.getPullRequest(namespace, project, id, squash);
}
@@ -157,6 +164,29 @@ export default class GitLabClient implements GitClient {
return mr.web_url;
}
// https://docs.gitlab.com/ee/api/notes.html#create-new-issue-note
async createPullRequestComment(mrUrl: string, comment: string): Promise<string | undefined> {
const commentUrl: string | undefined = undefined;
try{
const { namespace, project, id } = this.extractMergeRequestData(mrUrl);
const projectId = this.getProjectId(namespace, project);
const { data } = await this.client.post(`/projects/${projectId}/merge_requests/${id}/notes`, {
body: comment,
});
if (!data) {
throw new Error("Merge request comment creation failed");
}
} catch(error) {
this.logger.error(`Error creating comment on merge request ${mrUrl}: ${error}`);
}
return commentUrl;
}
// UTILS
/**
* Retrieve a gitlab user given its username
* @param username

View File

@@ -25,6 +25,7 @@ export default class GitLabMapper implements GitResponseMapper<MergeRequestSchem
}
async mapPullRequest(mr: MergeRequestSchema, commits?: string[]): Promise<GitPullRequest> {
return {
number: mr.iid,
author: mr.author.username,
@@ -47,9 +48,14 @@ export default class GitLabMapper implements GitResponseMapper<MergeRequestSchem
}
private getSha(mr: MergeRequestSchema) {
// if mr is merged, use merge_commit_sha otherwise use sha
// if mr is merged, use merge_commit_sha (or squash_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];
const sha = this.isMerged(mr) ? (mr.squash_commit_sha ? mr.squash_commit_sha : mr.merge_commit_sha as string) : mr.sha;
if (!sha) {
throw new Error("Trying to backport a single squashed/merged commit that does not exist! Aborting...");
}
return [sha];
}
async mapSourceRepo(mr: MergeRequestSchema): Promise<GitRepository> {

View File

@@ -16,6 +16,10 @@ export default class ConsoleLoggerService implements LoggerService {
this.context = newContext;
}
getContext(): string | undefined {
return this.context;
}
clearContext() {
this.context = undefined;
}

View File

@@ -5,6 +5,8 @@ export default interface LoggerService {
setContext(newContext: string): void;
getContext(): string | undefined;
clearContext(): void;
trace(message: string): void;

View File

@@ -0,0 +1,22 @@
import { MESSAGE_ERROR_PLACEHOLDER, MESSAGE_TARGET_BRANCH_PLACEHOLDER } from "@bp/service/configs/configs.types";
/**
* Inject the error message in the provided `message`.
* This is injected in place of the MESSAGE_ERROR_PLACEHOLDER placeholder
* @param message string that needs to be updated
* @param errMsg the error message that needs to be injected
*/
export const injectError = (message: string, errMsg: string): string => {
return message.replace(MESSAGE_ERROR_PLACEHOLDER, errMsg);
};
/**
* Inject the target branch into the provided `message`.
* This is injected in place of the MESSAGE_TARGET_BRANCH_PLACEHOLDER placeholder
* @param message string that needs to be updated
* @param targetBranch the target branch to inject
* @returns
*/
export const injectTargetBranch = (message: string, targetBranch: string): string => {
return message.replace(MESSAGE_TARGET_BRANCH_PLACEHOLDER, targetBranch);
};

View File

@@ -5,15 +5,16 @@ import PullRequestConfigsParser from "@bp/service/configs/pullrequest/pr-configs
import GitCLIService from "@bp/service/git/git-cli";
import GitClient from "@bp/service/git/git-client";
import GitClientFactory from "@bp/service/git/git-client-factory";
import { BackportPullRequest, GitClientType, GitPullRequest } from "@bp/service/git/git.types";
import { BackportPullRequest, GitClientType } from "@bp/service/git/git.types";
import LoggerService from "@bp/service/logger/logger-service";
import LoggerServiceFactory from "@bp/service/logger/logger-service-factory";
import { inferGitClient, inferGitApiUrl, getGitTokenFromEnv } from "@bp/service/git/git-util";
import { injectError, injectTargetBranch } from "./runner-util";
interface Git {
gitClientType: GitClientType;
gitClientApi: GitClient;
gitCli: GitCLIService;
gitClientApi: Pick<GitClient, ("createPullRequest" | "createPullRequestComment")>;
gitCli: Pick<GitCLIService, ("clone" | "createLocalBranch" | "fetch" | "cherryPick" | "push")>;
}
/**
@@ -83,17 +84,18 @@ export default class Runner {
const failures: string[] = [];
// we need sequential backporting as they will operate on the same folder
// avoid cloning the same repo multiple times
for(const pr of backportPRs) {
for (const pr of backportPRs) {
this.logger.setContext(pr.base);
try {
await this.executeBackport(configs, pr, {
gitClientType: gitClientType,
gitClientApi: gitApi,
gitCli: git,
});
} catch(error) {
this.logger.error(`Something went wrong backporting to ${pr.base}: ${error}`);
} catch (error) {
failures.push(error as string);
}
this.logger.clearContext();
}
if (failures.length > 0) {
@@ -123,46 +125,147 @@ export default class Runner {
}
async executeBackport(configs: Configs, backportPR: BackportPullRequest, git: Git): Promise<void> {
this.logger.setContext(backportPR.base);
const originalPR: GitPullRequest = configs.originalPullRequest;
// 4. clone the repository
this.logger.debug("Cloning repo..");
await git.gitCli.clone(configs.originalPullRequest.targetRepo.cloneUrl, configs.folder, backportPR.base);
// 5. create new branch from target one and checkout
this.logger.debug("Creating local branch..");
await git.gitCli.createLocalBranch(configs.folder, backportPR.head);
// 6. fetch pull request remote if source owner != target owner or pull request still open
if (configs.originalPullRequest.sourceRepo.owner !== configs.originalPullRequest.targetRepo.owner ||
configs.originalPullRequest.state === "open") {
this.logger.debug("Fetching pull request remote..");
const prefix = git.gitClientType === GitClientType.GITLAB ? "merge-requests" : "pull" ; // default is for gitlab
await git.gitCli.fetch(configs.folder, `${prefix}/${configs.originalPullRequest.number}/head:pr/${configs.originalPullRequest.number}`);
let i = 0;
for (const step of backportSteps(this.logger, configs, backportPR, git)) {
try {
await step();
} catch (error) {
this.logger.error(`Something went wrong backporting to ${backportPR.base}: ${error}`);
if (!configs.dryRun && configs.errorNotification.enabled && configs.errorNotification.message.length > 0) {
// notify the failure as comment in the original pull request
let comment = injectError(configs.errorNotification.message, error as string);
comment = injectTargetBranch(comment, backportPR.base);
try {
let script = "\n\nReconstruction of the attempted steps (beware that escaping may be missing):\n```sh\n";
script += await backportScript(configs, backportPR, git, i);
script += "```";
comment += script;
} catch (scriptError) {
this.logger.error(`Something went wrong reconstructing the script: ${scriptError}`);
}
await git.gitClientApi.createPullRequestComment(configs.originalPullRequest.url, comment);
}
throw error;
}
i++;
}
// 7. apply all changes to the new branch
this.logger.debug("Cherry picking commits..");
for (const sha of originalPR.commits.reverse()!) {
await git.gitCli.cherryPick(configs.folder, sha, configs.mergeStrategy, configs.mergeStrategyOption, configs.cherryPickOptions);
}
if (!configs.dryRun) {
// 8. push the new branch to origin
await git.gitCli.push(configs.folder, backportPR.head);
// 9. create pull request new branch -> target branch (using octokit)
const prUrl = await git.gitClientApi.createPullRequest(backportPR);
this.logger.info(`Pull request created: ${prUrl}`);
} else {
this.logger.warn("Pull request creation and remote push skipped");
this.logger.info(`${JSON.stringify(backportPR, null, 2)}`);
}
this.logger.clearContext();
}
}
}
function* backportSteps(logger: Pick<LoggerService, "debug" | "info" | "warn">, configs: Configs, backportPR: BackportPullRequest, git: Git): Generator<() => Promise<void>, void, unknown> {
// every failible operation should be in one dedicated closure
// 4. clone the repository
yield async () => {
logger.debug("Cloning repo..");
await git.gitCli.clone(configs.originalPullRequest.targetRepo.cloneUrl, configs.folder, backportPR.base);
};
// 5. create new branch from target one and checkout
yield async () => {
logger.debug("Creating local branch..");
await git.gitCli.createLocalBranch(configs.folder, backportPR.head);
};
// 6. fetch pull request remote if source owner != target owner or pull request still open
if (configs.originalPullRequest.sourceRepo.owner !== configs.originalPullRequest.targetRepo.owner ||
configs.originalPullRequest.state === "open") {
yield async () => {
logger.debug("Fetching pull request remote..");
const prefix = git.gitClientType === GitClientType.GITLAB ? "merge-requests" : "pull"; // default is for gitlab
await git.gitCli.fetch(configs.folder, `${prefix}/${configs.originalPullRequest.number}/head:pr/${configs.originalPullRequest.number}`);
};
}
// 7. apply all changes to the new branch
yield async () => {
logger.debug("Cherry picking commits..");
};
for (const sha of configs.originalPullRequest.commits) {
yield async () => {
await git.gitCli.cherryPick(configs.folder, sha, configs.mergeStrategy, configs.mergeStrategyOption, configs.cherryPickOptions);
};
}
if (!configs.dryRun) {
// 8. push the new branch to origin
yield async () => {
await git.gitCli.push(configs.folder, backportPR.head);
};
// 9. create pull request new branch -> target branch (using octokit)
yield async () => {
const prUrl = await git.gitClientApi.createPullRequest(backportPR);
logger.info(`Pull request created: ${prUrl}`);
};
} else {
yield async () => {
logger.warn("Pull request creation and remote push skipped");
logger.info(`${JSON.stringify(backportPR, null, 2)}`);
};
}
}
// backportScript reconstruct the git commands that were run to attempt the backport.
async function backportScript(configs: Configs, backportPR: BackportPullRequest, git: Git, failed: number): Promise<string> {
let s = "";
const fakeLogger = {
debug: function(_message: string): void { /*discard*/ },
info: function(_message: string): void { /*discard*/ },
warn: function(_message: string): void { /*discard*/ },
};
const fakeGitCli: Git["gitCli"] = {
async clone(_from: string, _to: string, _branch: string): Promise<void> {
/* consider that the user already has the repo cloned (or knows how to clone) */
s += `git fetch origin ${backportPR.base}`;
},
async createLocalBranch(_cwd: string, newBranch: string): Promise<void> {
s += `git switch -c ${newBranch} origin/${backportPR.base}`;
},
async fetch(_cwd: string, branch: string, remote = "origin"): Promise<void> {
s += `git fetch ${remote} ${branch}`;
},
async cherryPick(_cwd: string, sha: string, strategy = "recursive", strategyOption = "theirs", cherryPickOptions: string | undefined): Promise<void> {
s += `git cherry-pick -m 1 --strategy=${strategy} --strategy-option=${strategyOption} `;
if (cherryPickOptions !== undefined) {
s += cherryPickOptions + " ";
}
s += sha;
},
async push(_cwd: string, branch: string, remote = "origin", force = false): Promise<void> {
s += `git push ${remote} ${branch}`;
if (force) {
s += " --force";
}
}
};
let i = 0;
let steps = "";
for (const step of backportSteps(fakeLogger, configs, backportPR, {
gitClientType: git.gitClientType,
gitClientApi: {
async createPullRequest(_backport: BackportPullRequest): Promise<string> {
s += `# ${git.gitClientType}.createPullRequest`;
return "";
},
async createPullRequestComment(_prUrl: string, _comment: string): Promise<string | undefined> {
s += `# ${git.gitClientType}.createPullRequestComment`;
return "";
}
},
gitCli: fakeGitCli,
})) {
if (i == failed) {
s += "# the step below failed\n";
}
await step();
if (s.length > 0 || i == failed) {
steps += s + "\n";
s = "";
}
i++;
}
return steps;
}

View File

@@ -79,9 +79,11 @@ describe("cli args parser", () => {
expect(args.labels).toEqual([]);
expect(args.inheritLabels).toEqual(false);
expect(args.squash).toEqual(true);
expect(args.autoNoSquash).toEqual(false);
expect(args.strategy).toEqual(undefined);
expect(args.strategyOption).toEqual(undefined);
expect(args.cherryPickOptions).toEqual(undefined);
expect(args.enableErrorNotification).toEqual(false);
});
test("with config file [default, short]", () => {
@@ -109,9 +111,11 @@ describe("cli args parser", () => {
expect(args.labels).toEqual([]);
expect(args.inheritLabels).toEqual(false);
expect(args.squash).toEqual(true);
expect(args.autoNoSquash).toEqual(false);
expect(args.strategy).toEqual(undefined);
expect(args.strategyOption).toEqual(undefined);
expect(args.cherryPickOptions).toEqual(undefined);
expect(args.enableErrorNotification).toEqual(false);
});
test("valid execution [default, long]", () => {
@@ -501,7 +505,7 @@ describe("cli args parser", () => {
"https://localhost/whatever/pulls/1"
]);
expect(() => parser.parse()).toThrowError("Missing option: target branch(es) or target regular expression must be provided");
expect(() => parser.parse()).toThrow("Missing option: target branch(es) or target regular expression must be provided");
});
test("invalid execution with missing mandatory target branch", () => {
@@ -510,7 +514,7 @@ describe("cli args parser", () => {
"https://localhost/whatever/pulls/1"
]);
expect(() => parser.parse()).toThrowError("Missing option: target branch(es) or target regular expression must be provided");
expect(() => parser.parse()).toThrow("Missing option: target branch(es) or target regular expression must be provided");
});
test("invalid execution with missing mandatory pull request", () => {
@@ -519,6 +523,19 @@ describe("cli args parser", () => {
"target",
]);
expect(() => parser.parse()).toThrowError("Missing option: pull request must be provided");
expect(() => parser.parse()).toThrow("Missing option: pull request must be provided");
});
test("enable error notification flag", () => {
addProcessArgs([
"-tb",
"target, old",
"-pr",
"https://localhost/whatever/pulls/1",
"--enable-err-notification",
]);
const args: Args = parser.parse();
expect(args.enableErrorNotification).toEqual(true);
});
});

View File

@@ -295,14 +295,13 @@ describe("gha args parser", () => {
expect(args.cherryPickOptions).toEqual(undefined);
});
test("invalid execution with empty target branch", () => {
spyGetInput({
"target-branch": " ",
"pull-request": "https://localhost/whatever/pulls/1"
});
expect(() => parser.parse()).toThrowError("Missing option: target branch(es) or target regular expression must be provided");
expect(() => parser.parse()).toThrow("Missing option: target branch(es) or target regular expression must be provided");
});
test("invalid execution with missing mandatory target branch", () => {
@@ -310,7 +309,7 @@ describe("gha args parser", () => {
"pull-request": "https://localhost/whatever/pulls/1"
});
expect(() => parser.parse()).toThrowError("Missing option: target branch(es) or target regular expression must be provided");
expect(() => parser.parse()).toThrow("Missing option: target branch(es) or target regular expression must be provided");
});
test("invalid execution with missin mandatory pull request", () => {
@@ -318,6 +317,17 @@ describe("gha args parser", () => {
"target-branch": "target,old",
});
expect(() => parser.parse()).toThrowError("Missing option: pull request must be provided");
expect(() => parser.parse()).toThrow("Missing option: pull request must be provided");
});
test("enable error notification flag", () => {
spyGetInput({
"target-branch": "target,old",
"pull-request": "https://localhost/whatever/pulls/1",
"enable-err-notification": "true"
});
const args: Args = parser.parse();
expect(args.enableErrorNotification).toEqual(true);
});
});

View File

@@ -56,10 +56,10 @@ describe("github pull request config parser", () => {
const configs: Configs = await configParser.parseAndValidate(args);
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, true);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledWith("owner", "reponame", 2368, undefined);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), []);
expect(configs.dryRun).toEqual(false);
expect(configs.auth).toEqual("");
@@ -128,10 +128,10 @@ describe("github pull request config parser", () => {
const configs: Configs = await configParser.parseAndValidate(args);
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, true);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledWith("owner", "reponame", 2368, undefined);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), []);
expect(configs.dryRun).toEqual(false);
expect(configs.auth).toEqual("");
@@ -201,10 +201,10 @@ describe("github pull request config parser", () => {
const configs: Configs = await configParser.parseAndValidate(args);
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, true);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledWith("owner", "reponame", 2368, undefined);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), []);
expect(configs.dryRun).toEqual(false);
expect(configs.auth).toEqual("");
@@ -274,10 +274,10 @@ describe("github pull request config parser", () => {
const configs: Configs = await configParser.parseAndValidate(args);
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, true);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledWith("owner", "reponame", 2368, undefined);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), []);
expect(configs.dryRun).toEqual(false);
expect(configs.auth).toEqual("");
@@ -364,10 +364,10 @@ describe("github pull request config parser", () => {
const configs: Configs = await configParser.parseAndValidate(args);
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(GitHubClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledWith("owner", "reponame", 8632, false);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), ["0404fb922ab75c3a8aecad5c97d9af388df04695", "11da4e38aa3e577ffde6d546f1c52e53b04d3151"]);
expect(configs.dryRun).toEqual(false);
expect(configs.git).toEqual({
@@ -435,10 +435,10 @@ describe("github pull request config parser", () => {
const configs: Configs = await configParser.parseAndValidate(args);
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(GitHubClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledWith("owner", "reponame", 8632, false);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), ["0404fb922ab75c3a8aecad5c97d9af388df04695", "11da4e38aa3e577ffde6d546f1c52e53b04d3151"]);
expect(configs.dryRun).toEqual(false);
expect(configs.git).toEqual({

View File

@@ -88,10 +88,10 @@ describe("github pull request config parser", () => {
const configs: Configs = await configParser.parseAndValidate(args);
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, true);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledWith("owner", "reponame", 2368, undefined);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), []);
expect(configs.dryRun).toEqual(false);
expect(configs.git).toEqual({
@@ -139,6 +139,10 @@ describe("github pull request config parser", () => {
labels: [],
comments: [],
});
expect(configs.errorNotification).toEqual({
enabled: false,
message: "The backport to `{{target-branch}}` failed. Check the latest run for more details."
});
});
test("override folder", async () => {
@@ -181,10 +185,10 @@ describe("github pull request config parser", () => {
const configs: Configs = await configParser.parseAndValidate(args);
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 4444, true);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledWith("owner", "reponame", 4444, undefined);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), ["0404fb922ab75c3a8aecad5c97d9af388df04695", "11da4e38aa3e577ffde6d546f1c52e53b04d3151"]);
expect(configs.dryRun).toEqual(true);
expect(configs.auth).toEqual("whatever");
@@ -217,8 +221,7 @@ describe("github pull request config parser", () => {
},
bpBranchName: undefined,
nCommits: 2,
// taken from head.sha
commits: ["91748965051fae1330ad58d15cf694e103267c87"]
commits: ["0404fb922ab75c3a8aecad5c97d9af388df04695", "11da4e38aa3e577ffde6d546f1c52e53b04d3151"],
});
});
@@ -257,10 +260,10 @@ describe("github pull request config parser", () => {
const configs: Configs = await configParser.parseAndValidate(args);
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, true);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledWith("owner", "reponame", 2368, undefined);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), []);
expect(configs.dryRun).toEqual(false);
expect(configs.git).toEqual({
@@ -330,10 +333,10 @@ describe("github pull request config parser", () => {
const configs: Configs = await configParser.parseAndValidate(args);
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, true);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledWith("owner", "reponame", 2368, undefined);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), []);
expect(configs.dryRun).toEqual(false);
expect(configs.auth).toEqual("");
@@ -371,10 +374,10 @@ describe("github pull request config parser", () => {
const configs: Configs = await configParser.parseAndValidate(args);
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, true);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledWith("owner", "reponame", 2368, undefined);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), []);
expect(configs.dryRun).toEqual(false);
expect(configs.git).toEqual({
@@ -443,10 +446,10 @@ describe("github pull request config parser", () => {
const configs: Configs = await configParser.parseAndValidate(args);
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, true);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledWith("owner", "reponame", 2368, undefined);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), []);
expect(configs.dryRun).toEqual(false);
expect(configs.git).toEqual({
@@ -517,10 +520,10 @@ describe("github pull request config parser", () => {
const configs: Configs = await configParser.parseAndValidate(args);
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, true);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledWith("owner", "reponame", 2368, undefined);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), []);
expect(configs.dryRun).toEqual(false);
expect(configs.git).toEqual({
@@ -580,10 +583,10 @@ describe("github pull request config parser", () => {
const args: Args = argsParser.parse();
const configs: Configs = await configParser.parseAndValidate(args);
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, true);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledWith("owner", "reponame", 2368, true);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), []);
expect(configs.dryRun).toEqual(false);
expect(configs.git).toEqual({
@@ -642,10 +645,10 @@ describe("github pull request config parser", () => {
const args: Args = argsParser.parse();
const configs: Configs = await configParser.parseAndValidate(args);
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, true);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledWith("owner", "reponame", 2368, true);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), []);
expect(configs.dryRun).toEqual(false);
expect(configs.git).toEqual({
@@ -712,10 +715,10 @@ describe("github pull request config parser", () => {
const configs: Configs = await configParser.parseAndValidate(args);
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(GitHubClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledWith("owner", "reponame", 8632, false);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), ["0404fb922ab75c3a8aecad5c97d9af388df04695", "11da4e38aa3e577ffde6d546f1c52e53b04d3151"]);
expect(configs.dryRun).toEqual(false);
expect(configs.git).toEqual({
@@ -790,10 +793,10 @@ describe("github pull request config parser", () => {
const configs: Configs = await configParser.parseAndValidate(args);
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, true);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledWith("owner", "reponame", 2368, undefined);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), []);
expect(configs.dryRun).toEqual(false);
expect(configs.git).toEqual({
@@ -887,10 +890,10 @@ describe("github pull request config parser", () => {
const configs: Configs = await configParser.parseAndValidate(args);
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, true);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledWith("owner", "reponame", 2368, undefined);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), []);
expect(configs.dryRun).toEqual(false);
expect(configs.git).toEqual({
@@ -940,4 +943,26 @@ describe("github pull request config parser", () => {
comments: ["First comment", "Second comment"],
});
});
test("enable error notification message", async () => {
const args: Args = {
dryRun: false,
auth: "",
pullRequest: mergedPRUrl,
targetBranch: "prod",
enableErrorNotification: true,
};
const configs: Configs = await configParser.parseAndValidate(args);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubClient.prototype.getPullRequest).toHaveBeenCalledWith("owner", "reponame", 2368, undefined);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), []);
expect(configs.errorNotification).toEqual({
"enabled": true,
"message": "The backport to `{{target-branch}}` failed. Check the latest run for more details."
});
});
});

View File

@@ -51,14 +51,15 @@ describe("gitlab merge request config parser", () => {
labels: [],
inheritLabels: false,
comments: [],
squash: true,
};
const configs: Configs = await configParser.parseAndValidate(args);
expect(GitLabClient.prototype.getPullRequest).toBeCalledTimes(1);
expect(GitLabClient.prototype.getPullRequest).toBeCalledWith("superuser", "backporting-example", 1, true);
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledTimes(1);
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
expect(GitLabClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.getPullRequest).toHaveBeenCalledWith("superuser", "backporting-example", 1, true);
expect(GitLabMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), []);
expect(configs.dryRun).toEqual(false);
expect(configs.auth).toEqual("");
@@ -123,14 +124,15 @@ describe("gitlab merge request config parser", () => {
labels: [],
inheritLabels: false,
comments: [],
squash: true,
};
const configs: Configs = await configParser.parseAndValidate(args);
expect(GitLabClient.prototype.getPullRequest).toBeCalledTimes(1);
expect(GitLabClient.prototype.getPullRequest).toBeCalledWith("superuser", "backporting-example", 1, true);
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledTimes(1);
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
expect(GitLabClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.getPullRequest).toHaveBeenCalledWith("superuser", "backporting-example", 1, true);
expect(GitLabMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), []);
expect(configs.dryRun).toEqual(false);
expect(configs.auth).toEqual("");
@@ -195,15 +197,16 @@ describe("gitlab merge request config parser", () => {
labels: [],
inheritLabels: false,
comments: [],
bpBranchName: "custom-branch"
bpBranchName: "custom-branch",
squash: true,
};
const configs: Configs = await configParser.parseAndValidate(args);
expect(GitLabClient.prototype.getPullRequest).toBeCalledTimes(1);
expect(GitLabClient.prototype.getPullRequest).toBeCalledWith("superuser", "backporting-example", 1, true);
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledTimes(1);
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
expect(GitLabClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.getPullRequest).toHaveBeenCalledWith("superuser", "backporting-example", 1, true);
expect(GitLabMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), []);
expect(configs.dryRun).toEqual(false);
expect(configs.auth).toEqual("");
@@ -268,15 +271,16 @@ describe("gitlab merge request config parser", () => {
labels: [],
inheritLabels: false,
comments: [],
bpBranchName: "custom1, custom2, custom3"
bpBranchName: "custom1, custom2, custom3",
squash: true,
};
const configs: Configs = await configParser.parseAndValidate(args);
expect(GitLabClient.prototype.getPullRequest).toBeCalledTimes(1);
expect(GitLabClient.prototype.getPullRequest).toBeCalledWith("superuser", "backporting-example", 1, true);
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledTimes(1);
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
expect(GitLabClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.getPullRequest).toHaveBeenCalledWith("superuser", "backporting-example", 1, true);
expect(GitLabMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), []);
expect(configs.dryRun).toEqual(false);
expect(configs.auth).toEqual("");

View File

@@ -88,14 +88,15 @@ describe("gitlab merge request config parser", () => {
reviewers: [],
assignees: [],
inheritReviewers: true,
squash: true,
};
const configs: Configs = await configParser.parseAndValidate(args);
expect(GitLabClient.prototype.getPullRequest).toBeCalledTimes(1);
expect(GitLabClient.prototype.getPullRequest).toBeCalledWith("superuser", "backporting-example", 1, true);
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledTimes(1);
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
expect(GitLabClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.getPullRequest).toHaveBeenCalledWith("superuser", "backporting-example", 1, true);
expect(GitLabMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), []);
expect(configs.dryRun).toEqual(false);
expect(configs.git).toEqual({
@@ -143,6 +144,10 @@ describe("gitlab merge request config parser", () => {
labels: [],
comments: [],
});
expect(configs.errorNotification).toEqual({
"enabled": false,
"message": "The backport to `{{target-branch}}` failed. Check the latest run for more details."
});
});
@@ -158,14 +163,15 @@ describe("gitlab merge request config parser", () => {
reviewers: [],
assignees: [],
inheritReviewers: true,
squash: true,
};
const configs: Configs = await configParser.parseAndValidate(args);
expect(GitLabClient.prototype.getPullRequest).toBeCalledTimes(1);
expect(GitLabClient.prototype.getPullRequest).toBeCalledWith("superuser", "backporting-example", 1, true);
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledTimes(1);
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
expect(GitLabClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.getPullRequest).toHaveBeenCalledWith("superuser", "backporting-example", 1, true);
expect(GitLabMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), []);
expect(configs.dryRun).toEqual(true);
expect(configs.auth).toEqual("whatever");
@@ -187,14 +193,15 @@ describe("gitlab merge request config parser", () => {
reviewers: [],
assignees: [],
inheritReviewers: true,
squash: true,
};
const configs: Configs = await configParser.parseAndValidate(args);
expect(GitLabClient.prototype.getPullRequest).toBeCalledTimes(1);
expect(GitLabClient.prototype.getPullRequest).toBeCalledWith("superuser", "backporting-example", 2, true);
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledTimes(1);
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
expect(GitLabClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.getPullRequest).toHaveBeenCalledWith("superuser", "backporting-example", 2, true);
expect(GitLabMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), []);
expect(configs.dryRun).toEqual(true);
expect(configs.auth).toEqual("whatever");
@@ -243,6 +250,7 @@ describe("gitlab merge request config parser", () => {
reviewers: [],
assignees: [],
inheritReviewers: true,
squash: true,
};
await expect(() => configParser.parseAndValidate(args)).rejects.toThrow("Provided pull request is closed and not merged");
@@ -262,14 +270,15 @@ describe("gitlab merge request config parser", () => {
reviewers: [],
assignees: [],
inheritReviewers: true,
squash: true,
};
const configs: Configs = await configParser.parseAndValidate(args);
expect(GitLabClient.prototype.getPullRequest).toBeCalledTimes(1);
expect(GitLabClient.prototype.getPullRequest).toBeCalledWith("superuser", "backporting-example", 1, true);
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledTimes(1);
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
expect(GitLabClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.getPullRequest).toHaveBeenCalledWith("superuser", "backporting-example", 1, true);
expect(GitLabMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), []);
expect(configs.dryRun).toEqual(false);
expect(configs.git).toEqual({
@@ -333,14 +342,15 @@ describe("gitlab merge request config parser", () => {
reviewers: ["user1", "user2"],
assignees: ["user3", "user4"],
inheritReviewers: true, // not taken into account
squash: true,
};
const configs: Configs = await configParser.parseAndValidate(args);
expect(GitLabClient.prototype.getPullRequest).toBeCalledTimes(1);
expect(GitLabClient.prototype.getPullRequest).toBeCalledWith("superuser", "backporting-example", 1, true);
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledTimes(1);
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
expect(GitLabClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.getPullRequest).toHaveBeenCalledWith("superuser", "backporting-example", 1, true);
expect(GitLabMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), []);
expect(configs.dryRun).toEqual(false);
expect(configs.git).toEqual({
@@ -404,14 +414,15 @@ describe("gitlab merge request config parser", () => {
reviewers: [],
assignees: ["user3", "user4"],
inheritReviewers: false,
squash: true,
};
const configs: Configs = await configParser.parseAndValidate(args);
expect(GitLabClient.prototype.getPullRequest).toBeCalledTimes(1);
expect(GitLabClient.prototype.getPullRequest).toBeCalledWith("superuser", "backporting-example", 1, true);
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledTimes(1);
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
expect(GitLabClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.getPullRequest).toHaveBeenCalledWith("superuser", "backporting-example", 1, true);
expect(GitLabMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), []);
expect(configs.dryRun).toEqual(false);
expect(configs.git).toEqual({
@@ -477,14 +488,15 @@ describe("gitlab merge request config parser", () => {
inheritReviewers: false,
labels: ["custom-label", "backport-prod"], // also include the one inherited
inheritLabels: true,
squash: true,
};
const configs: Configs = await configParser.parseAndValidate(args);
expect(GitLabClient.prototype.getPullRequest).toBeCalledTimes(1);
expect(GitLabClient.prototype.getPullRequest).toBeCalledWith("superuser", "backporting-example", 1, true);
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledTimes(1);
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
expect(GitLabClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.getPullRequest).toHaveBeenCalledWith("superuser", "backporting-example", 1, true);
expect(GitLabMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), []);
expect(configs.dryRun).toEqual(false);
expect(configs.git).toEqual({
@@ -542,10 +554,10 @@ describe("gitlab merge request config parser", () => {
const args: Args = argsParser.parse();
const configs: Configs = await configParser.parseAndValidate(args);
expect(GitLabClient.prototype.getPullRequest).toBeCalledTimes(1);
expect(GitLabClient.prototype.getPullRequest).toBeCalledWith("superuser", "backporting-example", 1, true);
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledTimes(1);
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
expect(GitLabClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.getPullRequest).toHaveBeenCalledWith("superuser", "backporting-example", 1, true);
expect(GitLabMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), []);
expect(configs.dryRun).toEqual(false);
expect(configs.git).toEqual({
@@ -603,10 +615,10 @@ describe("gitlab merge request config parser", () => {
const args: Args = argsParser.parse();
const configs: Configs = await configParser.parseAndValidate(args);
expect(GitLabClient.prototype.getPullRequest).toBeCalledTimes(1);
expect(GitLabClient.prototype.getPullRequest).toBeCalledWith("superuser", "backporting-example", 1, true);
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledTimes(1);
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
expect(GitLabClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.getPullRequest).toHaveBeenCalledWith("superuser", "backporting-example", 1, true);
expect(GitLabMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), []);
expect(configs.dryRun).toEqual(false);
expect(configs.git).toEqual({
@@ -672,10 +684,10 @@ describe("gitlab merge request config parser", () => {
const configs: Configs = await configParser.parseAndValidate(args);
expect(GitLabClient.prototype.getPullRequest).toBeCalledTimes(1);
expect(GitLabClient.prototype.getPullRequest).toBeCalledWith("superuser", "backporting-example", 2, false);
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledTimes(1);
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), ["e4dd336a4a20f394df6665994df382fb1d193a11", "974519f65c9e0ed65277cd71026657a09fca05e7"]);
expect(GitLabClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.getPullRequest).toHaveBeenCalledWith("superuser", "backporting-example", 2, false);
expect(GitLabMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), ["e4dd336a4a20f394df6665994df382fb1d193a11", "974519f65c9e0ed65277cd71026657a09fca05e7"]);
expect(configs.dryRun).toEqual(true);
expect(configs.auth).toEqual("whatever");
@@ -742,14 +754,15 @@ describe("gitlab merge request config parser", () => {
labels: [],
inheritLabels: false,
comments: ["First comment", "Second comment"],
squash: true,
};
const configs: Configs = await configParser.parseAndValidate(args);
expect(GitLabClient.prototype.getPullRequest).toBeCalledTimes(1);
expect(GitLabClient.prototype.getPullRequest).toBeCalledWith("superuser", "backporting-example", 1, true);
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledTimes(1);
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
expect(GitLabClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.getPullRequest).toHaveBeenCalledWith("superuser", "backporting-example", 1, true);
expect(GitLabMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), []);
expect(configs.dryRun).toEqual(false);
expect(configs.git).toEqual({
@@ -816,14 +829,15 @@ describe("gitlab merge request config parser", () => {
labels: [],
inheritLabels: false,
comments: ["First comment", "Second comment"],
squash: true,
};
const configs: Configs = await configParser.parseAndValidate(args);
expect(GitLabClient.prototype.getPullRequest).toBeCalledTimes(1);
expect(GitLabClient.prototype.getPullRequest).toBeCalledWith("superuser", "backporting-example", 1, true);
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledTimes(1);
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
expect(GitLabClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.getPullRequest).toHaveBeenCalledWith("superuser", "backporting-example", 1, true);
expect(GitLabMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), []);
expect(configs.dryRun).toEqual(false);
expect(configs.git).toEqual({
@@ -872,4 +886,26 @@ describe("gitlab merge request config parser", () => {
comments: ["First comment", "Second comment"],
});
});
test("enable error notification message", async () => {
const args: Args = {
dryRun: false,
auth: "",
pullRequest: mergedPRUrl,
targetBranch: "prod",
enableErrorNotification: true,
};
const configs: Configs = await configParser.parseAndValidate(args);
expect(GitLabClient.prototype.getPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.getPullRequest).toHaveBeenCalledWith("superuser", "backporting-example", 1, undefined);
expect(GitLabMapper.prototype.mapPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabMapper.prototype.mapPullRequest).toHaveBeenCalledWith(expect.anything(), []);
expect(configs.errorNotification).toEqual({
"enabled": true,
"message": "The backport to `{{target-branch}}` failed. Check the latest run for more details.",
});
});
});

View File

@@ -88,11 +88,11 @@ describe("git cli service", () => {
});
test("fetch", async () => {
await expect(git.fetch(cwd, currentBranch)).resolves.not.toThrowError();
await expect(git.fetch(cwd, currentBranch)).resolves.not.toThrow();
});
test("local branch", async () => {
await expect(git.createLocalBranch(cwd, "new-local-branch")).resolves.not.toThrowError();
await expect(git.createLocalBranch(cwd, "new-local-branch")).resolves.not.toThrow();
// use rev-parse to double check the current branch is the new one
const output = spawnSync("git", ["rev-parse", "--abbrev-ref", "HEAD"], { cwd }).stdout.toString().trim();

View File

@@ -1,4 +1,4 @@
import { inferGitApiUrl, inferGitClient } from "@bp/service/git/git-util";
import { inferGitApiUrl, inferGitClient, inferSquash } from "@bp/service/git/git-util";
import { GitClientType } from "@bp/service/git/git.types";
describe("check git utilities", () => {
@@ -44,7 +44,7 @@ describe("check git utilities", () => {
});
test("not recognized git client type", ()=> {
expect(() => inferGitClient("https://not.recognized/superuser/backporting-example/-/merge_requests/4")).toThrowError("Remote git service not recognized from pr url: https://not.recognized/superuser/backporting-example/-/merge_requests/4");
expect(() => inferGitClient("https://not.recognized/superuser/backporting-example/-/merge_requests/4")).toThrow("Remote git service not recognized from pr url: https://not.recognized/superuser/backporting-example/-/merge_requests/4");
});
test("check infer github client using github api", ()=> {
@@ -54,4 +54,11 @@ describe("check git utilities", () => {
test("check infer codeberg client", ()=> {
expect(inferGitClient("https://codeberg.org/lampajr/backporting-example/pulls/1")).toStrictEqual(GitClientType.CODEBERG);
});
});
test("check inferSquash", ()=> {
expect(inferSquash(true, undefined)).toStrictEqual(false);
expect(inferSquash(false, "SHA")).toStrictEqual(true);
expect(inferSquash(false, undefined)).toStrictEqual(false);
expect(inferSquash(false, null)).toStrictEqual(false);
});
});

View File

@@ -22,7 +22,7 @@ describe("github service", () => {
});
test("get pull request: success", async () => {
const res: GitPullRequest = await gitClient.getPullRequest(TARGET_OWNER, REPO, MERGED_PR_FIXTURE.number);
const res: GitPullRequest = await gitClient.getPullRequest(TARGET_OWNER, REPO, MERGED_PR_FIXTURE.number, true);
expect(res.sourceRepo).toEqual({
owner: "fork",
project: "reponame",

View File

@@ -31,7 +31,7 @@ describe("github service", () => {
});
test("get merged pull request", async () => {
const res: GitPullRequest = await gitClient.getPullRequest("superuser", "backporting-example", 1);
const res: GitPullRequest = await gitClient.getPullRequest("superuser", "backporting-example", 1, true);
// check content
expect(res.sourceRepo).toEqual({
@@ -49,14 +49,14 @@ describe("github service", () => {
expect(res.commits).toEqual(["ebb1eca696c42fd067658bd9b5267709f78ef38e"]);
// check axios invocation
expect(axiosInstanceSpy.get).toBeCalledTimes(3); // merge request and 2 repos
expect(axiosInstanceSpy.get).toBeCalledWith("/projects/superuser%2Fbackporting-example/merge_requests/1");
expect(axiosInstanceSpy.get).toBeCalledWith("/projects/76316");
expect(axiosInstanceSpy.get).toBeCalledWith("/projects/76316");
expect(axiosInstanceSpy.get).toHaveBeenCalledTimes(3); // merge request and 2 repos
expect(axiosInstanceSpy.get).toHaveBeenCalledWith("/projects/superuser%2Fbackporting-example/merge_requests/1");
expect(axiosInstanceSpy.get).toHaveBeenCalledWith("/projects/76316");
expect(axiosInstanceSpy.get).toHaveBeenCalledWith("/projects/76316");
});
test("get open pull request", async () => {
const res: GitPullRequest = await gitClient.getPullRequest("superuser", "backporting-example", 2);
const res: GitPullRequest = await gitClient.getPullRequest("superuser", "backporting-example", 2, true);
expect(res.sourceRepo).toEqual({
owner: "superuser",
project: "backporting-example",
@@ -72,10 +72,10 @@ describe("github service", () => {
expect(res.commits).toEqual(["9e15674ebd48e05c6e428a1fa31dbb60a778d644"]);
// check axios invocation
expect(axiosInstanceSpy.get).toBeCalledTimes(3); // merge request and 2 repos
expect(axiosInstanceSpy.get).toBeCalledWith("/projects/superuser%2Fbackporting-example/merge_requests/2");
expect(axiosInstanceSpy.get).toBeCalledWith("/projects/76316");
expect(axiosInstanceSpy.get).toBeCalledWith("/projects/76316");
expect(axiosInstanceSpy.get).toHaveBeenCalledTimes(3); // merge request and 2 repos
expect(axiosInstanceSpy.get).toHaveBeenCalledWith("/projects/superuser%2Fbackporting-example/merge_requests/2");
expect(axiosInstanceSpy.get).toHaveBeenCalledWith("/projects/76316");
expect(axiosInstanceSpy.get).toHaveBeenCalledWith("/projects/76316");
});
test("create backport pull request without reviewers and assignees", async () => {
@@ -96,8 +96,8 @@ describe("github service", () => {
expect(url).toStrictEqual("https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/" + NEW_GITLAB_MR_ID);
// check axios invocation
expect(axiosInstanceSpy.post).toBeCalledTimes(1);
expect(axiosInstanceSpy.post).toBeCalledWith("/projects/superuser%2Fbackporting-example/merge_requests", expect.objectContaining({
expect(axiosInstanceSpy.post).toHaveBeenCalledTimes(1);
expect(axiosInstanceSpy.post).toHaveBeenCalledWith("/projects/superuser%2Fbackporting-example/merge_requests", expect.objectContaining({
source_branch: "bp-branch",
target_branch: "old/branch",
title: "Backport Title",
@@ -105,8 +105,8 @@ describe("github service", () => {
reviewer_ids: [],
assignee_ids: [],
}));
expect(axiosInstanceSpy.get).toBeCalledTimes(0); // no reviewers nor assignees
expect(axiosInstanceSpy.put).toBeCalledTimes(0); // no reviewers nor assignees
expect(axiosInstanceSpy.get).toHaveBeenCalledTimes(0); // no reviewers nor assignees
expect(axiosInstanceSpy.put).toHaveBeenCalledTimes(0); // no reviewers nor assignees
});
test("create backport pull request with reviewers", async () => {
@@ -127,8 +127,8 @@ describe("github service", () => {
expect(url).toStrictEqual("https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/" + NEW_GITLAB_MR_ID);
// check axios invocation
expect(axiosInstanceSpy.post).toBeCalledTimes(1);
expect(axiosInstanceSpy.post).toBeCalledWith("/projects/superuser%2Fbackporting-example/merge_requests", expect.objectContaining({
expect(axiosInstanceSpy.post).toHaveBeenCalledTimes(1);
expect(axiosInstanceSpy.post).toHaveBeenCalledWith("/projects/superuser%2Fbackporting-example/merge_requests", expect.objectContaining({
source_branch: "bp-branch",
target_branch: "old/branch",
title: "Backport Title",
@@ -136,11 +136,11 @@ describe("github service", () => {
reviewer_ids: [],
assignee_ids: [],
}));
expect(axiosInstanceSpy.get).toBeCalledTimes(2); // just reviewers, one invalid
expect(axiosInstanceSpy.get).toBeCalledWith("/users?username=superuser");
expect(axiosInstanceSpy.get).toBeCalledWith("/users?username=invalid");
expect(axiosInstanceSpy.put).toBeCalledTimes(1); // just reviewers
expect(axiosInstanceSpy.put).toBeCalledWith("/projects/superuser%2Fbackporting-example/merge_requests/" + NEW_GITLAB_MR_ID, {
expect(axiosInstanceSpy.get).toHaveBeenCalledTimes(2); // just reviewers, one invalid
expect(axiosInstanceSpy.get).toHaveBeenCalledWith("/users?username=superuser");
expect(axiosInstanceSpy.get).toHaveBeenCalledWith("/users?username=invalid");
expect(axiosInstanceSpy.put).toHaveBeenCalledTimes(1); // just reviewers
expect(axiosInstanceSpy.put).toHaveBeenCalledWith("/projects/superuser%2Fbackporting-example/merge_requests/" + NEW_GITLAB_MR_ID, {
reviewer_ids: [14041],
});
});
@@ -163,8 +163,8 @@ describe("github service", () => {
expect(url).toStrictEqual("https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/" + NEW_GITLAB_MR_ID);
// check axios invocation
expect(axiosInstanceSpy.post).toBeCalledTimes(1);
expect(axiosInstanceSpy.post).toBeCalledWith("/projects/superuser%2Fbackporting-example/merge_requests", expect.objectContaining({
expect(axiosInstanceSpy.post).toHaveBeenCalledTimes(1);
expect(axiosInstanceSpy.post).toHaveBeenCalledWith("/projects/superuser%2Fbackporting-example/merge_requests", expect.objectContaining({
source_branch: "bp-branch",
target_branch: "old/branch",
title: "Backport Title",
@@ -172,11 +172,11 @@ describe("github service", () => {
reviewer_ids: [],
assignee_ids: [],
}));
expect(axiosInstanceSpy.get).toBeCalledTimes(2); // just assignees, one invalid
expect(axiosInstanceSpy.get).toBeCalledWith("/users?username=superuser");
expect(axiosInstanceSpy.get).toBeCalledWith("/users?username=invalid");
expect(axiosInstanceSpy.put).toBeCalledTimes(1); // just assignees
expect(axiosInstanceSpy.put).toBeCalledWith("/projects/superuser%2Fbackporting-example/merge_requests/" + NEW_GITLAB_MR_ID, {
expect(axiosInstanceSpy.get).toHaveBeenCalledTimes(2); // just assignees, one invalid
expect(axiosInstanceSpy.get).toHaveBeenCalledWith("/users?username=superuser");
expect(axiosInstanceSpy.get).toHaveBeenCalledWith("/users?username=invalid");
expect(axiosInstanceSpy.put).toHaveBeenCalledTimes(1); // just assignees
expect(axiosInstanceSpy.put).toHaveBeenCalledWith("/projects/superuser%2Fbackporting-example/merge_requests/" + NEW_GITLAB_MR_ID, {
assignee_ids: [14041],
});
});
@@ -199,8 +199,8 @@ describe("github service", () => {
expect(url).toStrictEqual("https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/" + SECOND_NEW_GITLAB_MR_ID);
// check axios invocation
expect(axiosInstanceSpy.post).toBeCalledTimes(1);
expect(axiosInstanceSpy.post).toBeCalledWith("/projects/superuser%2Fbackporting-example/merge_requests", expect.objectContaining({
expect(axiosInstanceSpy.post).toHaveBeenCalledTimes(1);
expect(axiosInstanceSpy.post).toHaveBeenCalledWith("/projects/superuser%2Fbackporting-example/merge_requests", expect.objectContaining({
source_branch: "bp-branch-2",
target_branch: "old/branch",
title: "Backport Title",
@@ -208,11 +208,11 @@ describe("github service", () => {
reviewer_ids: [],
assignee_ids: [],
}));
expect(axiosInstanceSpy.get).toBeCalledTimes(2); // just reviewers, one invalid
expect(axiosInstanceSpy.get).toBeCalledWith("/users?username=superuser");
expect(axiosInstanceSpy.get).toBeCalledWith("/users?username=invalid");
expect(axiosInstanceSpy.put).toBeCalledTimes(1); // just reviewers
expect(axiosInstanceSpy.put).toBeCalledWith("/projects/superuser%2Fbackporting-example/merge_requests/" + SECOND_NEW_GITLAB_MR_ID, {
expect(axiosInstanceSpy.get).toHaveBeenCalledTimes(2); // just reviewers, one invalid
expect(axiosInstanceSpy.get).toHaveBeenCalledWith("/users?username=superuser");
expect(axiosInstanceSpy.get).toHaveBeenCalledWith("/users?username=invalid");
expect(axiosInstanceSpy.put).toHaveBeenCalledTimes(1); // just reviewers
expect(axiosInstanceSpy.put).toHaveBeenCalledWith("/projects/superuser%2Fbackporting-example/merge_requests/" + SECOND_NEW_GITLAB_MR_ID, {
reviewer_ids: [14041],
});
});
@@ -235,8 +235,8 @@ describe("github service", () => {
expect(url).toStrictEqual("https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/" + SECOND_NEW_GITLAB_MR_ID);
// check axios invocation
expect(axiosInstanceSpy.post).toBeCalledTimes(1);
expect(axiosInstanceSpy.post).toBeCalledWith("/projects/superuser%2Fbackporting-example/merge_requests", expect.objectContaining({
expect(axiosInstanceSpy.post).toHaveBeenCalledTimes(1);
expect(axiosInstanceSpy.post).toHaveBeenCalledWith("/projects/superuser%2Fbackporting-example/merge_requests", expect.objectContaining({
source_branch: "bp-branch-2",
target_branch: "old/branch",
title: "Backport Title",
@@ -244,11 +244,11 @@ describe("github service", () => {
reviewer_ids: [],
assignee_ids: [],
}));
expect(axiosInstanceSpy.get).toBeCalledTimes(2); // just assignees, one invalid
expect(axiosInstanceSpy.get).toBeCalledWith("/users?username=superuser");
expect(axiosInstanceSpy.get).toBeCalledWith("/users?username=invalid");
expect(axiosInstanceSpy.put).toBeCalledTimes(1); // just assignees
expect(axiosInstanceSpy.put).toBeCalledWith("/projects/superuser%2Fbackporting-example/merge_requests/" + SECOND_NEW_GITLAB_MR_ID, {
expect(axiosInstanceSpy.get).toHaveBeenCalledTimes(2); // just assignees, one invalid
expect(axiosInstanceSpy.get).toHaveBeenCalledWith("/users?username=superuser");
expect(axiosInstanceSpy.get).toHaveBeenCalledWith("/users?username=invalid");
expect(axiosInstanceSpy.put).toHaveBeenCalledTimes(1); // just assignees
expect(axiosInstanceSpy.put).toHaveBeenCalledWith("/projects/superuser%2Fbackporting-example/merge_requests/" + SECOND_NEW_GITLAB_MR_ID, {
assignee_ids: [14041],
});
});
@@ -271,8 +271,8 @@ describe("github service", () => {
expect(url).toStrictEqual("https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/" + SECOND_NEW_GITLAB_MR_ID);
// check axios invocation
expect(axiosInstanceSpy.post).toBeCalledTimes(1);
expect(axiosInstanceSpy.post).toBeCalledWith("/projects/superuser%2Fbackporting-example/merge_requests", expect.objectContaining({
expect(axiosInstanceSpy.post).toHaveBeenCalledTimes(1);
expect(axiosInstanceSpy.post).toHaveBeenCalledWith("/projects/superuser%2Fbackporting-example/merge_requests", expect.objectContaining({
source_branch: "bp-branch-2",
target_branch: "old/branch",
title: "Backport Title",
@@ -280,9 +280,9 @@ describe("github service", () => {
reviewer_ids: [],
assignee_ids: [],
}));
expect(axiosInstanceSpy.get).toBeCalledTimes(0);
expect(axiosInstanceSpy.put).toBeCalledTimes(1); // just labels
expect(axiosInstanceSpy.put).toBeCalledWith("/projects/superuser%2Fbackporting-example/merge_requests/" + SECOND_NEW_GITLAB_MR_ID, {
expect(axiosInstanceSpy.get).toHaveBeenCalledTimes(0);
expect(axiosInstanceSpy.put).toHaveBeenCalledTimes(1); // just labels
expect(axiosInstanceSpy.put).toHaveBeenCalledWith("/projects/superuser%2Fbackporting-example/merge_requests/" + SECOND_NEW_GITLAB_MR_ID, {
labels: "label1,label2",
});
});
@@ -305,8 +305,8 @@ describe("github service", () => {
expect(url).toStrictEqual("https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/" + SECOND_NEW_GITLAB_MR_ID);
// check axios invocation
expect(axiosInstanceSpy.post).toBeCalledTimes(3); // also comments
expect(axiosInstanceSpy.post).toBeCalledWith("/projects/superuser%2Fbackporting-example/merge_requests", expect.objectContaining({
expect(axiosInstanceSpy.post).toHaveBeenCalledTimes(3); // also comments
expect(axiosInstanceSpy.post).toHaveBeenCalledWith("/projects/superuser%2Fbackporting-example/merge_requests", expect.objectContaining({
source_branch: "bp-branch-2",
target_branch: "old/branch",
title: "Backport Title",
@@ -314,18 +314,18 @@ describe("github service", () => {
reviewer_ids: [],
assignee_ids: [],
}));
expect(axiosInstanceSpy.get).toBeCalledTimes(0);
expect(axiosInstanceSpy.get).toHaveBeenCalledTimes(0);
expect(axiosInstanceSpy.post).toBeCalledWith("/projects/superuser%2Fbackporting-example/merge_requests/" + SECOND_NEW_GITLAB_MR_ID + "/notes", {
expect(axiosInstanceSpy.post).toHaveBeenCalledWith("/projects/superuser%2Fbackporting-example/merge_requests/" + SECOND_NEW_GITLAB_MR_ID + "/notes", {
body: "this is first comment",
});
expect(axiosInstanceSpy.post).toBeCalledWith("/projects/superuser%2Fbackporting-example/merge_requests/" + SECOND_NEW_GITLAB_MR_ID + "/notes", {
expect(axiosInstanceSpy.post).toHaveBeenCalledWith("/projects/superuser%2Fbackporting-example/merge_requests/" + SECOND_NEW_GITLAB_MR_ID + "/notes", {
body: "this is second comment",
});
});
test("get pull request for nested namespaces", async () => {
const res: GitPullRequest = await gitClient.getPullRequestFromUrl("https://my.gitlab.host.com/mysuperorg/6/mysuperproduct/mysuperunit/backporting-example/-/merge_requests/4");
const res: GitPullRequest = await gitClient.getPullRequestFromUrl("https://my.gitlab.host.com/mysuperorg/6/mysuperproduct/mysuperunit/backporting-example/-/merge_requests/4", true);
// check content
expect(res.sourceRepo).toEqual({
@@ -343,9 +343,9 @@ describe("github service", () => {
expect(res.commits).toEqual(["ebb1eca696c42fd067658bd9b5267709f78ef38e"]);
// check axios invocation
expect(axiosInstanceSpy.get).toBeCalledTimes(3); // merge request and 2 repos
expect(axiosInstanceSpy.get).toBeCalledWith("/projects/mysuperorg%2F6%2Fmysuperproduct%2Fmysuperunit%2Fbackporting-example/merge_requests/4");
expect(axiosInstanceSpy.get).toBeCalledWith("/projects/1645");
expect(axiosInstanceSpy.get).toBeCalledWith("/projects/1645");
expect(axiosInstanceSpy.get).toHaveBeenCalledTimes(3); // merge request and 2 repos
expect(axiosInstanceSpy.get).toHaveBeenCalledWith("/projects/mysuperorg%2F6%2Fmysuperproduct%2Fmysuperunit%2Fbackporting-example/merge_requests/4");
expect(axiosInstanceSpy.get).toHaveBeenCalledWith("/projects/1645");
expect(axiosInstanceSpy.get).toHaveBeenCalledWith("/projects/1645");
});
});

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -44,6 +44,7 @@ jest.mock("axios", () => {
jest.mock("@bp/service/git/git-cli");
jest.spyOn(GitLabClient.prototype, "createPullRequest");
jest.spyOn(GitLabClient.prototype, "createPullRequestComment");
jest.spyOn(GitClientFactory, "getOrCreate");
@@ -88,23 +89,24 @@ describe("cli runner", () => {
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-9e15674");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp-target-9e15674");
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2");
expect(GitCLIService.prototype.fetch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.fetch).toHaveBeenCalledWith(cwd, "merge-requests/2/head:pr/2");
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toBeCalledTimes(0);
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(0);
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(0);
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledTimes(0);
expect(GitLabClient.prototype.createPullRequestComment).toHaveBeenCalledTimes(0);
});
test("dry run with relative folder", async () => {
@@ -122,26 +124,26 @@ describe("cli runner", () => {
const cwd = process.cwd() + "/folder";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-9e15674");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp-target-9e15674");
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2");
expect(GitCLIService.prototype.fetch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.fetch).toHaveBeenCalledWith(cwd, "merge-requests/2/head:pr/2");
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined, undefined);
expect(GitCLIService.prototype.addRemote).toBeCalledTimes(0);
expect(GitCLIService.prototype.addRemote).toBeCalledTimes(0);
expect(GitCLIService.prototype.addRemote).toHaveBeenCalledTimes(0);
expect(GitCLIService.prototype.addRemote).toHaveBeenCalledTimes(0);
expect(GitCLIService.prototype.push).toBeCalledTimes(0);
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(0);
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(0);
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledTimes(0);
});
test("without dry run", async () => {
@@ -156,26 +158,26 @@ describe("cli runner", () => {
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-9e15674");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp-target-9e15674");
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2");
expect(GitCLIService.prototype.fetch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.fetch).toHaveBeenCalledWith(cwd, "merge-requests/2/head:pr/2");
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-9e15674");
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp-target-9e15674");
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "superuser",
repo: "backporting-example",
head: "bp-target-9e15674",
@@ -199,6 +201,7 @@ describe("cli runner", () => {
]);
await expect(() => runner.execute()).rejects.toThrow("Provided pull request is closed and not merged");
expect(GitLabClient.prototype.createPullRequestComment).toHaveBeenCalledTimes(0);
});
test("merged pull request", async () => {
@@ -213,27 +216,27 @@ describe("cli runner", () => {
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-ebb1eca");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp-target-ebb1eca");
// 0 occurrences as the mr is already merged and the owner is the same for
// both source and target repositories
expect(GitCLIService.prototype.fetch).toBeCalledTimes(0);
expect(GitCLIService.prototype.fetch).toHaveBeenCalledTimes(0);
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-ebb1eca");
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp-target-ebb1eca");
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "superuser",
repo: "backporting-example",
head: "bp-target-ebb1eca",
@@ -246,6 +249,7 @@ describe("cli runner", () => {
comments: [],
}
);
expect(GitLabClient.prototype.createPullRequestComment).toHaveBeenCalledTimes(0);
});
@@ -273,26 +277,26 @@ describe("cli runner", () => {
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp_branch_name");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp_branch_name");
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2");
expect(GitCLIService.prototype.fetch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.fetch).toHaveBeenCalledWith(cwd, "merge-requests/2/head:pr/2");
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp_branch_name");
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp_branch_name");
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "superuser",
repo: "backporting-example",
head: "bp_branch_name",
@@ -330,26 +334,26 @@ describe("cli runner", () => {
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp_branch_name");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp_branch_name");
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2");
expect(GitCLIService.prototype.fetch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.fetch).toHaveBeenCalledWith(cwd, "merge-requests/2/head:pr/2");
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp_branch_name");
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp_branch_name");
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "superuser",
repo: "backporting-example",
head: "bp_branch_name",
@@ -379,27 +383,27 @@ describe("cli runner", () => {
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-ebb1eca");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp-target-ebb1eca");
// 0 occurrences as the mr is already merged and the owner is the same for
// both source and target repositories
expect(GitCLIService.prototype.fetch).toBeCalledTimes(0);
expect(GitCLIService.prototype.fetch).toHaveBeenCalledTimes(0);
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-ebb1eca");
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp-target-ebb1eca");
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "superuser",
repo: "backporting-example",
head: "bp-target-ebb1eca",
@@ -428,27 +432,27 @@ describe("cli runner", () => {
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-ebb1eca");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp-target-ebb1eca");
// 0 occurrences as the mr is already merged and the owner is the same for
// both source and target repositories
expect(GitCLIService.prototype.fetch).toBeCalledTimes(0);
expect(GitCLIService.prototype.fetch).toHaveBeenCalledTimes(0);
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-ebb1eca");
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp-target-ebb1eca");
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "superuser",
repo: "backporting-example",
head: "bp-target-ebb1eca",
@@ -473,27 +477,27 @@ describe("cli runner", () => {
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITLAB, "my-token", "https://my.gitlab.host.com/api/v4");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITLAB, "my-token", "https://my.gitlab.host.com/api/v4");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "prod");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "prod");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-prod-ebb1eca");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp-prod-ebb1eca");
// 0 occurrences as the mr is already merged and the owner is the same for
// both source and target repositories
expect(GitCLIService.prototype.fetch).toBeCalledTimes(0);
expect(GitCLIService.prototype.fetch).toHaveBeenCalledTimes(0);
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-prod-ebb1eca");
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp-prod-ebb1eca");
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "superuser",
repo: "backporting-example",
head: "bp-prod-ebb1eca",
@@ -521,23 +525,23 @@ describe("cli runner", () => {
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-e4dd336");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp-target-e4dd336");
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "e4dd336a4a20f394df6665994df382fb1d193a11", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "e4dd336a4a20f394df6665994df382fb1d193a11", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-e4dd336");
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp-target-e4dd336");
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "superuser",
repo: "backporting-example",
head: "bp-target-e4dd336",
@@ -565,27 +569,27 @@ describe("cli runner", () => {
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-e4dd336-974519f");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp-target-e4dd336-974519f");
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2");
expect(GitCLIService.prototype.fetch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.fetch).toHaveBeenCalledWith(cwd, "merge-requests/2/head:pr/2");
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(2);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "e4dd336a4a20f394df6665994df382fb1d193a11", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "974519f65c9e0ed65277cd71026657a09fca05e7", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(2);
expect(GitCLIService.prototype.cherryPick).toHaveBeenNthCalledWith(1, cwd, "e4dd336a4a20f394df6665994df382fb1d193a11", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenNthCalledWith(2, cwd, "974519f65c9e0ed65277cd71026657a09fca05e7", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-e4dd336-974519f");
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp-target-e4dd336-974519f");
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "superuser",
repo: "backporting-example",
head: "bp-target-e4dd336-974519f",
@@ -600,6 +604,50 @@ describe("cli runner", () => {
);
});
test("merged MR with --auto-no-squash", async () => {
addProcessArgs([
"-tb",
"target",
"-pr",
"https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/5",
"--auto-no-squash",
]);
await runner.execute();
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp-target-e4dd336");
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "e4dd336a4a20f394df6665994df382fb1d193a11", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp-target-e4dd336");
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "superuser",
repo: "backporting-example",
head: "bp-target-e4dd336",
base: "target",
title: "[target] Update test.txt",
body: expect.stringContaining("**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/5"),
reviewers: ["superuser"],
assignees: [],
labels: [],
comments: [],
}
);
});
test("auth using GITLAB_TOKEN takes precedence over GIT_TOKEN env variable", async () => {
process.env[AuthTokenId.GIT_TOKEN] = "mygittoken";
process.env[AuthTokenId.GITLAB_TOKEN] = "mygitlabtoken";
@@ -612,8 +660,8 @@ describe("cli runner", () => {
await runner.execute();
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITLAB, "mygitlabtoken", "https://my.gitlab.host.com/api/v4");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITLAB, "mygitlabtoken", "https://my.gitlab.host.com/api/v4");
// Not interested in all subsequent calls, already tested in other test cases
});
@@ -631,8 +679,8 @@ describe("cli runner", () => {
await runner.execute();
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITLAB, "mytoken", "https://my.gitlab.host.com/api/v4");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITLAB, "mytoken", "https://my.gitlab.host.com/api/v4");
// Not interested in all subsequent calls, already tested in other test cases
});
@@ -649,9 +697,20 @@ describe("cli runner", () => {
await runner.execute();
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
// Not interested in all subsequent calls, already tested in other test cases
});
test("throw error if missing squash commit", async () => {
addProcessArgs([
"-tb",
"target",
"-pr",
"https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/6"
]);
await expect(() => runner.execute()).rejects.toThrow("Trying to backport a single squashed/merged commit that does not exist! Aborting...");
});
});

View File

@@ -30,6 +30,7 @@ const GITHUB_MERGED_PR_W_OVERRIDES_CONFIG_FILE_CONTENT = {
jest.mock("@bp/service/git/git-cli");
jest.spyOn(GitHubClient.prototype, "createPullRequest");
jest.spyOn(GitHubClient.prototype, "createPullRequestComment");
jest.spyOn(GitClientFactory, "getOrCreate");
let parser: ArgsParser;
@@ -70,23 +71,24 @@ describe("gha runner", () => {
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://github.com/owner/reponame.git", cwd, "target");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-28f63db");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp-target-28f63db");
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
expect(GitCLIService.prototype.fetch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.fetch).toHaveBeenCalledWith(cwd, "pull/2368/head:pr/2368");
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toBeCalledTimes(0);
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(0);
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(0);
expect(GitHubClient.prototype.createPullRequest).toHaveBeenCalledTimes(0);
expect(GitHubClient.prototype.createPullRequestComment).toHaveBeenCalledTimes(0);
});
test("without dry run", async () => {
@@ -99,26 +101,26 @@ describe("gha runner", () => {
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://github.com/owner/reponame.git", cwd, "target");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-28f63db");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp-target-28f63db");
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
expect(GitCLIService.prototype.fetch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.fetch).toHaveBeenCalledWith(cwd, "pull/2368/head:pr/2368");
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-28f63db");
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp-target-28f63db");
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1);
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
expect(GitHubClient.prototype.createPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "owner",
repo: "reponame",
head: "bp-target-28f63db",
@@ -131,7 +133,7 @@ describe("gha runner", () => {
comments: [],
}
);
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
expect(GitHubClient.prototype.createPullRequest).toHaveReturnedTimes(1);
});
test("closed and not merged pull request", async () => {
@@ -153,26 +155,26 @@ describe("gha runner", () => {
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://github.com/owner/reponame.git", cwd, "target");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-9174896");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp-target-9174896");
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/4444/head:pr/4444");
expect(GitCLIService.prototype.fetch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.fetch).toHaveBeenCalledWith(cwd, "pull/4444/head:pr/4444");
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "91748965051fae1330ad58d15cf694e103267c87", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "91748965051fae1330ad58d15cf694e103267c87", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-9174896");
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp-target-9174896");
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1);
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
expect(GitHubClient.prototype.createPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "owner",
repo: "reponame",
head: "bp-target-9174896",
@@ -185,7 +187,7 @@ describe("gha runner", () => {
comments: [],
}
);
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
expect(GitHubClient.prototype.createPullRequest).toHaveReturnedTimes(1);
});
test("override backporting pr data", async () => {
@@ -204,26 +206,26 @@ describe("gha runner", () => {
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://github.com/owner/reponame.git", cwd, "target");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp_branch_name");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp_branch_name");
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
expect(GitCLIService.prototype.fetch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.fetch).toHaveBeenCalledWith(cwd, "pull/2368/head:pr/2368");
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp_branch_name");
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp_branch_name");
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1);
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
expect(GitHubClient.prototype.createPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "owner",
repo: "reponame",
head: "bp_branch_name",
@@ -236,7 +238,7 @@ describe("gha runner", () => {
comments: [],
}
);
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
expect(GitHubClient.prototype.createPullRequest).toHaveReturnedTimes(1);
});
test("set empty reviewers", async () => {
@@ -256,26 +258,26 @@ describe("gha runner", () => {
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://github.com/owner/reponame.git", cwd, "target");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp_branch_name");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp_branch_name");
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
expect(GitCLIService.prototype.fetch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.fetch).toHaveBeenCalledWith(cwd, "pull/2368/head:pr/2368");
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp_branch_name");
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp_branch_name");
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1);
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
expect(GitHubClient.prototype.createPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "owner",
repo: "reponame",
head: "bp_branch_name",
@@ -288,7 +290,7 @@ describe("gha runner", () => {
comments: [],
}
);
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
expect(GitHubClient.prototype.createPullRequest).toHaveReturnedTimes(1);
});
test("set custom labels with inheritance", async () => {
@@ -303,26 +305,26 @@ describe("gha runner", () => {
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://github.com/owner/reponame.git", cwd, "target");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-28f63db");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp-target-28f63db");
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
expect(GitCLIService.prototype.fetch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.fetch).toHaveBeenCalledWith(cwd, "pull/2368/head:pr/2368");
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-28f63db");
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp-target-28f63db");
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1);
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
expect(GitHubClient.prototype.createPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "owner",
repo: "reponame",
head: "bp-target-28f63db",
@@ -335,7 +337,7 @@ describe("gha runner", () => {
comments: [],
}
);
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
expect(GitHubClient.prototype.createPullRequest).toHaveReturnedTimes(1);
});
test("set custom labels without inheritance", async () => {
@@ -350,26 +352,26 @@ describe("gha runner", () => {
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://github.com/owner/reponame.git", cwd, "target");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-28f63db");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp-target-28f63db");
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
expect(GitCLIService.prototype.fetch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.fetch).toHaveBeenCalledWith(cwd, "pull/2368/head:pr/2368");
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-28f63db");
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp-target-28f63db");
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1);
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
expect(GitHubClient.prototype.createPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "owner",
repo: "reponame",
head: "bp-target-28f63db",
@@ -382,7 +384,7 @@ describe("gha runner", () => {
comments: [],
}
);
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
expect(GitHubClient.prototype.createPullRequest).toHaveReturnedTimes(1);
});
test("using config file with overrides", async () => {
@@ -394,26 +396,26 @@ describe("gha runner", () => {
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITHUB, "my-auth-token", "https://api.github.com");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITHUB, "my-auth-token", "https://api.github.com");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://github.com/owner/reponame.git", cwd, "target");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp_branch_name");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp_branch_name");
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
expect(GitCLIService.prototype.fetch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.fetch).toHaveBeenCalledWith(cwd, "pull/2368/head:pr/2368");
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp_branch_name");
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp_branch_name");
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1);
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
expect(GitHubClient.prototype.createPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "owner",
repo: "reponame",
head: "bp_branch_name",
@@ -426,7 +428,7 @@ describe("gha runner", () => {
comments: [],
}
);
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
expect(GitHubClient.prototype.createPullRequest).toHaveReturnedTimes(1);
});
// to check: https://github.com/kiegroup/git-backporting/issues/52
@@ -440,26 +442,26 @@ describe("gha runner", () => {
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://github.com/owner/reponame.git", cwd, "target");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-28f63db");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp-target-28f63db");
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
expect(GitCLIService.prototype.fetch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.fetch).toHaveBeenCalledWith(cwd, "pull/2368/head:pr/2368");
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-28f63db");
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp-target-28f63db");
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1);
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
expect(GitHubClient.prototype.createPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "owner",
repo: "reponame",
head: "bp-target-28f63db",
@@ -472,7 +474,7 @@ describe("gha runner", () => {
comments: [],
}
);
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
expect(GitHubClient.prototype.createPullRequest).toHaveReturnedTimes(1);
});
test("multiple commits pr", async () => {
@@ -486,26 +488,26 @@ describe("gha runner", () => {
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("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).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp-target-0404fb9-11da4e3");
expect(GitCLIService.prototype.fetch).toBeCalledTimes(0);
expect(GitCLIService.prototype.fetch).toHaveBeenCalledTimes(0);
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(2);
expect(GitCLIService.prototype.cherryPick).toHaveBeenLastCalledWith(cwd, "0404fb922ab75c3a8aecad5c97d9af388df04695", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "11da4e38aa3e577ffde6d546f1c52e53b04d3151", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(2);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "0404fb922ab75c3a8aecad5c97d9af388df04695", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenLastCalledWith(cwd, "11da4e38aa3e577ffde6d546f1c52e53b04d3151", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-0404fb9-11da4e3");
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp-target-0404fb9-11da4e3");
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1);
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
expect(GitHubClient.prototype.createPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "owner",
repo: "reponame",
head: "bp-target-0404fb9-11da4e3",
@@ -518,7 +520,7 @@ describe("gha runner", () => {
comments: [],
}
);
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
expect(GitHubClient.prototype.createPullRequest).toHaveReturnedTimes(1);
});
test("using github api url and different strategy", async () => {
@@ -533,26 +535,26 @@ describe("gha runner", () => {
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://github.com/owner/reponame.git", cwd, "target");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-28f63db");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp-target-28f63db");
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
expect(GitCLIService.prototype.fetch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.fetch).toHaveBeenCalledWith(cwd, "pull/2368/head:pr/2368");
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", "ort", "ours", undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", "ort", "ours", undefined);
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-28f63db");
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp-target-28f63db");
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1);
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
expect(GitHubClient.prototype.createPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "owner",
repo: "reponame",
head: "bp-target-28f63db",
@@ -565,7 +567,7 @@ describe("gha runner", () => {
comments: [],
}
);
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
expect(GitHubClient.prototype.createPullRequest).toHaveReturnedTimes(1);
});
test("using github api url and additional cherry-pick options", async () => {
@@ -579,26 +581,26 @@ describe("gha runner", () => {
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://github.com/owner/reponame.git", cwd, "target");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-28f63db");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp-target-28f63db");
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
expect(GitCLIService.prototype.fetch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.fetch).toHaveBeenCalledWith(cwd, "pull/2368/head:pr/2368");
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, "-x --allow-empty");
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, "-x --allow-empty");
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-28f63db");
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp-target-28f63db");
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1);
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
expect(GitHubClient.prototype.createPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "owner",
repo: "reponame",
head: "bp-target-28f63db",
@@ -611,7 +613,7 @@ describe("gha runner", () => {
comments: [],
}
);
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
expect(GitHubClient.prototype.createPullRequest).toHaveReturnedTimes(1);
});
test("additional pr comments", async () => {
@@ -625,26 +627,26 @@ describe("gha runner", () => {
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://github.com/owner/reponame.git", cwd, "target");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-28f63db");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp-target-28f63db");
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
expect(GitCLIService.prototype.fetch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.fetch).toHaveBeenCalledWith(cwd, "pull/2368/head:pr/2368");
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-28f63db");
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp-target-28f63db");
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1);
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
expect(GitHubClient.prototype.createPullRequest).toHaveBeenCalledTimes(1);
expect(GitHubClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "owner",
repo: "reponame",
head: "bp-target-28f63db",
@@ -657,7 +659,7 @@ describe("gha runner", () => {
comments: ["first comment", "second comment"],
}
);
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
expect(GitHubClient.prototype.createPullRequest).toHaveReturnedTimes(1);
});
test("with multiple target branches", async () => {
@@ -671,34 +673,34 @@ describe("gha runner", () => {
const cwd = "/tmp/folder";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com");
expect(GitCLIService.prototype.clone).toBeCalledTimes(3);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "v1");
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "v2");
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "v3");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(3);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://github.com/owner/reponame.git", cwd, "v1");
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://github.com/owner/reponame.git", cwd, "v2");
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://github.com/owner/reponame.git", cwd, "v3");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(3);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-v1-28f63db");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-v2-28f63db");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-v3-28f63db");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(3);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp-v1-28f63db");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp-v2-28f63db");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp-v3-28f63db");
expect(GitCLIService.prototype.fetch).toBeCalledTimes(3);
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
expect(GitCLIService.prototype.fetch).toHaveBeenCalledTimes(3);
expect(GitCLIService.prototype.fetch).toHaveBeenCalledWith(cwd, "pull/2368/head:pr/2368");
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(3);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(3);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toBeCalledTimes(3);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-v1-28f63db");
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-v2-28f63db");
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-v3-28f63db");
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(3);
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp-v1-28f63db");
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp-v2-28f63db");
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp-v3-28f63db");
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(3);
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
expect(GitHubClient.prototype.createPullRequest).toHaveBeenCalledTimes(3);
expect(GitHubClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "owner",
repo: "reponame",
head: "bp-v1-28f63db",
@@ -710,7 +712,7 @@ describe("gha runner", () => {
labels: [],
comments: [],
});
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
expect(GitHubClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "owner",
repo: "reponame",
head: "bp-v2-28f63db",
@@ -722,7 +724,7 @@ describe("gha runner", () => {
labels: [],
comments: [],
});
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
expect(GitHubClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "owner",
repo: "reponame",
head: "bp-v3-28f63db",
@@ -734,7 +736,7 @@ describe("gha runner", () => {
labels: [],
comments: [],
});
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(3);
expect(GitHubClient.prototype.createPullRequest).toHaveReturnedTimes(3);
});
test("with multiple target branches and single custom bp branch", async () => {
@@ -749,34 +751,34 @@ describe("gha runner", () => {
const cwd = "/tmp/folder";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITHUB, undefined, "https://api.github.com");
expect(GitCLIService.prototype.clone).toBeCalledTimes(3);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "v1");
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "v2");
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "v3");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(3);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://github.com/owner/reponame.git", cwd, "v1");
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://github.com/owner/reponame.git", cwd, "v2");
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://github.com/owner/reponame.git", cwd, "v3");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(3);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "custom-v1");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "custom-v2");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "custom-v3");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(3);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "custom-v1");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "custom-v2");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "custom-v3");
expect(GitCLIService.prototype.fetch).toBeCalledTimes(3);
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
expect(GitCLIService.prototype.fetch).toHaveBeenCalledTimes(3);
expect(GitCLIService.prototype.fetch).toHaveBeenCalledWith(cwd, "pull/2368/head:pr/2368");
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(3);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(3);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toBeCalledTimes(3);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "custom-v1");
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "custom-v2");
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "custom-v3");
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(3);
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "custom-v1");
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "custom-v2");
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "custom-v3");
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(3);
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
expect(GitHubClient.prototype.createPullRequest).toHaveBeenCalledTimes(3);
expect(GitHubClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "owner",
repo: "reponame",
head: "custom-v1",
@@ -788,7 +790,7 @@ describe("gha runner", () => {
labels: [],
comments: [],
});
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
expect(GitHubClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "owner",
repo: "reponame",
head: "custom-v2",
@@ -800,7 +802,7 @@ describe("gha runner", () => {
labels: [],
comments: [],
});
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
expect(GitHubClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "owner",
repo: "reponame",
head: "custom-v3",
@@ -812,7 +814,7 @@ describe("gha runner", () => {
labels: [],
comments: [],
});
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(3);
expect(GitHubClient.prototype.createPullRequest).toHaveReturnedTimes(3);
});
test("explicitly set git client", async () => {
@@ -826,11 +828,11 @@ describe("gha runner", () => {
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.CODEBERG, undefined, "https://api.github.com");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.CODEBERG, undefined, "https://api.github.com");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://github.com/owner/reponame.git", cwd, "target");
});
});

View File

@@ -43,6 +43,7 @@ jest.mock("axios", () => {
jest.mock("@bp/service/git/git-cli");
jest.spyOn(GitLabClient.prototype, "createPullRequest");
jest.spyOn(GitLabClient.prototype, "createPullRequestComment");
jest.spyOn(GitClientFactory, "getOrCreate");
let parser: ArgsParser;
@@ -81,23 +82,24 @@ describe("gha runner", () => {
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-9e15674");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp-target-9e15674");
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2");
expect(GitCLIService.prototype.fetch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.fetch).toHaveBeenCalledWith(cwd, "merge-requests/2/head:pr/2");
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toBeCalledTimes(0);
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(0);
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(0);
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledTimes(0);
expect(GitLabClient.prototype.createPullRequestComment).toHaveBeenCalledTimes(0);
});
test("without dry run", async () => {
@@ -110,26 +112,26 @@ describe("gha runner", () => {
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-9e15674");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp-target-9e15674");
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2");
expect(GitCLIService.prototype.fetch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.fetch).toHaveBeenCalledWith(cwd, "merge-requests/2/head:pr/2");
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-9e15674");
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp-target-9e15674");
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "superuser",
repo: "backporting-example",
head: "bp-target-9e15674",
@@ -163,25 +165,25 @@ describe("gha runner", () => {
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-ebb1eca");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp-target-ebb1eca");
expect(GitCLIService.prototype.fetch).toBeCalledTimes(0);
expect(GitCLIService.prototype.fetch).toHaveBeenCalledTimes(0);
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-ebb1eca");
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp-target-ebb1eca");
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "superuser",
repo: "backporting-example",
head: "bp-target-ebb1eca",
@@ -212,26 +214,26 @@ describe("gha runner", () => {
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp_branch_name");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp_branch_name");
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2");
expect(GitCLIService.prototype.fetch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.fetch).toHaveBeenCalledWith(cwd, "merge-requests/2/head:pr/2");
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp_branch_name");
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp_branch_name");
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "superuser",
repo: "backporting-example",
head: "bp_branch_name",
@@ -263,26 +265,26 @@ describe("gha runner", () => {
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp_branch_name");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp_branch_name");
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2");
expect(GitCLIService.prototype.fetch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.fetch).toHaveBeenCalledWith(cwd, "merge-requests/2/head:pr/2");
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp_branch_name");
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp_branch_name");
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "superuser",
repo: "backporting-example",
head: "bp_branch_name",
@@ -309,25 +311,25 @@ describe("gha runner", () => {
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-ebb1eca");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp-target-ebb1eca");
expect(GitCLIService.prototype.fetch).toBeCalledTimes(0);
expect(GitCLIService.prototype.fetch).toHaveBeenCalledTimes(0);
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-ebb1eca");
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp-target-ebb1eca");
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "superuser",
repo: "backporting-example",
head: "bp-target-ebb1eca",
@@ -353,25 +355,25 @@ describe("gha runner", () => {
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-ebb1eca");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp-target-ebb1eca");
expect(GitCLIService.prototype.fetch).toBeCalledTimes(0);
expect(GitCLIService.prototype.fetch).toHaveBeenCalledTimes(0);
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-ebb1eca");
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp-target-ebb1eca");
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "superuser",
repo: "backporting-example",
head: "bp-target-ebb1eca",
@@ -395,27 +397,27 @@ describe("gha runner", () => {
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITLAB, "my-token", "https://my.gitlab.host.com/api/v4");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITLAB, "my-token", "https://my.gitlab.host.com/api/v4");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "prod");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "prod");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-prod-ebb1eca");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp-prod-ebb1eca");
// 0 occurrences as the mr is already merged and the owner is the same for
// both source and target repositories
expect(GitCLIService.prototype.fetch).toBeCalledTimes(0);
expect(GitCLIService.prototype.fetch).toHaveBeenCalledTimes(0);
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-prod-ebb1eca");
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp-prod-ebb1eca");
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "superuser",
repo: "backporting-example",
head: "bp-prod-ebb1eca",
@@ -441,23 +443,23 @@ describe("gha runner", () => {
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-e4dd336");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp-target-e4dd336");
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "e4dd336a4a20f394df6665994df382fb1d193a11", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "e4dd336a4a20f394df6665994df382fb1d193a11", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-e4dd336");
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp-target-e4dd336");
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "superuser",
repo: "backporting-example",
head: "bp-target-e4dd336",
@@ -483,27 +485,27 @@ describe("gha runner", () => {
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitCLIService.prototype.clone).toBeCalledTimes(1);
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-e4dd336-974519f");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp-target-e4dd336-974519f");
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2");
expect(GitCLIService.prototype.fetch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.fetch).toHaveBeenCalledWith(cwd, "merge-requests/2/head:pr/2");
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(2);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "e4dd336a4a20f394df6665994df382fb1d193a11", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "974519f65c9e0ed65277cd71026657a09fca05e7", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(2);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "e4dd336a4a20f394df6665994df382fb1d193a11", undefined, undefined, undefined);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "974519f65c9e0ed65277cd71026657a09fca05e7", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-e4dd336-974519f");
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp-target-e4dd336-974519f");
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "superuser",
repo: "backporting-example",
head: "bp-target-e4dd336-974519f",
@@ -517,4 +519,46 @@ describe("gha runner", () => {
}
);
});
test("merged MR with auto-no-squash", async () => {
spyGetInput({
"target-branch": "target",
"pull-request": "https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/5",
"auto-no-squash": "true",
});
await runner.execute();
const cwd = process.cwd() + "/bp";
expect(GitClientFactory.getOrCreate).toHaveBeenCalledTimes(1);
expect(GitClientFactory.getOrCreate).toHaveBeenCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
expect(GitCLIService.prototype.clone).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.clone).toHaveBeenCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.createLocalBranch).toHaveBeenCalledWith(cwd, "bp-target-e4dd336");
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.cherryPick).toHaveBeenCalledWith(cwd, "e4dd336a4a20f394df6665994df382fb1d193a11", undefined, undefined, undefined);
expect(GitCLIService.prototype.push).toHaveBeenCalledTimes(1);
expect(GitCLIService.prototype.push).toHaveBeenCalledWith(cwd, "bp-target-e4dd336");
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledTimes(1);
expect(GitLabClient.prototype.createPullRequest).toHaveBeenCalledWith({
owner: "superuser",
repo: "backporting-example",
head: "bp-target-e4dd336",
base: "target",
title: "[target] Update test.txt",
body: expect.stringContaining("**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/5"),
reviewers: ["superuser"],
assignees: [],
labels: [],
comments: [],
}
);
});
});

View File

@@ -0,0 +1,19 @@
import { injectError, injectTargetBranch } from "@bp/service/runner/runner-util";
describe("check runner utilities", () => {
test("properly inject error message", () => {
expect(injectError("Original message: {{error}}", "to inject")).toStrictEqual("Original message: to inject");
});
test("missing error placeholder in the original message", () => {
expect(injectError("Original message: {{wrong}}", "to inject")).toStrictEqual("Original message: {{wrong}}");
});
test("properly inject target branch into message", () => {
expect(injectTargetBranch("Original message: {{target-branch}}", "to inject")).toStrictEqual("Original message: to inject");
});
test("missing target branch placeholder in the original message", () => {
expect(injectTargetBranch("Original message: {{wrong}}", "to inject")).toStrictEqual("Original message: {{wrong}}");
});
});

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,8 @@
import LoggerServiceFactory from "@bp/service/logger/logger-service-factory";
import { Moctokit } from "@kie/mock-github";
import { TARGET_OWNER, REPO, MERGED_PR_FIXTURE, OPEN_PR_FIXTURE, NOT_MERGED_PR_FIXTURE, NOT_FOUND_PR_NUMBER, MULT_COMMITS_PR_FIXTURE, MULT_COMMITS_PR_COMMITS, NEW_PR_URL, NEW_PR_NUMBER } from "./github-data";
import { CLOSED_NOT_MERGED_MR, MERGED_SQUASHED_MR, NESTED_NAMESPACE_MR, OPEN_MR, OPEN_PR_COMMITS, PROJECT_EXAMPLE, NESTED_PROJECT_EXAMPLE, SUPERUSER, MERGED_SQUASHED_MR_COMMITS } from "./gitlab-data";
import { TARGET_OWNER, REPO, MERGED_PR_FIXTURE, OPEN_PR_FIXTURE, NOT_MERGED_PR_FIXTURE, NOT_FOUND_PR_NUMBER, MULT_COMMITS_PR_FIXTURE, MULT_COMMITS_PR_COMMITS, NEW_PR_URL, NEW_PR_NUMBER, GITHUB_GET_COMMIT } from "./github-data";
import { CLOSED_NOT_MERGED_MR, MERGED_SQUASHED_MR, NESTED_NAMESPACE_MR, OPEN_MR, OPEN_PR_COMMITS, PROJECT_EXAMPLE, NESTED_PROJECT_EXAMPLE, SUPERUSER, MERGED_SQUASHED_MR_COMMITS, MERGED_NOT_SQUASHED_MR, MERGED_NOT_SQUASHED_MR_COMMITS, UNDEFINED_COMMITS_MR } from "./gitlab-data";
import { CB_TARGET_OWNER, CB_REPO, CB_MERGED_PR_FIXTURE, CB_OPEN_PR_FIXTURE, CB_NOT_MERGED_PR_FIXTURE, CB_NOT_FOUND_PR_NUMBER, CB_MULT_COMMITS_PR_FIXTURE, CB_MULT_COMMITS_PR_COMMITS, CB_NEW_PR_URL, CB_NEW_PR_NUMBER, CODEBERG_GET_COMMIT } from "./codeberg-data";
// high number, for each test we are not expecting
// to send more than 3 reqs per api endpoint
@@ -24,6 +25,10 @@ export const getAxiosMocked = (url: string) => {
data = CLOSED_NOT_MERGED_MR;
} else if (url.endsWith("merge_requests/4")) {
data = NESTED_NAMESPACE_MR;
} else if (url.endsWith("merge_requests/5")) {
data = MERGED_NOT_SQUASHED_MR;
} else if (url.endsWith("merge_requests/6")) {
data = UNDEFINED_COMMITS_MR;
} else if (url.endsWith("projects/76316")) {
data = PROJECT_EXAMPLE;
} else if (url.endsWith("projects/1645")) {
@@ -34,6 +39,8 @@ export const getAxiosMocked = (url: string) => {
data = MERGED_SQUASHED_MR_COMMITS;
} else if (url.endsWith("merge_requests/2/commits")) {
data = OPEN_PR_COMMITS;
} else if (url.endsWith("merge_requests/5/commits")) {
data = MERGED_NOT_SQUASHED_MR_COMMITS;
}
return {
@@ -157,6 +164,17 @@ export const mockGitHubClient = (apiUrl = "https://api.github.com"): Moctokit =>
data: MULT_COMMITS_PR_COMMITS
});
mock.rest.pulls
.listCommits({
owner: TARGET_OWNER,
repo: REPO,
pull_number: OPEN_PR_FIXTURE.number
})
.reply({
status: 200,
data: MULT_COMMITS_PR_COMMITS
});
mock.rest.pulls
.create()
.reply({
@@ -200,6 +218,17 @@ export const mockGitHubClient = (apiUrl = "https://api.github.com"): Moctokit =>
data: {}
});
mock.rest.git
.getCommit({
owner: TARGET_OWNER,
repo: REPO,
commit_sha: "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc",
})
.reply({
status: 200,
data: GITHUB_GET_COMMIT,
});
// invalid requests
mock.rest.pulls
.get({
@@ -217,3 +246,151 @@ export const mockGitHubClient = (apiUrl = "https://api.github.com"): Moctokit =>
return mock;
};
// CODEBERG - OCTOKIT
export const mockCodebergClient = (apiUrl = "https://codeberg.org/api/v1"): Moctokit => {
logger.debug("Setting up moctokit..");
const mock = new Moctokit(apiUrl);
// setup the mock requests here
// valid requests
mock.rest.pulls
.get({
owner: CB_TARGET_OWNER,
repo: CB_REPO,
pull_number: CB_MERGED_PR_FIXTURE.number
})
.reply({
status: 200,
data: CB_MERGED_PR_FIXTURE
});
mock.rest.pulls
.get({
owner: CB_TARGET_OWNER,
repo: CB_REPO,
pull_number: CB_MULT_COMMITS_PR_FIXTURE.number
})
.reply({
status: 200,
data: CB_MULT_COMMITS_PR_FIXTURE
});
mock.rest.pulls
.get({
owner: CB_TARGET_OWNER,
repo: CB_REPO,
pull_number: CB_OPEN_PR_FIXTURE.number
})
.reply({
status: 200,
data: CB_OPEN_PR_FIXTURE
});
mock.rest.pulls
.get({
owner: CB_TARGET_OWNER,
repo: CB_REPO,
pull_number: CB_NOT_MERGED_PR_FIXTURE.number
})
.reply({
status: 200,
data: CB_NOT_MERGED_PR_FIXTURE
});
mock.rest.pulls
.listCommits({
owner: CB_TARGET_OWNER,
repo: CB_REPO,
pull_number: CB_MULT_COMMITS_PR_FIXTURE.number
})
.reply({
status: 200,
data: CB_MULT_COMMITS_PR_COMMITS
});
mock.rest.pulls
.listCommits({
owner: CB_TARGET_OWNER,
repo: CB_REPO,
pull_number: CB_OPEN_PR_FIXTURE.number
})
.reply({
status: 200,
data: CB_MULT_COMMITS_PR_COMMITS
});
mock.rest.pulls
.create()
.reply({
repeat: REPEAT,
status: 201,
data: {
number: CB_NEW_PR_NUMBER,
html_url: CB_NEW_PR_URL,
}
});
mock.rest.pulls
.requestReviewers()
.reply({
repeat: REPEAT,
status: 201,
data: CB_MERGED_PR_FIXTURE
});
mock.rest.issues
.addAssignees()
.reply({
repeat: REPEAT,
status: 201,
data: {}
});
mock.rest.issues
.addLabels()
.reply({
repeat: REPEAT,
status: 200,
data: {}
});
mock.rest.issues
.createComment()
.reply({
repeat: REPEAT,
status: 201,
data: {}
});
mock.rest.git
.getCommit({
owner: CB_TARGET_OWNER,
repo: CB_REPO,
commit_sha: "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc",
})
.reply({
status: 200,
data: CODEBERG_GET_COMMIT,
});
// invalid requests
mock.rest.pulls
.get({
owner: CB_TARGET_OWNER,
repo: CB_REPO,
pull_number: CB_NOT_FOUND_PR_NUMBER
})
.reply({
repeat: REPEAT,
status: 404,
data: {
message: "Not found"
}
});
return mock;
};

View File

@@ -1832,6 +1832,14 @@ export const MULT_COMMITS_PR_FIXTURE = {
"changed_files": 2
};
export const GITHUB_GET_COMMIT = {
"parents": [
{
"sha": "SHA"
}
]
};
export const MULT_COMMITS_PR_COMMITS = [
{
"sha": "0404fb922ab75c3a8aecad5c97d9af388df04695",

View File

@@ -755,6 +755,29 @@ export const OPEN_PR_COMMITS = [
}
];
export const MERGED_NOT_SQUASHED_MR_COMMITS = [
{
"id":"e4dd336a4a20f394df6665994df382fb1d193a11",
"short_id":"e4dd336a",
"created_at":"2023-06-29T09:59:10.000Z",
"parent_ids":[
],
"title":"Add new file",
"message":"Add new file",
"author_name":"Super User",
"author_email":"superuser@email.com",
"authored_date":"2023-06-29T09:59:10.000Z",
"committer_name":"Super User",
"committer_email":"superuser@email.com",
"committed_date":"2023-06-29T09:59:10.000Z",
"trailers":{
},
"web_url":"https://gitlab.com/superuser/backporting-example/-/commit/e4dd336a4a20f394df6665994df382fb1d193a11"
},
];
export const SUPERUSER = {
"id":14041,
"username":"superuser",
@@ -898,3 +921,273 @@ export const NESTED_NAMESPACE_MR = {
"can_merge":true
}
};
export const MERGED_NOT_SQUASHED_MR = {
"id":807106,
"iid":1,
"project_id":76316,
"title":"Update test.txt",
"description":"This is the body",
"state":"merged",
"created_at":"2023-06-28T14:32:40.943Z",
"updated_at":"2023-06-28T14:37:12.108Z",
"merged_by":{
"id":14041,
"username":"superuser",
"name":"Super User",
"state":"active",
"avatar_url":"https://my.gitlab.host.com/uploads/-/system/user/avatar/14041/avatar.png",
"web_url":"https://my.gitlab.host.com/superuser"
},
"merge_user":{
"id":14041,
"username":"superuser",
"name":"Super User",
"state":"active",
"avatar_url":"https://my.gitlab.host.com/uploads/-/system/user/avatar/14041/avatar.png",
"web_url":"https://my.gitlab.host.com/superuser"
},
"merged_at":"2023-06-28T14:37:11.667Z",
"closed_by":null,
"closed_at":null,
"target_branch":"main",
"source_branch":"feature",
"user_notes_count":0,
"upvotes":0,
"downvotes":0,
"author":{
"id":14041,
"username":"superuser",
"name":"Super User",
"state":"active",
"avatar_url":"https://my.gitlab.host.com/uploads/-/system/user/avatar/14041/avatar.png",
"web_url":"https://my.gitlab.host.com/superuser"
},
"assignees":[
{
"id":14041,
"username":"superuser",
"name":"Super User",
"state":"active",
"avatar_url":"https://my.gitlab.host.com/uploads/-/system/user/avatar/14041/avatar.png",
"web_url":"https://my.gitlab.host.com/superuser"
}
],
"assignee":{
"id":14041,
"username":"superuser",
"name":"Super User",
"state":"active",
"avatar_url":"https://my.gitlab.host.com/uploads/-/system/user/avatar/14041/avatar.png",
"web_url":"https://my.gitlab.host.com/superuser"
},
"reviewers":[
{
"id":1404188,
"username":"superuser1",
"name":"Super User",
"state":"active",
"avatar_url":"https://my.gitlab.host.com/uploads/-/system/user/avatar/14041/avatar.png",
"web_url":"https://my.gitlab.host.com/superuser"
},
{
"id":1404199,
"username":"superuser2",
"name":"Super User",
"state":"active",
"avatar_url":"https://my.gitlab.host.com/uploads/-/system/user/avatar/14041/avatar.png",
"web_url":"https://my.gitlab.host.com/superuser"
}
],
"source_project_id":76316,
"target_project_id":76316,
"labels":[
"backport-prod"
],
"draft":false,
"work_in_progress":false,
"milestone":null,
"merge_when_pipeline_succeeds":false,
"merge_status":"can_be_merged",
"detailed_merge_status":"not_open",
"sha":"9e15674ebd48e05c6e428a1fa31dbb60a778d644",
"merge_commit_sha":"4d369c3e9a8d1d5b7e56c892a8ab2a7666583ac3",
"squash_commit_sha":null,
"discussion_locked":null,
"should_remove_source_branch":true,
"force_remove_source_branch":true,
"reference":"!5",
"references":{
"short":"!5",
"relative":"!5",
"full":"superuser/backporting-example!5"
},
"web_url":"https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/5",
"time_stats":{
"time_estimate":0,
"total_time_spent":0,
"human_time_estimate":null,
"human_total_time_spent":null
},
"squash":false,
"squash_on_merge":false,
"task_completion_status":{
"count":0,
"completed_count":0
},
"has_conflicts":false,
"blocking_discussions_resolved":true,
"approvals_before_merge":null,
"subscribed":true,
"changes_count":"1",
"latest_build_started_at":null,
"latest_build_finished_at":null,
"first_deployed_to_production_at":null,
"pipeline":null,
"head_pipeline":null,
"diff_refs":{
"base_sha":"2c553a0c4c133a51806badce5fa4842b7253cb3b",
"head_sha":"9e15674ebd48e05c6e428a1fa31dbb60a778d644",
"start_sha":"2c553a0c4c133a51806badce5fa4842b7253cb3b"
},
"merge_error":null,
"first_contribution":false,
"user":{
"can_merge":true
}
};
export const UNDEFINED_COMMITS_MR = {
"id":807106,
"iid":6,
"project_id":76316,
"title":"Update test.txt",
"description":"This is the body",
"state":"merged",
"created_at":"2023-06-28T14:32:40.943Z",
"updated_at":"2023-06-28T14:37:12.108Z",
"merged_by":{
"id":14041,
"username":"superuser",
"name":"Super User",
"state":"active",
"avatar_url":"https://my.gitlab.host.com/uploads/-/system/user/avatar/14041/avatar.png",
"web_url":"https://my.gitlab.host.com/superuser"
},
"merge_user":{
"id":14041,
"username":"superuser",
"name":"Super User",
"state":"active",
"avatar_url":"https://my.gitlab.host.com/uploads/-/system/user/avatar/14041/avatar.png",
"web_url":"https://my.gitlab.host.com/superuser"
},
"merged_at":"2023-06-28T14:37:11.667Z",
"closed_by":null,
"closed_at":null,
"target_branch":"main",
"source_branch":"feature",
"user_notes_count":0,
"upvotes":0,
"downvotes":0,
"author":{
"id":14041,
"username":"superuser",
"name":"Super User",
"state":"active",
"avatar_url":"https://my.gitlab.host.com/uploads/-/system/user/avatar/14041/avatar.png",
"web_url":"https://my.gitlab.host.com/superuser"
},
"assignees":[
{
"id":14041,
"username":"superuser",
"name":"Super User",
"state":"active",
"avatar_url":"https://my.gitlab.host.com/uploads/-/system/user/avatar/14041/avatar.png",
"web_url":"https://my.gitlab.host.com/superuser"
}
],
"assignee":{
"id":14041,
"username":"superuser",
"name":"Super User",
"state":"active",
"avatar_url":"https://my.gitlab.host.com/uploads/-/system/user/avatar/14041/avatar.png",
"web_url":"https://my.gitlab.host.com/superuser"
},
"reviewers":[
{
"id":1404188,
"username":"superuser1",
"name":"Super User",
"state":"active",
"avatar_url":"https://my.gitlab.host.com/uploads/-/system/user/avatar/14041/avatar.png",
"web_url":"https://my.gitlab.host.com/superuser"
},
{
"id":1404199,
"username":"superuser2",
"name":"Super User",
"state":"active",
"avatar_url":"https://my.gitlab.host.com/uploads/-/system/user/avatar/14041/avatar.png",
"web_url":"https://my.gitlab.host.com/superuser"
}
],
"source_project_id":76316,
"target_project_id":76316,
"labels":[
"backport-prod"
],
"draft":false,
"work_in_progress":false,
"milestone":null,
"merge_when_pipeline_succeeds":false,
"merge_status":"can_be_merged",
"detailed_merge_status":"not_open",
"sha":"9e15674ebd48e05c6e428a1fa31dbb60a778d644",
"merge_commit_sha":undefined,
"squash_commit_sha":undefined,
"discussion_locked":null,
"should_remove_source_branch":true,
"force_remove_source_branch":true,
"reference":"!2",
"references":{
"short":"!2",
"relative":"!2",
"full":"superuser/backporting-example!6"
},
"web_url":"https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/6",
"time_stats":{
"time_estimate":0,
"total_time_spent":0,
"human_time_estimate":null,
"human_total_time_spent":null
},
"squash":true,
"squash_on_merge":true,
"task_completion_status":{
"count":0,
"completed_count":0
},
"has_conflicts":false,
"blocking_discussions_resolved":true,
"approvals_before_merge":null,
"subscribed":true,
"changes_count":"1",
"latest_build_started_at":null,
"latest_build_finished_at":null,
"first_deployed_to_production_at":null,
"pipeline":null,
"head_pipeline":null,
"diff_refs":{
"base_sha":"2c553a0c4c133a51806badce5fa4842b7253cb3b",
"head_sha":"9e15674ebd48e05c6e428a1fa31dbb60a778d644",
"start_sha":"2c553a0c4c133a51806badce5fa4842b7253cb3b"
},
"merge_error":null,
"first_contribution":false,
"user":{
"can_merge":true
}
};