mirror of
https://github.com/kiegroup/git-backporting.git
synced 2025-06-28 13:43:48 +00:00
Compare commits
No commits in common. "main" and "v4.1.0" have entirely different histories.
65 changed files with 8975 additions and 16359 deletions
23
.github/ISSUE_TEMPLATE/bug.md
vendored
23
.github/ISSUE_TEMPLATE/bug.md
vendored
|
@ -1,23 +0,0 @@
|
||||||
---
|
|
||||||
name: Bug report
|
|
||||||
about: Create a report to help us improve
|
|
||||||
title: ''
|
|
||||||
labels: 'bug'
|
|
||||||
assignees: ''
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**Describe the bug**
|
|
||||||
A clear and concise description of what the bug is.
|
|
||||||
|
|
||||||
**To Reproduce**
|
|
||||||
Steps to reproduce the behavior:
|
|
||||||
1. Do this '...'
|
|
||||||
2. Do that '....'
|
|
||||||
3. See error
|
|
||||||
|
|
||||||
**Expected behavior**
|
|
||||||
A clear and concise description of what you expected to happen.
|
|
||||||
|
|
||||||
**Additional context**
|
|
||||||
Add any other context about the problem here.
|
|
8
.github/ISSUE_TEMPLATE/chore.md
vendored
8
.github/ISSUE_TEMPLATE/chore.md
vendored
|
@ -1,8 +0,0 @@
|
||||||
---
|
|
||||||
name: Chore issue
|
|
||||||
about: General purpose issues related to chores, project management, etc.
|
|
||||||
title: ''
|
|
||||||
labels: 'chore'
|
|
||||||
assignees: ''
|
|
||||||
|
|
||||||
---
|
|
20
.github/ISSUE_TEMPLATE/feature.md
vendored
20
.github/ISSUE_TEMPLATE/feature.md
vendored
|
@ -1,20 +0,0 @@
|
||||||
---
|
|
||||||
name: Feature request
|
|
||||||
about: Suggest an idea for this project
|
|
||||||
title: ''
|
|
||||||
labels: 'feature'
|
|
||||||
assignees: ''
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**Is your feature request related to a problem? Please describe.**
|
|
||||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
|
||||||
|
|
||||||
**Describe the solution you'd like**
|
|
||||||
A clear and concise description of what you want to happen.
|
|
||||||
|
|
||||||
**Describe alternatives you've considered**
|
|
||||||
A clear and concise description of any alternative solutions or features you've considered.
|
|
||||||
|
|
||||||
**Additional context**
|
|
||||||
Add any other context or screenshots about the feature request here.
|
|
25
.github/pull_request_template.md
vendored
25
.github/pull_request_template.md
vendored
|
@ -1,27 +1,22 @@
|
||||||
**Thank you for submitting this pull request**
|
**Thank you for submitting this pull request**
|
||||||
|
|
||||||
fixes _(please add the issue ID if it exists)_
|
fix _(please add the issue ID if it exists)_
|
||||||
|
|
||||||
## Description
|
### Referenced pull requests
|
||||||
<!--- Describe your changes in detail -->
|
|
||||||
|
|
||||||
## How Has This Been Tested?
|
<!-- Add URLs of all referenced pull requests if they exist. This is only required when making
|
||||||
<!--- Please describe in detail how you tested your changes. -->
|
changes that span multiple kiegroup repositories and depend on each other. -->
|
||||||
<!--- Include details of your testing environment, and the tests you ran to -->
|
<!-- Example:
|
||||||
<!--- see how your change affects other areas of the code, etc. -->
|
- https://github.com/kiegroup/droolsjbpm-build-bootstrap/pull/1234
|
||||||
|
- https://github.com/kiegroup/drools/pull/3000
|
||||||
|
- https://github.com/kiegroup/optaplanner/pull/899
|
||||||
|
- etc.
|
||||||
|
-->
|
||||||
|
|
||||||
### Checklist
|
### Checklist
|
||||||
- [ ] Tests added if applicable.
|
- [ ] Tests added if applicable.
|
||||||
- [ ] Documentation updated if applicable.
|
- [ ] Documentation updated if applicable.
|
||||||
|
|
||||||
### Merge criteria:
|
|
||||||
<!--- This PR will be merged by any repository approver when it meets all the points in the checklist -->
|
|
||||||
<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
|
|
||||||
|
|
||||||
- [ ] The commits and have meaningful messages; the author will squash them _after approval_ or will ask to merge with squash.
|
|
||||||
- [ ] Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
|
|
||||||
- [ ] The developer has manually tested the changes and verified that the changes work
|
|
||||||
|
|
||||||
> **Note:** `dist/cli/index.js` and `dist/gha/index.js` are automatically generated by git hooks and gh workflows.
|
> **Note:** `dist/cli/index.js` and `dist/gha/index.js` are automatically generated by git hooks and gh workflows.
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
|
|
8
.github/workflows/ci.yml
vendored
8
.github/workflows/ci.yml
vendored
|
@ -13,15 +13,15 @@ jobs:
|
||||||
name: ${{ matrix.os }} - node ${{ matrix.node-version }}
|
name: ${{ matrix.os }} - node ${{ matrix.node-version }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node-version: [16, 18, 20]
|
node-version: [16, 18]
|
||||||
os: [ubuntu-latest]
|
os: [ubuntu-latest]
|
||||||
fail-fast: false
|
fail-fast: true
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v3
|
||||||
- name: Setup Node ${{ matrix.node-version }}
|
- name: Setup Node ${{ matrix.node-version }}
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.node-version }}
|
node-version: ${{ matrix.node-version }}
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
|
|
22
.github/workflows/coverage.yml
vendored
22
.github/workflows/coverage.yml
vendored
|
@ -1,22 +0,0 @@
|
||||||
name: 'coverage report'
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request_target:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
paths-ignore:
|
|
||||||
- 'LICENSE*'
|
|
||||||
- '**.gitignore'
|
|
||||||
- '**.md'
|
|
||||||
- '**.txt'
|
|
||||||
- '.github/ISSUE_TEMPLATE/**'
|
|
||||||
- '.github/dependabot.yml'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
coverage:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: ArtiomTr/jest-coverage-report-action@v2
|
|
||||||
with:
|
|
||||||
test-script: npm test
|
|
4
.github/workflows/prepare-release.yml
vendored
4
.github/workflows/prepare-release.yml
vendored
|
@ -19,11 +19,11 @@ jobs:
|
||||||
name: Prepare release
|
name: Prepare release
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: 18
|
node-version: 18
|
||||||
- name: Git config
|
- name: Git config
|
||||||
|
|
16
.github/workflows/pull-request.yml
vendored
16
.github/workflows/pull-request.yml
vendored
|
@ -3,30 +3,22 @@
|
||||||
|
|
||||||
name: "pull request check"
|
name: "pull request check"
|
||||||
|
|
||||||
on:
|
on: pull_request
|
||||||
pull_request:
|
|
||||||
paths-ignore:
|
|
||||||
- 'LICENSE*'
|
|
||||||
- '**.gitignore'
|
|
||||||
- '**.md'
|
|
||||||
- '**.txt'
|
|
||||||
- '.github/ISSUE_TEMPLATE/**'
|
|
||||||
- '.github/dependabot.yml'
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
name: ${{ matrix.os }} - node ${{ matrix.node-version }}
|
name: ${{ matrix.os }} - node ${{ matrix.node-version }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node-version: [16, 18, 20]
|
node-version: [16, 18]
|
||||||
os: [ubuntu-latest]
|
os: [ubuntu-latest]
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v3
|
||||||
- name: Setup Node ${{ matrix.node-version }}
|
- name: Setup Node ${{ matrix.node-version }}
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.node-version }}
|
node-version: ${{ matrix.node-version }}
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
|
|
4
.github/workflows/release.yml
vendored
4
.github/workflows/release.yml
vendored
|
@ -17,11 +17,11 @@ jobs:
|
||||||
name: Release package
|
name: Release package
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: 18
|
node-version: 18
|
||||||
- name: Git config
|
- name: Git config
|
||||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -14,4 +14,3 @@ build/
|
||||||
|
|
||||||
# temporary files created during tests
|
# temporary files created during tests
|
||||||
*test*.json
|
*test*.json
|
||||||
bp
|
|
||||||
|
|
137
CHANGELOG.md
137
CHANGELOG.md
|
@ -1,142 +1,5 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
## <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)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* gha input is target-branch-pattern, not target-reg-exp ([#120](https://github.com/kiegroup/git-backporting/issues/120)) ([e6f86f8](https://github.com/kiegroup/git-backporting/commit/e6f86f8f839bc86adf36fa0d3c8dcad6cab2f92e))
|
|
||||||
|
|
||||||
## [4.7.0](https://github.com/kiegroup/git-backporting/compare/v4.6.0...v4.7.0) (2024-04-02)
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* add --cherry-pick-options to add to all cherry-pick run ([#116](https://github.com/kiegroup/git-backporting/issues/116)) ([fe6be83](https://github.com/kiegroup/git-backporting/commit/fe6be83074476d91c1b038fd7f03c4868e96f113))
|
|
||||||
* **gh75:** extract target branched from pr labels ([#112](https://github.com/kiegroup/git-backporting/issues/112)) ([53cc505](https://github.com/kiegroup/git-backporting/commit/53cc505f17630fb30daa70f75895323325cc0c7d))
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* return GitHub no-squash commits in order ([#115](https://github.com/kiegroup/git-backporting/issues/115)) ([6d9b9db](https://github.com/kiegroup/git-backporting/commit/6d9b9db590f9713e2b056bcc8e20fc3f3c70618b))
|
|
||||||
|
|
||||||
## [4.6.0](https://github.com/kiegroup/git-backporting/compare/v4.5.2...v4.6.0) (2024-03-25)
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* add --git-client to explicitly set the type of forge ([#106](https://github.com/kiegroup/git-backporting/issues/106)) ([80a0b55](https://github.com/kiegroup/git-backporting/commit/80a0b554f0c1920a178e28bd678f709581a1b224))
|
|
||||||
|
|
||||||
## [4.5.2](https://github.com/kiegroup/git-backporting/compare/v4.5.1...v4.5.2) (2024-03-08)
|
|
||||||
|
|
||||||
### Improvements
|
|
||||||
|
|
||||||
* upgrade to node20 for gha ([c8ede8d](https://github.com/kiegroup/git-backporting/commit/c8ede8d4e2428cb3f4dc2d727f24b37e5781cbb1))
|
|
||||||
|
|
||||||
## [4.5.1](https://github.com/kiegroup/git-backporting/compare/v4.5.0...v4.5.1) (2024-02-23)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* --auth when --git-user contains space ([#95](https://github.com/kiegroup/git-backporting/issues/95)) ([9bcd6e6](https://github.com/kiegroup/git-backporting/commit/9bcd6e6b5547974c45ade756b623eb385bb76019))
|
|
||||||
* --no-squash on single-commit GitLab MR ([#93](https://github.com/kiegroup/git-backporting/issues/93)) ([300fa91](https://github.com/kiegroup/git-backporting/commit/300fa91a8ae065b7f6f6370882b10929bbde6309))
|
|
||||||
* **gh-96:** fix git token parsing ([#98](https://github.com/kiegroup/git-backporting/issues/98)) ([c57fca6](https://github.com/kiegroup/git-backporting/commit/c57fca6bd6b9c241c11ad1f728cc9bc0acfd7f88))
|
|
||||||
|
|
||||||
## [4.5.0](https://github.com/kiegroup/git-backporting/compare/v4.4.1...v4.5.0) (2023-12-10)
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* **gh-85:** take git tokens from environment ([#88](https://github.com/kiegroup/git-backporting/issues/88)) ([70da575](https://github.com/kiegroup/git-backporting/commit/70da575afce603190eafed927637922a37fbd087))
|
|
||||||
|
|
||||||
## [4.4.1](https://github.com/kiegroup/git-backporting/compare/v4.4.0...v4.4.1) (2023-12-05)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* namespace parsing in gitlab ([#84](https://github.com/kiegroup/git-backporting/issues/84)) ([ed32d22](https://github.com/kiegroup/git-backporting/commit/ed32d2275b6008d31e456c41beecd536eceb23dc))
|
|
||||||
|
|
||||||
## [4.4.0](https://github.com/kiegroup/git-backporting/compare/v4.3.0...v4.4.0) (2023-08-18)
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* integrate with codeberg ([#80](https://github.com/kiegroup/git-backporting/issues/80)) ([9f0fbc0](https://github.com/kiegroup/git-backporting/commit/9f0fbc0b2fd8d449207660323be87f6d2fa8c017))
|
|
||||||
* **issue-77:** handle multiple target branches ([#78](https://github.com/kiegroup/git-backporting/issues/78)) ([5fc72e1](https://github.com/kiegroup/git-backporting/commit/5fc72e127bedb3177f4e17ff1182827c78154ef1))
|
|
||||||
|
|
||||||
## [4.3.0](https://github.com/kiegroup/git-backporting/compare/v4.2.0...v4.3.0) (2023-07-27)
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* **issue-70:** additional pr comments ([bed7e29](https://github.com/kiegroup/git-backporting/commit/bed7e29ddc1ba5498faa2c7cc33ec3b127947dcf))
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* gha skip whitespace trim on body ([#73](https://github.com/kiegroup/git-backporting/issues/73)) ([29589a6](https://github.com/kiegroup/git-backporting/commit/29589a63b503b30820a13a442de533239dec06f4))
|
|
||||||
* preserve new lines in body and comments ([#72](https://github.com/kiegroup/git-backporting/issues/72)) ([fa43ffc](https://github.com/kiegroup/git-backporting/commit/fa43ffc1dc5572a06309c28e93ee6ab5fba14780))
|
|
||||||
|
|
||||||
## [4.2.0](https://github.com/kiegroup/git-backporting/compare/v4.1.0...v4.2.0) (2023-07-13)
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* **issue-62:** make cherry-pick strategy configurable ([#63](https://github.com/kiegroup/git-backporting/issues/63)) ([265955d](https://github.com/kiegroup/git-backporting/commit/265955dda77a8191fd1f64517fec20e8d5f8c5b4))
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* **issue-57:** truncate the bp branch name ([#58](https://github.com/kiegroup/git-backporting/issues/58)) ([ead1322](https://github.com/kiegroup/git-backporting/commit/ead1322c0f6bb5de96c487e8f6b6565734144853))
|
|
||||||
|
|
||||||
|
|
||||||
### Performance Improvements
|
|
||||||
|
|
||||||
* use concurrent promises instead of awaiting them one by one ([#59](https://github.com/kiegroup/git-backporting/issues/59)) ([49a7350](https://github.com/kiegroup/git-backporting/commit/49a73504066396ca2a074f55bb23815e13ae462e))
|
|
||||||
|
|
||||||
## [4.1.0](https://github.com/kiegroup/git-backporting/compare/v4.0.0...v4.1.0) (2023-07-11)
|
## [4.1.0](https://github.com/kiegroup/git-backporting/compare/v4.0.0...v4.1.0) (2023-07-11)
|
||||||
|
|
||||||
|
|
||||||
|
|
97
README.md
97
README.md
|
@ -14,6 +14,10 @@
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## :bangbang: Starting from v4 git-backporting has been moved under @kiegroup organization and renamed :bangbang:
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
**Git Backporting** is a [NodeJS](https://nodejs.org/) command line tool that provides capabilities to *backport* pull requests (on *GitHub*) and merge requests (on *GitLab*) in an automated way. This tool also comes with a predefined *GitHub* action in order to make CI/CD integration easier for all users.
|
**Git Backporting** is a [NodeJS](https://nodejs.org/) command line tool that provides capabilities to *backport* pull requests (on *GitHub*) and merge requests (on *GitLab*) in an automated way. This tool also comes with a predefined *GitHub* action in order to make CI/CD integration easier for all users.
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,13 +28,14 @@ Table of content
|
||||||
* **[CLI tool](#cli-tool)**
|
* **[CLI tool](#cli-tool)**
|
||||||
* **[GitHub action](#github-action)**
|
* **[GitHub action](#github-action)**
|
||||||
* **[Future works](#future-works)**
|
* **[Future works](#future-works)**
|
||||||
|
* **[Migrating to v4](#migrating-to-v4)**
|
||||||
* **[Development](#development)**
|
* **[Development](#development)**
|
||||||
* **[Contributing](#contributing)**
|
* **[Contributing](#contributing)**
|
||||||
* **[License](#license)**
|
* **[License](#license)**
|
||||||
|
|
||||||
## Who is this tool for?
|
## Who is this tool for?
|
||||||
|
|
||||||
`git-backporting` is a fully configurable tool that provides capabilities to *backport* pull requests (on *GitHub*) and merge requests (on *GitLab*) in an automated way.
|
`git-backporting` is a tool that provides capabilities to *backport* pull requests (on *GitHub*) and merge requests (on *GitLab*) in an automated way.
|
||||||
|
|
||||||
> *What is backporting?* - backporting is an action aiming to move a change (usually a commit) from a branch (usually the main one) to another one, which is generally referring to a still maintained release branch. Keeping it simple: it is about to move a specific change or a set of them from one branch to another.
|
> *What is backporting?* - backporting is an action aiming to move a change (usually a commit) from a branch (usually the main one) to another one, which is generally referring to a still maintained release branch. Keeping it simple: it is about to move a specific change or a set of them from one branch to another.
|
||||||
|
|
||||||
|
@ -38,15 +43,15 @@ Therefore this tools is for anybody who is working on projects where they have t
|
||||||
|
|
||||||
## CLI tool
|
## CLI tool
|
||||||
|
|
||||||
> All instructions provided below pertain to version `v4` of the tool. If you wish to use an earlier version, please refer to the documentation from the corresponding tag/release.
|
|
||||||
|
|
||||||
This tool is released on the [public npm registry](https://www.npmjs.com/), therefore it can be easily installed using `npm`:
|
This tool is released on the [public npm registry](https://www.npmjs.com/), therefore it can be easily installed using `npm`:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ npm install -g @kie/git-backporting
|
$ npm install -g @kie/git-backporting
|
||||||
```
|
```
|
||||||
|
|
||||||
Then you just have to choose the pull request (or merge request on *Gitlab*) that you would like to backport and the target branch and then simply run the following command:
|
> **NOTE**: if you want to download version 3 or older you must use the older package name `@lampajr/bper` instead of `@kie/git-backporting`.
|
||||||
|
|
||||||
|
Then you just have to choose the pull request (or merge request on *Gitlab*) that you would like to backport and the target branch and the simply run the following command:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ git-backporting -tb <branch> -pr <pull-request-url> -a <git-token>
|
$ git-backporting -tb <branch> -pr <pull-request-url> -a <git-token>
|
||||||
|
@ -59,6 +64,8 @@ $ git-backporting -tb develop -pr https://github.com/kiegroup/git-backporting-ex
|
||||||
|
|
||||||
This is the easiest invocation where you let the tool set / compute most of the backported pull request data. Obviously most of that data can be overridden with appropriate tool options, more details can be found in the [inputs](#inputs) section.
|
This is the easiest invocation where you let the tool set / compute most of the backported pull request data. Obviously most of that data can be overridden with appropriate tool options, more details can be found in the [inputs](#inputs) section.
|
||||||
|
|
||||||
|
> **NOTE**: if you are still using version 3 or older you must use the older CLI tool name `bper` instead of `git-backporting`.
|
||||||
|
|
||||||
### Requirements
|
### Requirements
|
||||||
|
|
||||||
* Node 16 or higher, more details on Node can be found [here](https://nodejs.org/en).
|
* Node 16 or higher, more details on Node can be found [here](https://nodejs.org/en).
|
||||||
|
@ -66,39 +73,19 @@ This is the easiest invocation where you let the tool set / compute most of the
|
||||||
|
|
||||||
### How it works?
|
### How it works?
|
||||||
|
|
||||||
It works in this way: given the provided `pull/merge request` it infers the server API to use (either *Github* or *Gitlab* for now) and retrieves the corresponding pull request object (original pull/merge request to be backported into another branch).
|
The simply works in this way: given the provided `pull/merge request` it infers the git client to use (either *Github* or *Gitlab* for now) and it retrieve the corresponding pull request object (original pull/merge request to be backported into another branch).
|
||||||
|
|
||||||
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).
|
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. The `--no-squash` and `--auto-no-squash` options control this behavior according the following table.
|
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).
|
||||||
|
|
||||||
| 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.
|
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.
|
||||||
|
|
||||||
#### cherry-pick strategy
|
Right now all commits are cherry-picked using the following git-equivalent command:
|
||||||
|
|
||||||
The default cherry-pick strategy is `recursive` with `theirs` option for automatic conflicts resolution. Therefore, by default, all commits are cherry-picked using the following git-equivalent command:
|
|
||||||
```bash
|
```bash
|
||||||
$ git cherry-pick -m 1 --strategy=recursive --strategy-option=theirs <sha>
|
$ git cherry-pick -m 1 --strategy=recursive --strategy-option=theirs <sha>
|
||||||
```
|
```
|
||||||
|
|
||||||
From version `v4.2.0` both can be configured via the `strategy` or `strategy-option` inputs if using the action and the `--strategy` or `--strategy-option` arguments if using the CLI.
|
|
||||||
|
|
||||||
The [default strategy](https://git-scm.com/docs/git-merge#Documentation/git-merge.txt--sltstrategygt) of the `git-cherry-pick` command is different from the defaults of `git-backporting`.
|
|
||||||
```bash
|
|
||||||
$ git cherry-pick -m 1 <sha>
|
|
||||||
```
|
|
||||||
is the same as:
|
|
||||||
```bash
|
|
||||||
$ git cherry-pick -m 1 --strategy=ort --strategy-option=find-renames <sha>
|
|
||||||
```
|
|
||||||
If there is a conflict the backport will fail and require manual intervention.
|
|
||||||
|
|
||||||
> **NOTE**: If there are any conflicts, the tool will block the process and exit signalling the failure as there are still no ways to interactively resolve them. In these cases a manual cherry-pick is needed, or alternatively users could manually resume the process in the cloned repository (here the user will have to resolve the conflicts, push the branch and create the pull request - all manually).
|
> **NOTE**: If there are any conflicts, the tool will block the process and exit signalling the failure as there are still no ways to interactively resolve them. In these cases a manual cherry-pick is needed, or alternatively users could manually resume the process in the cloned repository (here the user will have to resolve the conflicts, push the branch and create the pull request - all manually).
|
||||||
|
|
||||||
### Inputs
|
### Inputs
|
||||||
|
@ -109,13 +96,11 @@ This tool comes with some inputs that allow users to override the default behavi
|
||||||
|---------------|----------------------|--------------|--------------------------------------------------------------------------------------------------------------------------------------------------------|-------------|
|
|---------------|----------------------|--------------|--------------------------------------------------------------------------------------------------------------------------------------------------------|-------------|
|
||||||
| Version | -V, --version | - | Current version of the tool | |
|
| Version | -V, --version | - | Current version of the tool | |
|
||||||
| Help | -h, --help | - | Display the help message | |
|
| Help | -h, --help | - | Display the help message | |
|
||||||
| Target Branches | -tb, --target-branch | N | Comma separated list of branches where the changes must be backported to | |
|
| Target Branch | -tb, --target-branch | N | Branch where the changes must be backported to | |
|
||||||
| Target Branches Pattern | -tbp, --target-branch-pattern | N | Regular expression pattern to extract target branch(es) from pr labels. The branches will be extracted from the pattern's required `target` named capturing group, e.g., `^backport (?<target>([^ ]+))$` | |
|
|
||||||
| Pull Request | -pr, --pull-request | N | Original pull request url, the one that must be backported, e.g., https://github.com/kiegroup/git-backporting/pull/1 | |
|
| Pull Request | -pr, --pull-request | N | Original pull request url, the one that must be backported, e.g., https://github.com/kiegroup/git-backporting/pull/1 | |
|
||||||
| Configuration File | -cf, --config-file | N | Configuration file, in JSON format, containing all options to be overridded, note that if provided all other CLI options will be ignored | |
|
| Configuration File | -cf, --config-file | N | Configuration file, in JSON format, containing all options to be overridded, note that if provided all other CLI options will be ignored | |
|
||||||
| Auth | -a, --auth | N | Git access/authorization token, if provided all token env variables will be ignored. See [auth token](#authorization-token) section for more details | "" |
|
| Auth | -a, --auth | N | `GITHUB_TOKEN`, `GITLAB_TOKEN` or a `repo` scoped [Personal Access Token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) | "" |
|
||||||
| Folder | -f, --folder | N | Local folder full name of the repository that will be checked out, e.g., /tmp/folder | {cwd}/bp |
|
| Folder | -f, --folder | N | Local folder full name of the repository that will be checked out, e.g., /tmp/folder | {cwd}/bp |
|
||||||
| Git Client | --git-client | N | Git client type <github|gitlab|codeberg>, if not set it is infered from pull-request
|
|
||||||
| Git User | -gu, --git-user | N | Local git user name | "GitHub" |
|
| Git User | -gu, --git-user | N | Local git user name | "GitHub" |
|
||||||
| Git Email | -ge, --git-email | N | Local git user email | "noreply@github.com" |
|
| Git Email | -ge, --git-email | N | Local git user email | "noreply@github.com" |
|
||||||
| Title | --title | N | Backporting pull request title | "{original-pr-title}" |
|
| Title | --title | N | Backporting pull request title | "{original-pr-title}" |
|
||||||
|
@ -124,30 +109,13 @@ This tool comes with some inputs that allow users to override the default behavi
|
||||||
| Reviewers | --reviewers | N | Backporting pull request comma-separated reviewers list | [] |
|
| Reviewers | --reviewers | N | Backporting pull request comma-separated reviewers list | [] |
|
||||||
| Assignees | --assignes | N | Backporting pull request comma-separated assignees list | [] |
|
| Assignees | --assignes | N | Backporting pull request comma-separated assignees list | [] |
|
||||||
| No Reviewers Inheritance | --no-inherit-reviewers | N | Considered only if reviewers is empty, if true keep reviewers as empty list, otherwise inherit from original pull request | false |
|
| No Reviewers Inheritance | --no-inherit-reviewers | N | Considered only if reviewers is empty, if true keep reviewers as empty list, otherwise inherit from original pull request | false |
|
||||||
| 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} |
|
| Backport Branch Name | --bp-branch-name | N | Name of the backporting pull request branch | bp-{target-branch}-{sha} |
|
||||||
| Labels | --labels | N | Provide custom labels to be added to the backporting pull request | [] |
|
| 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 |
|
| Inherit labels | --inherit-labels | N | If enabled inherit lables from the original pull request | 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. | |
|
| No squash | --no-squash | N | If provided the backporting will try to backport all pull request commits without squashing | false |
|
||||||
| 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 |
|
| 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).
|
> **NOTE**: `pull request` and `target branch` are *mandatory*, they must be provided as CLI options or as part of the configuration file (if used).
|
||||||
|
|
||||||
#### Authorization token
|
|
||||||
|
|
||||||
Since version `4.5.0` we introduced a new feature that allows user to provide the git access token through environment variables. These env variables are taken into consideration only if the `--auth/-a` is not provided as argument/input.
|
|
||||||
Here the supported list of env variables:
|
|
||||||
- `GITHUB_TOKEN`: this is checked only if backporting on Github platform.
|
|
||||||
- `GITLAB_TOKEN`: this is checked only if backporting on Gitlab platform.
|
|
||||||
- `CODEBERG_TOKEN`: this is checked only if backporting on Codeberg platform.
|
|
||||||
- `GIT_TOKEN`: this is considered if none of the previous envs are set.
|
|
||||||
|
|
||||||
> **NOTE**: if `--auth` argument is provided, all env variables will be ignored even if not empty.
|
|
||||||
|
|
||||||
#### Configuration file example
|
#### Configuration file example
|
||||||
|
|
||||||
|
@ -161,7 +129,7 @@ This is an example of a configuration file that can be used.
|
||||||
"auth": "*****"
|
"auth": "*****"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
Keep in mind that its structure MUST match the [Args](src/service/args/args.types.ts) interface, which is actually a camel-case version of the CLI options.
|
Keep in mind that its structue MUST match the [Args](src/service/args/args.types.ts) interface, which is actually a camel-case version of the CLI options.
|
||||||
|
|
||||||
### Supported git services
|
### Supported git services
|
||||||
|
|
||||||
|
@ -170,8 +138,6 @@ Right now **Git Backporting** supports the following git management services:
|
||||||
|
|
||||||
* ***GITLAB***: This has been introduced since version `3.0.0`, it works for both public and private *GitLab* servers. The interaction with this service is performed using plain [*axios*](https://axios-http.com) requests. The *gitlab* api version that is used to make requests is `v4`, at the moment there is no possibility to override it.
|
* ***GITLAB***: This has been introduced since version `3.0.0`, it works for both public and private *GitLab* servers. The interaction with this service is performed using plain [*axios*](https://axios-http.com) requests. The *gitlab* api version that is used to make requests is `v4`, at the moment there is no possibility to override it.
|
||||||
|
|
||||||
* ***CODEBERG***: Introduced since version `4.4.0`, it works for public [codeberg.org](https://codeberg.org/) platform. Thanks to the api compatibility with GitHub, the interaction with this service is performed using using [*octokit*](https://octokit.github.io/rest.js) client library.
|
|
||||||
|
|
||||||
> **NOTE**: by default, all gitlab requests are performed setting `rejectUnauthorized=false`, planning to make this configurable too.
|
> **NOTE**: by default, all gitlab requests are performed setting `rejectUnauthorized=false`, planning to make this configurable too.
|
||||||
|
|
||||||
## GitHub action
|
## GitHub action
|
||||||
|
@ -225,9 +191,6 @@ on:
|
||||||
- closed
|
- closed
|
||||||
- labeled
|
- labeled
|
||||||
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
backporting:
|
backporting:
|
||||||
name: "Backporting"
|
name: "Backporting"
|
||||||
|
@ -250,6 +213,7 @@ jobs:
|
||||||
with:
|
with:
|
||||||
target-branch: v1
|
target-branch: v1
|
||||||
pull-request: ${{ github.event.pull_request.url }}
|
pull-request: ${{ github.event.pull_request.url }}
|
||||||
|
auth: ${{ secrets.GITHUB_TOKEN }}
|
||||||
```
|
```
|
||||||
|
|
||||||
For a complete description of all inputs see [Inputs section](#inputs).
|
For a complete description of all inputs see [Inputs section](#inputs).
|
||||||
|
@ -263,6 +227,23 @@ For a complete description of all inputs see [Inputs section](#inputs).
|
||||||
- Integrate it into other CI/CD services like gitlab CI.
|
- Integrate it into other CI/CD services like gitlab CI.
|
||||||
- Provide some reusable *GitHub* workflows.
|
- Provide some reusable *GitHub* workflows.
|
||||||
|
|
||||||
|
## Migrating to v4
|
||||||
|
|
||||||
|
From version `v4.0.0` the project has been moved under [@kiegroup](https://github.com/kiegroup) organization. During this migration we changed some things that you should be aware of. I'll try to summarize them in the following table:
|
||||||
|
|
||||||
|
> **NOTE**: these changes did not affect the tool features.
|
||||||
|
|
||||||
|
| | **v4 (after migration)** | v3 or older (before migration) |
|
||||||
|
|-------------|--------------------------|--------------------------------|
|
||||||
|
| Owner | kiegroup | lampajr |
|
||||||
|
| Repository | git-backporting | backporting |
|
||||||
|
| NPM package | @kie/git-backporting | @lampajr/bper |
|
||||||
|
| CLI tool | git-backporting | bper |
|
||||||
|
|
||||||
|
So everytime you would use older version keep in mind of these changes.
|
||||||
|
|
||||||
|
> **REMARK**: since from capabilities point of view `v3.1.1` and `v4.0.0` are equivalent we would recommend to directly start using `v4`.
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
### Package release
|
### Package release
|
||||||
|
@ -324,4 +305,4 @@ Every change must be submitted through a *GitHub* pull request (PR). Backporting
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
Git backporting open source project is licensed under the [MIT](./LICENSE) license.
|
Backporting (BPer) open source project is licensed under the [MIT](./LICENSE) license.
|
97
action.yml
97
action.yml
|
@ -1,122 +1,67 @@
|
||||||
name: "Backporting GitHub Action"
|
name: "Backporting GitHub Action"
|
||||||
description: GitHub action providing an automated way to backport pull requests from one branch to another
|
description: "GitHub action providing an automated way to backport pull requests from one branch to another"
|
||||||
inputs:
|
inputs:
|
||||||
pull-request:
|
pull-request:
|
||||||
description: >
|
description: "URL of the pull request to backport, e.g., https://github.com/kiegroup/git-backporting/pull/1"
|
||||||
URL of the pull request to backport, e.g., "https://github.com/kiegroup/git-backporting/pull/1"
|
|
||||||
required: false
|
required: false
|
||||||
target-branch:
|
target-branch:
|
||||||
description: >
|
description: "Branch where the pull request must be backported to"
|
||||||
Comma separated list of branches where the pull request must be backported to
|
|
||||||
required: false
|
|
||||||
target-branch-pattern:
|
|
||||||
description: >
|
|
||||||
Regular expression pattern to extract target branch(es) from pr labels.
|
|
||||||
The branches will be extracted from the pattern's required `target` named capturing group,
|
|
||||||
for instance "^backport (?<target>([^ ]+))$"
|
|
||||||
required: false
|
required: false
|
||||||
config-file:
|
config-file:
|
||||||
description: >
|
description: "Path to a file containing the json configuration for this tool, the object must match the Args interface"
|
||||||
Path to a file containing the json configuration for this tool,
|
|
||||||
the object must match the Args interface
|
|
||||||
required: false
|
required: false
|
||||||
dry-run:
|
dry-run:
|
||||||
description: >
|
description: "If enabled the tool does not create any pull request nor push anything remotely"
|
||||||
If enabled the tool does not create any pull request nor push anything remotely
|
|
||||||
required: false
|
required: false
|
||||||
default: "false"
|
default: "false"
|
||||||
auth:
|
auth:
|
||||||
description: >
|
description: "GITHUB_TOKEN or a `repo` scoped Personal Access Token (PAT)"
|
||||||
GITHUB_TOKEN or a `repo` scoped Personal Access Token (PAT),
|
|
||||||
if not provided will look for existing env variables like GITHUB_TOKEN
|
|
||||||
default: ${{ github.token }}
|
default: ${{ github.token }}
|
||||||
required: false
|
required: false
|
||||||
git-client:
|
|
||||||
description: >
|
|
||||||
Git client type <github|gitlab|codeberg>, if not set it is infered from pull-request
|
|
||||||
required: false
|
|
||||||
git-user:
|
git-user:
|
||||||
description: Local git user name
|
description: "Local git user name"
|
||||||
default: "GitHub"
|
default: "GitHub"
|
||||||
required: false
|
required: false
|
||||||
git-email:
|
git-email:
|
||||||
description: Local git user email
|
description: "Local git user email"
|
||||||
default: "noreply@github.com"
|
default: "noreply@github.com"
|
||||||
required: false
|
required: false
|
||||||
title:
|
title:
|
||||||
description: >
|
description: "Backporting PR title. Default is the original PR title prefixed by the target branch"
|
||||||
Backporting PR title. Default is the original PR title prefixed by the target branch
|
|
||||||
required: false
|
|
||||||
body-prefix:
|
|
||||||
description: >
|
|
||||||
Backporting PR body prefix. Default is `Backport: <original-pr-link>`
|
|
||||||
required: false
|
required: false
|
||||||
body:
|
body:
|
||||||
description: >
|
description: "Backporting PR body. Default is the original PR body prefixed by `backport: <original-pr-link>`"
|
||||||
Backporting PR body. Default is the original PR body
|
required: false
|
||||||
|
body-prefix:
|
||||||
|
description: "Backporting PR body prefix. Default is `backport: <original-pr-link>`"
|
||||||
required: false
|
required: false
|
||||||
bp-branch-name:
|
bp-branch-name:
|
||||||
description: >
|
description: "Backporting PR branch name. Default is auto-generated from commit"
|
||||||
Comma separated list of backporting PR branch names.
|
|
||||||
Default is auto-generated from commit and target branches
|
|
||||||
required: false
|
required: false
|
||||||
reviewers:
|
reviewers:
|
||||||
description: >
|
description: "Comma separated list of reviewers for the backporting pull request"
|
||||||
Comma separated list of reviewers for the backporting pull request
|
|
||||||
required: false
|
required: false
|
||||||
assignees:
|
assignees:
|
||||||
description: >
|
description: "Comma separated list of reviewers for the backporting pull request"
|
||||||
Comma separated list of reviewers for the backporting pull request
|
|
||||||
required: false
|
required: false
|
||||||
no-inherit-reviewers:
|
no-inherit-reviewers:
|
||||||
description: >
|
description: "Considered only if reviewers is empty, if true keep reviewers as empty list, otherwise inherit from original pull request"
|
||||||
Considered only if reviewers is empty, if true keep reviewers as empty list,
|
|
||||||
otherwise inherit from original pull request
|
|
||||||
required: false
|
required: false
|
||||||
default: "false"
|
default: "false"
|
||||||
labels:
|
labels:
|
||||||
description: >
|
description: "Comma separated list of labels to be assigned to the backported pull request"
|
||||||
Comma separated list of labels to be assigned to the backported pull request
|
|
||||||
required: false
|
required: false
|
||||||
inherit-labels:
|
inherit-labels:
|
||||||
description: >
|
description: "If true the backported pull request will inherit labels from the original one"
|
||||||
If true the backported pull request will inherit labels from the original one
|
|
||||||
required: false
|
required: false
|
||||||
default: "false"
|
default: "false"
|
||||||
no-squash:
|
no-squash:
|
||||||
description: >
|
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
|
|
||||||
strategy:
|
|
||||||
description: Cherry-pick merge strategy
|
|
||||||
required: false
|
|
||||||
default: "recursive"
|
|
||||||
strategy-option:
|
|
||||||
description: Cherry-pick merge strategy option
|
|
||||||
required: false
|
|
||||||
default: "theirs"
|
|
||||||
cherry-pick-options:
|
|
||||||
description: >
|
|
||||||
Additional cherry-pick options
|
|
||||||
required: false
|
|
||||||
comments:
|
|
||||||
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
|
required: false
|
||||||
default: "false"
|
default: "false"
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: node20
|
using: node16
|
||||||
main: dist/gha/index.js
|
main: dist/gha/index.js
|
||||||
|
|
||||||
branding:
|
branding:
|
||||||
|
|
2705
dist/cli/index.js
vendored
2705
dist/cli/index.js
vendored
File diff suppressed because it is too large
Load diff
2693
dist/gha/index.js
vendored
2693
dist/gha/index.js
vendored
File diff suppressed because it is too large
Load diff
|
@ -1,53 +0,0 @@
|
||||||
name: Automated Backporting on PR merge using Git Backporting
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request_target:
|
|
||||||
types: [closed, labeled]
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
compute-targets:
|
|
||||||
if: ${{ github.event.pull_request.state == 'closed' && github.event.pull_request.merged }}
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
outputs:
|
|
||||||
target-branches: ${{ steps.set-targets.outputs.targets }}
|
|
||||||
env:
|
|
||||||
LABELS: ${{ toJSON(github.event.pull_request.labels) }}
|
|
||||||
steps:
|
|
||||||
- name: Set target branches
|
|
||||||
id: set-targets
|
|
||||||
uses: kiegroup/kie-ci/.ci/actions/parse-labels@main
|
|
||||||
with:
|
|
||||||
labels: ${LABELS}
|
|
||||||
|
|
||||||
backporting:
|
|
||||||
if: ${{ github.event.pull_request.state == 'closed' && github.event.pull_request.merged && needs.compute-targets.outputs.target-branches != '[]' }}
|
|
||||||
name: "[${{ matrix.target-branch }}] - Backporting"
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: compute-targets
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
target-branch: ${{ fromJSON(needs.compute-targets.outputs.target-branches) }}
|
|
||||||
fail-fast: true
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
- name: Backporting
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
dry-run: true
|
|
||||||
pull-request: ${{ github.event.pull_request.html_url }}
|
|
||||||
target-branch: ${{ matrix.target-branch }}
|
|
||||||
auth: "${{ env.GITHUB_TOKEN }}"
|
|
||||||
title: "[${{ matrix.target-branch }}] ${{ github.event.pull_request.title }}"
|
|
||||||
body-prefix: "**Backport:** ${{ github.event.pull_request.html_url }}\r\n\r\n**Note**: comment 'ok to test' to properly launch Jenkins jobs\r\n\r\n"
|
|
||||||
body: "${{ github.event.pull_request.body }}"
|
|
||||||
labels: "cherry-pick :cherries:"
|
|
||||||
inherit-labels: false
|
|
||||||
bp-branch-name: "${{ matrix.target-branch }}_${{ github.event.pull_request.head.ref }}"
|
|
|
@ -1,79 +0,0 @@
|
||||||
{
|
|
||||||
"pull_request": {
|
|
||||||
"url": "https://api.github.com/repos/lampajr/backporting-example/pulls/66",
|
|
||||||
"html_url": "https://github.com/lampajr/backporting-example/pull/66",
|
|
||||||
"diff_url": "https://github.com/lampajr/backporting-example/pull/66.diff",
|
|
||||||
"patch_url": "https://github.com/lampajr/backporting-example/pull/66.patch",
|
|
||||||
"issue_url": "https://api.github.com/repos/lampajr/backporting-example/issues/66",
|
|
||||||
"number": 66,
|
|
||||||
"state": "closed",
|
|
||||||
"title": "Feature1: multiple changes",
|
|
||||||
"user": {
|
|
||||||
"login": "lampajr"
|
|
||||||
},
|
|
||||||
"body": "This is the body of multiple change",
|
|
||||||
"merge_commit_sha": "0bcaa01cdd509ca434e123d2e2b9ce7f66234bd7",
|
|
||||||
"assignee": null,
|
|
||||||
"assignees": [
|
|
||||||
|
|
||||||
],
|
|
||||||
"requested_reviewers": [
|
|
||||||
|
|
||||||
],
|
|
||||||
"requested_teams": [
|
|
||||||
|
|
||||||
],
|
|
||||||
"labels": [
|
|
||||||
{
|
|
||||||
"name": "backport-develop",
|
|
||||||
"color": "AB975B",
|
|
||||||
"default": false,
|
|
||||||
"description": ""
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"head": {
|
|
||||||
"label": "lampajr:feature1",
|
|
||||||
"ref": "feature1",
|
|
||||||
"sha": "69e49388ea2ca9be272b188a9271806d487bf01e",
|
|
||||||
"user": {
|
|
||||||
"login": "lampajr"
|
|
||||||
},
|
|
||||||
"repo": {
|
|
||||||
"name": "backporting-example",
|
|
||||||
"full_name": "lampajr/backporting-example",
|
|
||||||
"owner": {
|
|
||||||
"login": "lampajr"
|
|
||||||
},
|
|
||||||
"html_url": "https://github.com/lampajr/backporting-example",
|
|
||||||
"clone_url": "https://github.com/lampajr/backporting-example.git"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"base": {
|
|
||||||
"label": "lampajr:main",
|
|
||||||
"ref": "main",
|
|
||||||
"sha": "c85b8fcdb741814b3e90e6e5729455cf46ff26ea",
|
|
||||||
"user": {
|
|
||||||
"login": "lampajr"
|
|
||||||
},
|
|
||||||
"repo": {
|
|
||||||
"name": "backporting-example",
|
|
||||||
"full_name": "lampajr/backporting-example",
|
|
||||||
"owner": {
|
|
||||||
"login": "lampajr"
|
|
||||||
},
|
|
||||||
"html_url": "https://github.com/lampajr/backporting-example",
|
|
||||||
"description": "Playground repository for automated backporting testing",
|
|
||||||
"url": "https://api.github.com/repos/lampajr/backporting-example",
|
|
||||||
"issues_url": "https://api.github.com/repos/lampajr/backporting-example/issues{/number}",
|
|
||||||
"pulls_url": "https://api.github.com/repos/lampajr/backporting-example/pulls{/number}",
|
|
||||||
"clone_url": "https://github.com/lampajr/backporting-example.git"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"merged": true,
|
|
||||||
"merged_by": {
|
|
||||||
"login": "lampajr"
|
|
||||||
},
|
|
||||||
"comments": 0,
|
|
||||||
"commits": 2
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,2 +0,0 @@
|
||||||
[tools]
|
|
||||||
node = "20"
|
|
10204
package-lock.json
generated
10204
package-lock.json
generated
File diff suppressed because it is too large
Load diff
12
package.json
12
package.json
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@kie/git-backporting",
|
"name": "@kie/git-backporting",
|
||||||
"version": "4.8.5",
|
"version": "4.1.0",
|
||||||
"description": "Git backporting is a tool to execute automatic pull request git backporting.",
|
"description": "Git backporting is a tool to execute automatic pull request git backporting.",
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
@ -23,7 +23,7 @@
|
||||||
"package:cli": "ncc build ./build/src/bin/cli.js -o dist/cli",
|
"package:cli": "ncc build ./build/src/bin/cli.js -o dist/cli",
|
||||||
"package:gha": "ncc build ./build/src/bin/gha.js -o dist/gha",
|
"package:gha": "ncc build ./build/src/bin/gha.js -o dist/gha",
|
||||||
"build": "npm run clean && npm run compile && npm run package",
|
"build": "npm run clean && npm run compile && npm run package",
|
||||||
"test": "jest --silent",
|
"test": "jest",
|
||||||
"test:report": "npm test -- --coverage --testResultsProcessor=jest-sonar-reporter",
|
"test:report": "npm test -- --coverage --testResultsProcessor=jest-sonar-reporter",
|
||||||
"lint": "eslint . --ext .ts",
|
"lint": "eslint . --ext .ts",
|
||||||
"lint:fix": "npm run lint -- --fix",
|
"lint:fix": "npm run lint -- --fix",
|
||||||
|
@ -54,8 +54,7 @@
|
||||||
"@commitlint/config-conventional": "^17.4.0",
|
"@commitlint/config-conventional": "^17.4.0",
|
||||||
"@gitbeaker/rest": "^39.1.0",
|
"@gitbeaker/rest": "^39.1.0",
|
||||||
"@kie/mock-github": "^1.1.0",
|
"@kie/mock-github": "^1.1.0",
|
||||||
"@octokit/webhooks-types": "^6.8.0",
|
"@release-it/conventional-changelog": "^5.1.1",
|
||||||
"@release-it/conventional-changelog": "^10.0.0",
|
|
||||||
"@types/fs-extra": "^9.0.13",
|
"@types/fs-extra": "^9.0.13",
|
||||||
"@types/jest": "^29.2.4",
|
"@types/jest": "^29.2.4",
|
||||||
"@types/node": "^18.11.17",
|
"@types/node": "^18.11.17",
|
||||||
|
@ -66,13 +65,14 @@
|
||||||
"husky": "^8.0.2",
|
"husky": "^8.0.2",
|
||||||
"jest": "^29.0.0",
|
"jest": "^29.0.0",
|
||||||
"jest-sonar-reporter": "^2.0.0",
|
"jest-sonar-reporter": "^2.0.0",
|
||||||
"release-it": "^19.0.2",
|
"release-it": "^15.6.0",
|
||||||
"semver": "^7.3.8",
|
"semver": "^7.3.8",
|
||||||
"ts-jest": "^29.0.0",
|
"ts-jest": "^29.0.0",
|
||||||
"ts-node": "^10.8.1",
|
"ts-node": "^10.8.1",
|
||||||
"tsc-alias": "^1.8.2",
|
"tsc-alias": "^1.8.2",
|
||||||
"tsconfig-paths": "^4.1.0",
|
"tsconfig-paths": "^4.1.0",
|
||||||
"typescript": "^4.9.3"
|
"typescript": "^4.9.3",
|
||||||
|
"@octokit/webhooks-types": "^6.8.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.0",
|
"@actions/core": "^1.10.0",
|
||||||
|
|
|
@ -16,22 +16,17 @@ export default abstract class ArgsParser {
|
||||||
public parse(): Args {
|
public parse(): Args {
|
||||||
const args = this.readArgs();
|
const args = this.readArgs();
|
||||||
|
|
||||||
if (!args.pullRequest) {
|
|
||||||
throw new Error("Missing option: pull request must be provided");
|
|
||||||
}
|
|
||||||
// validate and fill with defaults
|
// validate and fill with defaults
|
||||||
if ((!args.targetBranch || args.targetBranch.trim().length == 0) && !args.targetBranchPattern) {
|
if (!args.pullRequest || !args.targetBranch) {
|
||||||
throw new Error("Missing option: target branch(es) or target regular expression must be provided");
|
throw new Error("Missing option: pull request and target branch must be provided");
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pullRequest: args.pullRequest,
|
pullRequest: args.pullRequest,
|
||||||
targetBranch: args.targetBranch,
|
targetBranch: args.targetBranch,
|
||||||
targetBranchPattern: args.targetBranchPattern,
|
|
||||||
dryRun: this.getOrDefault(args.dryRun, false),
|
dryRun: this.getOrDefault(args.dryRun, false),
|
||||||
auth: this.getOrDefault(args.auth),
|
auth: this.getOrDefault(args.auth),
|
||||||
folder: this.getOrDefault(args.folder),
|
folder: this.getOrDefault(args.folder),
|
||||||
gitClient: this.getOrDefault(args.gitClient),
|
|
||||||
gitUser: this.getOrDefault(args.gitUser),
|
gitUser: this.getOrDefault(args.gitUser),
|
||||||
gitEmail: this.getOrDefault(args.gitEmail),
|
gitEmail: this.getOrDefault(args.gitEmail),
|
||||||
title: this.getOrDefault(args.title),
|
title: this.getOrDefault(args.title),
|
||||||
|
@ -44,12 +39,6 @@ export default abstract class ArgsParser {
|
||||||
labels: this.getOrDefault(args.labels, []),
|
labels: this.getOrDefault(args.labels, []),
|
||||||
inheritLabels: this.getOrDefault(args.inheritLabels, false),
|
inheritLabels: this.getOrDefault(args.inheritLabels, false),
|
||||||
squash: this.getOrDefault(args.squash, true),
|
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),
|
|
||||||
enableErrorNotification: this.getOrDefault(args.enableErrorNotification, false),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -44,13 +44,7 @@ export function getAsCommaSeparatedList(value: string): string[] | undefined {
|
||||||
return trimmed !== "" ? trimmed.split(",").map(v => v.trim()) : undefined;
|
return trimmed !== "" ? trimmed.split(",").map(v => v.trim()) : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getAsSemicolonSeparatedList(value: string): string[] | undefined {
|
export function getAsBooleanOrDefault(value: string): boolean | undefined {
|
||||||
// trim the value
|
|
||||||
const trimmed: string = value.trim();
|
|
||||||
return trimmed !== "" ? trimmed.split(";").map(v => v.trim()) : undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getAsBooleanOrUndefined(value: string): boolean | undefined {
|
|
||||||
const trimmed = value.trim();
|
const trimmed = value.trim();
|
||||||
return trimmed !== "" ? trimmed.toLowerCase() === "true" : undefined;
|
return trimmed !== "" ? trimmed.toLowerCase() === "true" : undefined;
|
||||||
}
|
}
|
|
@ -1,32 +1,22 @@
|
||||||
/**
|
/**
|
||||||
* Tool's input arguments interface
|
* Input arguments
|
||||||
*/
|
*/
|
||||||
export interface Args {
|
export interface Args {
|
||||||
// NOTE: keep targetBranch as singular and of type string for backward compatibilities
|
targetBranch: string, // branch on the target repo where the change should be backported to
|
||||||
targetBranch?: string, // comma separated list of branches on the target repo where the change should be backported to
|
|
||||||
targetBranchPattern?: string, // regular expression to extract target branch(es) from pull request labels
|
|
||||||
pullRequest: string, // url of the pull request to backport
|
pullRequest: string, // url of the pull request to backport
|
||||||
dryRun?: boolean, // if enabled do not push anything remotely
|
dryRun?: boolean, // if enabled do not push anything remotely
|
||||||
auth?: string, // git service auth, like github token
|
auth?: string, // git service auth, like github token
|
||||||
folder?: string, // local folder where the repositories should be cloned
|
folder?: string, // local folder where the repositories should be cloned
|
||||||
gitClient?: string, // git client
|
|
||||||
gitUser?: string, // local git user, default 'GitHub'
|
gitUser?: string, // local git user, default 'GitHub'
|
||||||
gitEmail?: string, // local git email, default 'noreply@github.com'
|
gitEmail?: string, // local git email, default 'noreply@github.com'
|
||||||
title?: string, // backport pr title, default original pr title prefixed by target branch
|
title?: string, // backport pr title, default original pr title prefixed by target branch
|
||||||
body?: string, // backport pr title, default original pr body prefixed by bodyPrefix
|
body?: string, // backport pr title, default original pr body prefixed by bodyPrefix
|
||||||
bodyPrefix?: string, // backport pr body prefix, default `backport <original-pr-link>`
|
bodyPrefix?: string, // backport pr body prefix, default `backport <original-pr-link>`
|
||||||
// NOTE: keep bpBranchName as singular and of type string for backward compatibilities
|
bpBranchName?: string, // backport pr branch name, default computed from commit
|
||||||
bpBranchName?: string, // comma separated list of backport pr branch names, default computed from commit and target branches
|
|
||||||
reviewers?: string[], // backport pr reviewers
|
reviewers?: string[], // backport pr reviewers
|
||||||
assignees?: string[], // backport pr assignees
|
assignees?: string[], // backport pr assignees
|
||||||
inheritReviewers?: boolean, // if true and reviewers == [] then inherit reviewers from original pr
|
inheritReviewers?: boolean, // if true and reviewers == [] then inherit reviewers from original pr
|
||||||
labels?: string[], // backport pr labels
|
labels?: string[], // backport pr labels
|
||||||
inheritLabels?: boolean, // if true inherit labels from original pr
|
inheritLabels?: boolean, // if true inherit labels from original pr
|
||||||
squash?: boolean,
|
squash?: boolean, // if false use squashed/merged commit otherwise backport all commits as part of the pr
|
||||||
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
|
|
||||||
}
|
}
|
|
@ -2,7 +2,7 @@ import ArgsParser from "@bp/service/args/args-parser";
|
||||||
import { Args } from "@bp/service/args/args.types";
|
import { Args } from "@bp/service/args/args.types";
|
||||||
import { Command } from "commander";
|
import { Command } from "commander";
|
||||||
import { name, version, description } from "@bp/../package.json";
|
import { name, version, description } from "@bp/../package.json";
|
||||||
import { getAsCleanedCommaSeparatedList, getAsCommaSeparatedList, getAsSemicolonSeparatedList, readConfigFile } from "@bp/service/args/args-utils";
|
import { getAsCleanedCommaSeparatedList, getAsCommaSeparatedList, readConfigFile } from "@bp/service/args/args-utils";
|
||||||
|
|
||||||
export default class CLIArgsParser extends ArgsParser {
|
export default class CLIArgsParser extends ArgsParser {
|
||||||
|
|
||||||
|
@ -10,31 +10,23 @@ export default class CLIArgsParser extends ArgsParser {
|
||||||
return new Command(name)
|
return new Command(name)
|
||||||
.version(version)
|
.version(version)
|
||||||
.description(description)
|
.description(description)
|
||||||
.option("-tb, --target-branch <branches>", "comma separated list of branches where changes must be backported to")
|
.option("-tb, --target-branch <branch>", "branch where changes must be backported to")
|
||||||
.option("-tbp, --target-branch-pattern <pattern>", "regular expression pattern to extract target branch(es) from pr labels, the branches will be extracted from the pattern's required `target` named capturing group")
|
|
||||||
.option("-pr, --pull-request <pr-url>", "pull request url, e.g., https://github.com/kiegroup/git-backporting/pull/1")
|
.option("-pr, --pull-request <pr-url>", "pull request url, e.g., https://github.com/kiegroup/git-backporting/pull/1")
|
||||||
.option("-d, --dry-run", "if enabled the tool does not create any pull request nor push anything remotely")
|
.option("-d, --dry-run", "if enabled the tool does not create any pull request nor push anything remotely")
|
||||||
.option("-a, --auth <auth>", "git authentication string, if not provided fallback by looking for existing env variables like GITHUB_TOKEN")
|
.option("-a, --auth <auth>", "git service authentication string, e.g., github token")
|
||||||
.option("--git-client <github|gitlab|codeberg>", "git client type, if not set it is infered from --pull-request")
|
|
||||||
.option("-gu, --git-user <git-user>", "local git user name, default is 'GitHub'")
|
.option("-gu, --git-user <git-user>", "local git user name, default is 'GitHub'")
|
||||||
.option("-ge, --git-email <git-email>", "local git user email, default is 'noreply@github.com'")
|
.option("-ge, --git-email <git-email>", "local git user email, default is 'noreply@github.com'")
|
||||||
.option("-f, --folder <folder>", "local folder where the repo will be checked out, e.g., /tmp/folder")
|
.option("-f, --folder <folder>", "local folder where the repo will be checked out, e.g., /tmp/folder")
|
||||||
.option("--title <bp-title>", "backport pr title, default original pr title prefixed by target branch")
|
.option("--title <bp-title>", "backport pr title, default original pr title prefixed by target branch")
|
||||||
.option("--body <bp-body>", "backport pr title, default original pr body prefixed by bodyPrefix")
|
.option("--body <bp-body>", "backport pr title, default original pr body prefixed by bodyPrefix")
|
||||||
.option("--body-prefix <bp-body-prefix>", "backport pr body prefix, default `backport <original-pr-link>`")
|
.option("--body-prefix <bp-body-prefix>", "backport pr body prefix, default `backport <original-pr-link>`")
|
||||||
.option("--bp-branch-name <bp-branch-names>", "comma separated list of backport pr branch names, default auto-generated by the commit and target branch")
|
.option("--bp-branch-name <bp-branch-name>", "backport pr branch name, default auto-generated by the commit")
|
||||||
.option("--reviewers <reviewers>", "comma separated list of reviewers for the backporting pull request", getAsCleanedCommaSeparatedList)
|
.option("--reviewers <reviewers>", "comma separated list of reviewers for the backporting pull request", getAsCleanedCommaSeparatedList)
|
||||||
.option("--assignees <assignees>", "comma separated list of assignees for the backporting pull request", getAsCleanedCommaSeparatedList)
|
.option("--assignees <assignees>", "comma separated list of assignees for the backporting pull request", getAsCleanedCommaSeparatedList)
|
||||||
.option("--no-inherit-reviewers", "if provided and reviewers option is empty then inherit them from original pull request")
|
.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("--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("--inherit-labels", "if true the backported pull request will inherit labels from the original one")
|
||||||
.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("--no-squash", "if provided the tool will backport all commits as part of the pull request")
|
||||||
.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");
|
.option("-cf, --config-file <config-file>", "configuration file containing all valid options, the json must match Args interface");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,9 +45,7 @@ export default class CLIArgsParser extends ArgsParser {
|
||||||
auth: opts.auth,
|
auth: opts.auth,
|
||||||
pullRequest: opts.pullRequest,
|
pullRequest: opts.pullRequest,
|
||||||
targetBranch: opts.targetBranch,
|
targetBranch: opts.targetBranch,
|
||||||
targetBranchPattern: opts.targetBranchPattern,
|
|
||||||
folder: opts.folder,
|
folder: opts.folder,
|
||||||
gitClient: opts.gitClient,
|
|
||||||
gitUser: opts.gitUser,
|
gitUser: opts.gitUser,
|
||||||
gitEmail: opts.gitEmail,
|
gitEmail: opts.gitEmail,
|
||||||
title: opts.title,
|
title: opts.title,
|
||||||
|
@ -68,12 +58,6 @@ export default class CLIArgsParser extends ArgsParser {
|
||||||
labels: opts.labels,
|
labels: opts.labels,
|
||||||
inheritLabels: opts.inheritLabels,
|
inheritLabels: opts.inheritLabels,
|
||||||
squash: opts.squash,
|
squash: opts.squash,
|
||||||
autoNoSquash: opts.autoNoSquash,
|
|
||||||
strategy: opts.strategy,
|
|
||||||
strategyOption: opts.strategyOption,
|
|
||||||
cherryPickOptions: opts.cherryPickOptions,
|
|
||||||
comments: opts.comments,
|
|
||||||
enableErrorNotification: opts.enableErrNotification,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import ArgsParser from "@bp/service/args/args-parser";
|
import ArgsParser from "@bp/service/args/args-parser";
|
||||||
import { Args } from "@bp/service/args/args.types";
|
import { Args } from "@bp/service/args/args.types";
|
||||||
import { getInput } from "@actions/core";
|
import { getInput } from "@actions/core";
|
||||||
import { getAsBooleanOrUndefined, getAsCleanedCommaSeparatedList, getAsCommaSeparatedList, getAsSemicolonSeparatedList, getOrUndefined, readConfigFile } from "@bp/service/args/args-utils";
|
import { getAsBooleanOrDefault, getAsCleanedCommaSeparatedList, getAsCommaSeparatedList, getOrUndefined, readConfigFile } from "@bp/service/args/args-utils";
|
||||||
|
|
||||||
export default class GHAArgsParser extends ArgsParser {
|
export default class GHAArgsParser extends ArgsParser {
|
||||||
|
|
||||||
|
@ -13,31 +13,23 @@ export default class GHAArgsParser extends ArgsParser {
|
||||||
args = readConfigFile(configFile);
|
args = readConfigFile(configFile);
|
||||||
} else {
|
} else {
|
||||||
args = {
|
args = {
|
||||||
dryRun: getAsBooleanOrUndefined(getInput("dry-run")),
|
dryRun: getAsBooleanOrDefault(getInput("dry-run")),
|
||||||
auth: getOrUndefined(getInput("auth")),
|
auth: getOrUndefined(getInput("auth")),
|
||||||
pullRequest: getInput("pull-request"),
|
pullRequest: getInput("pull-request"),
|
||||||
targetBranch: getOrUndefined(getInput("target-branch")),
|
targetBranch: getInput("target-branch"),
|
||||||
targetBranchPattern: getOrUndefined(getInput("target-branch-pattern")),
|
|
||||||
folder: getOrUndefined(getInput("folder")),
|
folder: getOrUndefined(getInput("folder")),
|
||||||
gitClient: getOrUndefined(getInput("git-client")),
|
|
||||||
gitUser: getOrUndefined(getInput("git-user")),
|
gitUser: getOrUndefined(getInput("git-user")),
|
||||||
gitEmail: getOrUndefined(getInput("git-email")),
|
gitEmail: getOrUndefined(getInput("git-email")),
|
||||||
title: getOrUndefined(getInput("title")),
|
title: getOrUndefined(getInput("title")),
|
||||||
body: getOrUndefined(getInput("body", { trimWhitespace: false })),
|
body: getOrUndefined(getInput("body")),
|
||||||
bodyPrefix: getOrUndefined(getInput("body-prefix", { trimWhitespace: false })),
|
bodyPrefix: getOrUndefined(getInput("body-prefix")),
|
||||||
bpBranchName: getOrUndefined(getInput("bp-branch-name")),
|
bpBranchName: getOrUndefined(getInput("bp-branch-name")),
|
||||||
reviewers: getAsCleanedCommaSeparatedList(getInput("reviewers")),
|
reviewers: getAsCleanedCommaSeparatedList(getInput("reviewers")),
|
||||||
assignees: getAsCleanedCommaSeparatedList(getInput("assignees")),
|
assignees: getAsCleanedCommaSeparatedList(getInput("assignees")),
|
||||||
inheritReviewers: !getAsBooleanOrUndefined(getInput("no-inherit-reviewers")),
|
inheritReviewers: !getAsBooleanOrDefault(getInput("no-inherit-reviewers")),
|
||||||
labels: getAsCommaSeparatedList(getInput("labels")),
|
labels: getAsCommaSeparatedList(getInput("labels")),
|
||||||
inheritLabels: getAsBooleanOrUndefined(getInput("inherit-labels")),
|
inheritLabels: getAsBooleanOrDefault(getInput("inherit-labels")),
|
||||||
squash: !getAsBooleanOrUndefined(getInput("no-squash")),
|
squash: !getAsBooleanOrDefault(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")),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,12 +24,12 @@ import LoggerServiceFactory from "../logger/logger-service-factory";
|
||||||
|
|
||||||
// if pr is opened check if the there exists one single commit
|
// if pr is opened check if the there exists one single commit
|
||||||
if (configs.originalPullRequest.state == "open") {
|
if (configs.originalPullRequest.state == "open") {
|
||||||
this.logger.warn("Trying to backport an open pull request");
|
this.logger.warn("Trying to backport an open pull request!");
|
||||||
}
|
}
|
||||||
|
|
||||||
// if PR is closed and not merged throw an error
|
// if PR is closed and not merged log a warning
|
||||||
if (configs.originalPullRequest.state == "closed" && !configs.originalPullRequest.merged) {
|
if (configs.originalPullRequest.state == "closed" && !configs.originalPullRequest.merged) {
|
||||||
throw new Error("Provided pull request is closed and not merged");
|
throw new Error("Provided pull request is closed and not merged!");
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.resolve(configs);
|
return Promise.resolve(configs);
|
||||||
|
|
|
@ -1,20 +1,12 @@
|
||||||
|
|
||||||
|
|
||||||
import { BackportPullRequest, GitPullRequest } from "@bp/service/git/git.types";
|
import { GitPullRequest } from "@bp/service/git/git.types";
|
||||||
|
|
||||||
export const MESSAGE_ERROR_PLACEHOLDER = "{{error}}";
|
|
||||||
export const MESSAGE_TARGET_BRANCH_PLACEHOLDER = "{{target-branch}}";
|
|
||||||
|
|
||||||
export interface LocalGit {
|
export interface LocalGit {
|
||||||
user: string, // local git user
|
user: string, // local git user
|
||||||
email: string, // local git email
|
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
|
* Internal configuration object
|
||||||
*/
|
*/
|
||||||
|
@ -23,21 +15,8 @@ export interface Configs {
|
||||||
auth?: string,
|
auth?: string,
|
||||||
git: LocalGit,
|
git: LocalGit,
|
||||||
folder: string,
|
folder: string,
|
||||||
mergeStrategy?: string, // cherry-pick merge strategy
|
targetBranch: string,
|
||||||
mergeStrategyOption?: string, // cherry-pick merge strategy option
|
|
||||||
cherryPickOptions?: string, // additional cherry-pick options
|
|
||||||
originalPullRequest: GitPullRequest,
|
originalPullRequest: GitPullRequest,
|
||||||
backportPullRequests: BackportPullRequest[],
|
backportPullRequest: GitPullRequest,
|
||||||
errorNotification: ErrorNotification,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum AuthTokenId {
|
|
||||||
// github specific token
|
|
||||||
GITHUB_TOKEN = "GITHUB_TOKEN",
|
|
||||||
// gitlab specific token
|
|
||||||
GITLAB_TOKEN = "GITLAB_TOKEN",
|
|
||||||
// codeberg specific token
|
|
||||||
CODEBERG_TOKEN = "CODEBERG_TOKEN",
|
|
||||||
// generic git token
|
|
||||||
GIT_TOKEN = "GIT_TOKEN",
|
|
||||||
}
|
|
|
@ -1,10 +1,9 @@
|
||||||
import { getAsCleanedCommaSeparatedList, getAsCommaSeparatedList } from "@bp/service/args/args-utils";
|
|
||||||
import { Args } from "@bp/service/args/args.types";
|
import { Args } from "@bp/service/args/args.types";
|
||||||
import ConfigsParser from "@bp/service/configs/configs-parser";
|
import ConfigsParser from "@bp/service/configs/configs-parser";
|
||||||
import { Configs, MESSAGE_TARGET_BRANCH_PLACEHOLDER } from "@bp/service/configs/configs.types";
|
import { Configs } from "@bp/service/configs/configs.types";
|
||||||
import GitClient from "@bp/service/git/git-client";
|
import GitClient from "@bp/service/git/git-client";
|
||||||
import GitClientFactory from "@bp/service/git/git-client-factory";
|
import GitClientFactory from "@bp/service/git/git-client-factory";
|
||||||
import { BackportPullRequest, GitPullRequest } from "@bp/service/git/git.types";
|
import { GitPullRequest } from "@bp/service/git/git.types";
|
||||||
|
|
||||||
export default class PullRequestConfigsParser extends ConfigsParser {
|
export default class PullRequestConfigsParser extends ConfigsParser {
|
||||||
|
|
||||||
|
@ -17,11 +16,8 @@ export default class PullRequestConfigsParser extends ConfigsParser {
|
||||||
|
|
||||||
public async parse(args: Args): Promise<Configs> {
|
public async parse(args: Args): Promise<Configs> {
|
||||||
let pr: GitPullRequest;
|
let pr: GitPullRequest;
|
||||||
if (args.autoNoSquash) {
|
|
||||||
args.squash = undefined;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
pr = await this.gitClient.getPullRequestFromUrl(args.pullRequest, args.squash);
|
pr = await this.gitClient.getPullRequestFromUrl(args.pullRequest, args.squash!);
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
this.logger.error("Something went wrong retrieving pull request");
|
this.logger.error("Something went wrong retrieving pull request");
|
||||||
throw error;
|
throw error;
|
||||||
|
@ -29,40 +25,17 @@ export default class PullRequestConfigsParser extends ConfigsParser {
|
||||||
|
|
||||||
const folder: string = args.folder ?? this.getDefaultFolder();
|
const folder: string = args.folder ?? this.getDefaultFolder();
|
||||||
|
|
||||||
let targetBranches: string[] = [];
|
|
||||||
if (args.targetBranchPattern) {
|
|
||||||
// parse labels to extract target branch(es)
|
|
||||||
targetBranches = this.getTargetBranchesFromLabels(args.targetBranchPattern, pr.labels);
|
|
||||||
if (targetBranches.length === 0) {
|
|
||||||
throw new Error(`Unable to extract target branches with regular expression "${args.targetBranchPattern}"`);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// target branch must be provided if targetRegExp is missing
|
|
||||||
targetBranches = [...new Set(getAsCommaSeparatedList(args.targetBranch!)!)];
|
|
||||||
}
|
|
||||||
const bpBranchNames: string[] = [...new Set(args.bpBranchName ? (getAsCleanedCommaSeparatedList(args.bpBranchName) ?? []) : [])];
|
|
||||||
|
|
||||||
if (bpBranchNames.length > 1 && bpBranchNames.length != targetBranches.length) {
|
|
||||||
throw new Error(`The number of backport branch names, if provided, must match the number of target branches or just one, provided ${bpBranchNames.length} branch names instead`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
dryRun: args.dryRun!,
|
dryRun: args.dryRun!,
|
||||||
auth: args.auth, // this has been already pre-processed before parsing configs
|
auth: args.auth,
|
||||||
folder: `${folder.startsWith("/") ? "" : process.cwd() + "/"}${args.folder ?? this.getDefaultFolder()}`,
|
folder: `${folder.startsWith("/") ? "" : process.cwd() + "/"}${args.folder ?? this.getDefaultFolder()}`,
|
||||||
mergeStrategy: args.strategy,
|
targetBranch: args.targetBranch,
|
||||||
mergeStrategyOption: args.strategyOption,
|
|
||||||
cherryPickOptions: args.cherryPickOptions,
|
|
||||||
originalPullRequest: pr,
|
originalPullRequest: pr,
|
||||||
backportPullRequests: this.generateBackportPullRequestsData(pr, args, targetBranches, bpBranchNames),
|
backportPullRequest: this.getDefaultBackportPullRequest(pr, args),
|
||||||
git: {
|
git: {
|
||||||
user: args.gitUser ?? this.gitClient.getDefaultGitUser(),
|
user: args.gitUser ?? this.gitClient.getDefaultGitUser(),
|
||||||
email: args.gitEmail ?? this.gitClient.getDefaultGitEmail(),
|
email: args.gitEmail ?? this.gitClient.getDefaultGitEmail(),
|
||||||
},
|
}
|
||||||
errorNotification: {
|
|
||||||
enabled: args.enableErrorNotification ?? false,
|
|
||||||
message: this.getDefaultErrorComment(),
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,38 +43,6 @@ export default class PullRequestConfigsParser extends ConfigsParser {
|
||||||
return "bp";
|
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
|
|
||||||
* @param pattern reg exp pattern to extract target branch from label name
|
|
||||||
* @param labels list of labels to check
|
|
||||||
* @returns list of target branches
|
|
||||||
*/
|
|
||||||
private getTargetBranchesFromLabels(pattern: string, labels: string[]): string[] {
|
|
||||||
this.logger.debug(`Extracting branches from [${labels}] using ${pattern}`);
|
|
||||||
const regExp = new RegExp(pattern);
|
|
||||||
|
|
||||||
const branches: string[] = [];
|
|
||||||
for (const l of labels) {
|
|
||||||
const result = regExp.exec(l);
|
|
||||||
|
|
||||||
if (result?.groups) {
|
|
||||||
const { target } = result.groups;
|
|
||||||
if (target){
|
|
||||||
branches.push(target);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return [...new Set(branches)];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a backport pull request starting from the target branch and
|
* Create a backport pull request starting from the target branch and
|
||||||
* the original pr to be backported
|
* the original pr to be backported
|
||||||
|
@ -109,13 +50,7 @@ export default class PullRequestConfigsParser extends ConfigsParser {
|
||||||
* @param targetBranch target branch where the backport should be applied
|
* @param targetBranch target branch where the backport should be applied
|
||||||
* @returns {GitPullRequest}
|
* @returns {GitPullRequest}
|
||||||
*/
|
*/
|
||||||
private generateBackportPullRequestsData(
|
private getDefaultBackportPullRequest(originalPullRequest: GitPullRequest, args: Args): GitPullRequest {
|
||||||
originalPullRequest: GitPullRequest,
|
|
||||||
args: Args,
|
|
||||||
targetBranches: string[],
|
|
||||||
bpBranchNames: string[]
|
|
||||||
): BackportPullRequest[] {
|
|
||||||
|
|
||||||
const reviewers = args.reviewers ?? [];
|
const reviewers = args.reviewers ?? [];
|
||||||
if (reviewers.length == 0 && args.inheritReviewers) {
|
if (reviewers.length == 0 && args.inheritReviewers) {
|
||||||
// inherit only if args.reviewers is empty and args.inheritReviewers set to true
|
// inherit only if args.reviewers is empty and args.inheritReviewers set to true
|
||||||
|
@ -126,45 +61,23 @@ export default class PullRequestConfigsParser extends ConfigsParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
const bodyPrefix = args.bodyPrefix ?? `**Backport:** ${originalPullRequest.htmlUrl}\r\n\r\n`;
|
const bodyPrefix = args.bodyPrefix ?? `**Backport:** ${originalPullRequest.htmlUrl}\r\n\r\n`;
|
||||||
const body = bodyPrefix + (args.body ?? `${originalPullRequest.body}`);
|
const body = args.body ?? `${originalPullRequest.body}`;
|
||||||
|
|
||||||
const labels = args.labels ?? [];
|
const labels = args.labels ?? [];
|
||||||
if (args.inheritLabels) {
|
if (args.inheritLabels) {
|
||||||
labels.push(...originalPullRequest.labels);
|
labels.push(...originalPullRequest.labels);
|
||||||
}
|
}
|
||||||
|
|
||||||
return targetBranches.map((tb, idx) => {
|
|
||||||
|
|
||||||
// if there multiple branch names take the corresponding one, otherwise get the the first one if it exists
|
|
||||||
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("-");
|
|
||||||
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
|
|
||||||
// so append "-${tb}" to the provided name
|
|
||||||
backportBranch = backportBranch + `-${tb}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (backportBranch.length > 250) {
|
|
||||||
this.logger.warn(`Backport branch (length=${backportBranch.length}) exceeded the max length of 250 chars, branch name truncated!`);
|
|
||||||
backportBranch = backportBranch.slice(0, 250);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
owner: originalPullRequest.targetRepo.owner,
|
author: args.gitUser ?? this.gitClient.getDefaultGitUser(),
|
||||||
repo: originalPullRequest.targetRepo.project,
|
title: args.title ?? `[${args.targetBranch}] ${originalPullRequest.title}`,
|
||||||
head: backportBranch,
|
body: `${bodyPrefix}${body}`,
|
||||||
base: tb,
|
|
||||||
title: args.title ?? `[${tb}] ${originalPullRequest.title}`,
|
|
||||||
// preserve new line chars
|
|
||||||
body: body.replace(/\\n/g, "\n").replace(/\\r/g, "\r"),
|
|
||||||
reviewers: [...new Set(reviewers)],
|
reviewers: [...new Set(reviewers)],
|
||||||
assignees: [...new Set(args.assignees)],
|
assignees: [...new Set(args.assignees)],
|
||||||
labels: [...new Set(labels)],
|
labels: [...new Set(labels)],
|
||||||
comments: args.comments?.map(c => c.replace(/\\n/g, "\n").replace(/\\r/g, "\r")) ?? [],
|
targetRepo: originalPullRequest.targetRepo,
|
||||||
|
sourceRepo: originalPullRequest.targetRepo,
|
||||||
|
branchName: args.bpBranchName,
|
||||||
};
|
};
|
||||||
}) as BackportPullRequest[];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -35,9 +35,8 @@ export default class GitCLIService {
|
||||||
* @param remoteURL remote link, e.g., https://github.com/kiegroup/git-backporting-example.git
|
* @param remoteURL remote link, e.g., https://github.com/kiegroup/git-backporting-example.git
|
||||||
*/
|
*/
|
||||||
private remoteWithAuth(remoteURL: string): string {
|
private remoteWithAuth(remoteURL: string): string {
|
||||||
if (this.auth) {
|
if (this.auth && this.gitData.user) {
|
||||||
// Anything will work as a username.
|
return remoteURL.replace("://", `://${this.gitData.user}:${this.auth}@`);
|
||||||
return remoteURL.replace("://", `://token:${this.auth}@`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// return remote as it is
|
// return remote as it is
|
||||||
|
@ -61,25 +60,12 @@ export default class GitCLIService {
|
||||||
* @param branch branch which should be cloned
|
* @param branch branch which should be cloned
|
||||||
*/
|
*/
|
||||||
async clone(from: string, to: string, branch: string): Promise<void> {
|
async clone(from: string, to: string, branch: string): Promise<void> {
|
||||||
this.logger.info(`Cloning repository ${from} to ${to}`);
|
this.logger.info(`Cloning repository ${from} to ${to}.`);
|
||||||
if (!fs.existsSync(to)) {
|
if (!fs.existsSync(to)) {
|
||||||
await simpleGit().clone(this.remoteWithAuth(from), to, ["--quiet", "--shallow-submodules", "--no-tags", "--branch", branch]);
|
await simpleGit().clone(this.remoteWithAuth(from), to, ["--quiet", "--shallow-submodules", "--no-tags", "--branch", branch]);
|
||||||
return;
|
} else {
|
||||||
|
this.logger.warn(`Folder ${to} already exist. Won't clone`);
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -88,7 +74,7 @@ export default class GitCLIService {
|
||||||
* @param newBranch new branch name
|
* @param newBranch new branch name
|
||||||
*/
|
*/
|
||||||
async createLocalBranch(cwd: string, newBranch: string): Promise<void> {
|
async createLocalBranch(cwd: string, newBranch: string): Promise<void> {
|
||||||
this.logger.info(`Creating branch ${newBranch}`);
|
this.logger.info(`Creating branch ${newBranch}.`);
|
||||||
await this.git(cwd).checkoutLocalBranch(newBranch);
|
await this.git(cwd).checkoutLocalBranch(newBranch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +85,7 @@ export default class GitCLIService {
|
||||||
* @param remoteName [optional] name of the remote, by default 'fork' is used
|
* @param remoteName [optional] name of the remote, by default 'fork' is used
|
||||||
*/
|
*/
|
||||||
async addRemote(cwd: string, remote: string, remoteName = "fork"): Promise<void> {
|
async addRemote(cwd: string, remote: string, remoteName = "fork"): Promise<void> {
|
||||||
this.logger.info(`Adding new remote ${remote}`);
|
this.logger.info(`Adding new remote ${remote}.`);
|
||||||
await this.git(cwd).addRemote(remoteName, this.remoteWithAuth(remote));
|
await this.git(cwd).addRemote(remoteName, this.remoteWithAuth(remote));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +96,7 @@ export default class GitCLIService {
|
||||||
* @param remote [optional] the remote to fetch, by default origin
|
* @param remote [optional] the remote to fetch, by default origin
|
||||||
*/
|
*/
|
||||||
async fetch(cwd: string, branch: string, remote = "origin"): Promise<void> {
|
async fetch(cwd: string, branch: string, remote = "origin"): Promise<void> {
|
||||||
this.logger.info(`Fetching ${remote} ${branch}`);
|
this.logger.info(`Fetching ${remote} ${branch}.`);
|
||||||
await this.git(cwd).fetch(remote, branch, ["--quiet"]);
|
await this.git(cwd).fetch(remote, branch, ["--quiet"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,40 +105,9 @@ export default class GitCLIService {
|
||||||
* @param cwd repository in which the sha should be cherry picked to
|
* @param cwd repository in which the sha should be cherry picked to
|
||||||
* @param sha commit sha
|
* @param sha commit sha
|
||||||
*/
|
*/
|
||||||
async cherryPick(cwd: string, sha: string, strategy = "recursive", strategyOption = "theirs", cherryPickOptions: string | undefined): Promise<void> {
|
async cherryPick(cwd: string, sha: string): Promise<void> {
|
||||||
this.logger.info(`Cherry picking ${sha}`);
|
this.logger.info(`Cherry picking ${sha}.`);
|
||||||
|
await this.git(cwd).raw(["cherry-pick", "-m", "1", "--strategy=recursive", "--strategy-option=theirs", sha]);
|
||||||
let options = ["cherry-pick", "-m", "1", `--strategy=${strategy}`, `--strategy-option=${strategyOption}`];
|
|
||||||
if (cherryPickOptions !== undefined) {
|
|
||||||
options = options.concat(cherryPickOptions.split(" "));
|
|
||||||
}
|
|
||||||
options.push(sha);
|
|
||||||
this.logger.debug(`Cherry picking command git ${options}`);
|
|
||||||
try {
|
|
||||||
await this.git(cwd).raw(options);
|
|
||||||
} catch(error) {
|
|
||||||
const diff = await this.git(cwd).diff();
|
|
||||||
if (diff) {
|
|
||||||
throw new Error(`${error}\r\nShowing git diff:\r\n` + diff);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -162,7 +117,7 @@ export default class GitCLIService {
|
||||||
* @param remote [optional] remote to which the branch should be pushed to, by default 'origin'
|
* @param remote [optional] remote to which the branch should be pushed to, by default 'origin'
|
||||||
*/
|
*/
|
||||||
async push(cwd: string, branch: string, remote = "origin", force = false): Promise<void> {
|
async push(cwd: string, branch: string, remote = "origin", force = false): Promise<void> {
|
||||||
this.logger.info(`Pushing ${branch} to ${remote}`);
|
this.logger.info(`Pushing ${branch} to ${remote}.`);
|
||||||
|
|
||||||
const options = ["--quiet"];
|
const options = ["--quiet"];
|
||||||
if (force) {
|
if (force) {
|
||||||
|
|
|
@ -13,10 +13,9 @@ export default class GitClientFactory {
|
||||||
private static logger: LoggerService = LoggerServiceFactory.getLogger();
|
private static logger: LoggerService = LoggerServiceFactory.getLogger();
|
||||||
private static instance?: GitClient;
|
private static instance?: GitClient;
|
||||||
|
|
||||||
// this method assumes there already exists a singleton client instance, otherwise it will fail
|
|
||||||
public static getClient(): GitClient {
|
public static getClient(): GitClient {
|
||||||
if (!GitClientFactory.instance) {
|
if (!GitClientFactory.instance) {
|
||||||
throw new Error("You must call `getOrCreate` method first");
|
throw new Error("You must call `getOrCreate` method first!");
|
||||||
}
|
}
|
||||||
|
|
||||||
return GitClientFactory.instance;
|
return GitClientFactory.instance;
|
||||||
|
@ -30,7 +29,7 @@ export default class GitClientFactory {
|
||||||
public static getOrCreate(type: GitClientType, authToken: string | undefined, apiUrl: string): GitClient {
|
public static getOrCreate(type: GitClientType, authToken: string | undefined, apiUrl: string): GitClient {
|
||||||
|
|
||||||
if (GitClientFactory.instance) {
|
if (GitClientFactory.instance) {
|
||||||
GitClientFactory.logger.warn("Git service already initialized");
|
GitClientFactory.logger.warn("Git service already initialized!");
|
||||||
return GitClientFactory.instance;
|
return GitClientFactory.instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,9 +42,6 @@ export default class GitClientFactory {
|
||||||
case GitClientType.GITLAB:
|
case GitClientType.GITLAB:
|
||||||
GitClientFactory.instance = new GitLabClient(authToken, apiUrl);
|
GitClientFactory.instance = new GitLabClient(authToken, apiUrl);
|
||||||
break;
|
break;
|
||||||
case GitClientType.CODEBERG:
|
|
||||||
GitClientFactory.instance = new GitHubService(authToken, apiUrl, true);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
throw new Error(`Invalid git service type received: ${type}`);
|
throw new Error(`Invalid git service type received: ${type}`);
|
||||||
}
|
}
|
||||||
|
@ -53,9 +49,8 @@ export default class GitClientFactory {
|
||||||
return GitClientFactory.instance;
|
return GitClientFactory.instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is used for testing purposes
|
|
||||||
public static reset(): void {
|
public static reset(): void {
|
||||||
GitClientFactory.logger.warn("Resetting git service");
|
GitClientFactory.logger.warn("Resetting git service!");
|
||||||
GitClientFactory.instance = undefined;
|
GitClientFactory.instance = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
import { BackportPullRequest, GitClientType, GitPullRequest } from "@bp/service/git/git.types";
|
import { BackportPullRequest, GitPullRequest } from "@bp/service/git/git.types";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Git management service interface, which provides a common API for interacting
|
* Git management service interface, which provides a common API for interacting
|
||||||
|
@ -6,11 +6,6 @@ import { BackportPullRequest, GitClientType, GitPullRequest } from "@bp/service/
|
||||||
*/
|
*/
|
||||||
export default interface GitClient {
|
export default interface GitClient {
|
||||||
|
|
||||||
/**
|
|
||||||
* @returns {GitClientType} specific git client enum type
|
|
||||||
*/
|
|
||||||
getClientType(): GitClientType
|
|
||||||
|
|
||||||
// READ
|
// READ
|
||||||
|
|
||||||
getDefaultGitUser(): string;
|
getDefaultGitUser(): string;
|
||||||
|
@ -25,7 +20,7 @@ import { BackportPullRequest, GitClientType, GitPullRequest } from "@bp/service/
|
||||||
* @param squash if true keep just one single commit, otherwise get the full list
|
* @param squash if true keep just one single commit, otherwise get the full list
|
||||||
* @returns {Promise<PullRequest>}
|
* @returns {Promise<PullRequest>}
|
||||||
*/
|
*/
|
||||||
getPullRequest(owner: string, repo: string, prNumber: number, squash: boolean | undefined): Promise<GitPullRequest>;
|
getPullRequest(owner: string, repo: string, prNumber: number, squash: boolean): Promise<GitPullRequest>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a pull request object from the underneath git service
|
* Get a pull request object from the underneath git service
|
||||||
|
@ -33,7 +28,7 @@ import { BackportPullRequest, GitClientType, GitPullRequest } from "@bp/service/
|
||||||
* @param squash if true keep just one single commit, otherwise get the full list
|
* @param squash if true keep just one single commit, otherwise get the full list
|
||||||
* @returns {Promise<PullRequest>}
|
* @returns {Promise<PullRequest>}
|
||||||
*/
|
*/
|
||||||
getPullRequestFromUrl(prUrl: string, squash: boolean | undefined): Promise<GitPullRequest>;
|
getPullRequestFromUrl(prUrl: string, squash: boolean): Promise<GitPullRequest>;
|
||||||
|
|
||||||
// WRITE
|
// WRITE
|
||||||
|
|
||||||
|
@ -43,12 +38,4 @@ import { BackportPullRequest, GitClientType, GitPullRequest } from "@bp/service/
|
||||||
* @returns {Promise<string>} the pull request url
|
* @returns {Promise<string>} the pull request url
|
||||||
*/
|
*/
|
||||||
createPullRequest(backport: BackportPullRequest): Promise<string>;
|
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>;
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,6 +1,4 @@
|
||||||
import LoggerServiceFactory from "@bp/service/logger/logger-service-factory";
|
|
||||||
import { GitClientType } from "@bp/service/git/git.types";
|
import { GitClientType } from "@bp/service/git/git.types";
|
||||||
import { AuthTokenId } from "@bp/service/configs/configs.types";
|
|
||||||
|
|
||||||
const PUBLIC_GITHUB_URL = "https://github.com";
|
const PUBLIC_GITHUB_URL = "https://github.com";
|
||||||
const PUBLIC_GITHUB_API = "https://api.github.com";
|
const PUBLIC_GITHUB_API = "https://api.github.com";
|
||||||
|
@ -18,8 +16,6 @@ export const inferGitClient = (prUrl: string): GitClientType => {
|
||||||
return GitClientType.GITHUB;
|
return GitClientType.GITHUB;
|
||||||
} else if (stdPrUrl.includes(GitClientType.GITLAB.toString())) {
|
} else if (stdPrUrl.includes(GitClientType.GITLAB.toString())) {
|
||||||
return GitClientType.GITLAB;
|
return GitClientType.GITLAB;
|
||||||
} else if (stdPrUrl.includes(GitClientType.CODEBERG.toString())) {
|
|
||||||
return GitClientType.CODEBERG;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error(`Remote git service not recognized from pr url: ${prUrl}`);
|
throw new Error(`Remote git service not recognized from pr url: ${prUrl}`);
|
||||||
|
@ -41,64 +37,3 @@ export const inferGitApiUrl = (prUrl: string, apiVersion = "v4"): string => {
|
||||||
|
|
||||||
return `${baseUrl}/api/${apiVersion}`;
|
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.
|
|
||||||
* @param gitType
|
|
||||||
* @returns tuple where
|
|
||||||
* - the first element is the corresponding env value
|
|
||||||
* - the second element is true if the value is not undefined nor empty
|
|
||||||
*/
|
|
||||||
export const getGitTokenFromEnv = (gitType: GitClientType): string | undefined => {
|
|
||||||
let [token] = getEnv(AuthTokenId.GIT_TOKEN);
|
|
||||||
let [specToken, specOk]: [string | undefined, boolean] = [undefined, false];
|
|
||||||
if (GitClientType.GITHUB == gitType) {
|
|
||||||
[specToken, specOk] = getEnv(AuthTokenId.GITHUB_TOKEN);
|
|
||||||
} else if (GitClientType.GITLAB == gitType) {
|
|
||||||
[specToken, specOk] = getEnv(AuthTokenId.GITLAB_TOKEN);
|
|
||||||
} else if (GitClientType.CODEBERG == gitType) {
|
|
||||||
[specToken, specOk] = getEnv(AuthTokenId.CODEBERG_TOKEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (specOk) {
|
|
||||||
token = specToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
return token;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get process env variable given the input key string
|
|
||||||
* @param key
|
|
||||||
* @returns tuple where
|
|
||||||
* - the first element is the corresponding env value
|
|
||||||
* - the second element is true if the value is not undefined nor empty
|
|
||||||
*/
|
|
||||||
export const getEnv = (key: string): [string | undefined, boolean] => {
|
|
||||||
const val = process.env[key];
|
|
||||||
return [val, val !== undefined && val !== ""];
|
|
||||||
};
|
|
|
@ -1,7 +1,7 @@
|
||||||
export interface GitPullRequest {
|
export interface GitPullRequest {
|
||||||
number?: number,
|
number?: number,
|
||||||
author: string,
|
author: string,
|
||||||
url: string,
|
url?: string,
|
||||||
htmlUrl?: string,
|
htmlUrl?: string,
|
||||||
state?: GitRepoState,
|
state?: GitRepoState,
|
||||||
merged?: boolean,
|
merged?: boolean,
|
||||||
|
@ -13,8 +13,8 @@ export interface GitPullRequest {
|
||||||
labels: string[],
|
labels: string[],
|
||||||
targetRepo: GitRepository,
|
targetRepo: GitRepository,
|
||||||
sourceRepo: GitRepository,
|
sourceRepo: GitRepository,
|
||||||
nCommits: number, // number of commits in the pr
|
nCommits?: number, // number of commits in the pr
|
||||||
commits: string[], // merge commit or last one
|
commits?: string[], // merge commit or last one
|
||||||
branchName?: string,
|
branchName?: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,14 +34,12 @@ export interface BackportPullRequest {
|
||||||
reviewers: string[], // pr list of reviewers
|
reviewers: string[], // pr list of reviewers
|
||||||
assignees: string[], // pr list of assignees
|
assignees: string[], // pr list of assignees
|
||||||
labels: string[], // pr list of assigned labels
|
labels: string[], // pr list of assigned labels
|
||||||
comments: string[], // pr list of additional comments
|
branchName?: string,
|
||||||
// branchName?: string,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum GitClientType {
|
export enum GitClientType {
|
||||||
GITHUB = "github",
|
GITHUB = "github",
|
||||||
GITLAB = "gitlab",
|
GITLAB = "gitlab",
|
||||||
CODEBERG = "codeberg",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum GitRepoState {
|
export enum GitRepoState {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import GitClient from "@bp/service/git/git-client";
|
import GitClient from "@bp/service/git/git-client";
|
||||||
import { inferSquash } from "@bp/service/git/git-util";
|
import { BackportPullRequest, GitPullRequest } from "@bp/service/git/git.types";
|
||||||
import { BackportPullRequest, GitClientType, GitPullRequest } from "@bp/service/git/git.types";
|
|
||||||
import GitHubMapper from "@bp/service/git/github/github-mapper";
|
import GitHubMapper from "@bp/service/git/github/github-mapper";
|
||||||
import OctokitFactory from "@bp/service/git/github/octokit-factory";
|
import OctokitFactory from "@bp/service/git/github/octokit-factory";
|
||||||
import LoggerService from "@bp/service/logger/logger-service";
|
import LoggerService from "@bp/service/logger/logger-service";
|
||||||
|
@ -12,56 +11,34 @@ export default class GitHubClient implements GitClient {
|
||||||
|
|
||||||
private logger: LoggerService;
|
private logger: LoggerService;
|
||||||
private apiUrl: string;
|
private apiUrl: string;
|
||||||
private isForCodeberg: boolean;
|
|
||||||
private octokit: Octokit;
|
private octokit: Octokit;
|
||||||
private mapper: GitHubMapper;
|
private mapper: GitHubMapper;
|
||||||
|
|
||||||
constructor(token: string | undefined, apiUrl: string, isForCodeberg = false) {
|
constructor(token: string | undefined, apiUrl: string) {
|
||||||
this.apiUrl = apiUrl;
|
this.apiUrl = apiUrl;
|
||||||
this.isForCodeberg = isForCodeberg;
|
|
||||||
this.logger = LoggerServiceFactory.getLogger();
|
this.logger = LoggerServiceFactory.getLogger();
|
||||||
this.octokit = OctokitFactory.getOctokit(token, this.apiUrl);
|
this.octokit = OctokitFactory.getOctokit(token, this.apiUrl);
|
||||||
this.mapper = new GitHubMapper();
|
this.mapper = new GitHubMapper();
|
||||||
}
|
}
|
||||||
|
|
||||||
getClientType(): GitClientType {
|
|
||||||
return this.isForCodeberg ? GitClientType.CODEBERG : GitClientType.GITHUB;
|
|
||||||
}
|
|
||||||
|
|
||||||
// READ
|
// READ
|
||||||
|
|
||||||
getDefaultGitUser(): string {
|
getDefaultGitUser(): string {
|
||||||
return this.apiUrl.includes(GitClientType.CODEBERG.toString()) ? "Codeberg" : "GitHub";
|
return "GitHub";
|
||||||
}
|
}
|
||||||
|
|
||||||
getDefaultGitEmail(): string {
|
getDefaultGitEmail(): string {
|
||||||
return "noreply@github.com";
|
return "noreply@github.com";
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPullRequest(owner: string, repo: string, prNumber: number, squash: boolean | undefined): Promise<GitPullRequest> {
|
async getPullRequest(owner: string, repo: string, prNumber: number, squash = true): Promise<GitPullRequest> {
|
||||||
this.logger.debug(`Fetching pull request ${owner}/${repo}/${prNumber}`);
|
this.logger.info(`Getting pull request ${owner}/${repo}/${prNumber}.`);
|
||||||
const { data } = await this.octokit.rest.pulls.get({
|
const { data } = await this.octokit.rest.pulls.get({
|
||||||
owner: owner,
|
owner: owner,
|
||||||
repo: repo,
|
repo: repo,
|
||||||
pull_number: prNumber,
|
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[] = [];
|
const commits: string[] = [];
|
||||||
if (!squash) {
|
if (!squash) {
|
||||||
// fetch all commits
|
// fetch all commits
|
||||||
|
@ -73,11 +50,6 @@ export default class GitHubClient implements GitClient {
|
||||||
});
|
});
|
||||||
|
|
||||||
commits.push(...data.map(c => c.sha));
|
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) {
|
} catch(error) {
|
||||||
throw new Error(`Failed to retrieve commits for pull request n. ${prNumber}`);
|
throw new Error(`Failed to retrieve commits for pull request n. ${prNumber}`);
|
||||||
}
|
}
|
||||||
|
@ -86,7 +58,7 @@ export default class GitHubClient implements GitClient {
|
||||||
return this.mapper.mapPullRequest(data as PullRequest, commits);
|
return this.mapper.mapPullRequest(data as PullRequest, commits);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPullRequestFromUrl(prUrl: string, squash: boolean | undefined): Promise<GitPullRequest> {
|
async getPullRequestFromUrl(prUrl: string, squash = true): Promise<GitPullRequest> {
|
||||||
const { owner, project, id } = this.extractPullRequestData(prUrl);
|
const { owner, project, id } = this.extractPullRequestData(prUrl);
|
||||||
return this.getPullRequest(owner, project, id, squash);
|
return this.getPullRequest(owner, project, id, squash);
|
||||||
}
|
}
|
||||||
|
@ -94,7 +66,7 @@ export default class GitHubClient implements GitClient {
|
||||||
// WRITE
|
// WRITE
|
||||||
|
|
||||||
async createPullRequest(backport: BackportPullRequest): Promise<string> {
|
async createPullRequest(backport: BackportPullRequest): Promise<string> {
|
||||||
this.logger.info(`Creating pull request ${backport.head} -> ${backport.base}`);
|
this.logger.info(`Creating pull request ${backport.head} -> ${backport.base}.`);
|
||||||
this.logger.info(`${JSON.stringify(backport, null, 2)}`);
|
this.logger.info(`${JSON.stringify(backport, null, 2)}`);
|
||||||
|
|
||||||
const { data } = await this.octokit.pulls.create({
|
const { data } = await this.octokit.pulls.create({
|
||||||
|
@ -110,82 +82,48 @@ export default class GitHubClient implements GitClient {
|
||||||
throw new Error("Pull request creation failed");
|
throw new Error("Pull request creation failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
const promises = [];
|
|
||||||
|
|
||||||
if (backport.labels.length > 0) {
|
if (backport.labels.length > 0) {
|
||||||
promises.push(
|
try {
|
||||||
this.octokit.issues.addLabels({
|
await this.octokit.issues.addLabels({
|
||||||
owner: backport.owner,
|
owner: backport.owner,
|
||||||
repo: backport.repo,
|
repo: backport.repo,
|
||||||
issue_number: (data as PullRequest).number,
|
issue_number: (data as PullRequest).number,
|
||||||
labels: backport.labels,
|
labels: backport.labels,
|
||||||
}).catch(error => this.logger.error(`Error setting labels: ${error}`))
|
});
|
||||||
);
|
} catch (error) {
|
||||||
|
this.logger.error(`Error setting labels: ${error}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (backport.reviewers.length > 0) {
|
if (backport.reviewers.length > 0) {
|
||||||
promises.push(
|
try {
|
||||||
this.octokit.pulls.requestReviewers({
|
await this.octokit.pulls.requestReviewers({
|
||||||
owner: backport.owner,
|
owner: backport.owner,
|
||||||
repo: backport.repo,
|
repo: backport.repo,
|
||||||
pull_number: (data as PullRequest).number,
|
pull_number: (data as PullRequest).number,
|
||||||
reviewers: backport.reviewers,
|
reviewers: backport.reviewers,
|
||||||
}).catch(error => this.logger.error(`Error requesting reviewers: ${error}`))
|
});
|
||||||
);
|
} catch (error) {
|
||||||
|
this.logger.error(`Error requesting reviewers: ${error}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (backport.assignees.length > 0) {
|
if (backport.assignees.length > 0) {
|
||||||
promises.push(
|
try {
|
||||||
this.octokit.issues.addAssignees({
|
await this.octokit.issues.addAssignees({
|
||||||
owner: backport.owner,
|
owner: backport.owner,
|
||||||
repo: backport.repo,
|
repo: backport.repo,
|
||||||
issue_number: (data as PullRequest).number,
|
issue_number: (data as PullRequest).number,
|
||||||
assignees: backport.assignees,
|
assignees: backport.assignees,
|
||||||
}).catch(error => this.logger.error(`Error setting assignees: ${error}`))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (backport.comments.length > 0) {
|
|
||||||
backport.comments.forEach(c => {
|
|
||||||
promises.push(
|
|
||||||
this.octokit.issues.createComment({
|
|
||||||
owner: backport.owner,
|
|
||||||
repo: backport.repo,
|
|
||||||
issue_number: (data as PullRequest).number,
|
|
||||||
body: c,
|
|
||||||
}).catch(error => this.logger.error(`Error posting comment: ${error}`))
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(`Error setting assignees: ${error}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all(promises);
|
|
||||||
|
|
||||||
return data.html_url;
|
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
|
// UTILS
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -24,9 +24,9 @@ export default class GitHubMapper implements GitResponseMapper<PullRequest, "ope
|
||||||
state: this.mapGitState(pr.state), // TODO fix using custom mapper
|
state: this.mapGitState(pr.state), // TODO fix using custom mapper
|
||||||
merged: pr.merged ?? false,
|
merged: pr.merged ?? false,
|
||||||
mergedBy: pr.merged_by?.login,
|
mergedBy: pr.merged_by?.login,
|
||||||
reviewers: pr.requested_reviewers?.filter(r => r && "login" in r).map((r => (r as User)?.login)) ?? [],
|
reviewers: pr.requested_reviewers.filter(r => "login" in r).map((r => (r as User)?.login)),
|
||||||
assignees: pr.assignees?.filter(r => r && "login" in r).map(r => r.login) ?? [],
|
assignees: pr.assignees.filter(r => "login" in r).map(r => r.login),
|
||||||
labels: pr.labels?.map(l => l.name) ?? [],
|
labels: pr.labels.map(l => l.name),
|
||||||
sourceRepo: await this.mapSourceRepo(pr),
|
sourceRepo: await this.mapSourceRepo(pr),
|
||||||
targetRepo: await this.mapTargetRepo(pr),
|
targetRepo: await this.mapTargetRepo(pr),
|
||||||
nCommits: pr.commits,
|
nCommits: pr.commits,
|
||||||
|
|
|
@ -12,6 +12,7 @@ export default class OctokitFactory {
|
||||||
|
|
||||||
public static getOctokit(token: string | undefined, apiUrl: string): Octokit {
|
public static getOctokit(token: string | undefined, apiUrl: string): Octokit {
|
||||||
if (!OctokitFactory.octokit) {
|
if (!OctokitFactory.octokit) {
|
||||||
|
OctokitFactory.logger.info("Creating octokit instance.");
|
||||||
OctokitFactory.octokit = new Octokit({
|
OctokitFactory.octokit = new Octokit({
|
||||||
auth: token,
|
auth: token,
|
||||||
userAgent: "kiegroup/git-backporting",
|
userAgent: "kiegroup/git-backporting",
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import LoggerService from "@bp/service/logger/logger-service";
|
import LoggerService from "@bp/service/logger/logger-service";
|
||||||
import GitClient from "@bp/service/git/git-client";
|
import GitClient from "@bp/service/git/git-client";
|
||||||
import { inferSquash } from "@bp/service/git/git-util";
|
import { GitPullRequest, BackportPullRequest } from "@bp/service/git/git.types";
|
||||||
import { GitPullRequest, BackportPullRequest, GitClientType } from "@bp/service/git/git.types";
|
|
||||||
import LoggerServiceFactory from "@bp/service/logger/logger-service-factory";
|
import LoggerServiceFactory from "@bp/service/logger/logger-service-factory";
|
||||||
import { CommitSchema, MergeRequestSchema, UserSchema } from "@gitbeaker/rest";
|
import { CommitSchema, MergeRequestSchema, UserSchema } from "@gitbeaker/rest";
|
||||||
import GitLabMapper from "@bp/service/git/gitlab/gitlab-mapper";
|
import GitLabMapper from "@bp/service/git/gitlab/gitlab-mapper";
|
||||||
|
@ -31,10 +30,6 @@ export default class GitLabClient implements GitClient {
|
||||||
this.mapper = new GitLabMapper(this.client);
|
this.mapper = new GitLabMapper(this.client);
|
||||||
}
|
}
|
||||||
|
|
||||||
getClientType(): GitClientType {
|
|
||||||
return GitClientType.GITLAB;
|
|
||||||
}
|
|
||||||
|
|
||||||
getDefaultGitUser(): string {
|
getDefaultGitUser(): string {
|
||||||
return "Gitlab";
|
return "Gitlab";
|
||||||
}
|
}
|
||||||
|
@ -46,15 +41,9 @@ export default class GitLabClient implements GitClient {
|
||||||
// READ
|
// READ
|
||||||
|
|
||||||
// example: <host>/api/v4/projects/<namespace>%2Fbackporting-example/merge_requests/1
|
// example: <host>/api/v4/projects/<namespace>%2Fbackporting-example/merge_requests/1
|
||||||
async getPullRequest(namespace: string, repo: string, mrNumber: number, squash: boolean | undefined): Promise<GitPullRequest> {
|
async getPullRequest(namespace: string, repo: string, mrNumber: number, squash = true): Promise<GitPullRequest> {
|
||||||
const projectId = this.getProjectId(namespace, repo);
|
const projectId = this.getProjectId(namespace, repo);
|
||||||
const url = `/projects/${projectId}/merge_requests/${mrNumber}`;
|
const { data } = await this.client.get(`/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[] = [];
|
const commits: string[] = [];
|
||||||
if (!squash) {
|
if (!squash) {
|
||||||
|
@ -72,7 +61,7 @@ export default class GitLabClient implements GitClient {
|
||||||
return this.mapper.mapPullRequest(data as MergeRequestSchema, commits);
|
return this.mapper.mapPullRequest(data as MergeRequestSchema, commits);
|
||||||
}
|
}
|
||||||
|
|
||||||
getPullRequestFromUrl(mrUrl: string, squash: boolean | undefined): Promise<GitPullRequest> {
|
getPullRequestFromUrl(mrUrl: string, squash = true): Promise<GitPullRequest> {
|
||||||
const { namespace, project, id } = this.extractMergeRequestData(mrUrl);
|
const { namespace, project, id } = this.extractMergeRequestData(mrUrl);
|
||||||
return this.getPullRequest(namespace, project, id, squash);
|
return this.getPullRequest(namespace, project, id, squash);
|
||||||
}
|
}
|
||||||
|
@ -80,7 +69,7 @@ export default class GitLabClient implements GitClient {
|
||||||
// WRITE
|
// WRITE
|
||||||
|
|
||||||
async createPullRequest(backport: BackportPullRequest): Promise<string> {
|
async createPullRequest(backport: BackportPullRequest): Promise<string> {
|
||||||
this.logger.info(`Creating pull request ${backport.head} -> ${backport.base}`);
|
this.logger.info(`Creating pull request ${backport.head} -> ${backport.base}.`);
|
||||||
this.logger.info(`${JSON.stringify(backport, null, 2)}`);
|
this.logger.info(`${JSON.stringify(backport, null, 2)}`);
|
||||||
|
|
||||||
const projectId = this.getProjectId(backport.owner, backport.repo);
|
const projectId = this.getProjectId(backport.owner, backport.repo);
|
||||||
|
@ -95,97 +84,68 @@ export default class GitLabClient implements GitClient {
|
||||||
});
|
});
|
||||||
|
|
||||||
const mr = data as MergeRequestSchema;
|
const mr = data as MergeRequestSchema;
|
||||||
const promises = [];
|
|
||||||
|
|
||||||
// labels
|
// labels
|
||||||
if (backport.labels.length > 0) {
|
if (backport.labels.length > 0) {
|
||||||
|
try {
|
||||||
this.logger.info("Setting labels: " + backport.labels);
|
this.logger.info("Setting labels: " + backport.labels);
|
||||||
promises.push(
|
await this.client.put(`/projects/${projectId}/merge_requests/${mr.iid}`, {
|
||||||
this.client.put(`/projects/${projectId}/merge_requests/${mr.iid}`, {
|
|
||||||
labels: backport.labels.join(","),
|
labels: backport.labels.join(","),
|
||||||
}).catch(error => this.logger.warn("Failure trying to update labels. " + error))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// comments
|
|
||||||
if (backport.comments.length > 0) {
|
|
||||||
this.logger.info("Posting comments: " + backport.comments);
|
|
||||||
backport.comments.forEach(c => {
|
|
||||||
promises.push(
|
|
||||||
this.client.post(`/projects/${projectId}/merge_requests/${mr.iid}/notes`, {
|
|
||||||
body: c,
|
|
||||||
}).catch(error => this.logger.warn("Failure trying to post comment. " + error))
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
} catch(error) {
|
||||||
|
this.logger.warn("Failure trying to update labels. " + error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// reviewers
|
// reviewers
|
||||||
const reviewerIds = await Promise.all(backport.reviewers.map(async r => {
|
const reviewerIds: number[] = [];
|
||||||
|
for(const r of backport.reviewers) {
|
||||||
|
try {
|
||||||
this.logger.debug("Retrieving user: " + r);
|
this.logger.debug("Retrieving user: " + r);
|
||||||
return this.getUser(r).then(user => user.id).catch(
|
const user = await this.getUser(r);
|
||||||
() => {
|
reviewerIds.push(user.id);
|
||||||
|
} catch(error) {
|
||||||
this.logger.warn(`Failed to retrieve reviewer ${r}`);
|
this.logger.warn(`Failed to retrieve reviewer ${r}`);
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
);
|
}
|
||||||
}));
|
|
||||||
|
|
||||||
if (reviewerIds.length > 0) {
|
if (reviewerIds.length > 0) {
|
||||||
|
try {
|
||||||
this.logger.info("Setting reviewers: " + reviewerIds);
|
this.logger.info("Setting reviewers: " + reviewerIds);
|
||||||
promises.push(
|
await this.client.put(`/projects/${projectId}/merge_requests/${mr.iid}`, {
|
||||||
this.client.put(`/projects/${projectId}/merge_requests/${mr.iid}`, {
|
|
||||||
reviewer_ids: reviewerIds.filter(r => r !== undefined),
|
reviewer_ids: reviewerIds.filter(r => r !== undefined),
|
||||||
}).catch(error => this.logger.warn("Failure trying to update reviewers. " + error))
|
});
|
||||||
);
|
} catch(error) {
|
||||||
|
this.logger.warn("Failure trying to update reviewers. " + error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// assignees
|
// assignees
|
||||||
const assigneeIds = await Promise.all(backport.assignees.map(async a => {
|
const assigneeIds: number[] = [];
|
||||||
|
for(const a of backport.assignees) {
|
||||||
|
try {
|
||||||
this.logger.debug("Retrieving user: " + a);
|
this.logger.debug("Retrieving user: " + a);
|
||||||
return this.getUser(a).then(user => user.id).catch(
|
const user = await this.getUser(a);
|
||||||
() => {
|
assigneeIds.push(user.id);
|
||||||
|
} catch(error) {
|
||||||
this.logger.warn(`Failed to retrieve assignee ${a}`);
|
this.logger.warn(`Failed to retrieve assignee ${a}`);
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
);
|
}
|
||||||
}));
|
|
||||||
|
|
||||||
if (assigneeIds.length > 0) {
|
if (assigneeIds.length > 0) {
|
||||||
|
try {
|
||||||
this.logger.info("Setting assignees: " + assigneeIds);
|
this.logger.info("Setting assignees: " + assigneeIds);
|
||||||
promises.push(
|
await this.client.put(`/projects/${projectId}/merge_requests/${mr.iid}`, {
|
||||||
this.client.put(`/projects/${projectId}/merge_requests/${mr.iid}`, {
|
|
||||||
assignee_ids: assigneeIds.filter(a => a !== undefined),
|
assignee_ids: assigneeIds.filter(a => a !== undefined),
|
||||||
}).catch(error => this.logger.warn("Failure trying to update assignees. " + error))
|
});
|
||||||
);
|
} catch(error) {
|
||||||
|
this.logger.warn("Failure trying to update assignees. " + error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all(promises);
|
|
||||||
|
|
||||||
return mr.web_url;
|
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
|
* Retrieve a gitlab user given its username
|
||||||
|
@ -215,18 +175,9 @@ export default class GitLabClient implements GitClient {
|
||||||
* @returns {{owner: string, project: string}}
|
* @returns {{owner: string, project: string}}
|
||||||
*/
|
*/
|
||||||
private extractMergeRequestData(mrUrl: string): {namespace: string, project: string, id: number} {
|
private extractMergeRequestData(mrUrl: string): {namespace: string, project: string, id: number} {
|
||||||
const { pathname } = new URL(mrUrl);
|
const elems: string[] = mrUrl.replace("/-/", "/").split("/");
|
||||||
const elems: string[] = pathname.substring(1).replace("/-/", "/").split("/");
|
|
||||||
let namespace = "";
|
|
||||||
|
|
||||||
for (let i = 0; i < elems.length - 3; i++) {
|
|
||||||
namespace += elems[i] + "/";
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace = namespace.substring(0, namespace.length - 1);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
namespace: namespace,
|
namespace: elems[elems.length - 4],
|
||||||
project: elems[elems.length - 3],
|
project: elems[elems.length - 3],
|
||||||
id: parseInt(mrUrl.substring(mrUrl.lastIndexOf("/") + 1, mrUrl.length)),
|
id: parseInt(mrUrl.substring(mrUrl.lastIndexOf("/") + 1, mrUrl.length)),
|
||||||
};
|
};
|
||||||
|
|
|
@ -41,8 +41,8 @@ export default class GitLabMapper implements GitResponseMapper<MergeRequestSchem
|
||||||
sourceRepo: await this.mapSourceRepo(mr),
|
sourceRepo: await this.mapSourceRepo(mr),
|
||||||
targetRepo: await this.mapTargetRepo(mr),
|
targetRepo: await this.mapTargetRepo(mr),
|
||||||
// if commits list is provided use that as source
|
// if commits list is provided use that as source
|
||||||
nCommits: (commits && commits.length > 0) ? commits.length : 1,
|
nCommits: (commits && commits.length > 1) ? commits.length : 1,
|
||||||
commits: (commits && commits.length > 0) ? commits : this.getSha(mr)
|
commits: (commits && commits.length > 1) ? commits : this.getSha(mr)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,48 +5,32 @@ export default class ConsoleLoggerService implements LoggerService {
|
||||||
|
|
||||||
private readonly logger: Logger;
|
private readonly logger: Logger;
|
||||||
private readonly verbose: boolean;
|
private readonly verbose: boolean;
|
||||||
private context?: string;
|
|
||||||
|
|
||||||
constructor(verbose = true) {
|
constructor(verbose = true) {
|
||||||
this.logger = new Logger();
|
this.logger = new Logger();
|
||||||
this.verbose = verbose;
|
this.verbose = verbose;
|
||||||
}
|
}
|
||||||
|
|
||||||
setContext(newContext: string) {
|
|
||||||
this.context = newContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
getContext(): string | undefined {
|
|
||||||
return this.context;
|
|
||||||
}
|
|
||||||
|
|
||||||
clearContext() {
|
|
||||||
this.context = undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
trace(message: string): void {
|
trace(message: string): void {
|
||||||
this.logger.log("TRACE", this.fromContext(message));
|
this.logger.log("[TRACE]", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
debug(message: string): void {
|
debug(message: string): void {
|
||||||
if (this.verbose) {
|
if (this.verbose) {
|
||||||
this.logger.log("DEBUG", this.fromContext(message));
|
this.logger.log("[DEBUG]", message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
info(message: string): void {
|
info(message: string): void {
|
||||||
this.logger.log("INFO", this.fromContext(message));
|
this.logger.log("[INFO]", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
warn(message: string): void {
|
warn(message: string): void {
|
||||||
this.logger.log("WARN", this.fromContext(message));
|
this.logger.log("[WARN]", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
error(message: string): void {
|
error(message: string): void {
|
||||||
this.logger.log("ERROR", this.fromContext(message));
|
this.logger.log("[ERROR]", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
private fromContext(msg: string): string {
|
|
||||||
return this.context ? `[${this.context}] ${msg}` : msg;
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -3,12 +3,6 @@
|
||||||
*/
|
*/
|
||||||
export default interface LoggerService {
|
export default interface LoggerService {
|
||||||
|
|
||||||
setContext(newContext: string): void;
|
|
||||||
|
|
||||||
getContext(): string | undefined;
|
|
||||||
|
|
||||||
clearContext(): void;
|
|
||||||
|
|
||||||
trace(message: string): void;
|
trace(message: string): void;
|
||||||
|
|
||||||
debug(message: string): void;
|
debug(message: string): void;
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
log(prefix: string, ...str: string[]) {
|
log(prefix: string, ...str: string[]) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log.apply(console, [`[${prefix.padEnd(5)}]`, ...str]);
|
console.log.apply(console, [prefix, ...str]);
|
||||||
}
|
}
|
||||||
|
|
||||||
emptyLine() {
|
emptyLine() {
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
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);
|
|
||||||
};
|
|
|
@ -8,14 +8,7 @@ import GitClientFactory from "@bp/service/git/git-client-factory";
|
||||||
import { BackportPullRequest, GitClientType, GitPullRequest } from "@bp/service/git/git.types";
|
import { BackportPullRequest, GitClientType, GitPullRequest } from "@bp/service/git/git.types";
|
||||||
import LoggerService from "@bp/service/logger/logger-service";
|
import LoggerService from "@bp/service/logger/logger-service";
|
||||||
import LoggerServiceFactory from "@bp/service/logger/logger-service-factory";
|
import LoggerServiceFactory from "@bp/service/logger/logger-service-factory";
|
||||||
import { inferGitClient, inferGitApiUrl, getGitTokenFromEnv } from "@bp/service/git/git-util";
|
import { inferGitClient, inferGitApiUrl } from "@bp/service/git/git-util";
|
||||||
import { injectError, injectTargetBranch } from "./runner-util";
|
|
||||||
|
|
||||||
interface Git {
|
|
||||||
gitClientType: GitClientType;
|
|
||||||
gitClientApi: GitClient;
|
|
||||||
gitCli: GitCLIService;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main runner implementation, it implements the core logic flow
|
* Main runner implementation, it implements the core logic flow
|
||||||
|
@ -37,13 +30,13 @@ export default class Runner {
|
||||||
try {
|
try {
|
||||||
await this.execute();
|
await this.execute();
|
||||||
|
|
||||||
this.logger.info("Process succeeded");
|
this.logger.info("Process succeeded!");
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(`${error}`);
|
this.logger.error(`${error}`);
|
||||||
|
|
||||||
this.logger.info("Process failed");
|
this.logger.info("Process failed!");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,118 +50,71 @@ export default class Runner {
|
||||||
const args: Args = this.argsParser.parse();
|
const args: Args = this.argsParser.parse();
|
||||||
|
|
||||||
if (args.dryRun) {
|
if (args.dryRun) {
|
||||||
this.logger.warn("Dry run enabled");
|
this.logger.warn("Dry run enabled!");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. init git service
|
// 2. init git service
|
||||||
let gitClientType: GitClientType;
|
const gitClientType: GitClientType = inferGitClient(args.pullRequest);
|
||||||
if (args.gitClient === undefined) {
|
// right now the apiVersion is set to v4
|
||||||
gitClientType = inferGitClient(args.pullRequest);
|
const apiUrl = inferGitApiUrl(args.pullRequest);
|
||||||
} else {
|
const gitApi: GitClient = GitClientFactory.getOrCreate(gitClientType, args.auth, apiUrl);
|
||||||
gitClientType = args.gitClient as GitClientType;
|
|
||||||
}
|
|
||||||
// the api version is ignored in case of github
|
|
||||||
const apiUrl = inferGitApiUrl(args.pullRequest, gitClientType === GitClientType.CODEBERG ? "v1" : undefined);
|
|
||||||
const token = this.fetchToken(args, gitClientType);
|
|
||||||
const gitApi: GitClient = GitClientFactory.getOrCreate(gitClientType, token, apiUrl);
|
|
||||||
|
|
||||||
// 3. parse configs
|
// 3. parse configs
|
||||||
this.logger.debug("Parsing configs..");
|
this.logger.debug("Parsing configs..");
|
||||||
args.auth = token; // override auth
|
|
||||||
const configs: Configs = await new PullRequestConfigsParser().parseAndValidate(args);
|
const configs: Configs = await new PullRequestConfigsParser().parseAndValidate(args);
|
||||||
const backportPRs: BackportPullRequest[] = configs.backportPullRequests;
|
const originalPR: GitPullRequest = configs.originalPullRequest;
|
||||||
|
const backportPR: GitPullRequest = configs.backportPullRequest;
|
||||||
|
|
||||||
// start local git operations
|
// start local git operations
|
||||||
const git: GitCLIService = new GitCLIService(configs.auth, configs.git);
|
const git: GitCLIService = new GitCLIService(configs.auth, configs.git);
|
||||||
|
|
||||||
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) {
|
|
||||||
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}`);
|
|
||||||
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, pr.base);
|
|
||||||
await gitApi.createPullRequestComment(configs.originalPullRequest.url, comment);
|
|
||||||
}
|
|
||||||
failures.push(error as string);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (failures.length > 0) {
|
|
||||||
throw new Error(`Failure occurred during one of the backports: [${failures.join(" ; ")}]`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch the GIT token from the provided Args obj, if not empty, otherwise fallback
|
|
||||||
* to the environment variables.
|
|
||||||
* @param args input arguments
|
|
||||||
* @param gitType git client type
|
|
||||||
* @returns the provided or fetched token, or undefined if not set anywhere
|
|
||||||
*/
|
|
||||||
fetchToken(args: Args, gitType: GitClientType): string | undefined {
|
|
||||||
let token = args.auth;
|
|
||||||
if (token === undefined) {
|
|
||||||
// try to fetch the auth from env variable
|
|
||||||
this.logger.info("Auth argument not provided, checking available tokens from env..");
|
|
||||||
token = getGitTokenFromEnv(gitType);
|
|
||||||
if (!token) {
|
|
||||||
this.logger.info("Git token not found in the environment");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return token;
|
|
||||||
}
|
|
||||||
|
|
||||||
async executeBackport(configs: Configs, backportPR: BackportPullRequest, git: Git): Promise<void> {
|
|
||||||
this.logger.setContext(backportPR.base);
|
|
||||||
|
|
||||||
const originalPR: GitPullRequest = configs.originalPullRequest;
|
|
||||||
|
|
||||||
// 4. clone the repository
|
// 4. clone the repository
|
||||||
this.logger.debug("Cloning repo..");
|
this.logger.debug("Cloning repo..");
|
||||||
await git.gitCli.clone(configs.originalPullRequest.targetRepo.cloneUrl, configs.folder, backportPR.base);
|
await git.clone(configs.originalPullRequest.targetRepo.cloneUrl, configs.folder, configs.targetBranch);
|
||||||
|
|
||||||
// 5. create new branch from target one and checkout
|
// 5. create new branch from target one and checkout
|
||||||
this.logger.debug("Creating local branch..");
|
this.logger.debug("Creating local branch..");
|
||||||
await git.gitCli.createLocalBranch(configs.folder, backportPR.head);
|
const backportBranch = backportPR.branchName ?? `bp-${configs.targetBranch}-${originalPR.commits!.join("-")}`;
|
||||||
|
await git.createLocalBranch(configs.folder, backportBranch);
|
||||||
|
|
||||||
// 6. fetch pull request remote if source owner != target owner or pull request still open
|
// 6. fetch pull request remote if source owner != target owner or pull request still open
|
||||||
if (configs.originalPullRequest.sourceRepo.owner !== configs.originalPullRequest.targetRepo.owner ||
|
if (configs.originalPullRequest.sourceRepo.owner !== configs.originalPullRequest.targetRepo.owner ||
|
||||||
configs.originalPullRequest.state === "open") {
|
configs.originalPullRequest.state === "open") {
|
||||||
this.logger.debug("Fetching pull request remote..");
|
this.logger.debug("Fetching pull request remote..");
|
||||||
const prefix = git.gitClientType === GitClientType.GITLAB ? "merge-requests" : "pull" ; // default is for gitlab
|
const prefix = gitClientType === GitClientType.GITHUB ? "pull" : "merge-requests"; // default is for gitlab
|
||||||
await git.gitCli.fetch(configs.folder, `${prefix}/${configs.originalPullRequest.number}/head:pr/${configs.originalPullRequest.number}`);
|
await git.fetch(configs.folder, `${prefix}/${configs.originalPullRequest.number}/head:pr/${configs.originalPullRequest.number}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7. apply all changes to the new branch
|
// 7. apply all changes to the new branch
|
||||||
this.logger.debug("Cherry picking commits..");
|
this.logger.debug("Cherry picking commits..");
|
||||||
for (const sha of originalPR.commits) {
|
for (const sha of originalPR.commits!) {
|
||||||
await git.gitCli.cherryPick(configs.folder, sha, configs.mergeStrategy, configs.mergeStrategyOption, configs.cherryPickOptions);
|
await git.cherryPick(configs.folder, sha);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const backport: BackportPullRequest = {
|
||||||
|
owner: originalPR.targetRepo.owner,
|
||||||
|
repo: originalPR.targetRepo.project,
|
||||||
|
head: backportBranch,
|
||||||
|
base: configs.targetBranch,
|
||||||
|
title: backportPR.title,
|
||||||
|
body: backportPR.body,
|
||||||
|
reviewers: backportPR.reviewers,
|
||||||
|
assignees: backportPR.assignees,
|
||||||
|
labels: backportPR.labels,
|
||||||
|
};
|
||||||
|
|
||||||
if (!configs.dryRun) {
|
if (!configs.dryRun) {
|
||||||
// 8. push the new branch to origin
|
// 8. push the new branch to origin
|
||||||
await git.gitCli.push(configs.folder, backportPR.head);
|
await git.push(configs.folder, backportBranch);
|
||||||
|
|
||||||
// 9. create pull request new branch -> target branch (using octokit)
|
// 9. create pull request new branch -> target branch (using octokit)
|
||||||
const prUrl = await git.gitClientApi.createPullRequest(backportPR);
|
const prUrl = await gitApi.createPullRequest(backport);
|
||||||
this.logger.info(`Pull request created: ${prUrl}`);
|
this.logger.info(`Pull request created: ${prUrl}`);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
this.logger.warn("Pull request creation and remote push skipped");
|
this.logger.warn("Pull request creation and remote push skipped!");
|
||||||
this.logger.info(`${JSON.stringify(backportPR, null, 2)}`);
|
this.logger.info(`${JSON.stringify(backport, null, 2)}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.clearContext();
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -15,7 +15,6 @@ const RANDOM_CONFIG_FILE_CONTENT = {
|
||||||
"targetBranch": "target-branch-name",
|
"targetBranch": "target-branch-name",
|
||||||
"pullRequest": "https://github.com/user/repo/pull/123",
|
"pullRequest": "https://github.com/user/repo/pull/123",
|
||||||
"folder": "/path/to/local/folder",
|
"folder": "/path/to/local/folder",
|
||||||
"gitClient": "codeberg",
|
|
||||||
"gitUser": "YourGitUser",
|
"gitUser": "YourGitUser",
|
||||||
"gitEmail": "your-email@example.com",
|
"gitEmail": "your-email@example.com",
|
||||||
"title": "Backport: Original PR Title",
|
"title": "Backport: Original PR Title",
|
||||||
|
@ -45,11 +44,11 @@ describe("cli args parser", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// reset process.env variables
|
|
||||||
resetProcessArgs();
|
|
||||||
|
|
||||||
// create a fresh new instance every time
|
// create a fresh new instance every time
|
||||||
parser = new CLIArgsParser();
|
parser = new CLIArgsParser();
|
||||||
|
|
||||||
|
// reset process.env variables
|
||||||
|
resetProcessArgs();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("valid execution [default, short]", () => {
|
test("valid execution [default, short]", () => {
|
||||||
|
@ -63,7 +62,6 @@ describe("cli args parser", () => {
|
||||||
const args: Args = parser.parse();
|
const args: Args = parser.parse();
|
||||||
expect(args.dryRun).toEqual(false);
|
expect(args.dryRun).toEqual(false);
|
||||||
expect(args.auth).toEqual(undefined);
|
expect(args.auth).toEqual(undefined);
|
||||||
expect(args.gitClient).toEqual(undefined);
|
|
||||||
expect(args.gitUser).toEqual(undefined);
|
expect(args.gitUser).toEqual(undefined);
|
||||||
expect(args.gitEmail).toEqual(undefined);
|
expect(args.gitEmail).toEqual(undefined);
|
||||||
expect(args.folder).toEqual(undefined);
|
expect(args.folder).toEqual(undefined);
|
||||||
|
@ -79,11 +77,6 @@ describe("cli args parser", () => {
|
||||||
expect(args.labels).toEqual([]);
|
expect(args.labels).toEqual([]);
|
||||||
expect(args.inheritLabels).toEqual(false);
|
expect(args.inheritLabels).toEqual(false);
|
||||||
expect(args.squash).toEqual(true);
|
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]", () => {
|
test("with config file [default, short]", () => {
|
||||||
|
@ -95,7 +88,6 @@ describe("cli args parser", () => {
|
||||||
const args: Args = parser.parse();
|
const args: Args = parser.parse();
|
||||||
expect(args.dryRun).toEqual(false);
|
expect(args.dryRun).toEqual(false);
|
||||||
expect(args.auth).toEqual(undefined);
|
expect(args.auth).toEqual(undefined);
|
||||||
expect(args.gitClient).toEqual(undefined);
|
|
||||||
expect(args.gitUser).toEqual(undefined);
|
expect(args.gitUser).toEqual(undefined);
|
||||||
expect(args.gitEmail).toEqual(undefined);
|
expect(args.gitEmail).toEqual(undefined);
|
||||||
expect(args.folder).toEqual(undefined);
|
expect(args.folder).toEqual(undefined);
|
||||||
|
@ -111,11 +103,6 @@ describe("cli args parser", () => {
|
||||||
expect(args.labels).toEqual([]);
|
expect(args.labels).toEqual([]);
|
||||||
expect(args.inheritLabels).toEqual(false);
|
expect(args.inheritLabels).toEqual(false);
|
||||||
expect(args.squash).toEqual(true);
|
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]", () => {
|
test("valid execution [default, long]", () => {
|
||||||
|
@ -129,7 +116,6 @@ describe("cli args parser", () => {
|
||||||
const args: Args = parser.parse();
|
const args: Args = parser.parse();
|
||||||
expect(args.dryRun).toEqual(false);
|
expect(args.dryRun).toEqual(false);
|
||||||
expect(args.auth).toEqual(undefined);
|
expect(args.auth).toEqual(undefined);
|
||||||
expect(args.gitClient).toEqual(undefined);
|
|
||||||
expect(args.gitUser).toEqual(undefined);
|
expect(args.gitUser).toEqual(undefined);
|
||||||
expect(args.gitEmail).toEqual(undefined);
|
expect(args.gitEmail).toEqual(undefined);
|
||||||
expect(args.folder).toEqual(undefined);
|
expect(args.folder).toEqual(undefined);
|
||||||
|
@ -145,9 +131,6 @@ describe("cli args parser", () => {
|
||||||
expect(args.labels).toEqual([]);
|
expect(args.labels).toEqual([]);
|
||||||
expect(args.inheritLabels).toEqual(false);
|
expect(args.inheritLabels).toEqual(false);
|
||||||
expect(args.squash).toEqual(true);
|
expect(args.squash).toEqual(true);
|
||||||
expect(args.strategy).toEqual(undefined);
|
|
||||||
expect(args.strategyOption).toEqual(undefined);
|
|
||||||
expect(args.cherryPickOptions).toEqual(undefined);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("with config file [default, long]", () => {
|
test("with config file [default, long]", () => {
|
||||||
|
@ -159,7 +142,6 @@ describe("cli args parser", () => {
|
||||||
const args: Args = parser.parse();
|
const args: Args = parser.parse();
|
||||||
expect(args.dryRun).toEqual(false);
|
expect(args.dryRun).toEqual(false);
|
||||||
expect(args.auth).toEqual(undefined);
|
expect(args.auth).toEqual(undefined);
|
||||||
expect(args.gitClient).toEqual(undefined);
|
|
||||||
expect(args.gitUser).toEqual(undefined);
|
expect(args.gitUser).toEqual(undefined);
|
||||||
expect(args.gitEmail).toEqual(undefined);
|
expect(args.gitEmail).toEqual(undefined);
|
||||||
expect(args.folder).toEqual(undefined);
|
expect(args.folder).toEqual(undefined);
|
||||||
|
@ -175,9 +157,6 @@ describe("cli args parser", () => {
|
||||||
expect(args.labels).toEqual([]);
|
expect(args.labels).toEqual([]);
|
||||||
expect(args.inheritLabels).toEqual(false);
|
expect(args.inheritLabels).toEqual(false);
|
||||||
expect(args.squash).toEqual(true);
|
expect(args.squash).toEqual(true);
|
||||||
expect(args.strategy).toEqual(undefined);
|
|
||||||
expect(args.strategyOption).toEqual(undefined);
|
|
||||||
expect(args.cherryPickOptions).toEqual(undefined);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("valid execution [override, short]", () => {
|
test("valid execution [override, short]", () => {
|
||||||
|
@ -198,7 +177,6 @@ describe("cli args parser", () => {
|
||||||
const args: Args = parser.parse();
|
const args: Args = parser.parse();
|
||||||
expect(args.dryRun).toEqual(true);
|
expect(args.dryRun).toEqual(true);
|
||||||
expect(args.auth).toEqual("bearer-token");
|
expect(args.auth).toEqual("bearer-token");
|
||||||
expect(args.gitClient).toEqual(undefined);
|
|
||||||
expect(args.gitUser).toEqual("Me");
|
expect(args.gitUser).toEqual("Me");
|
||||||
expect(args.gitEmail).toEqual("me@email.com");
|
expect(args.gitEmail).toEqual("me@email.com");
|
||||||
expect(args.folder).toEqual(undefined);
|
expect(args.folder).toEqual(undefined);
|
||||||
|
@ -214,9 +192,6 @@ describe("cli args parser", () => {
|
||||||
expect(args.labels).toEqual([]);
|
expect(args.labels).toEqual([]);
|
||||||
expect(args.inheritLabels).toEqual(false);
|
expect(args.inheritLabels).toEqual(false);
|
||||||
expect(args.squash).toEqual(true);
|
expect(args.squash).toEqual(true);
|
||||||
expect(args.strategy).toEqual(undefined);
|
|
||||||
expect(args.strategyOption).toEqual(undefined);
|
|
||||||
expect(args.cherryPickOptions).toEqual(undefined);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("valid execution [override, long]", () => {
|
test("valid execution [override, long]", () => {
|
||||||
|
@ -228,8 +203,6 @@ describe("cli args parser", () => {
|
||||||
"target",
|
"target",
|
||||||
"--pull-request",
|
"--pull-request",
|
||||||
"https://localhost/whatever/pulls/1",
|
"https://localhost/whatever/pulls/1",
|
||||||
"--git-client",
|
|
||||||
"codeberg",
|
|
||||||
"--git-user",
|
"--git-user",
|
||||||
"Me",
|
"Me",
|
||||||
"--git-email",
|
"--git-email",
|
||||||
|
@ -255,7 +228,6 @@ describe("cli args parser", () => {
|
||||||
const args: Args = parser.parse();
|
const args: Args = parser.parse();
|
||||||
expect(args.dryRun).toEqual(true);
|
expect(args.dryRun).toEqual(true);
|
||||||
expect(args.auth).toEqual("bearer-token");
|
expect(args.auth).toEqual("bearer-token");
|
||||||
expect(args.gitClient).toEqual("codeberg");
|
|
||||||
expect(args.gitUser).toEqual("Me");
|
expect(args.gitUser).toEqual("Me");
|
||||||
expect(args.gitEmail).toEqual("me@email.com");
|
expect(args.gitEmail).toEqual("me@email.com");
|
||||||
expect(args.folder).toEqual(undefined);
|
expect(args.folder).toEqual(undefined);
|
||||||
|
@ -271,9 +243,6 @@ describe("cli args parser", () => {
|
||||||
expectArrayEqual(args.labels!, ["cherry-pick :cherries:", "another spaced label"]);
|
expectArrayEqual(args.labels!, ["cherry-pick :cherries:", "another spaced label"]);
|
||||||
expect(args.inheritLabels).toEqual(true);
|
expect(args.inheritLabels).toEqual(true);
|
||||||
expect(args.squash).toEqual(true);
|
expect(args.squash).toEqual(true);
|
||||||
expect(args.strategy).toEqual(undefined);
|
|
||||||
expect(args.strategyOption).toEqual(undefined);
|
|
||||||
expect(args.cherryPickOptions).toEqual(undefined);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("override using config file", () => {
|
test("override using config file", () => {
|
||||||
|
@ -285,7 +254,6 @@ describe("cli args parser", () => {
|
||||||
const args: Args = parser.parse();
|
const args: Args = parser.parse();
|
||||||
expect(args.dryRun).toEqual(true);
|
expect(args.dryRun).toEqual(true);
|
||||||
expect(args.auth).toEqual("your-git-service-auth-token");
|
expect(args.auth).toEqual("your-git-service-auth-token");
|
||||||
expect(args.gitClient).toEqual("codeberg");
|
|
||||||
expect(args.gitUser).toEqual("YourGitUser");
|
expect(args.gitUser).toEqual("YourGitUser");
|
||||||
expect(args.gitEmail).toEqual("your-email@example.com");
|
expect(args.gitEmail).toEqual("your-email@example.com");
|
||||||
expect(args.folder).toEqual("/path/to/local/folder");
|
expect(args.folder).toEqual("/path/to/local/folder");
|
||||||
|
@ -301,9 +269,6 @@ describe("cli args parser", () => {
|
||||||
expectArrayEqual(args.labels!, ["cherry-pick :cherries:"]);
|
expectArrayEqual(args.labels!, ["cherry-pick :cherries:"]);
|
||||||
expect(args.inheritLabels).toEqual(true);
|
expect(args.inheritLabels).toEqual(true);
|
||||||
expect(args.squash).toEqual(true);
|
expect(args.squash).toEqual(true);
|
||||||
expect(args.strategy).toEqual(undefined);
|
|
||||||
expect(args.strategyOption).toEqual(undefined);
|
|
||||||
expect(args.cherryPickOptions).toEqual(undefined);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("ignore custom option when config file is set", () => {
|
test("ignore custom option when config file is set", () => {
|
||||||
|
@ -317,8 +282,6 @@ describe("cli args parser", () => {
|
||||||
"target",
|
"target",
|
||||||
"--pull-request",
|
"--pull-request",
|
||||||
"https://localhost/whatever/pulls/1",
|
"https://localhost/whatever/pulls/1",
|
||||||
"--git-client",
|
|
||||||
"github",
|
|
||||||
"--git-user",
|
"--git-user",
|
||||||
"Me",
|
"Me",
|
||||||
"--git-email",
|
"--git-email",
|
||||||
|
@ -344,7 +307,6 @@ describe("cli args parser", () => {
|
||||||
const args: Args = parser.parse();
|
const args: Args = parser.parse();
|
||||||
expect(args.dryRun).toEqual(true);
|
expect(args.dryRun).toEqual(true);
|
||||||
expect(args.auth).toEqual("your-git-service-auth-token");
|
expect(args.auth).toEqual("your-git-service-auth-token");
|
||||||
expect(args.gitClient).toEqual("codeberg");
|
|
||||||
expect(args.gitUser).toEqual("YourGitUser");
|
expect(args.gitUser).toEqual("YourGitUser");
|
||||||
expect(args.gitEmail).toEqual("your-email@example.com");
|
expect(args.gitEmail).toEqual("your-email@example.com");
|
||||||
expect(args.folder).toEqual("/path/to/local/folder");
|
expect(args.folder).toEqual("/path/to/local/folder");
|
||||||
|
@ -360,9 +322,6 @@ describe("cli args parser", () => {
|
||||||
expectArrayEqual(args.labels!, ["cherry-pick :cherries:"]);
|
expectArrayEqual(args.labels!, ["cherry-pick :cherries:"]);
|
||||||
expect(args.inheritLabels).toEqual(true);
|
expect(args.inheritLabels).toEqual(true);
|
||||||
expect(args.squash).toEqual(true);
|
expect(args.squash).toEqual(true);
|
||||||
expect(args.strategy).toEqual(undefined);
|
|
||||||
expect(args.strategyOption).toEqual(undefined);
|
|
||||||
expect(args.cherryPickOptions).toEqual(undefined);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("override squash to false", () => {
|
test("override squash to false", () => {
|
||||||
|
@ -377,7 +336,6 @@ describe("cli args parser", () => {
|
||||||
const args: Args = parser.parse();
|
const args: Args = parser.parse();
|
||||||
expect(args.dryRun).toEqual(false);
|
expect(args.dryRun).toEqual(false);
|
||||||
expect(args.auth).toEqual(undefined);
|
expect(args.auth).toEqual(undefined);
|
||||||
expect(args.gitClient).toEqual(undefined);
|
|
||||||
expect(args.gitUser).toEqual(undefined);
|
expect(args.gitUser).toEqual(undefined);
|
||||||
expect(args.gitEmail).toEqual(undefined);
|
expect(args.gitEmail).toEqual(undefined);
|
||||||
expect(args.folder).toEqual(undefined);
|
expect(args.folder).toEqual(undefined);
|
||||||
|
@ -394,148 +352,4 @@ describe("cli args parser", () => {
|
||||||
expect(args.inheritLabels).toEqual(false);
|
expect(args.inheritLabels).toEqual(false);
|
||||||
expect(args.squash).toEqual(false);
|
expect(args.squash).toEqual(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("override cherry pick strategies and options", () => {
|
|
||||||
addProcessArgs([
|
|
||||||
"--target-branch",
|
|
||||||
"target",
|
|
||||||
"--pull-request",
|
|
||||||
"https://localhost/whatever/pulls/1",
|
|
||||||
"--strategy",
|
|
||||||
"ort",
|
|
||||||
"--strategy-option",
|
|
||||||
"ours",
|
|
||||||
"--cherry-pick-options",
|
|
||||||
"--allow-empty -x",
|
|
||||||
]);
|
|
||||||
|
|
||||||
const args: Args = parser.parse();
|
|
||||||
expect(args.dryRun).toEqual(false);
|
|
||||||
expect(args.auth).toEqual(undefined);
|
|
||||||
expect(args.gitClient).toEqual(undefined);
|
|
||||||
expect(args.gitUser).toEqual(undefined);
|
|
||||||
expect(args.gitEmail).toEqual(undefined);
|
|
||||||
expect(args.folder).toEqual(undefined);
|
|
||||||
expect(args.targetBranch).toEqual("target");
|
|
||||||
expect(args.pullRequest).toEqual("https://localhost/whatever/pulls/1");
|
|
||||||
expect(args.title).toEqual(undefined);
|
|
||||||
expect(args.body).toEqual(undefined);
|
|
||||||
expect(args.bodyPrefix).toEqual(undefined);
|
|
||||||
expect(args.bpBranchName).toEqual(undefined);
|
|
||||||
expect(args.reviewers).toEqual([]);
|
|
||||||
expect(args.assignees).toEqual([]);
|
|
||||||
expect(args.inheritReviewers).toEqual(true);
|
|
||||||
expect(args.labels).toEqual([]);
|
|
||||||
expect(args.inheritLabels).toEqual(false);
|
|
||||||
expect(args.squash).toEqual(true);
|
|
||||||
expect(args.strategy).toEqual("ort");
|
|
||||||
expect(args.strategyOption).toEqual("ours");
|
|
||||||
expect(args.cherryPickOptions).toEqual("--allow-empty -x");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("additional pr comments", () => {
|
|
||||||
addProcessArgs([
|
|
||||||
"--target-branch",
|
|
||||||
"target",
|
|
||||||
"--pull-request",
|
|
||||||
"https://localhost/whatever/pulls/1",
|
|
||||||
"--comments",
|
|
||||||
"first comment;second comment",
|
|
||||||
]);
|
|
||||||
|
|
||||||
const args: Args = parser.parse();
|
|
||||||
expect(args.dryRun).toEqual(false);
|
|
||||||
expect(args.auth).toEqual(undefined);
|
|
||||||
expect(args.gitClient).toEqual(undefined);
|
|
||||||
expect(args.gitUser).toEqual(undefined);
|
|
||||||
expect(args.gitEmail).toEqual(undefined);
|
|
||||||
expect(args.folder).toEqual(undefined);
|
|
||||||
expect(args.targetBranch).toEqual("target");
|
|
||||||
expect(args.pullRequest).toEqual("https://localhost/whatever/pulls/1");
|
|
||||||
expect(args.title).toEqual(undefined);
|
|
||||||
expect(args.body).toEqual(undefined);
|
|
||||||
expect(args.bodyPrefix).toEqual(undefined);
|
|
||||||
expect(args.bpBranchName).toEqual(undefined);
|
|
||||||
expect(args.reviewers).toEqual([]);
|
|
||||||
expect(args.assignees).toEqual([]);
|
|
||||||
expect(args.inheritReviewers).toEqual(true);
|
|
||||||
expect(args.labels).toEqual([]);
|
|
||||||
expect(args.inheritLabels).toEqual(false);
|
|
||||||
expect(args.squash).toEqual(true);
|
|
||||||
expectArrayEqual(args.comments!,["first comment", "second comment"]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("valid execution with multiple branches", () => {
|
|
||||||
addProcessArgs([
|
|
||||||
"-tb",
|
|
||||||
"target, old",
|
|
||||||
"-pr",
|
|
||||||
"https://localhost/whatever/pulls/1"
|
|
||||||
]);
|
|
||||||
|
|
||||||
const args: Args = parser.parse();
|
|
||||||
expect(args.dryRun).toEqual(false);
|
|
||||||
expect(args.auth).toEqual(undefined);
|
|
||||||
expect(args.gitClient).toEqual(undefined);
|
|
||||||
expect(args.gitUser).toEqual(undefined);
|
|
||||||
expect(args.gitEmail).toEqual(undefined);
|
|
||||||
expect(args.folder).toEqual(undefined);
|
|
||||||
expect(args.targetBranch).toEqual("target, old");
|
|
||||||
expect(args.pullRequest).toEqual("https://localhost/whatever/pulls/1");
|
|
||||||
expect(args.title).toEqual(undefined);
|
|
||||||
expect(args.body).toEqual(undefined);
|
|
||||||
expect(args.bodyPrefix).toEqual(undefined);
|
|
||||||
expect(args.bpBranchName).toEqual(undefined);
|
|
||||||
expect(args.reviewers).toEqual([]);
|
|
||||||
expect(args.assignees).toEqual([]);
|
|
||||||
expect(args.inheritReviewers).toEqual(true);
|
|
||||||
expect(args.labels).toEqual([]);
|
|
||||||
expect(args.inheritLabels).toEqual(false);
|
|
||||||
expect(args.squash).toEqual(true);
|
|
||||||
expect(args.strategy).toEqual(undefined);
|
|
||||||
expect(args.strategyOption).toEqual(undefined);
|
|
||||||
expect(args.cherryPickOptions).toEqual(undefined);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("invalid execution with empty target branch", () => {
|
|
||||||
addProcessArgs([
|
|
||||||
"-tb",
|
|
||||||
" ",
|
|
||||||
"-pr",
|
|
||||||
"https://localhost/whatever/pulls/1"
|
|
||||||
]);
|
|
||||||
|
|
||||||
expect(() => parser.parse()).toThrowError("Missing option: target branch(es) or target regular expression must be provided");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("invalid execution with missing mandatory target branch", () => {
|
|
||||||
addProcessArgs([
|
|
||||||
"-pr",
|
|
||||||
"https://localhost/whatever/pulls/1"
|
|
||||||
]);
|
|
||||||
|
|
||||||
expect(() => parser.parse()).toThrowError("Missing option: target branch(es) or target regular expression must be provided");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("invalid execution with missing mandatory pull request", () => {
|
|
||||||
addProcessArgs([
|
|
||||||
"-tb",
|
|
||||||
"target",
|
|
||||||
]);
|
|
||||||
|
|
||||||
expect(() => parser.parse()).toThrowError("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);
|
|
||||||
});
|
|
||||||
});
|
});
|
|
@ -70,9 +70,6 @@ describe("gha args parser", () => {
|
||||||
expect(args.labels).toEqual([]);
|
expect(args.labels).toEqual([]);
|
||||||
expect(args.inheritLabels).toEqual(false);
|
expect(args.inheritLabels).toEqual(false);
|
||||||
expect(args.squash).toEqual(true);
|
expect(args.squash).toEqual(true);
|
||||||
expect(args.strategy).toEqual(undefined);
|
|
||||||
expect(args.strategyOption).toEqual(undefined);
|
|
||||||
expect(args.cherryPickOptions).toEqual(undefined);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("valid execution [override]", () => {
|
test("valid execution [override]", () => {
|
||||||
|
@ -112,9 +109,6 @@ describe("gha args parser", () => {
|
||||||
expectArrayEqual(args.labels!, ["cherry-pick :cherries:", "another spaced label"]);
|
expectArrayEqual(args.labels!, ["cherry-pick :cherries:", "another spaced label"]);
|
||||||
expect(args.inheritLabels).toEqual(true);
|
expect(args.inheritLabels).toEqual(true);
|
||||||
expect(args.squash).toEqual(true);
|
expect(args.squash).toEqual(true);
|
||||||
expect(args.strategy).toEqual(undefined);
|
|
||||||
expect(args.strategyOption).toEqual(undefined);
|
|
||||||
expect(args.cherryPickOptions).toEqual(undefined);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("using config file", () => {
|
test("using config file", () => {
|
||||||
|
@ -140,9 +134,6 @@ describe("gha args parser", () => {
|
||||||
expectArrayEqual(args.labels!, []);
|
expectArrayEqual(args.labels!, []);
|
||||||
expect(args.inheritLabels).toEqual(false);
|
expect(args.inheritLabels).toEqual(false);
|
||||||
expect(args.squash).toEqual(true);
|
expect(args.squash).toEqual(true);
|
||||||
expect(args.strategy).toEqual(undefined);
|
|
||||||
expect(args.strategyOption).toEqual(undefined);
|
|
||||||
expect(args.cherryPickOptions).toEqual(undefined);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("ignore custom options when using config file", () => {
|
test("ignore custom options when using config file", () => {
|
||||||
|
@ -183,9 +174,6 @@ describe("gha args parser", () => {
|
||||||
expectArrayEqual(args.labels!, ["cherry-pick :cherries:"]);
|
expectArrayEqual(args.labels!, ["cherry-pick :cherries:"]);
|
||||||
expect(args.inheritLabels).toEqual(true);
|
expect(args.inheritLabels).toEqual(true);
|
||||||
expect(args.squash).toEqual(true);
|
expect(args.squash).toEqual(true);
|
||||||
expect(args.strategy).toEqual(undefined);
|
|
||||||
expect(args.strategyOption).toEqual(undefined);
|
|
||||||
expect(args.cherryPickOptions).toEqual(undefined);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("override squash to false", () => {
|
test("override squash to false", () => {
|
||||||
|
@ -212,122 +200,4 @@ describe("gha args parser", () => {
|
||||||
expect(args.inheritLabels).toEqual(false);
|
expect(args.inheritLabels).toEqual(false);
|
||||||
expect(args.squash).toEqual(false);
|
expect(args.squash).toEqual(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("override cherry pick strategy", () => {
|
|
||||||
spyGetInput({
|
|
||||||
"target-branch": "target",
|
|
||||||
"pull-request": "https://localhost/whatever/pulls/1",
|
|
||||||
"strategy": "ort",
|
|
||||||
"strategy-option": "ours",
|
|
||||||
});
|
|
||||||
|
|
||||||
const args: Args = parser.parse();
|
|
||||||
expect(args.dryRun).toEqual(false);
|
|
||||||
expect(args.auth).toEqual(undefined);
|
|
||||||
expect(args.gitUser).toEqual(undefined);
|
|
||||||
expect(args.gitEmail).toEqual(undefined);
|
|
||||||
expect(args.folder).toEqual(undefined);
|
|
||||||
expect(args.targetBranch).toEqual("target");
|
|
||||||
expect(args.pullRequest).toEqual("https://localhost/whatever/pulls/1");
|
|
||||||
expect(args.title).toEqual(undefined);
|
|
||||||
expect(args.body).toEqual(undefined);
|
|
||||||
expect(args.reviewers).toEqual([]);
|
|
||||||
expect(args.assignees).toEqual([]);
|
|
||||||
expect(args.inheritReviewers).toEqual(true);
|
|
||||||
expect(args.labels).toEqual([]);
|
|
||||||
expect(args.inheritLabels).toEqual(false);
|
|
||||||
expect(args.squash).toEqual(true);
|
|
||||||
expect(args.strategy).toEqual("ort");
|
|
||||||
expect(args.strategyOption).toEqual("ours");
|
|
||||||
expect(args.cherryPickOptions).toEqual(undefined);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("additional pr comments", () => {
|
|
||||||
spyGetInput({
|
|
||||||
"target-branch": "target",
|
|
||||||
"pull-request": "https://localhost/whatever/pulls/1",
|
|
||||||
"comments": "first comment;second comment",
|
|
||||||
});
|
|
||||||
|
|
||||||
const args: Args = parser.parse();
|
|
||||||
expect(args.dryRun).toEqual(false);
|
|
||||||
expect(args.auth).toEqual(undefined);
|
|
||||||
expect(args.gitUser).toEqual(undefined);
|
|
||||||
expect(args.gitEmail).toEqual(undefined);
|
|
||||||
expect(args.folder).toEqual(undefined);
|
|
||||||
expect(args.targetBranch).toEqual("target");
|
|
||||||
expect(args.pullRequest).toEqual("https://localhost/whatever/pulls/1");
|
|
||||||
expect(args.title).toEqual(undefined);
|
|
||||||
expect(args.body).toEqual(undefined);
|
|
||||||
expect(args.reviewers).toEqual([]);
|
|
||||||
expect(args.assignees).toEqual([]);
|
|
||||||
expect(args.inheritReviewers).toEqual(true);
|
|
||||||
expect(args.labels).toEqual([]);
|
|
||||||
expect(args.inheritLabels).toEqual(false);
|
|
||||||
expect(args.squash).toEqual(true);
|
|
||||||
expectArrayEqual(args.comments!,["first comment", "second comment"]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("valid execution with multiple branches", () => {
|
|
||||||
spyGetInput({
|
|
||||||
"target-branch": "target,old",
|
|
||||||
"pull-request": "https://localhost/whatever/pulls/1"
|
|
||||||
});
|
|
||||||
|
|
||||||
const args: Args = parser.parse();
|
|
||||||
expect(args.dryRun).toEqual(false);
|
|
||||||
expect(args.auth).toEqual(undefined);
|
|
||||||
expect(args.gitUser).toEqual(undefined);
|
|
||||||
expect(args.gitEmail).toEqual(undefined);
|
|
||||||
expect(args.folder).toEqual(undefined);
|
|
||||||
expect(args.targetBranch).toEqual("target,old");
|
|
||||||
expect(args.pullRequest).toEqual("https://localhost/whatever/pulls/1");
|
|
||||||
expect(args.title).toEqual(undefined);
|
|
||||||
expect(args.body).toEqual(undefined);
|
|
||||||
expect(args.reviewers).toEqual([]);
|
|
||||||
expect(args.assignees).toEqual([]);
|
|
||||||
expect(args.inheritReviewers).toEqual(true);
|
|
||||||
expect(args.labels).toEqual([]);
|
|
||||||
expect(args.inheritLabels).toEqual(false);
|
|
||||||
expect(args.squash).toEqual(true);
|
|
||||||
expect(args.strategy).toEqual(undefined);
|
|
||||||
expect(args.strategyOption).toEqual(undefined);
|
|
||||||
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");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("invalid execution with missing mandatory target branch", () => {
|
|
||||||
spyGetInput({
|
|
||||||
"pull-request": "https://localhost/whatever/pulls/1"
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(() => parser.parse()).toThrowError("Missing option: target branch(es) or target regular expression must be provided");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("invalid execution with missin mandatory pull request", () => {
|
|
||||||
spyGetInput({
|
|
||||||
"target-branch": "target,old",
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(() => parser.parse()).toThrowError("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);
|
|
||||||
});
|
|
||||||
});
|
});
|
|
@ -1,493 +0,0 @@
|
||||||
import { Args } from "@bp/service/args/args.types";
|
|
||||||
import { Configs } from "@bp/service/configs/configs.types";
|
|
||||||
import PullRequestConfigsParser from "@bp/service/configs/pullrequest/pr-configs-parser";
|
|
||||||
import GitClientFactory from "@bp/service/git/git-client-factory";
|
|
||||||
import { GitClientType } from "@bp/service/git/git.types";
|
|
||||||
import { mockGitHubClient } from "../../../support/mock/git-client-mock-support";
|
|
||||||
import { resetProcessArgs } from "../../../support/utils";
|
|
||||||
import { MERGED_PR_FIXTURE, REPO, TARGET_OWNER, MULT_COMMITS_PR_FIXTURE } from "../../../support/mock/github-data";
|
|
||||||
import GitHubMapper from "@bp/service/git/github/github-mapper";
|
|
||||||
import GitHubClient from "@bp/service/git/github/github-client";
|
|
||||||
|
|
||||||
jest.spyOn(GitHubMapper.prototype, "mapPullRequest");
|
|
||||||
jest.spyOn(GitHubClient.prototype, "getPullRequest");
|
|
||||||
|
|
||||||
describe("github pull request config parser", () => {
|
|
||||||
|
|
||||||
const mergedPRUrl = `https://github.com/${TARGET_OWNER}/${REPO}/pull/${MERGED_PR_FIXTURE.number}`;
|
|
||||||
const multipleCommitsPRUrl = `https://github.com/${TARGET_OWNER}/${REPO}/pull/${MULT_COMMITS_PR_FIXTURE.number}`;
|
|
||||||
|
|
||||||
let configParser: PullRequestConfigsParser;
|
|
||||||
|
|
||||||
beforeAll(() => {
|
|
||||||
GitClientFactory.reset();
|
|
||||||
GitClientFactory.getOrCreate(GitClientType.GITHUB, "whatever", "http://localhost/api/v3");
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
// reset process.env variables
|
|
||||||
resetProcessArgs();
|
|
||||||
|
|
||||||
// mock octokit
|
|
||||||
mockGitHubClient("http://localhost/api/v3");
|
|
||||||
|
|
||||||
// create a fresh new instance every time
|
|
||||||
configParser = new PullRequestConfigsParser();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("multiple backports", async () => {
|
|
||||||
const args: Args = {
|
|
||||||
dryRun: false,
|
|
||||||
auth: "",
|
|
||||||
pullRequest: mergedPRUrl,
|
|
||||||
targetBranch: "v1, v2, v3",
|
|
||||||
gitUser: "Me",
|
|
||||||
gitEmail: "me@email.com",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body",
|
|
||||||
bodyPrefix: "New Body Prefix -",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
inheritReviewers: false,
|
|
||||||
labels: [],
|
|
||||||
inheritLabels: false,
|
|
||||||
comments: [],
|
|
||||||
};
|
|
||||||
|
|
||||||
const configs: Configs = await configParser.parseAndValidate(args);
|
|
||||||
|
|
||||||
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
|
|
||||||
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, undefined);
|
|
||||||
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
|
||||||
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
|
|
||||||
|
|
||||||
expect(configs.dryRun).toEqual(false);
|
|
||||||
expect(configs.auth).toEqual("");
|
|
||||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
|
||||||
expect(configs.backportPullRequests.length).toEqual(3);
|
|
||||||
expect(configs.backportPullRequests).toEqual(
|
|
||||||
expect.arrayContaining([
|
|
||||||
{
|
|
||||||
owner: "owner",
|
|
||||||
repo: "reponame",
|
|
||||||
head: "bp-v1-28f63db",
|
|
||||||
base: "v1",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body Prefix -New Body",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
owner: "owner",
|
|
||||||
repo: "reponame",
|
|
||||||
head: "bp-v2-28f63db",
|
|
||||||
base: "v2",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body Prefix -New Body",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
owner: "owner",
|
|
||||||
repo: "reponame",
|
|
||||||
head: "bp-v3-28f63db",
|
|
||||||
base: "v3",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body Prefix -New Body",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
},
|
|
||||||
])
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("multiple backports ignore duplicates", async () => {
|
|
||||||
const args: Args = {
|
|
||||||
dryRun: false,
|
|
||||||
auth: "",
|
|
||||||
pullRequest: mergedPRUrl,
|
|
||||||
targetBranch: "v1, v2, v2, v3",
|
|
||||||
gitUser: "Me",
|
|
||||||
gitEmail: "me@email.com",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body",
|
|
||||||
bodyPrefix: "New Body Prefix -",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
inheritReviewers: false,
|
|
||||||
labels: [],
|
|
||||||
inheritLabels: false,
|
|
||||||
comments: [],
|
|
||||||
};
|
|
||||||
|
|
||||||
const configs: Configs = await configParser.parseAndValidate(args);
|
|
||||||
|
|
||||||
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
|
|
||||||
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, undefined);
|
|
||||||
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
|
||||||
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
|
|
||||||
|
|
||||||
expect(configs.dryRun).toEqual(false);
|
|
||||||
expect(configs.auth).toEqual("");
|
|
||||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
|
||||||
expect(configs.backportPullRequests.length).toEqual(3);
|
|
||||||
expect(configs.backportPullRequests).toEqual(
|
|
||||||
expect.arrayContaining([
|
|
||||||
{
|
|
||||||
owner: "owner",
|
|
||||||
repo: "reponame",
|
|
||||||
head: "bp-v1-28f63db",
|
|
||||||
base: "v1",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body Prefix -New Body",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
owner: "owner",
|
|
||||||
repo: "reponame",
|
|
||||||
head: "bp-v2-28f63db",
|
|
||||||
base: "v2",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body Prefix -New Body",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
owner: "owner",
|
|
||||||
repo: "reponame",
|
|
||||||
head: "bp-v3-28f63db",
|
|
||||||
base: "v3",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body Prefix -New Body",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
},
|
|
||||||
])
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("multiple backports with custom branch name", async () => {
|
|
||||||
const args: Args = {
|
|
||||||
dryRun: false,
|
|
||||||
auth: "",
|
|
||||||
pullRequest: mergedPRUrl,
|
|
||||||
targetBranch: "v1, v2, v3",
|
|
||||||
gitUser: "Me",
|
|
||||||
gitEmail: "me@email.com",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body",
|
|
||||||
bodyPrefix: "New Body Prefix -",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
inheritReviewers: false,
|
|
||||||
labels: [],
|
|
||||||
inheritLabels: false,
|
|
||||||
comments: [],
|
|
||||||
bpBranchName: "custom-branch",
|
|
||||||
};
|
|
||||||
|
|
||||||
const configs: Configs = await configParser.parseAndValidate(args);
|
|
||||||
|
|
||||||
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
|
|
||||||
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, undefined);
|
|
||||||
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
|
||||||
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
|
|
||||||
|
|
||||||
expect(configs.dryRun).toEqual(false);
|
|
||||||
expect(configs.auth).toEqual("");
|
|
||||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
|
||||||
expect(configs.backportPullRequests.length).toEqual(3);
|
|
||||||
expect(configs.backportPullRequests).toEqual(
|
|
||||||
expect.arrayContaining([
|
|
||||||
{
|
|
||||||
owner: "owner",
|
|
||||||
repo: "reponame",
|
|
||||||
head: "custom-branch-v1",
|
|
||||||
base: "v1",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body Prefix -New Body",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
owner: "owner",
|
|
||||||
repo: "reponame",
|
|
||||||
head: "custom-branch-v2",
|
|
||||||
base: "v2",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body Prefix -New Body",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
owner: "owner",
|
|
||||||
repo: "reponame",
|
|
||||||
head: "custom-branch-v3",
|
|
||||||
base: "v3",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body Prefix -New Body",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
},
|
|
||||||
])
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("multiple backports with multiple custom branch names", async () => {
|
|
||||||
const args: Args = {
|
|
||||||
dryRun: false,
|
|
||||||
auth: "",
|
|
||||||
pullRequest: mergedPRUrl,
|
|
||||||
targetBranch: "v1, v2, v3",
|
|
||||||
gitUser: "Me",
|
|
||||||
gitEmail: "me@email.com",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body",
|
|
||||||
bodyPrefix: "New Body Prefix -",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
inheritReviewers: false,
|
|
||||||
labels: [],
|
|
||||||
inheritLabels: false,
|
|
||||||
comments: [],
|
|
||||||
bpBranchName: "custom-branch1, custom-branch2, custom-branch3",
|
|
||||||
};
|
|
||||||
|
|
||||||
const configs: Configs = await configParser.parseAndValidate(args);
|
|
||||||
|
|
||||||
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
|
|
||||||
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, undefined);
|
|
||||||
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
|
||||||
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
|
|
||||||
|
|
||||||
expect(configs.dryRun).toEqual(false);
|
|
||||||
expect(configs.auth).toEqual("");
|
|
||||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
|
||||||
expect(configs.backportPullRequests.length).toEqual(3);
|
|
||||||
expect(configs.backportPullRequests).toEqual(
|
|
||||||
expect.arrayContaining([
|
|
||||||
{
|
|
||||||
owner: "owner",
|
|
||||||
repo: "reponame",
|
|
||||||
head: "custom-branch1",
|
|
||||||
base: "v1",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body Prefix -New Body",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
owner: "owner",
|
|
||||||
repo: "reponame",
|
|
||||||
head: "custom-branch2",
|
|
||||||
base: "v2",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body Prefix -New Body",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
owner: "owner",
|
|
||||||
repo: "reponame",
|
|
||||||
head: "custom-branch3",
|
|
||||||
base: "v3",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body Prefix -New Body",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
},
|
|
||||||
])
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("multiple backports with incorrect number of bp branch names", async () => {
|
|
||||||
const args: Args = {
|
|
||||||
dryRun: false,
|
|
||||||
auth: "",
|
|
||||||
pullRequest: mergedPRUrl,
|
|
||||||
targetBranch: "v1, v2, v3",
|
|
||||||
gitUser: "Me",
|
|
||||||
gitEmail: "me@email.com",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body",
|
|
||||||
bodyPrefix: "New Body Prefix -",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
inheritReviewers: false,
|
|
||||||
labels: [],
|
|
||||||
inheritLabels: false,
|
|
||||||
comments: [],
|
|
||||||
bpBranchName: "custom-branch1, custom-branch2",
|
|
||||||
};
|
|
||||||
|
|
||||||
await expect(() => configParser.parseAndValidate(args)).rejects.toThrow("The number of backport branch names, if provided, must match the number of target branches or just one, provided 2 branch names instead");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("multiple backports and multiple commits", async () => {
|
|
||||||
const args: Args = {
|
|
||||||
dryRun: false,
|
|
||||||
auth: "",
|
|
||||||
pullRequest: multipleCommitsPRUrl,
|
|
||||||
targetBranch: "v4, v5, v6",
|
|
||||||
gitUser: "GitHub",
|
|
||||||
gitEmail: "noreply@github.com",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: [],
|
|
||||||
inheritReviewers: true,
|
|
||||||
squash: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
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(configs.dryRun).toEqual(false);
|
|
||||||
expect(configs.git).toEqual({
|
|
||||||
user: "GitHub",
|
|
||||||
email: "noreply@github.com"
|
|
||||||
});
|
|
||||||
expect(configs.auth).toEqual("");
|
|
||||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
|
||||||
expect(configs.backportPullRequests.length).toEqual(3);
|
|
||||||
expect(configs.backportPullRequests).toEqual(
|
|
||||||
expect.arrayContaining([
|
|
||||||
{
|
|
||||||
owner: "owner",
|
|
||||||
repo: "reponame",
|
|
||||||
head: "bp-v4-0404fb9-11da4e3",
|
|
||||||
base: "v4",
|
|
||||||
title: "[v4] PR Title",
|
|
||||||
body: "**Backport:** https://github.com/owner/reponame/pull/8632\r\n\r\nPlease review and merge",
|
|
||||||
reviewers: ["gh-user", "that-s-a-user"],
|
|
||||||
assignees: [],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
owner: "owner",
|
|
||||||
repo: "reponame",
|
|
||||||
head: "bp-v5-0404fb9-11da4e3",
|
|
||||||
base: "v5",
|
|
||||||
title: "[v5] PR Title",
|
|
||||||
body: "**Backport:** https://github.com/owner/reponame/pull/8632\r\n\r\nPlease review and merge",
|
|
||||||
reviewers: ["gh-user", "that-s-a-user"],
|
|
||||||
assignees: [],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
owner: "owner",
|
|
||||||
repo: "reponame",
|
|
||||||
head: "bp-v6-0404fb9-11da4e3",
|
|
||||||
base: "v6",
|
|
||||||
title: "[v6] PR Title",
|
|
||||||
body: "**Backport:** https://github.com/owner/reponame/pull/8632\r\n\r\nPlease review and merge",
|
|
||||||
reviewers: ["gh-user", "that-s-a-user"],
|
|
||||||
assignees: [],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
},
|
|
||||||
])
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("multiple extracted branches and multiple commits", async () => {
|
|
||||||
const args: Args = {
|
|
||||||
dryRun: false,
|
|
||||||
auth: "",
|
|
||||||
pullRequest: multipleCommitsPRUrl,
|
|
||||||
targetBranchPattern: "^backport (?<target>([^ ]+))$",
|
|
||||||
gitUser: "GitHub",
|
|
||||||
gitEmail: "noreply@github.com",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: [],
|
|
||||||
inheritReviewers: true,
|
|
||||||
squash: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
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(configs.dryRun).toEqual(false);
|
|
||||||
expect(configs.git).toEqual({
|
|
||||||
user: "GitHub",
|
|
||||||
email: "noreply@github.com"
|
|
||||||
});
|
|
||||||
expect(configs.auth).toEqual("");
|
|
||||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
|
||||||
expect(configs.backportPullRequests.length).toEqual(3);
|
|
||||||
expect(configs.backportPullRequests).toEqual(
|
|
||||||
expect.arrayContaining([
|
|
||||||
{
|
|
||||||
owner: "owner",
|
|
||||||
repo: "reponame",
|
|
||||||
head: "bp-v1-0404fb9-11da4e3",
|
|
||||||
base: "v1",
|
|
||||||
title: "[v1] PR Title",
|
|
||||||
body: "**Backport:** https://github.com/owner/reponame/pull/8632\r\n\r\nPlease review and merge",
|
|
||||||
reviewers: ["gh-user", "that-s-a-user"],
|
|
||||||
assignees: [],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
owner: "owner",
|
|
||||||
repo: "reponame",
|
|
||||||
head: "bp-v2-0404fb9-11da4e3",
|
|
||||||
base: "v2",
|
|
||||||
title: "[v2] PR Title",
|
|
||||||
body: "**Backport:** https://github.com/owner/reponame/pull/8632\r\n\r\nPlease review and merge",
|
|
||||||
reviewers: ["gh-user", "that-s-a-user"],
|
|
||||||
assignees: [],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
owner: "owner",
|
|
||||||
repo: "reponame",
|
|
||||||
head: "bp-v3-0404fb9-11da4e3",
|
|
||||||
base: "v3",
|
|
||||||
title: "[v3] PR Title",
|
|
||||||
body: "**Backport:** https://github.com/owner/reponame/pull/8632\r\n\r\nPlease review and merge",
|
|
||||||
reviewers: ["gh-user", "that-s-a-user"],
|
|
||||||
assignees: [],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
},
|
|
||||||
])
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
|
@ -5,7 +5,7 @@ import GitClientFactory from "@bp/service/git/git-client-factory";
|
||||||
import { GitClientType } from "@bp/service/git/git.types";
|
import { GitClientType } from "@bp/service/git/git.types";
|
||||||
import { mockGitHubClient } from "../../../support/mock/git-client-mock-support";
|
import { mockGitHubClient } from "../../../support/mock/git-client-mock-support";
|
||||||
import { addProcessArgs, createTestFile, removeTestFile, resetProcessArgs } from "../../../support/utils";
|
import { addProcessArgs, createTestFile, removeTestFile, resetProcessArgs } from "../../../support/utils";
|
||||||
import { MERGED_PR_FIXTURE, OPEN_PR_FIXTURE, NOT_MERGED_PR_FIXTURE, REPO, TARGET_OWNER, MULT_COMMITS_PR_FIXTURE } from "../../../support/mock/github-data";
|
import { mergedPullRequestFixture, openPullRequestFixture, notMergedPullRequestFixture, repo, targetOwner, multipleCommitsPullRequestFixture } from "../../../support/mock/github-data";
|
||||||
import CLIArgsParser from "@bp/service/args/cli/cli-args-parser";
|
import CLIArgsParser from "@bp/service/args/cli/cli-args-parser";
|
||||||
import GitHubMapper from "@bp/service/git/github/github-mapper";
|
import GitHubMapper from "@bp/service/git/github/github-mapper";
|
||||||
import GitHubClient from "@bp/service/git/github/github-client";
|
import GitHubClient from "@bp/service/git/github/github-client";
|
||||||
|
@ -13,14 +13,14 @@ import GitHubClient from "@bp/service/git/github/github-client";
|
||||||
const GITHUB_MERGED_PR_SIMPLE_CONFIG_FILE_CONTENT_PATHNAME = "./github-pr-configs-parser-simple-pr-merged.json";
|
const GITHUB_MERGED_PR_SIMPLE_CONFIG_FILE_CONTENT_PATHNAME = "./github-pr-configs-parser-simple-pr-merged.json";
|
||||||
const GITHUB_MERGED_PR_SIMPLE_CONFIG_FILE_CONTENT = {
|
const GITHUB_MERGED_PR_SIMPLE_CONFIG_FILE_CONTENT = {
|
||||||
"targetBranch": "prod",
|
"targetBranch": "prod",
|
||||||
"pullRequest": `https://github.com/${TARGET_OWNER}/${REPO}/pull/${MERGED_PR_FIXTURE.number}`,
|
"pullRequest": `https://github.com/${targetOwner}/${repo}/pull/${mergedPullRequestFixture.number}`,
|
||||||
};
|
};
|
||||||
|
|
||||||
const GITHUB_MERGED_PR_COMPLEX_CONFIG_FILE_CONTENT_PATHNAME = "./github-pr-configs-parser-complex-pr-merged.json";
|
const GITHUB_MERGED_PR_COMPLEX_CONFIG_FILE_CONTENT_PATHNAME = "./github-pr-configs-parser-complex-pr-merged.json";
|
||||||
const GITHUB_MERGED_PR_COMPLEX_CONFIG_FILE_CONTENT = {
|
const GITHUB_MERGED_PR_COMPLEX_CONFIG_FILE_CONTENT = {
|
||||||
"dryRun": false,
|
"dryRun": false,
|
||||||
"auth": "my-auth-token",
|
"auth": "my-auth-token",
|
||||||
"pullRequest": `https://github.com/${TARGET_OWNER}/${REPO}/pull/${MERGED_PR_FIXTURE.number}`,
|
"pullRequest": `https://github.com/${targetOwner}/${repo}/pull/${mergedPullRequestFixture.number}`,
|
||||||
"targetBranch": "prod",
|
"targetBranch": "prod",
|
||||||
"gitUser": "Me",
|
"gitUser": "Me",
|
||||||
"gitEmail": "me@email.com",
|
"gitEmail": "me@email.com",
|
||||||
|
@ -39,10 +39,10 @@ jest.spyOn(GitHubClient.prototype, "getPullRequest");
|
||||||
|
|
||||||
describe("github pull request config parser", () => {
|
describe("github pull request config parser", () => {
|
||||||
|
|
||||||
const mergedPRUrl = `https://github.com/${TARGET_OWNER}/${REPO}/pull/${MERGED_PR_FIXTURE.number}`;
|
const mergedPRUrl = `https://github.com/${targetOwner}/${repo}/pull/${mergedPullRequestFixture.number}`;
|
||||||
const openPRUrl = `https://github.com/${TARGET_OWNER}/${REPO}/pull/${OPEN_PR_FIXTURE.number}`;
|
const openPRUrl = `https://github.com/${targetOwner}/${repo}/pull/${openPullRequestFixture.number}`;
|
||||||
const notMergedPRUrl = `https://github.com/${TARGET_OWNER}/${REPO}/pull/${NOT_MERGED_PR_FIXTURE.number}`;
|
const notMergedPRUrl = `https://github.com/${targetOwner}/${repo}/pull/${notMergedPullRequestFixture.number}`;
|
||||||
const multipleCommitsPRUrl = `https://github.com/${TARGET_OWNER}/${REPO}/pull/${MULT_COMMITS_PR_FIXTURE.number}`;
|
const multipleCommitsPRUrl = `https://github.com/${targetOwner}/${repo}/pull/${multipleCommitsPullRequestFixture.number}`;
|
||||||
|
|
||||||
let argsParser: CLIArgsParser;
|
let argsParser: CLIArgsParser;
|
||||||
let configParser: PullRequestConfigsParser;
|
let configParser: PullRequestConfigsParser;
|
||||||
|
@ -63,12 +63,11 @@ describe("github pull request config parser", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
mockGitHubClient("http://localhost/api/v3");
|
||||||
|
|
||||||
// reset process.env variables
|
// reset process.env variables
|
||||||
resetProcessArgs();
|
resetProcessArgs();
|
||||||
|
|
||||||
// mock octokit
|
|
||||||
mockGitHubClient("http://localhost/api/v3");
|
|
||||||
|
|
||||||
// create a fresh new instance every time
|
// create a fresh new instance every time
|
||||||
argsParser = new CLIArgsParser();
|
argsParser = new CLIArgsParser();
|
||||||
configParser = new PullRequestConfigsParser();
|
configParser = new PullRequestConfigsParser();
|
||||||
|
@ -77,6 +76,7 @@ describe("github pull request config parser", () => {
|
||||||
test("parse configs from pull request", async () => {
|
test("parse configs from pull request", async () => {
|
||||||
const args: Args = {
|
const args: Args = {
|
||||||
dryRun: false,
|
dryRun: false,
|
||||||
|
auth: "",
|
||||||
pullRequest: mergedPRUrl,
|
pullRequest: mergedPRUrl,
|
||||||
targetBranch: "prod",
|
targetBranch: "prod",
|
||||||
gitUser: "GitHub",
|
gitUser: "GitHub",
|
||||||
|
@ -89,7 +89,7 @@ describe("github pull request config parser", () => {
|
||||||
const configs: Configs = await configParser.parseAndValidate(args);
|
const configs: Configs = await configParser.parseAndValidate(args);
|
||||||
|
|
||||||
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
|
||||||
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, undefined);
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, true);
|
||||||
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
||||||
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
|
||||||
|
|
||||||
|
@ -98,7 +98,8 @@ describe("github pull request config parser", () => {
|
||||||
user: "GitHub",
|
user: "GitHub",
|
||||||
email: "noreply@github.com"
|
email: "noreply@github.com"
|
||||||
});
|
});
|
||||||
expect(configs.auth).toEqual(undefined);
|
expect(configs.auth).toEqual("");
|
||||||
|
expect(configs.targetBranch).toEqual("prod");
|
||||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||||
expect(configs.originalPullRequest).toEqual({
|
expect(configs.originalPullRequest).toEqual({
|
||||||
number: 2368,
|
number: 2368,
|
||||||
|
@ -112,7 +113,7 @@ describe("github pull request config parser", () => {
|
||||||
body: "Please review and merge",
|
body: "Please review and merge",
|
||||||
reviewers: ["requested-gh-user", "gh-user"],
|
reviewers: ["requested-gh-user", "gh-user"],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: ["backport prod"],
|
labels: ["original-label"],
|
||||||
targetRepo: {
|
targetRepo: {
|
||||||
owner: "owner",
|
owner: "owner",
|
||||||
project: "reponame",
|
project: "reponame",
|
||||||
|
@ -126,22 +127,26 @@ describe("github pull request config parser", () => {
|
||||||
nCommits: 2,
|
nCommits: 2,
|
||||||
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"]
|
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"]
|
||||||
});
|
});
|
||||||
expect(configs.backportPullRequests.length).toEqual(1);
|
expect(configs.backportPullRequest).toEqual({
|
||||||
expect(configs.backportPullRequests[0]).toEqual({
|
author: "GitHub",
|
||||||
owner: "owner",
|
url: undefined,
|
||||||
repo: "reponame",
|
htmlUrl: undefined,
|
||||||
head: "bp-prod-28f63db",
|
|
||||||
base: "prod",
|
|
||||||
title: "[prod] PR Title",
|
title: "[prod] PR Title",
|
||||||
body: "**Backport:** https://github.com/owner/reponame/pull/2368\r\n\r\nPlease review and merge",
|
body: "**Backport:** https://github.com/owner/reponame/pull/2368\r\n\r\nPlease review and merge",
|
||||||
reviewers: ["gh-user", "that-s-a-user"],
|
reviewers: ["gh-user", "that-s-a-user"],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: [],
|
labels: [],
|
||||||
comments: [],
|
targetRepo: {
|
||||||
});
|
owner: "owner",
|
||||||
expect(configs.errorNotification).toEqual({
|
project: "reponame",
|
||||||
enabled: false,
|
cloneUrl: "https://github.com/owner/reponame.git"
|
||||||
message: "The backport to `{{target-branch}}` failed. Check the latest run for more details."
|
},
|
||||||
|
sourceRepo: {
|
||||||
|
owner: "owner",
|
||||||
|
project: "reponame",
|
||||||
|
cloneUrl: "https://github.com/owner/reponame.git"
|
||||||
|
},
|
||||||
|
bpBranchName: undefined,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -163,6 +168,7 @@ describe("github pull request config parser", () => {
|
||||||
|
|
||||||
expect(configs.dryRun).toEqual(true);
|
expect(configs.dryRun).toEqual(true);
|
||||||
expect(configs.auth).toEqual("whatever");
|
expect(configs.auth).toEqual("whatever");
|
||||||
|
expect(configs.targetBranch).toEqual("prod");
|
||||||
expect(configs.folder).toEqual("/tmp/test");
|
expect(configs.folder).toEqual("/tmp/test");
|
||||||
expect(configs.git).toEqual({
|
expect(configs.git).toEqual({
|
||||||
user: "GitHub",
|
user: "GitHub",
|
||||||
|
@ -186,12 +192,13 @@ describe("github pull request config parser", () => {
|
||||||
const configs: Configs = await configParser.parseAndValidate(args);
|
const configs: Configs = await configParser.parseAndValidate(args);
|
||||||
|
|
||||||
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
|
||||||
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 4444, undefined);
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 4444, true);
|
||||||
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
||||||
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), ["0404fb922ab75c3a8aecad5c97d9af388df04695", "11da4e38aa3e577ffde6d546f1c52e53b04d3151"]);
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
|
||||||
|
|
||||||
expect(configs.dryRun).toEqual(true);
|
expect(configs.dryRun).toEqual(true);
|
||||||
expect(configs.auth).toEqual("whatever");
|
expect(configs.auth).toEqual("whatever");
|
||||||
|
expect(configs.targetBranch).toEqual("prod");
|
||||||
expect(configs.git).toEqual({
|
expect(configs.git).toEqual({
|
||||||
user: "GitHub",
|
user: "GitHub",
|
||||||
email: "noreply@github.com"
|
email: "noreply@github.com"
|
||||||
|
@ -221,7 +228,8 @@ describe("github pull request config parser", () => {
|
||||||
},
|
},
|
||||||
bpBranchName: undefined,
|
bpBranchName: undefined,
|
||||||
nCommits: 2,
|
nCommits: 2,
|
||||||
commits: ["0404fb922ab75c3a8aecad5c97d9af388df04695", "11da4e38aa3e577ffde6d546f1c52e53b04d3151"],
|
// taken from head.sha
|
||||||
|
commits: ["91748965051fae1330ad58d15cf694e103267c87"]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -238,7 +246,7 @@ describe("github pull request config parser", () => {
|
||||||
inheritReviewers: true,
|
inheritReviewers: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
await expect(() => configParser.parseAndValidate(args)).rejects.toThrow("Provided pull request is closed and not merged");
|
await expect(() => configParser.parseAndValidate(args)).rejects.toThrow("Provided pull request is closed and not merged!");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("override backport pr data inheriting reviewers", async () => {
|
test("override backport pr data inheriting reviewers", async () => {
|
||||||
|
@ -255,13 +263,12 @@ describe("github pull request config parser", () => {
|
||||||
reviewers: [],
|
reviewers: [],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
inheritReviewers: true,
|
inheritReviewers: true,
|
||||||
bpBranchName: "custom-branch"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const configs: Configs = await configParser.parseAndValidate(args);
|
const configs: Configs = await configParser.parseAndValidate(args);
|
||||||
|
|
||||||
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
|
||||||
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, undefined);
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, true);
|
||||||
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
||||||
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
|
||||||
|
|
||||||
|
@ -271,6 +278,7 @@ describe("github pull request config parser", () => {
|
||||||
email: "me@email.com"
|
email: "me@email.com"
|
||||||
});
|
});
|
||||||
expect(configs.auth).toEqual("");
|
expect(configs.auth).toEqual("");
|
||||||
|
expect(configs.targetBranch).toEqual("prod");
|
||||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||||
expect(configs.originalPullRequest).toEqual({
|
expect(configs.originalPullRequest).toEqual({
|
||||||
number: 2368,
|
number: 2368,
|
||||||
|
@ -284,7 +292,7 @@ describe("github pull request config parser", () => {
|
||||||
body: "Please review and merge",
|
body: "Please review and merge",
|
||||||
reviewers: ["requested-gh-user", "gh-user"],
|
reviewers: ["requested-gh-user", "gh-user"],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: ["backport prod"],
|
labels: ["original-label"],
|
||||||
targetRepo: {
|
targetRepo: {
|
||||||
owner: "owner",
|
owner: "owner",
|
||||||
project: "reponame",
|
project: "reponame",
|
||||||
|
@ -299,60 +307,26 @@ describe("github pull request config parser", () => {
|
||||||
nCommits: 2,
|
nCommits: 2,
|
||||||
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"],
|
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"],
|
||||||
});
|
});
|
||||||
expect(configs.backportPullRequests.length).toEqual(1);
|
expect(configs.backportPullRequest).toEqual({
|
||||||
expect(configs.backportPullRequests[0]).toEqual({
|
author: "Me",
|
||||||
owner: "owner",
|
url: undefined,
|
||||||
repo: "reponame",
|
htmlUrl: undefined,
|
||||||
head: "custom-branch",
|
|
||||||
base: "prod",
|
|
||||||
title: "New Title",
|
title: "New Title",
|
||||||
body: "New Body Prefix -New Body",
|
body: "New Body Prefix -New Body",
|
||||||
reviewers: ["gh-user", "that-s-a-user"],
|
reviewers: ["gh-user", "that-s-a-user"],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: [],
|
labels: [],
|
||||||
comments: [],
|
targetRepo: {
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test("override backport with empty bp branch name", async () => {
|
|
||||||
const args: Args = {
|
|
||||||
dryRun: false,
|
|
||||||
auth: "",
|
|
||||||
pullRequest: mergedPRUrl,
|
|
||||||
targetBranch: "prod",
|
|
||||||
gitUser: "Me",
|
|
||||||
gitEmail: "me@email.com",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body",
|
|
||||||
bodyPrefix: "New Body Prefix -",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: [],
|
|
||||||
inheritReviewers: true,
|
|
||||||
bpBranchName: " "
|
|
||||||
};
|
|
||||||
|
|
||||||
const configs: Configs = await configParser.parseAndValidate(args);
|
|
||||||
|
|
||||||
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
|
|
||||||
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, undefined);
|
|
||||||
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
|
||||||
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
|
|
||||||
|
|
||||||
expect(configs.dryRun).toEqual(false);
|
|
||||||
expect(configs.auth).toEqual("");
|
|
||||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
|
||||||
expect(configs.backportPullRequests.length).toEqual(1);
|
|
||||||
expect(configs.backportPullRequests[0]).toEqual({
|
|
||||||
owner: "owner",
|
owner: "owner",
|
||||||
repo: "reponame",
|
project: "reponame",
|
||||||
head: "bp-prod-28f63db",
|
cloneUrl: "https://github.com/owner/reponame.git"
|
||||||
base: "prod",
|
},
|
||||||
title: "New Title",
|
sourceRepo: {
|
||||||
body: "New Body Prefix -New Body",
|
owner: "owner",
|
||||||
reviewers: ["gh-user", "that-s-a-user"],
|
project: "reponame",
|
||||||
assignees: [],
|
cloneUrl: "https://github.com/owner/reponame.git"
|
||||||
labels: [],
|
},
|
||||||
comments: [],
|
bpBranchName: undefined,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -375,7 +349,7 @@ describe("github pull request config parser", () => {
|
||||||
const configs: Configs = await configParser.parseAndValidate(args);
|
const configs: Configs = await configParser.parseAndValidate(args);
|
||||||
|
|
||||||
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
|
||||||
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, undefined);
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, true);
|
||||||
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
||||||
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
|
||||||
|
|
||||||
|
@ -385,6 +359,7 @@ describe("github pull request config parser", () => {
|
||||||
email: "me@email.com"
|
email: "me@email.com"
|
||||||
});
|
});
|
||||||
expect(configs.auth).toEqual("");
|
expect(configs.auth).toEqual("");
|
||||||
|
expect(configs.targetBranch).toEqual("prod");
|
||||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||||
expect(configs.originalPullRequest).toEqual({
|
expect(configs.originalPullRequest).toEqual({
|
||||||
number: 2368,
|
number: 2368,
|
||||||
|
@ -398,7 +373,7 @@ describe("github pull request config parser", () => {
|
||||||
body: "Please review and merge",
|
body: "Please review and merge",
|
||||||
reviewers: ["requested-gh-user", "gh-user"],
|
reviewers: ["requested-gh-user", "gh-user"],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: ["backport prod"],
|
labels: ["original-label"],
|
||||||
targetRepo: {
|
targetRepo: {
|
||||||
owner: "owner",
|
owner: "owner",
|
||||||
project: "reponame",
|
project: "reponame",
|
||||||
|
@ -413,18 +388,26 @@ describe("github pull request config parser", () => {
|
||||||
nCommits: 2,
|
nCommits: 2,
|
||||||
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"],
|
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"],
|
||||||
});
|
});
|
||||||
expect(configs.backportPullRequests.length).toEqual(1);
|
expect(configs.backportPullRequest).toEqual({
|
||||||
expect(configs.backportPullRequests[0]).toEqual({
|
author: "Me",
|
||||||
owner: "owner",
|
url: undefined,
|
||||||
repo: "reponame",
|
htmlUrl: undefined,
|
||||||
head: "bp-prod-28f63db",
|
|
||||||
base: "prod",
|
|
||||||
title: "New Title",
|
title: "New Title",
|
||||||
body: "New Body Prefix -New Body",
|
body: "New Body Prefix -New Body",
|
||||||
reviewers: ["user1", "user2"],
|
reviewers: ["user1", "user2"],
|
||||||
assignees: ["user3", "user4"],
|
assignees: ["user3", "user4"],
|
||||||
labels: [],
|
labels: [],
|
||||||
comments: [],
|
targetRepo: {
|
||||||
|
owner: "owner",
|
||||||
|
project: "reponame",
|
||||||
|
cloneUrl: "https://github.com/owner/reponame.git"
|
||||||
|
},
|
||||||
|
sourceRepo: {
|
||||||
|
owner: "owner",
|
||||||
|
project: "reponame",
|
||||||
|
cloneUrl: "https://github.com/owner/reponame.git"
|
||||||
|
},
|
||||||
|
bpBranchName: undefined,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -447,7 +430,7 @@ describe("github pull request config parser", () => {
|
||||||
const configs: Configs = await configParser.parseAndValidate(args);
|
const configs: Configs = await configParser.parseAndValidate(args);
|
||||||
|
|
||||||
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
|
||||||
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, undefined);
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, true);
|
||||||
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
||||||
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
|
||||||
|
|
||||||
|
@ -457,6 +440,7 @@ describe("github pull request config parser", () => {
|
||||||
email: "me@email.com"
|
email: "me@email.com"
|
||||||
});
|
});
|
||||||
expect(configs.auth).toEqual("");
|
expect(configs.auth).toEqual("");
|
||||||
|
expect(configs.targetBranch).toEqual("prod");
|
||||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||||
expect(configs.originalPullRequest).toEqual({
|
expect(configs.originalPullRequest).toEqual({
|
||||||
number: 2368,
|
number: 2368,
|
||||||
|
@ -470,7 +454,7 @@ describe("github pull request config parser", () => {
|
||||||
body: "Please review and merge",
|
body: "Please review and merge",
|
||||||
reviewers: ["requested-gh-user", "gh-user"],
|
reviewers: ["requested-gh-user", "gh-user"],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: ["backport prod"],
|
labels: ["original-label"],
|
||||||
targetRepo: {
|
targetRepo: {
|
||||||
owner: "owner",
|
owner: "owner",
|
||||||
project: "reponame",
|
project: "reponame",
|
||||||
|
@ -485,18 +469,26 @@ describe("github pull request config parser", () => {
|
||||||
nCommits: 2,
|
nCommits: 2,
|
||||||
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"],
|
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"],
|
||||||
});
|
});
|
||||||
expect(configs.backportPullRequests.length).toEqual(1);
|
expect(configs.backportPullRequest).toEqual({
|
||||||
expect(configs.backportPullRequests[0]).toEqual({
|
author: "Me",
|
||||||
owner: "owner",
|
url: undefined,
|
||||||
repo: "reponame",
|
htmlUrl: undefined,
|
||||||
head: "bp-prod-28f63db",
|
|
||||||
base: "prod",
|
|
||||||
title: "New Title",
|
title: "New Title",
|
||||||
body: "New Body Prefix -New Body",
|
body: "New Body Prefix -New Body",
|
||||||
reviewers: [],
|
reviewers: [],
|
||||||
assignees: ["user3", "user4"],
|
assignees: ["user3", "user4"],
|
||||||
labels: [],
|
labels: [],
|
||||||
comments: [],
|
targetRepo: {
|
||||||
|
owner: "owner",
|
||||||
|
project: "reponame",
|
||||||
|
cloneUrl: "https://github.com/owner/reponame.git"
|
||||||
|
},
|
||||||
|
sourceRepo: {
|
||||||
|
owner: "owner",
|
||||||
|
project: "reponame",
|
||||||
|
cloneUrl: "https://github.com/owner/reponame.git"
|
||||||
|
},
|
||||||
|
bpBranchName: undefined,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -514,14 +506,14 @@ describe("github pull request config parser", () => {
|
||||||
reviewers: [],
|
reviewers: [],
|
||||||
assignees: ["user3", "user4"],
|
assignees: ["user3", "user4"],
|
||||||
inheritReviewers: false,
|
inheritReviewers: false,
|
||||||
labels: ["custom-label", "backport prod"], // also include the one inherited
|
labels: ["custom-label", "original-label"], // also include the one inherited
|
||||||
inheritLabels: true,
|
inheritLabels: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
const configs: Configs = await configParser.parseAndValidate(args);
|
const configs: Configs = await configParser.parseAndValidate(args);
|
||||||
|
|
||||||
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
|
||||||
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, undefined);
|
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, true);
|
||||||
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
||||||
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
|
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
|
||||||
|
|
||||||
|
@ -531,6 +523,7 @@ describe("github pull request config parser", () => {
|
||||||
email: "me@email.com"
|
email: "me@email.com"
|
||||||
});
|
});
|
||||||
expect(configs.auth).toEqual("");
|
expect(configs.auth).toEqual("");
|
||||||
|
expect(configs.targetBranch).toEqual("prod");
|
||||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||||
expect(configs.originalPullRequest).toEqual({
|
expect(configs.originalPullRequest).toEqual({
|
||||||
number: 2368,
|
number: 2368,
|
||||||
|
@ -544,7 +537,7 @@ describe("github pull request config parser", () => {
|
||||||
body: "Please review and merge",
|
body: "Please review and merge",
|
||||||
reviewers: ["requested-gh-user", "gh-user"],
|
reviewers: ["requested-gh-user", "gh-user"],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: ["backport prod"],
|
labels: ["original-label"],
|
||||||
targetRepo: {
|
targetRepo: {
|
||||||
owner: "owner",
|
owner: "owner",
|
||||||
project: "reponame",
|
project: "reponame",
|
||||||
|
@ -559,18 +552,26 @@ describe("github pull request config parser", () => {
|
||||||
nCommits: 2,
|
nCommits: 2,
|
||||||
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"],
|
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"],
|
||||||
});
|
});
|
||||||
expect(configs.backportPullRequests.length).toEqual(1);
|
expect(configs.backportPullRequest).toEqual({
|
||||||
expect(configs.backportPullRequests[0]).toEqual({
|
author: "Me",
|
||||||
owner: "owner",
|
url: undefined,
|
||||||
repo: "reponame",
|
htmlUrl: undefined,
|
||||||
head: "bp-prod-28f63db",
|
|
||||||
base: "prod",
|
|
||||||
title: "New Title",
|
title: "New Title",
|
||||||
body: "New Body Prefix -New Body",
|
body: "New Body Prefix -New Body",
|
||||||
reviewers: [],
|
reviewers: [],
|
||||||
assignees: ["user3", "user4"],
|
assignees: ["user3", "user4"],
|
||||||
labels: ["custom-label", "backport prod"],
|
labels: ["custom-label", "original-label"],
|
||||||
comments: [],
|
targetRepo: {
|
||||||
|
owner: "owner",
|
||||||
|
project: "reponame",
|
||||||
|
cloneUrl: "https://github.com/owner/reponame.git"
|
||||||
|
},
|
||||||
|
sourceRepo: {
|
||||||
|
owner: "owner",
|
||||||
|
project: "reponame",
|
||||||
|
cloneUrl: "https://github.com/owner/reponame.git"
|
||||||
|
},
|
||||||
|
bpBranchName: undefined,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -594,6 +595,7 @@ describe("github pull request config parser", () => {
|
||||||
email: "noreply@github.com"
|
email: "noreply@github.com"
|
||||||
});
|
});
|
||||||
expect(configs.auth).toEqual(undefined);
|
expect(configs.auth).toEqual(undefined);
|
||||||
|
expect(configs.targetBranch).toEqual("prod");
|
||||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||||
expect(configs.originalPullRequest).toEqual({
|
expect(configs.originalPullRequest).toEqual({
|
||||||
number: 2368,
|
number: 2368,
|
||||||
|
@ -607,7 +609,7 @@ describe("github pull request config parser", () => {
|
||||||
body: "Please review and merge",
|
body: "Please review and merge",
|
||||||
reviewers: ["requested-gh-user", "gh-user"],
|
reviewers: ["requested-gh-user", "gh-user"],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: ["backport prod"],
|
labels: ["original-label"],
|
||||||
targetRepo: {
|
targetRepo: {
|
||||||
owner: "owner",
|
owner: "owner",
|
||||||
project: "reponame",
|
project: "reponame",
|
||||||
|
@ -621,18 +623,26 @@ describe("github pull request config parser", () => {
|
||||||
nCommits: 2,
|
nCommits: 2,
|
||||||
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"]
|
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"]
|
||||||
});
|
});
|
||||||
expect(configs.backportPullRequests.length).toEqual(1);
|
expect(configs.backportPullRequest).toEqual({
|
||||||
expect(configs.backportPullRequests[0]).toEqual({
|
author: "GitHub",
|
||||||
owner: "owner",
|
url: undefined,
|
||||||
repo: "reponame",
|
htmlUrl: undefined,
|
||||||
head: "bp-prod-28f63db",
|
|
||||||
base: "prod",
|
|
||||||
title: "[prod] PR Title",
|
title: "[prod] PR Title",
|
||||||
body: "**Backport:** https://github.com/owner/reponame/pull/2368\r\n\r\nPlease review and merge",
|
body: "**Backport:** https://github.com/owner/reponame/pull/2368\r\n\r\nPlease review and merge",
|
||||||
reviewers: ["gh-user", "that-s-a-user"],
|
reviewers: ["gh-user", "that-s-a-user"],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: [],
|
labels: [],
|
||||||
comments: [],
|
targetRepo: {
|
||||||
|
owner: "owner",
|
||||||
|
project: "reponame",
|
||||||
|
cloneUrl: "https://github.com/owner/reponame.git"
|
||||||
|
},
|
||||||
|
sourceRepo: {
|
||||||
|
owner: "owner",
|
||||||
|
project: "reponame",
|
||||||
|
cloneUrl: "https://github.com/owner/reponame.git"
|
||||||
|
},
|
||||||
|
bpBranchName: undefined,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -656,6 +666,7 @@ describe("github pull request config parser", () => {
|
||||||
email: "me@email.com"
|
email: "me@email.com"
|
||||||
});
|
});
|
||||||
expect(configs.auth).toEqual("my-auth-token");
|
expect(configs.auth).toEqual("my-auth-token");
|
||||||
|
expect(configs.targetBranch).toEqual("prod");
|
||||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||||
expect(configs.originalPullRequest).toEqual({
|
expect(configs.originalPullRequest).toEqual({
|
||||||
number: 2368,
|
number: 2368,
|
||||||
|
@ -669,7 +680,7 @@ describe("github pull request config parser", () => {
|
||||||
body: "Please review and merge",
|
body: "Please review and merge",
|
||||||
reviewers: ["requested-gh-user", "gh-user"],
|
reviewers: ["requested-gh-user", "gh-user"],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: ["backport prod"],
|
labels: ["original-label"],
|
||||||
targetRepo: {
|
targetRepo: {
|
||||||
owner: "owner",
|
owner: "owner",
|
||||||
project: "reponame",
|
project: "reponame",
|
||||||
|
@ -684,18 +695,26 @@ describe("github pull request config parser", () => {
|
||||||
nCommits: 2,
|
nCommits: 2,
|
||||||
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"],
|
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"],
|
||||||
});
|
});
|
||||||
expect(configs.backportPullRequests.length).toEqual(1);
|
expect(configs.backportPullRequest).toEqual({
|
||||||
expect(configs.backportPullRequests[0]).toEqual({
|
author: "Me",
|
||||||
owner: "owner",
|
url: undefined,
|
||||||
repo: "reponame",
|
htmlUrl: undefined,
|
||||||
head: "bp-prod-28f63db",
|
|
||||||
base: "prod",
|
|
||||||
title: "New Title",
|
title: "New Title",
|
||||||
body: "New Body Prefix -New Body",
|
body: "New Body Prefix -New Body",
|
||||||
reviewers: ["user1", "user2"],
|
reviewers: ["user1", "user2"],
|
||||||
assignees: ["user3", "user4"],
|
assignees: ["user3", "user4"],
|
||||||
labels: ["cherry-pick :cherries:", "backport prod"],
|
labels: ["cherry-pick :cherries:", "original-label"],
|
||||||
comments: [],
|
targetRepo: {
|
||||||
|
owner: "owner",
|
||||||
|
project: "reponame",
|
||||||
|
cloneUrl: "https://github.com/owner/reponame.git"
|
||||||
|
},
|
||||||
|
sourceRepo: {
|
||||||
|
owner: "owner",
|
||||||
|
project: "reponame",
|
||||||
|
cloneUrl: "https://github.com/owner/reponame.git"
|
||||||
|
},
|
||||||
|
bpBranchName: undefined,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -726,6 +745,7 @@ describe("github pull request config parser", () => {
|
||||||
email: "noreply@github.com"
|
email: "noreply@github.com"
|
||||||
});
|
});
|
||||||
expect(configs.auth).toEqual("");
|
expect(configs.auth).toEqual("");
|
||||||
|
expect(configs.targetBranch).toEqual("prod");
|
||||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||||
expect(configs.originalPullRequest).toEqual({
|
expect(configs.originalPullRequest).toEqual({
|
||||||
number: 8632,
|
number: 8632,
|
||||||
|
@ -739,11 +759,7 @@ describe("github pull request config parser", () => {
|
||||||
body: "Please review and merge",
|
body: "Please review and merge",
|
||||||
reviewers: ["requested-gh-user", "gh-user"],
|
reviewers: ["requested-gh-user", "gh-user"],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: [
|
labels: [],
|
||||||
"backport v1",
|
|
||||||
"backport v2",
|
|
||||||
"backport v3",
|
|
||||||
],
|
|
||||||
targetRepo: {
|
targetRepo: {
|
||||||
owner: "owner",
|
owner: "owner",
|
||||||
project: "reponame",
|
project: "reponame",
|
||||||
|
@ -757,212 +773,26 @@ describe("github pull request config parser", () => {
|
||||||
nCommits: 2,
|
nCommits: 2,
|
||||||
commits: ["0404fb922ab75c3a8aecad5c97d9af388df04695", "11da4e38aa3e577ffde6d546f1c52e53b04d3151"]
|
commits: ["0404fb922ab75c3a8aecad5c97d9af388df04695", "11da4e38aa3e577ffde6d546f1c52e53b04d3151"]
|
||||||
});
|
});
|
||||||
expect(configs.backportPullRequests.length).toEqual(1);
|
expect(configs.backportPullRequest).toEqual({
|
||||||
expect(configs.backportPullRequests[0]).toEqual({
|
author: "GitHub",
|
||||||
owner: "owner",
|
url: undefined,
|
||||||
repo: "reponame",
|
htmlUrl: undefined,
|
||||||
head: "bp-prod-0404fb9-11da4e3",
|
|
||||||
base: "prod",
|
|
||||||
title: "[prod] PR Title",
|
title: "[prod] PR Title",
|
||||||
body: "**Backport:** https://github.com/owner/reponame/pull/8632\r\n\r\nPlease review and merge",
|
body: "**Backport:** https://github.com/owner/reponame/pull/8632\r\n\r\nPlease review and merge",
|
||||||
reviewers: ["gh-user", "that-s-a-user"],
|
reviewers: ["gh-user", "that-s-a-user"],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: [],
|
labels: [],
|
||||||
comments: [],
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test("override backport pr with additional comments", async () => {
|
|
||||||
const args: Args = {
|
|
||||||
dryRun: false,
|
|
||||||
auth: "",
|
|
||||||
pullRequest: mergedPRUrl,
|
|
||||||
targetBranch: "prod",
|
|
||||||
gitUser: "Me",
|
|
||||||
gitEmail: "me@email.com",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body",
|
|
||||||
bodyPrefix: "New Body Prefix -",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
inheritReviewers: false,
|
|
||||||
labels: [],
|
|
||||||
inheritLabels: false,
|
|
||||||
comments: ["First comment", "Second comment"],
|
|
||||||
};
|
|
||||||
|
|
||||||
const configs: Configs = await configParser.parseAndValidate(args);
|
|
||||||
|
|
||||||
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
|
|
||||||
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, undefined);
|
|
||||||
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
|
||||||
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
|
|
||||||
|
|
||||||
expect(configs.dryRun).toEqual(false);
|
|
||||||
expect(configs.git).toEqual({
|
|
||||||
user: "Me",
|
|
||||||
email: "me@email.com"
|
|
||||||
});
|
|
||||||
expect(configs.auth).toEqual("");
|
|
||||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
|
||||||
expect(configs.originalPullRequest).toEqual({
|
|
||||||
number: 2368,
|
|
||||||
author: "gh-user",
|
|
||||||
url: "https://api.github.com/repos/owner/reponame/pulls/2368",
|
|
||||||
htmlUrl: "https://github.com/owner/reponame/pull/2368",
|
|
||||||
state: "closed",
|
|
||||||
merged: true,
|
|
||||||
mergedBy: "that-s-a-user",
|
|
||||||
title: "PR Title",
|
|
||||||
body: "Please review and merge",
|
|
||||||
reviewers: ["requested-gh-user", "gh-user"],
|
|
||||||
assignees: [],
|
|
||||||
labels: ["backport prod"],
|
|
||||||
targetRepo: {
|
targetRepo: {
|
||||||
owner: "owner",
|
owner: "owner",
|
||||||
project: "reponame",
|
project: "reponame",
|
||||||
cloneUrl: "https://github.com/owner/reponame.git"
|
cloneUrl: "https://github.com/owner/reponame.git"
|
||||||
},
|
},
|
||||||
sourceRepo: {
|
sourceRepo: {
|
||||||
owner: "fork",
|
|
||||||
project: "reponame",
|
|
||||||
cloneUrl: "https://github.com/fork/reponame.git"
|
|
||||||
},
|
|
||||||
bpBranchName: undefined,
|
|
||||||
nCommits: 2,
|
|
||||||
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"],
|
|
||||||
});
|
|
||||||
expect(configs.backportPullRequests.length).toEqual(1);
|
|
||||||
expect(configs.backportPullRequests[0]).toEqual({
|
|
||||||
owner: "owner",
|
|
||||||
repo: "reponame",
|
|
||||||
head: "bp-prod-28f63db",
|
|
||||||
base: "prod",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body Prefix -New Body",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
labels: [],
|
|
||||||
comments: ["First comment", "Second comment"],
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test("no extracted target branches from pr labels due to wrong group name", async () => {
|
|
||||||
const args: Args = {
|
|
||||||
dryRun: false,
|
|
||||||
auth: "",
|
|
||||||
pullRequest: mergedPRUrl,
|
|
||||||
targetBranchPattern: "^backport (?<wrong>([^ ]+))$",
|
|
||||||
gitUser: "Me",
|
|
||||||
gitEmail: "me@email.com",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body",
|
|
||||||
bodyPrefix: "New Body Prefix -",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
inheritReviewers: false,
|
|
||||||
labels: [],
|
|
||||||
inheritLabels: false,
|
|
||||||
comments: ["First comment", "Second comment"],
|
|
||||||
};
|
|
||||||
|
|
||||||
await expect(() => configParser.parseAndValidate(args)).rejects.toThrow("Unable to extract target branches with regular expression");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("extract target branches from pr labels", async () => {
|
|
||||||
const args: Args = {
|
|
||||||
dryRun: false,
|
|
||||||
auth: "",
|
|
||||||
pullRequest: mergedPRUrl,
|
|
||||||
targetBranchPattern: "^backport (?<target>([^ ]+))$",
|
|
||||||
gitUser: "Me",
|
|
||||||
gitEmail: "me@email.com",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body",
|
|
||||||
bodyPrefix: "New Body Prefix -",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
inheritReviewers: false,
|
|
||||||
labels: [],
|
|
||||||
inheritLabels: false,
|
|
||||||
comments: ["First comment", "Second comment"],
|
|
||||||
};
|
|
||||||
|
|
||||||
const configs: Configs = await configParser.parseAndValidate(args);
|
|
||||||
|
|
||||||
expect(GitHubClient.prototype.getPullRequest).toBeCalledTimes(1);
|
|
||||||
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, undefined);
|
|
||||||
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
|
||||||
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
|
|
||||||
|
|
||||||
expect(configs.dryRun).toEqual(false);
|
|
||||||
expect(configs.git).toEqual({
|
|
||||||
user: "Me",
|
|
||||||
email: "me@email.com"
|
|
||||||
});
|
|
||||||
expect(configs.auth).toEqual("");
|
|
||||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
|
||||||
expect(configs.originalPullRequest).toEqual({
|
|
||||||
number: 2368,
|
|
||||||
author: "gh-user",
|
|
||||||
url: "https://api.github.com/repos/owner/reponame/pulls/2368",
|
|
||||||
htmlUrl: "https://github.com/owner/reponame/pull/2368",
|
|
||||||
state: "closed",
|
|
||||||
merged: true,
|
|
||||||
mergedBy: "that-s-a-user",
|
|
||||||
title: "PR Title",
|
|
||||||
body: "Please review and merge",
|
|
||||||
reviewers: ["requested-gh-user", "gh-user"],
|
|
||||||
assignees: [],
|
|
||||||
labels: ["backport prod"],
|
|
||||||
targetRepo: {
|
|
||||||
owner: "owner",
|
owner: "owner",
|
||||||
project: "reponame",
|
project: "reponame",
|
||||||
cloneUrl: "https://github.com/owner/reponame.git"
|
cloneUrl: "https://github.com/owner/reponame.git"
|
||||||
},
|
},
|
||||||
sourceRepo: {
|
|
||||||
owner: "fork",
|
|
||||||
project: "reponame",
|
|
||||||
cloneUrl: "https://github.com/fork/reponame.git"
|
|
||||||
},
|
|
||||||
bpBranchName: undefined,
|
bpBranchName: undefined,
|
||||||
nCommits: 2,
|
|
||||||
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"],
|
|
||||||
});
|
|
||||||
expect(configs.backportPullRequests.length).toEqual(1);
|
|
||||||
expect(configs.backportPullRequests[0]).toEqual({
|
|
||||||
owner: "owner",
|
|
||||||
repo: "reponame",
|
|
||||||
head: "bp-prod-28f63db",
|
|
||||||
base: "prod",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body Prefix -New Body",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
labels: [],
|
|
||||||
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).toBeCalledTimes(1);
|
|
||||||
expect(GitHubClient.prototype.getPullRequest).toBeCalledWith("owner", "reponame", 2368, undefined);
|
|
||||||
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
|
||||||
expect(GitHubMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
|
|
||||||
|
|
||||||
expect(configs.errorNotification).toEqual({
|
|
||||||
"enabled": true,
|
|
||||||
"message": "The backport to `{{target-branch}}` failed. Check the latest run for more details."
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
|
@ -1,353 +0,0 @@
|
||||||
import { Args } from "@bp/service/args/args.types";
|
|
||||||
import { Configs } from "@bp/service/configs/configs.types";
|
|
||||||
import PullRequestConfigsParser from "@bp/service/configs/pullrequest/pr-configs-parser";
|
|
||||||
import GitClientFactory from "@bp/service/git/git-client-factory";
|
|
||||||
import { GitClientType } from "@bp/service/git/git.types";
|
|
||||||
import { getAxiosMocked } from "../../../support/mock/git-client-mock-support";
|
|
||||||
import { MERGED_SQUASHED_MR } from "../../../support/mock/gitlab-data";
|
|
||||||
import GitLabClient from "@bp/service/git/gitlab/gitlab-client";
|
|
||||||
import GitLabMapper from "@bp/service/git/gitlab/gitlab-mapper";
|
|
||||||
|
|
||||||
jest.spyOn(GitLabMapper.prototype, "mapPullRequest");
|
|
||||||
jest.spyOn(GitLabClient.prototype, "getPullRequest");
|
|
||||||
|
|
||||||
jest.mock("axios", () => {
|
|
||||||
return {
|
|
||||||
create: jest.fn(() => ({
|
|
||||||
get: getAxiosMocked,
|
|
||||||
})),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("gitlab merge request config parser", () => {
|
|
||||||
|
|
||||||
const mergedPRUrl = `https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/${MERGED_SQUASHED_MR.iid}`;
|
|
||||||
|
|
||||||
let configParser: PullRequestConfigsParser;
|
|
||||||
|
|
||||||
beforeAll(() => {
|
|
||||||
GitClientFactory.reset();
|
|
||||||
GitClientFactory.getOrCreate(GitClientType.GITLAB, "whatever", "my.gitlab.host.com");
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
configParser = new PullRequestConfigsParser();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("multiple backports", async () => {
|
|
||||||
const args: Args = {
|
|
||||||
dryRun: false,
|
|
||||||
auth: "",
|
|
||||||
pullRequest: mergedPRUrl,
|
|
||||||
targetBranch: "v1, v2, v3",
|
|
||||||
gitUser: "Me",
|
|
||||||
gitEmail: "me@email.com",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body",
|
|
||||||
bodyPrefix: "New Body Prefix -",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
inheritReviewers: false,
|
|
||||||
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(configs.dryRun).toEqual(false);
|
|
||||||
expect(configs.auth).toEqual("");
|
|
||||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
|
||||||
expect(configs.backportPullRequests.length).toEqual(3);
|
|
||||||
expect(configs.backportPullRequests).toEqual(
|
|
||||||
expect.arrayContaining([
|
|
||||||
{
|
|
||||||
owner: "superuser",
|
|
||||||
repo: "backporting-example",
|
|
||||||
head: "bp-v1-ebb1eca",
|
|
||||||
base: "v1",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body Prefix -New Body",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
owner: "superuser",
|
|
||||||
repo: "backporting-example",
|
|
||||||
head: "bp-v2-ebb1eca",
|
|
||||||
base: "v2",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body Prefix -New Body",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
owner: "superuser",
|
|
||||||
repo: "backporting-example",
|
|
||||||
head: "bp-v3-ebb1eca",
|
|
||||||
base: "v3",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body Prefix -New Body",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
}
|
|
||||||
])
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("multiple backports ignore duplicates", async () => {
|
|
||||||
const args: Args = {
|
|
||||||
dryRun: false,
|
|
||||||
auth: "",
|
|
||||||
pullRequest: mergedPRUrl,
|
|
||||||
targetBranch: "v1, v2, v3, v1",
|
|
||||||
gitUser: "Me",
|
|
||||||
gitEmail: "me@email.com",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body",
|
|
||||||
bodyPrefix: "New Body Prefix -",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
inheritReviewers: false,
|
|
||||||
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(configs.dryRun).toEqual(false);
|
|
||||||
expect(configs.auth).toEqual("");
|
|
||||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
|
||||||
expect(configs.backportPullRequests.length).toEqual(3);
|
|
||||||
expect(configs.backportPullRequests).toEqual(
|
|
||||||
expect.arrayContaining([
|
|
||||||
{
|
|
||||||
owner: "superuser",
|
|
||||||
repo: "backporting-example",
|
|
||||||
head: "bp-v1-ebb1eca",
|
|
||||||
base: "v1",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body Prefix -New Body",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
owner: "superuser",
|
|
||||||
repo: "backporting-example",
|
|
||||||
head: "bp-v2-ebb1eca",
|
|
||||||
base: "v2",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body Prefix -New Body",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
owner: "superuser",
|
|
||||||
repo: "backporting-example",
|
|
||||||
head: "bp-v3-ebb1eca",
|
|
||||||
base: "v3",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body Prefix -New Body",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
}
|
|
||||||
])
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("multiple backports with custom branch name", async () => {
|
|
||||||
const args: Args = {
|
|
||||||
dryRun: false,
|
|
||||||
auth: "",
|
|
||||||
pullRequest: mergedPRUrl,
|
|
||||||
targetBranch: "v1, v2, v3",
|
|
||||||
gitUser: "Me",
|
|
||||||
gitEmail: "me@email.com",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body",
|
|
||||||
bodyPrefix: "New Body Prefix -",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
inheritReviewers: false,
|
|
||||||
labels: [],
|
|
||||||
inheritLabels: false,
|
|
||||||
comments: [],
|
|
||||||
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(configs.dryRun).toEqual(false);
|
|
||||||
expect(configs.auth).toEqual("");
|
|
||||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
|
||||||
expect(configs.backportPullRequests.length).toEqual(3);
|
|
||||||
expect(configs.backportPullRequests).toEqual(
|
|
||||||
expect.arrayContaining([
|
|
||||||
{
|
|
||||||
owner: "superuser",
|
|
||||||
repo: "backporting-example",
|
|
||||||
head: "custom-branch-v1",
|
|
||||||
base: "v1",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body Prefix -New Body",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
owner: "superuser",
|
|
||||||
repo: "backporting-example",
|
|
||||||
head: "custom-branch-v2",
|
|
||||||
base: "v2",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body Prefix -New Body",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
owner: "superuser",
|
|
||||||
repo: "backporting-example",
|
|
||||||
head: "custom-branch-v3",
|
|
||||||
base: "v3",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body Prefix -New Body",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
}
|
|
||||||
])
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("multiple backports with multiple custom branch names", async () => {
|
|
||||||
const args: Args = {
|
|
||||||
dryRun: false,
|
|
||||||
auth: "",
|
|
||||||
pullRequest: mergedPRUrl,
|
|
||||||
targetBranch: "v1, v2, v3",
|
|
||||||
gitUser: "Me",
|
|
||||||
gitEmail: "me@email.com",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body",
|
|
||||||
bodyPrefix: "New Body Prefix -",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
inheritReviewers: false,
|
|
||||||
labels: [],
|
|
||||||
inheritLabels: false,
|
|
||||||
comments: [],
|
|
||||||
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(configs.dryRun).toEqual(false);
|
|
||||||
expect(configs.auth).toEqual("");
|
|
||||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
|
||||||
expect(configs.backportPullRequests.length).toEqual(3);
|
|
||||||
expect(configs.backportPullRequests).toEqual(
|
|
||||||
expect.arrayContaining([
|
|
||||||
{
|
|
||||||
owner: "superuser",
|
|
||||||
repo: "backporting-example",
|
|
||||||
head: "custom1",
|
|
||||||
base: "v1",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body Prefix -New Body",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
owner: "superuser",
|
|
||||||
repo: "backporting-example",
|
|
||||||
head: "custom2",
|
|
||||||
base: "v2",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body Prefix -New Body",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
owner: "superuser",
|
|
||||||
repo: "backporting-example",
|
|
||||||
head: "custom3",
|
|
||||||
base: "v3",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body Prefix -New Body",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
}
|
|
||||||
])
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("multiple backports with incorrect number of bp branch names", async () => {
|
|
||||||
const args: Args = {
|
|
||||||
dryRun: false,
|
|
||||||
auth: "",
|
|
||||||
pullRequest: mergedPRUrl,
|
|
||||||
targetBranch: "v1, v2, v3",
|
|
||||||
gitUser: "Me",
|
|
||||||
gitEmail: "me@email.com",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body",
|
|
||||||
bodyPrefix: "New Body Prefix -",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
inheritReviewers: false,
|
|
||||||
labels: [],
|
|
||||||
inheritLabels: false,
|
|
||||||
comments: [],
|
|
||||||
bpBranchName: "custom-branch1, custom-branch2, custom-branch2, custom-branch3, custom-branch4",
|
|
||||||
};
|
|
||||||
|
|
||||||
await expect(() => configParser.parseAndValidate(args)).rejects.toThrow("The number of backport branch names, if provided, must match the number of target branches or just one, provided 4 branch names instead");
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -6,7 +6,7 @@ import { GitClientType } from "@bp/service/git/git.types";
|
||||||
import { getAxiosMocked } from "../../../support/mock/git-client-mock-support";
|
import { getAxiosMocked } from "../../../support/mock/git-client-mock-support";
|
||||||
import { CLOSED_NOT_MERGED_MR, MERGED_SQUASHED_MR, OPEN_MR } from "../../../support/mock/gitlab-data";
|
import { CLOSED_NOT_MERGED_MR, MERGED_SQUASHED_MR, OPEN_MR } from "../../../support/mock/gitlab-data";
|
||||||
import GHAArgsParser from "@bp/service/args/gha/gha-args-parser";
|
import GHAArgsParser from "@bp/service/args/gha/gha-args-parser";
|
||||||
import { createTestFile, removeTestFile, resetEnvTokens, spyGetInput } from "../../../support/utils";
|
import { createTestFile, removeTestFile, spyGetInput } from "../../../support/utils";
|
||||||
import GitLabClient from "@bp/service/git/gitlab/gitlab-client";
|
import GitLabClient from "@bp/service/git/gitlab/gitlab-client";
|
||||||
import GitLabMapper from "@bp/service/git/gitlab/gitlab-mapper";
|
import GitLabMapper from "@bp/service/git/gitlab/gitlab-mapper";
|
||||||
|
|
||||||
|
@ -70,9 +70,6 @@ describe("gitlab merge request config parser", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// reset env tokens
|
|
||||||
resetEnvTokens();
|
|
||||||
|
|
||||||
argsParser = new GHAArgsParser();
|
argsParser = new GHAArgsParser();
|
||||||
configParser = new PullRequestConfigsParser();
|
configParser = new PullRequestConfigsParser();
|
||||||
});
|
});
|
||||||
|
@ -88,7 +85,6 @@ describe("gitlab merge request config parser", () => {
|
||||||
reviewers: [],
|
reviewers: [],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
inheritReviewers: true,
|
inheritReviewers: true,
|
||||||
squash: true,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const configs: Configs = await configParser.parseAndValidate(args);
|
const configs: Configs = await configParser.parseAndValidate(args);
|
||||||
|
@ -104,6 +100,7 @@ describe("gitlab merge request config parser", () => {
|
||||||
email: "noreply@gitlab.com"
|
email: "noreply@gitlab.com"
|
||||||
});
|
});
|
||||||
expect(configs.auth).toEqual(undefined);
|
expect(configs.auth).toEqual(undefined);
|
||||||
|
expect(configs.targetBranch).toEqual("prod");
|
||||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||||
expect(configs.originalPullRequest).toEqual({
|
expect(configs.originalPullRequest).toEqual({
|
||||||
number: 1,
|
number: 1,
|
||||||
|
@ -117,7 +114,7 @@ describe("gitlab merge request config parser", () => {
|
||||||
body: "This is the body",
|
body: "This is the body",
|
||||||
reviewers: ["superuser1", "superuser2"],
|
reviewers: ["superuser1", "superuser2"],
|
||||||
assignees: ["superuser"],
|
assignees: ["superuser"],
|
||||||
labels: ["backport-prod"],
|
labels: ["gitlab-original-label"],
|
||||||
targetRepo: {
|
targetRepo: {
|
||||||
owner: "superuser",
|
owner: "superuser",
|
||||||
project: "backporting-example",
|
project: "backporting-example",
|
||||||
|
@ -131,22 +128,26 @@ describe("gitlab merge request config parser", () => {
|
||||||
nCommits: 1,
|
nCommits: 1,
|
||||||
commits: ["ebb1eca696c42fd067658bd9b5267709f78ef38e"]
|
commits: ["ebb1eca696c42fd067658bd9b5267709f78ef38e"]
|
||||||
});
|
});
|
||||||
expect(configs.backportPullRequests.length).toEqual(1);
|
expect(configs.backportPullRequest).toEqual({
|
||||||
expect(configs.backportPullRequests[0]).toEqual({
|
author: "Gitlab",
|
||||||
owner: "superuser",
|
url: undefined,
|
||||||
repo: "backporting-example",
|
htmlUrl: undefined,
|
||||||
head: "bp-prod-ebb1eca",
|
|
||||||
base: "prod",
|
|
||||||
title: "[prod] Update test.txt",
|
title: "[prod] Update test.txt",
|
||||||
body: "**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1\r\n\r\nThis is the body",
|
body: "**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1\r\n\r\nThis is the body",
|
||||||
reviewers: ["superuser"],
|
reviewers: ["superuser"],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: [],
|
labels: [],
|
||||||
comments: [],
|
targetRepo: {
|
||||||
});
|
owner: "superuser",
|
||||||
expect(configs.errorNotification).toEqual({
|
project: "backporting-example",
|
||||||
"enabled": false,
|
cloneUrl: "https://my.gitlab.host.com/superuser/backporting-example.git"
|
||||||
"message": "The backport to `{{target-branch}}` failed. Check the latest run for more details."
|
},
|
||||||
|
sourceRepo: {
|
||||||
|
owner: "superuser",
|
||||||
|
project: "backporting-example",
|
||||||
|
cloneUrl: "https://my.gitlab.host.com/superuser/backporting-example.git"
|
||||||
|
},
|
||||||
|
bpBranchName: undefined,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -163,7 +164,6 @@ describe("gitlab merge request config parser", () => {
|
||||||
reviewers: [],
|
reviewers: [],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
inheritReviewers: true,
|
inheritReviewers: true,
|
||||||
squash: true,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const configs: Configs = await configParser.parseAndValidate(args);
|
const configs: Configs = await configParser.parseAndValidate(args);
|
||||||
|
@ -175,6 +175,7 @@ describe("gitlab merge request config parser", () => {
|
||||||
|
|
||||||
expect(configs.dryRun).toEqual(true);
|
expect(configs.dryRun).toEqual(true);
|
||||||
expect(configs.auth).toEqual("whatever");
|
expect(configs.auth).toEqual("whatever");
|
||||||
|
expect(configs.targetBranch).toEqual("prod");
|
||||||
expect(configs.folder).toEqual("/tmp/test");
|
expect(configs.folder).toEqual("/tmp/test");
|
||||||
expect(configs.git).toEqual({
|
expect(configs.git).toEqual({
|
||||||
user: "Gitlab",
|
user: "Gitlab",
|
||||||
|
@ -193,7 +194,6 @@ describe("gitlab merge request config parser", () => {
|
||||||
reviewers: [],
|
reviewers: [],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
inheritReviewers: true,
|
inheritReviewers: true,
|
||||||
squash: true,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const configs: Configs = await configParser.parseAndValidate(args);
|
const configs: Configs = await configParser.parseAndValidate(args);
|
||||||
|
@ -205,6 +205,7 @@ describe("gitlab merge request config parser", () => {
|
||||||
|
|
||||||
expect(configs.dryRun).toEqual(true);
|
expect(configs.dryRun).toEqual(true);
|
||||||
expect(configs.auth).toEqual("whatever");
|
expect(configs.auth).toEqual("whatever");
|
||||||
|
expect(configs.targetBranch).toEqual("prod");
|
||||||
expect(configs.git).toEqual({
|
expect(configs.git).toEqual({
|
||||||
user: "Gitlab",
|
user: "Gitlab",
|
||||||
email: "noreply@gitlab.com"
|
email: "noreply@gitlab.com"
|
||||||
|
@ -250,10 +251,9 @@ describe("gitlab merge request config parser", () => {
|
||||||
reviewers: [],
|
reviewers: [],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
inheritReviewers: true,
|
inheritReviewers: true,
|
||||||
squash: true,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
await expect(() => configParser.parseAndValidate(args)).rejects.toThrow("Provided pull request is closed and not merged");
|
await expect(() => configParser.parseAndValidate(args)).rejects.toThrow("Provided pull request is closed and not merged!");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("override backport pr data inheriting reviewers", async () => {
|
test("override backport pr data inheriting reviewers", async () => {
|
||||||
|
@ -270,7 +270,6 @@ describe("gitlab merge request config parser", () => {
|
||||||
reviewers: [],
|
reviewers: [],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
inheritReviewers: true,
|
inheritReviewers: true,
|
||||||
squash: true,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const configs: Configs = await configParser.parseAndValidate(args);
|
const configs: Configs = await configParser.parseAndValidate(args);
|
||||||
|
@ -286,6 +285,7 @@ describe("gitlab merge request config parser", () => {
|
||||||
email: "me@email.com"
|
email: "me@email.com"
|
||||||
});
|
});
|
||||||
expect(configs.auth).toEqual("");
|
expect(configs.auth).toEqual("");
|
||||||
|
expect(configs.targetBranch).toEqual("prod");
|
||||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||||
expect(configs.originalPullRequest).toEqual({
|
expect(configs.originalPullRequest).toEqual({
|
||||||
number: 1,
|
number: 1,
|
||||||
|
@ -299,7 +299,7 @@ describe("gitlab merge request config parser", () => {
|
||||||
body: "This is the body",
|
body: "This is the body",
|
||||||
reviewers: ["superuser1", "superuser2"],
|
reviewers: ["superuser1", "superuser2"],
|
||||||
assignees: ["superuser"],
|
assignees: ["superuser"],
|
||||||
labels: ["backport-prod"],
|
labels: ["gitlab-original-label"],
|
||||||
targetRepo: {
|
targetRepo: {
|
||||||
owner: "superuser",
|
owner: "superuser",
|
||||||
project: "backporting-example",
|
project: "backporting-example",
|
||||||
|
@ -313,18 +313,26 @@ describe("gitlab merge request config parser", () => {
|
||||||
nCommits: 1,
|
nCommits: 1,
|
||||||
commits: ["ebb1eca696c42fd067658bd9b5267709f78ef38e"]
|
commits: ["ebb1eca696c42fd067658bd9b5267709f78ef38e"]
|
||||||
});
|
});
|
||||||
expect(configs.backportPullRequests.length).toEqual(1);
|
expect(configs.backportPullRequest).toEqual({
|
||||||
expect(configs.backportPullRequests[0]).toEqual({
|
author: "Me",
|
||||||
owner: "superuser",
|
url: undefined,
|
||||||
repo: "backporting-example",
|
htmlUrl: undefined,
|
||||||
head: "bp-prod-ebb1eca",
|
|
||||||
base: "prod",
|
|
||||||
title: "New Title",
|
title: "New Title",
|
||||||
body: "New Body Prefix -New Body",
|
body: "New Body Prefix -New Body",
|
||||||
reviewers: ["superuser"],
|
reviewers: ["superuser"],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: [],
|
labels: [],
|
||||||
comments: [],
|
targetRepo: {
|
||||||
|
owner: "superuser",
|
||||||
|
project: "backporting-example",
|
||||||
|
cloneUrl: "https://my.gitlab.host.com/superuser/backporting-example.git"
|
||||||
|
},
|
||||||
|
sourceRepo: {
|
||||||
|
owner: "superuser",
|
||||||
|
project: "backporting-example",
|
||||||
|
cloneUrl: "https://my.gitlab.host.com/superuser/backporting-example.git"
|
||||||
|
},
|
||||||
|
bpBranchName: undefined,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -342,7 +350,6 @@ describe("gitlab merge request config parser", () => {
|
||||||
reviewers: ["user1", "user2"],
|
reviewers: ["user1", "user2"],
|
||||||
assignees: ["user3", "user4"],
|
assignees: ["user3", "user4"],
|
||||||
inheritReviewers: true, // not taken into account
|
inheritReviewers: true, // not taken into account
|
||||||
squash: true,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const configs: Configs = await configParser.parseAndValidate(args);
|
const configs: Configs = await configParser.parseAndValidate(args);
|
||||||
|
@ -358,6 +365,7 @@ describe("gitlab merge request config parser", () => {
|
||||||
email: "me@email.com"
|
email: "me@email.com"
|
||||||
});
|
});
|
||||||
expect(configs.auth).toEqual("");
|
expect(configs.auth).toEqual("");
|
||||||
|
expect(configs.targetBranch).toEqual("prod");
|
||||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||||
expect(configs.originalPullRequest).toEqual({
|
expect(configs.originalPullRequest).toEqual({
|
||||||
number: 1,
|
number: 1,
|
||||||
|
@ -371,7 +379,7 @@ describe("gitlab merge request config parser", () => {
|
||||||
body: "This is the body",
|
body: "This is the body",
|
||||||
reviewers: ["superuser1", "superuser2"],
|
reviewers: ["superuser1", "superuser2"],
|
||||||
assignees: ["superuser"],
|
assignees: ["superuser"],
|
||||||
labels: ["backport-prod"],
|
labels: ["gitlab-original-label"],
|
||||||
targetRepo: {
|
targetRepo: {
|
||||||
owner: "superuser",
|
owner: "superuser",
|
||||||
project: "backporting-example",
|
project: "backporting-example",
|
||||||
|
@ -385,18 +393,26 @@ describe("gitlab merge request config parser", () => {
|
||||||
nCommits: 1,
|
nCommits: 1,
|
||||||
commits: ["ebb1eca696c42fd067658bd9b5267709f78ef38e"]
|
commits: ["ebb1eca696c42fd067658bd9b5267709f78ef38e"]
|
||||||
});
|
});
|
||||||
expect(configs.backportPullRequests.length).toEqual(1);
|
expect(configs.backportPullRequest).toEqual({
|
||||||
expect(configs.backportPullRequests[0]).toEqual({
|
author: "Me",
|
||||||
owner: "superuser",
|
url: undefined,
|
||||||
repo: "backporting-example",
|
htmlUrl: undefined,
|
||||||
head: "bp-prod-ebb1eca",
|
|
||||||
base: "prod",
|
|
||||||
title: "New Title",
|
title: "New Title",
|
||||||
body: "New Body Prefix -New Body",
|
body: "New Body Prefix -New Body",
|
||||||
reviewers: ["user1", "user2"],
|
reviewers: ["user1", "user2"],
|
||||||
assignees: ["user3", "user4"],
|
assignees: ["user3", "user4"],
|
||||||
labels: [],
|
labels: [],
|
||||||
comments: [],
|
targetRepo: {
|
||||||
|
owner: "superuser",
|
||||||
|
project: "backporting-example",
|
||||||
|
cloneUrl: "https://my.gitlab.host.com/superuser/backporting-example.git"
|
||||||
|
},
|
||||||
|
sourceRepo: {
|
||||||
|
owner: "superuser",
|
||||||
|
project: "backporting-example",
|
||||||
|
cloneUrl: "https://my.gitlab.host.com/superuser/backporting-example.git"
|
||||||
|
},
|
||||||
|
bpBranchName: undefined,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -414,7 +430,6 @@ describe("gitlab merge request config parser", () => {
|
||||||
reviewers: [],
|
reviewers: [],
|
||||||
assignees: ["user3", "user4"],
|
assignees: ["user3", "user4"],
|
||||||
inheritReviewers: false,
|
inheritReviewers: false,
|
||||||
squash: true,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const configs: Configs = await configParser.parseAndValidate(args);
|
const configs: Configs = await configParser.parseAndValidate(args);
|
||||||
|
@ -430,6 +445,7 @@ describe("gitlab merge request config parser", () => {
|
||||||
email: "me@email.com"
|
email: "me@email.com"
|
||||||
});
|
});
|
||||||
expect(configs.auth).toEqual("");
|
expect(configs.auth).toEqual("");
|
||||||
|
expect(configs.targetBranch).toEqual("prod");
|
||||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||||
expect(configs.originalPullRequest).toEqual({
|
expect(configs.originalPullRequest).toEqual({
|
||||||
number: 1,
|
number: 1,
|
||||||
|
@ -443,7 +459,7 @@ describe("gitlab merge request config parser", () => {
|
||||||
body: "This is the body",
|
body: "This is the body",
|
||||||
reviewers: ["superuser1", "superuser2"],
|
reviewers: ["superuser1", "superuser2"],
|
||||||
assignees: ["superuser"],
|
assignees: ["superuser"],
|
||||||
labels: ["backport-prod"],
|
labels: ["gitlab-original-label"],
|
||||||
targetRepo: {
|
targetRepo: {
|
||||||
owner: "superuser",
|
owner: "superuser",
|
||||||
project: "backporting-example",
|
project: "backporting-example",
|
||||||
|
@ -457,18 +473,26 @@ describe("gitlab merge request config parser", () => {
|
||||||
nCommits: 1,
|
nCommits: 1,
|
||||||
commits: ["ebb1eca696c42fd067658bd9b5267709f78ef38e"]
|
commits: ["ebb1eca696c42fd067658bd9b5267709f78ef38e"]
|
||||||
});
|
});
|
||||||
expect(configs.backportPullRequests.length).toEqual(1);
|
expect(configs.backportPullRequest).toEqual({
|
||||||
expect(configs.backportPullRequests[0]).toEqual({
|
author: "Me",
|
||||||
owner: "superuser",
|
url: undefined,
|
||||||
repo: "backporting-example",
|
htmlUrl: undefined,
|
||||||
head: "bp-prod-ebb1eca",
|
|
||||||
base: "prod",
|
|
||||||
title: "New Title",
|
title: "New Title",
|
||||||
body: "New Body Prefix -New Body",
|
body: "New Body Prefix -New Body",
|
||||||
reviewers: [],
|
reviewers: [],
|
||||||
assignees: ["user3", "user4"],
|
assignees: ["user3", "user4"],
|
||||||
labels: [],
|
labels: [],
|
||||||
comments: [],
|
targetRepo: {
|
||||||
|
owner: "superuser",
|
||||||
|
project: "backporting-example",
|
||||||
|
cloneUrl: "https://my.gitlab.host.com/superuser/backporting-example.git"
|
||||||
|
},
|
||||||
|
sourceRepo: {
|
||||||
|
owner: "superuser",
|
||||||
|
project: "backporting-example",
|
||||||
|
cloneUrl: "https://my.gitlab.host.com/superuser/backporting-example.git"
|
||||||
|
},
|
||||||
|
bpBranchName: undefined,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -486,9 +510,8 @@ describe("gitlab merge request config parser", () => {
|
||||||
reviewers: [],
|
reviewers: [],
|
||||||
assignees: ["user3", "user4"],
|
assignees: ["user3", "user4"],
|
||||||
inheritReviewers: false,
|
inheritReviewers: false,
|
||||||
labels: ["custom-label", "backport-prod"], // also include the one inherited
|
labels: ["custom-label", "gitlab-original-label"], // also include the one inherited
|
||||||
inheritLabels: true,
|
inheritLabels: true,
|
||||||
squash: true,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const configs: Configs = await configParser.parseAndValidate(args);
|
const configs: Configs = await configParser.parseAndValidate(args);
|
||||||
|
@ -504,6 +527,7 @@ describe("gitlab merge request config parser", () => {
|
||||||
email: "me@email.com"
|
email: "me@email.com"
|
||||||
});
|
});
|
||||||
expect(configs.auth).toEqual("");
|
expect(configs.auth).toEqual("");
|
||||||
|
expect(configs.targetBranch).toEqual("prod");
|
||||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||||
expect(configs.originalPullRequest).toEqual({
|
expect(configs.originalPullRequest).toEqual({
|
||||||
number: 1,
|
number: 1,
|
||||||
|
@ -517,7 +541,7 @@ describe("gitlab merge request config parser", () => {
|
||||||
body: "This is the body",
|
body: "This is the body",
|
||||||
reviewers: ["superuser1", "superuser2"],
|
reviewers: ["superuser1", "superuser2"],
|
||||||
assignees: ["superuser"],
|
assignees: ["superuser"],
|
||||||
labels: ["backport-prod"],
|
labels: ["gitlab-original-label"],
|
||||||
targetRepo: {
|
targetRepo: {
|
||||||
owner: "superuser",
|
owner: "superuser",
|
||||||
project: "backporting-example",
|
project: "backporting-example",
|
||||||
|
@ -531,18 +555,26 @@ describe("gitlab merge request config parser", () => {
|
||||||
nCommits: 1,
|
nCommits: 1,
|
||||||
commits: ["ebb1eca696c42fd067658bd9b5267709f78ef38e"]
|
commits: ["ebb1eca696c42fd067658bd9b5267709f78ef38e"]
|
||||||
});
|
});
|
||||||
expect(configs.backportPullRequests.length).toEqual(1);
|
expect(configs.backportPullRequest).toEqual({
|
||||||
expect(configs.backportPullRequests[0]).toEqual({
|
author: "Me",
|
||||||
owner: "superuser",
|
url: undefined,
|
||||||
repo: "backporting-example",
|
htmlUrl: undefined,
|
||||||
head: "bp-prod-ebb1eca",
|
|
||||||
base: "prod",
|
|
||||||
title: "New Title",
|
title: "New Title",
|
||||||
body: "New Body Prefix -New Body",
|
body: "New Body Prefix -New Body",
|
||||||
reviewers: [],
|
reviewers: [],
|
||||||
assignees: ["user3", "user4"],
|
assignees: ["user3", "user4"],
|
||||||
labels: ["custom-label", "backport-prod"],
|
labels: ["custom-label", "gitlab-original-label"],
|
||||||
comments: [],
|
targetRepo: {
|
||||||
|
owner: "superuser",
|
||||||
|
project: "backporting-example",
|
||||||
|
cloneUrl: "https://my.gitlab.host.com/superuser/backporting-example.git"
|
||||||
|
},
|
||||||
|
sourceRepo: {
|
||||||
|
owner: "superuser",
|
||||||
|
project: "backporting-example",
|
||||||
|
cloneUrl: "https://my.gitlab.host.com/superuser/backporting-example.git"
|
||||||
|
},
|
||||||
|
bpBranchName: undefined,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -565,6 +597,7 @@ describe("gitlab merge request config parser", () => {
|
||||||
email: "noreply@gitlab.com"
|
email: "noreply@gitlab.com"
|
||||||
});
|
});
|
||||||
expect(configs.auth).toEqual(undefined);
|
expect(configs.auth).toEqual(undefined);
|
||||||
|
expect(configs.targetBranch).toEqual("prod");
|
||||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||||
expect(configs.originalPullRequest).toEqual({
|
expect(configs.originalPullRequest).toEqual({
|
||||||
number: 1,
|
number: 1,
|
||||||
|
@ -578,7 +611,7 @@ describe("gitlab merge request config parser", () => {
|
||||||
body: "This is the body",
|
body: "This is the body",
|
||||||
reviewers: ["superuser1", "superuser2"],
|
reviewers: ["superuser1", "superuser2"],
|
||||||
assignees: ["superuser"],
|
assignees: ["superuser"],
|
||||||
labels: ["backport-prod"],
|
labels: ["gitlab-original-label"],
|
||||||
targetRepo: {
|
targetRepo: {
|
||||||
owner: "superuser",
|
owner: "superuser",
|
||||||
project: "backporting-example",
|
project: "backporting-example",
|
||||||
|
@ -592,18 +625,26 @@ describe("gitlab merge request config parser", () => {
|
||||||
nCommits: 1,
|
nCommits: 1,
|
||||||
commits: ["ebb1eca696c42fd067658bd9b5267709f78ef38e"]
|
commits: ["ebb1eca696c42fd067658bd9b5267709f78ef38e"]
|
||||||
});
|
});
|
||||||
expect(configs.backportPullRequests.length).toEqual(1);
|
expect(configs.backportPullRequest).toEqual({
|
||||||
expect(configs.backportPullRequests[0]).toEqual({
|
author: "Gitlab",
|
||||||
owner: "superuser",
|
url: undefined,
|
||||||
repo: "backporting-example",
|
htmlUrl: undefined,
|
||||||
head: "bp-prod-ebb1eca",
|
|
||||||
base: "prod",
|
|
||||||
title: "[prod] Update test.txt",
|
title: "[prod] Update test.txt",
|
||||||
body: "**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1\r\n\r\nThis is the body",
|
body: "**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1\r\n\r\nThis is the body",
|
||||||
reviewers: ["superuser"],
|
reviewers: ["superuser"],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: [],
|
labels: [],
|
||||||
comments: [],
|
targetRepo: {
|
||||||
|
owner: "superuser",
|
||||||
|
project: "backporting-example",
|
||||||
|
cloneUrl: "https://my.gitlab.host.com/superuser/backporting-example.git"
|
||||||
|
},
|
||||||
|
sourceRepo: {
|
||||||
|
owner: "superuser",
|
||||||
|
project: "backporting-example",
|
||||||
|
cloneUrl: "https://my.gitlab.host.com/superuser/backporting-example.git"
|
||||||
|
},
|
||||||
|
bpBranchName: undefined,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -626,6 +667,7 @@ describe("gitlab merge request config parser", () => {
|
||||||
email: "me@email.com"
|
email: "me@email.com"
|
||||||
});
|
});
|
||||||
expect(configs.auth).toEqual("my-token");
|
expect(configs.auth).toEqual("my-token");
|
||||||
|
expect(configs.targetBranch).toEqual("prod");
|
||||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||||
expect(configs.originalPullRequest).toEqual({
|
expect(configs.originalPullRequest).toEqual({
|
||||||
number: 1,
|
number: 1,
|
||||||
|
@ -639,7 +681,7 @@ describe("gitlab merge request config parser", () => {
|
||||||
body: "This is the body",
|
body: "This is the body",
|
||||||
reviewers: ["superuser1", "superuser2"],
|
reviewers: ["superuser1", "superuser2"],
|
||||||
assignees: ["superuser"],
|
assignees: ["superuser"],
|
||||||
labels: ["backport-prod"],
|
labels: ["gitlab-original-label"],
|
||||||
targetRepo: {
|
targetRepo: {
|
||||||
owner: "superuser",
|
owner: "superuser",
|
||||||
project: "backporting-example",
|
project: "backporting-example",
|
||||||
|
@ -653,18 +695,26 @@ describe("gitlab merge request config parser", () => {
|
||||||
nCommits: 1,
|
nCommits: 1,
|
||||||
commits: ["ebb1eca696c42fd067658bd9b5267709f78ef38e"]
|
commits: ["ebb1eca696c42fd067658bd9b5267709f78ef38e"]
|
||||||
});
|
});
|
||||||
expect(configs.backportPullRequests.length).toEqual(1);
|
expect(configs.backportPullRequest).toEqual({
|
||||||
expect(configs.backportPullRequests[0]).toEqual({
|
author: "Me",
|
||||||
owner: "superuser",
|
url: undefined,
|
||||||
repo: "backporting-example",
|
htmlUrl: undefined,
|
||||||
head: "bp-prod-ebb1eca",
|
|
||||||
base: "prod",
|
|
||||||
title: "New Title",
|
title: "New Title",
|
||||||
body: "New Body Prefix -New Body",
|
body: "New Body Prefix -New Body",
|
||||||
reviewers: [],
|
reviewers: [],
|
||||||
assignees: ["user3", "user4"],
|
assignees: ["user3", "user4"],
|
||||||
labels: ["cherry-pick :cherries:", "backport-prod"],
|
labels: ["cherry-pick :cherries:", "gitlab-original-label"],
|
||||||
comments: [],
|
targetRepo: {
|
||||||
|
owner: "superuser",
|
||||||
|
project: "backporting-example",
|
||||||
|
cloneUrl: "https://my.gitlab.host.com/superuser/backporting-example.git"
|
||||||
|
},
|
||||||
|
sourceRepo: {
|
||||||
|
owner: "superuser",
|
||||||
|
project: "backporting-example",
|
||||||
|
cloneUrl: "https://my.gitlab.host.com/superuser/backporting-example.git"
|
||||||
|
},
|
||||||
|
bpBranchName: undefined,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -691,6 +741,7 @@ describe("gitlab merge request config parser", () => {
|
||||||
|
|
||||||
expect(configs.dryRun).toEqual(true);
|
expect(configs.dryRun).toEqual(true);
|
||||||
expect(configs.auth).toEqual("whatever");
|
expect(configs.auth).toEqual("whatever");
|
||||||
|
expect(configs.targetBranch).toEqual("prod");
|
||||||
expect(configs.git).toEqual({
|
expect(configs.git).toEqual({
|
||||||
user: "Gitlab",
|
user: "Gitlab",
|
||||||
email: "noreply@gitlab.com"
|
email: "noreply@gitlab.com"
|
||||||
|
@ -722,190 +773,5 @@ describe("gitlab merge request config parser", () => {
|
||||||
nCommits: 2,
|
nCommits: 2,
|
||||||
commits: ["e4dd336a4a20f394df6665994df382fb1d193a11", "974519f65c9e0ed65277cd71026657a09fca05e7"]
|
commits: ["e4dd336a4a20f394df6665994df382fb1d193a11", "974519f65c9e0ed65277cd71026657a09fca05e7"]
|
||||||
});
|
});
|
||||||
expect(configs.backportPullRequests.length).toEqual(1);
|
|
||||||
expect(configs.backportPullRequests[0]).toEqual({
|
|
||||||
owner: "superuser",
|
|
||||||
repo: "backporting-example",
|
|
||||||
head: "bp-prod-e4dd336-974519f",
|
|
||||||
base: "prod",
|
|
||||||
title: "[prod] Update test.txt opened",
|
|
||||||
body: "**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/2\r\n\r\nStill opened mr body",
|
|
||||||
reviewers: ["superuser"],
|
|
||||||
assignees: [],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test("override backport pr with additional comments", async () => {
|
|
||||||
const args: Args = {
|
|
||||||
dryRun: false,
|
|
||||||
auth: "",
|
|
||||||
pullRequest: mergedPRUrl,
|
|
||||||
targetBranch: "prod",
|
|
||||||
gitUser: "Me",
|
|
||||||
gitEmail: "me@email.com",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body",
|
|
||||||
bodyPrefix: "New Body Prefix -",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
inheritReviewers: false,
|
|
||||||
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(configs.dryRun).toEqual(false);
|
|
||||||
expect(configs.git).toEqual({
|
|
||||||
user: "Me",
|
|
||||||
email: "me@email.com"
|
|
||||||
});
|
|
||||||
expect(configs.auth).toEqual("");
|
|
||||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
|
||||||
expect(configs.originalPullRequest).toEqual({
|
|
||||||
number: 1,
|
|
||||||
author: "superuser",
|
|
||||||
url: "https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1",
|
|
||||||
htmlUrl: "https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1",
|
|
||||||
state: "merged",
|
|
||||||
merged: true,
|
|
||||||
mergedBy: "superuser",
|
|
||||||
title: "Update test.txt",
|
|
||||||
body: "This is the body",
|
|
||||||
reviewers: ["superuser1", "superuser2"],
|
|
||||||
assignees: ["superuser"],
|
|
||||||
labels: ["backport-prod"],
|
|
||||||
targetRepo: {
|
|
||||||
owner: "superuser",
|
|
||||||
project: "backporting-example",
|
|
||||||
cloneUrl: "https://my.gitlab.host.com/superuser/backporting-example.git"
|
|
||||||
},
|
|
||||||
sourceRepo: {
|
|
||||||
owner: "superuser",
|
|
||||||
project: "backporting-example",
|
|
||||||
cloneUrl: "https://my.gitlab.host.com/superuser/backporting-example.git"
|
|
||||||
},
|
|
||||||
nCommits: 1,
|
|
||||||
commits: ["ebb1eca696c42fd067658bd9b5267709f78ef38e"]
|
|
||||||
});
|
|
||||||
expect(configs.backportPullRequests.length).toEqual(1);
|
|
||||||
expect(configs.backportPullRequests[0]).toEqual({
|
|
||||||
owner: "superuser",
|
|
||||||
repo: "backporting-example",
|
|
||||||
head: "bp-prod-ebb1eca",
|
|
||||||
base: "prod",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body Prefix -New Body",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
labels: [],
|
|
||||||
comments: ["First comment", "Second comment"],
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test("extract target branches from pr labels", async () => {
|
|
||||||
const args: Args = {
|
|
||||||
dryRun: false,
|
|
||||||
auth: "",
|
|
||||||
pullRequest: mergedPRUrl,
|
|
||||||
targetBranchPattern: "^backport-(?<target>([^ ]+))$",
|
|
||||||
gitUser: "Me",
|
|
||||||
gitEmail: "me@email.com",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body",
|
|
||||||
bodyPrefix: "New Body Prefix -",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
inheritReviewers: false,
|
|
||||||
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(configs.dryRun).toEqual(false);
|
|
||||||
expect(configs.git).toEqual({
|
|
||||||
user: "Me",
|
|
||||||
email: "me@email.com"
|
|
||||||
});
|
|
||||||
expect(configs.auth).toEqual("");
|
|
||||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
|
||||||
expect(configs.originalPullRequest).toEqual({
|
|
||||||
number: 1,
|
|
||||||
author: "superuser",
|
|
||||||
url: "https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1",
|
|
||||||
htmlUrl: "https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1",
|
|
||||||
state: "merged",
|
|
||||||
merged: true,
|
|
||||||
mergedBy: "superuser",
|
|
||||||
title: "Update test.txt",
|
|
||||||
body: "This is the body",
|
|
||||||
reviewers: ["superuser1", "superuser2"],
|
|
||||||
assignees: ["superuser"],
|
|
||||||
labels: ["backport-prod"],
|
|
||||||
targetRepo: {
|
|
||||||
owner: "superuser",
|
|
||||||
project: "backporting-example",
|
|
||||||
cloneUrl: "https://my.gitlab.host.com/superuser/backporting-example.git"
|
|
||||||
},
|
|
||||||
sourceRepo: {
|
|
||||||
owner: "superuser",
|
|
||||||
project: "backporting-example",
|
|
||||||
cloneUrl: "https://my.gitlab.host.com/superuser/backporting-example.git"
|
|
||||||
},
|
|
||||||
nCommits: 1,
|
|
||||||
commits: ["ebb1eca696c42fd067658bd9b5267709f78ef38e"]
|
|
||||||
});
|
|
||||||
expect(configs.backportPullRequests.length).toEqual(1);
|
|
||||||
expect(configs.backportPullRequests[0]).toEqual({
|
|
||||||
owner: "superuser",
|
|
||||||
repo: "backporting-example",
|
|
||||||
head: "bp-prod-ebb1eca",
|
|
||||||
base: "prod",
|
|
||||||
title: "New Title",
|
|
||||||
body: "New Body Prefix -New Body",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: ["user3", "user4"],
|
|
||||||
labels: [],
|
|
||||||
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).toBeCalledTimes(1);
|
|
||||||
expect(GitLabClient.prototype.getPullRequest).toBeCalledWith("superuser", "backporting-example", 1, undefined);
|
|
||||||
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledTimes(1);
|
|
||||||
expect(GitLabMapper.prototype.mapPullRequest).toBeCalledWith(expect.anything(), []);
|
|
||||||
|
|
||||||
expect(configs.errorNotification).toEqual({
|
|
||||||
"enabled": true,
|
|
||||||
"message": "The backport to `{{target-branch}}` failed. Check the latest run for more details.",
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
|
@ -114,31 +114,4 @@ describe("git cli service", () => {
|
||||||
const output = spawnSync("git", ["cherry", "-v"], { cwd }).stdout.toString();
|
const output = spawnSync("git", ["cherry", "-v"], { cwd }).stdout.toString();
|
||||||
expect(output.includes(expressionToTest)).toBe(false);
|
expect(output.includes(expressionToTest)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
test("git clone on already created repo", async () => {
|
|
||||||
await git.clone("remote", cwd, "tbranch");
|
|
||||||
|
|
||||||
// use rev-parse to double check the current branch is the expected one
|
|
||||||
const post = spawnSync("git", ["rev-parse", "--abbrev-ref", "HEAD"], { cwd }).stdout.toString().trim();
|
|
||||||
expect(post).toEqual("tbranch");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("git clone set url with auth correctly for API token", async () => {
|
|
||||||
const git2 = new GitCLIService("api-token", {
|
|
||||||
user: "Backporting bot",
|
|
||||||
email: "bot@example.com",
|
|
||||||
});
|
|
||||||
const cwd2 = `${__dirname}/test-api-token`;
|
|
||||||
|
|
||||||
try {
|
|
||||||
await git2.clone(`file://${cwd}`, cwd2, "main");
|
|
||||||
const remoteURL = spawnSync("git", ["remote", "get-url", "origin"], { cwd: cwd2 }).stdout.toString().trim();
|
|
||||||
|
|
||||||
expect(remoteURL).toContain("api-token");
|
|
||||||
expect(remoteURL).not.toContain("Backporting bot");
|
|
||||||
} finally {
|
|
||||||
fs.rmSync(cwd2, { recursive: true, force: true });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
|
@ -20,11 +20,6 @@ describe("git client factory test", () => {
|
||||||
expect(client).toBeInstanceOf(GitLabClient);
|
expect(client).toBeInstanceOf(GitLabClient);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("correctly create codeberg client", () => {
|
|
||||||
const client = GitClientFactory.getOrCreate(GitClientType.CODEBERG, "auth", "apiurl");
|
|
||||||
expect(client).toBeInstanceOf(GitHubClient);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("check get service github", () => {
|
test("check get service github", () => {
|
||||||
const create = GitClientFactory.getOrCreate(GitClientType.GITHUB, "auth", "apiurl");
|
const create = GitClientFactory.getOrCreate(GitClientType.GITHUB, "auth", "apiurl");
|
||||||
const get = GitClientFactory.getClient();
|
const get = GitClientFactory.getClient();
|
||||||
|
@ -36,10 +31,4 @@ describe("git client factory test", () => {
|
||||||
const get = GitClientFactory.getClient();
|
const get = GitClientFactory.getClient();
|
||||||
expect(create).toStrictEqual(get);
|
expect(create).toStrictEqual(get);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("check get service codeberg", () => {
|
|
||||||
const create = GitClientFactory.getOrCreate(GitClientType.CODEBERG, "auth", "apiurl");
|
|
||||||
const get = GitClientFactory.getClient();
|
|
||||||
expect(create).toStrictEqual(get);
|
|
||||||
});
|
|
||||||
});
|
});
|
|
@ -1,4 +1,4 @@
|
||||||
import { inferGitApiUrl, inferGitClient, inferSquash } from "@bp/service/git/git-util";
|
import { inferGitApiUrl, inferGitClient } from "@bp/service/git/git-util";
|
||||||
import { GitClientType } from "@bp/service/git/git.types";
|
import { GitClientType } from "@bp/service/git/git.types";
|
||||||
|
|
||||||
describe("check git utilities", () => {
|
describe("check git utilities", () => {
|
||||||
|
@ -23,18 +23,6 @@ describe("check git utilities", () => {
|
||||||
expect(inferGitApiUrl("http://github.acme-inc.com/superuser/backporting-example/pull/4", "v3")).toStrictEqual("http://github.acme-inc.com/api/v3");
|
expect(inferGitApiUrl("http://github.acme-inc.com/superuser/backporting-example/pull/4", "v3")).toStrictEqual("http://github.acme-inc.com/api/v3");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("check infer github api from github api url", ()=> {
|
|
||||||
expect(inferGitApiUrl("https://api.github.com/repos/owner/repo/pulls/1")).toStrictEqual("https://api.github.com");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("check infer codeberg api", ()=> {
|
|
||||||
expect(inferGitApiUrl("https://codeberg.org/lampajr/backporting-example/pulls/1", "v1")).toStrictEqual("https://codeberg.org/api/v1");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("check infer codeberg api", ()=> {
|
|
||||||
expect(inferGitApiUrl("https://codeberg.org/lampajr/backporting-example/pulls/1", undefined)).toStrictEqual("https://codeberg.org/api/v4");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("check infer github client", ()=> {
|
test("check infer github client", ()=> {
|
||||||
expect(inferGitClient("https://github.com/superuser/backporting-example/pull/4")).toStrictEqual(GitClientType.GITHUB);
|
expect(inferGitClient("https://github.com/superuser/backporting-example/pull/4")).toStrictEqual(GitClientType.GITHUB);
|
||||||
});
|
});
|
||||||
|
@ -51,14 +39,7 @@ describe("check git utilities", () => {
|
||||||
expect(inferGitClient("https://api.github.com/repos/owner/repo/pulls/1")).toStrictEqual(GitClientType.GITHUB);
|
expect(inferGitClient("https://api.github.com/repos/owner/repo/pulls/1")).toStrictEqual(GitClientType.GITHUB);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("check infer codeberg client", ()=> {
|
test("check infer github api from github api url", ()=> {
|
||||||
expect(inferGitClient("https://codeberg.org/lampajr/backporting-example/pulls/1")).toStrictEqual(GitClientType.CODEBERG);
|
expect(inferGitApiUrl("https://api.github.com/repos/owner/repo/pulls/1")).toStrictEqual("https://api.github.com");
|
||||||
});
|
|
||||||
|
|
||||||
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);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
|
@ -1,7 +1,7 @@
|
||||||
import GitClientFactory from "@bp/service/git/git-client-factory";
|
import GitClientFactory from "@bp/service/git/git-client-factory";
|
||||||
import { GitPullRequest, GitClientType } from "@bp/service/git/git.types";
|
import { GitPullRequest, GitClientType } from "@bp/service/git/git.types";
|
||||||
import GitHubClient from "@bp/service/git/github/github-client";
|
import GitHubClient from "@bp/service/git/github/github-client";
|
||||||
import { MERGED_PR_FIXTURE, REPO, TARGET_OWNER } from "../../../support/mock/github-data";
|
import { mergedPullRequestFixture, repo, targetOwner } from "../../../support/mock/github-data";
|
||||||
import { mockGitHubClient } from "../../../support/mock/git-client-mock-support";
|
import { mockGitHubClient } from "../../../support/mock/git-client-mock-support";
|
||||||
|
|
||||||
describe("github service", () => {
|
describe("github service", () => {
|
||||||
|
@ -22,7 +22,7 @@ describe("github service", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("get pull request: success", async () => {
|
test("get pull request: success", async () => {
|
||||||
const res: GitPullRequest = await gitClient.getPullRequest(TARGET_OWNER, REPO, MERGED_PR_FIXTURE.number, true);
|
const res: GitPullRequest = await gitClient.getPullRequest(targetOwner, repo, mergedPullRequestFixture.number);
|
||||||
expect(res.sourceRepo).toEqual({
|
expect(res.sourceRepo).toEqual({
|
||||||
owner: "fork",
|
owner: "fork",
|
||||||
project: "reponame",
|
project: "reponame",
|
||||||
|
|
|
@ -31,7 +31,7 @@ describe("github service", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("get merged pull request", async () => {
|
test("get merged pull request", async () => {
|
||||||
const res: GitPullRequest = await gitClient.getPullRequest("superuser", "backporting-example", 1, true);
|
const res: GitPullRequest = await gitClient.getPullRequest("superuser", "backporting-example", 1);
|
||||||
|
|
||||||
// check content
|
// check content
|
||||||
expect(res.sourceRepo).toEqual({
|
expect(res.sourceRepo).toEqual({
|
||||||
|
@ -56,7 +56,7 @@ describe("github service", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("get open pull request", async () => {
|
test("get open pull request", async () => {
|
||||||
const res: GitPullRequest = await gitClient.getPullRequest("superuser", "backporting-example", 2, true);
|
const res: GitPullRequest = await gitClient.getPullRequest("superuser", "backporting-example", 2);
|
||||||
expect(res.sourceRepo).toEqual({
|
expect(res.sourceRepo).toEqual({
|
||||||
owner: "superuser",
|
owner: "superuser",
|
||||||
project: "backporting-example",
|
project: "backporting-example",
|
||||||
|
@ -89,7 +89,6 @@ describe("github service", () => {
|
||||||
reviewers: [],
|
reviewers: [],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: [],
|
labels: [],
|
||||||
comments: [],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const url: string = await gitClient.createPullRequest(backport);
|
const url: string = await gitClient.createPullRequest(backport);
|
||||||
|
@ -120,7 +119,6 @@ describe("github service", () => {
|
||||||
reviewers: ["superuser", "invalid"],
|
reviewers: ["superuser", "invalid"],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: [],
|
labels: [],
|
||||||
comments: [],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const url: string = await gitClient.createPullRequest(backport);
|
const url: string = await gitClient.createPullRequest(backport);
|
||||||
|
@ -156,7 +154,6 @@ describe("github service", () => {
|
||||||
reviewers: [],
|
reviewers: [],
|
||||||
assignees: ["superuser", "invalid"],
|
assignees: ["superuser", "invalid"],
|
||||||
labels: [],
|
labels: [],
|
||||||
comments: [],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const url: string = await gitClient.createPullRequest(backport);
|
const url: string = await gitClient.createPullRequest(backport);
|
||||||
|
@ -192,7 +189,6 @@ describe("github service", () => {
|
||||||
reviewers: ["superuser", "invalid"],
|
reviewers: ["superuser", "invalid"],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: [],
|
labels: [],
|
||||||
comments: [],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const url: string = await gitClient.createPullRequest(backport);
|
const url: string = await gitClient.createPullRequest(backport);
|
||||||
|
@ -228,7 +224,6 @@ describe("github service", () => {
|
||||||
reviewers: [],
|
reviewers: [],
|
||||||
assignees: ["superuser", "invalid"],
|
assignees: ["superuser", "invalid"],
|
||||||
labels: [],
|
labels: [],
|
||||||
comments: [],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const url: string = await gitClient.createPullRequest(backport);
|
const url: string = await gitClient.createPullRequest(backport);
|
||||||
|
@ -264,7 +259,6 @@ describe("github service", () => {
|
||||||
reviewers: [],
|
reviewers: [],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: ["label1", "label2"],
|
labels: ["label1", "label2"],
|
||||||
comments: [],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const url: string = await gitClient.createPullRequest(backport);
|
const url: string = await gitClient.createPullRequest(backport);
|
||||||
|
@ -286,66 +280,4 @@ describe("github service", () => {
|
||||||
labels: "label1,label2",
|
labels: "label1,label2",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test("create backport pull request with post comments", async () => {
|
|
||||||
const backport: BackportPullRequest = {
|
|
||||||
title: "Backport Title",
|
|
||||||
body: "Backport Body",
|
|
||||||
owner: "superuser",
|
|
||||||
repo: "backporting-example",
|
|
||||||
base: "old/branch",
|
|
||||||
head: "bp-branch-2",
|
|
||||||
reviewers: [],
|
|
||||||
assignees: [],
|
|
||||||
labels: [],
|
|
||||||
comments: ["this is first comment", "this is second comment"],
|
|
||||||
};
|
|
||||||
|
|
||||||
const url: string = await gitClient.createPullRequest(backport);
|
|
||||||
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({
|
|
||||||
source_branch: "bp-branch-2",
|
|
||||||
target_branch: "old/branch",
|
|
||||||
title: "Backport Title",
|
|
||||||
description: "Backport Body",
|
|
||||||
reviewer_ids: [],
|
|
||||||
assignee_ids: [],
|
|
||||||
}));
|
|
||||||
expect(axiosInstanceSpy.get).toBeCalledTimes(0);
|
|
||||||
|
|
||||||
expect(axiosInstanceSpy.post).toBeCalledWith("/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", {
|
|
||||||
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", true);
|
|
||||||
|
|
||||||
// check content
|
|
||||||
expect(res.sourceRepo).toEqual({
|
|
||||||
owner: "superuser",
|
|
||||||
project: "backporting-example",
|
|
||||||
cloneUrl: "https://my.gitlab.host.com/mysuperorg/6/mysuperproduct/mysuperunit/backporting-example.git"
|
|
||||||
});
|
|
||||||
expect(res.targetRepo).toEqual({
|
|
||||||
owner: "superuser",
|
|
||||||
project: "backporting-example",
|
|
||||||
cloneUrl: "https://my.gitlab.host.com/mysuperorg/6/mysuperproduct/mysuperunit/backporting-example.git"
|
|
||||||
});
|
|
||||||
expect(res.title).toBe("Update test.txt");
|
|
||||||
expect(res.commits!.length).toBe(1);
|
|
||||||
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");
|
|
||||||
});
|
|
||||||
});
|
});
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -3,12 +3,11 @@ import Runner from "@bp/service/runner/runner";
|
||||||
import GitCLIService from "@bp/service/git/git-cli";
|
import GitCLIService from "@bp/service/git/git-cli";
|
||||||
import GitLabClient from "@bp/service/git/gitlab/gitlab-client";
|
import GitLabClient from "@bp/service/git/gitlab/gitlab-client";
|
||||||
import CLIArgsParser from "@bp/service/args/cli/cli-args-parser";
|
import CLIArgsParser from "@bp/service/args/cli/cli-args-parser";
|
||||||
import { addProcessArgs, createTestFile, removeTestFile, resetEnvTokens, resetProcessArgs } from "../../support/utils";
|
import { addProcessArgs, createTestFile, removeTestFile, resetProcessArgs } from "../../support/utils";
|
||||||
import { getAxiosMocked } from "../../support/mock/git-client-mock-support";
|
import { getAxiosMocked } from "../../support/mock/git-client-mock-support";
|
||||||
import { MERGED_SQUASHED_MR } from "../../support/mock/gitlab-data";
|
import { MERGED_SQUASHED_MR } from "../../support/mock/gitlab-data";
|
||||||
import GitClientFactory from "@bp/service/git/git-client-factory";
|
import GitClientFactory from "@bp/service/git/git-client-factory";
|
||||||
import { GitClientType } from "@bp/service/git/git.types";
|
import { GitClientType } from "@bp/service/git/git.types";
|
||||||
import { AuthTokenId } from "@bp/service/configs/configs.types";
|
|
||||||
|
|
||||||
const GITLAB_MERGED_PR_COMPLEX_CONFIG_FILE_CONTENT_PATHNAME = "./cli-gitlab-runner-pr-merged-with-overrides.json";
|
const GITLAB_MERGED_PR_COMPLEX_CONFIG_FILE_CONTENT_PATHNAME = "./cli-gitlab-runner-pr-merged-with-overrides.json";
|
||||||
const GITLAB_MERGED_PR_COMPLEX_CONFIG_FILE_CONTENT = {
|
const GITLAB_MERGED_PR_COMPLEX_CONFIG_FILE_CONTENT = {
|
||||||
|
@ -37,14 +36,13 @@ jest.mock("axios", () => {
|
||||||
iid: 1, // FIXME: I am not testing this atm
|
iid: 1, // FIXME: I am not testing this atm
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
put: async () => undefined,
|
put: jest.fn(),
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
jest.mock("@bp/service/git/git-cli");
|
jest.mock("@bp/service/git/git-cli");
|
||||||
jest.spyOn(GitLabClient.prototype, "createPullRequest");
|
jest.spyOn(GitLabClient.prototype, "createPullRequest");
|
||||||
jest.spyOn(GitLabClient.prototype, "createPullRequestComment");
|
|
||||||
jest.spyOn(GitClientFactory, "getOrCreate");
|
jest.spyOn(GitClientFactory, "getOrCreate");
|
||||||
|
|
||||||
|
|
||||||
|
@ -62,12 +60,6 @@ afterAll(() => {
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// reset process.env variables
|
|
||||||
resetProcessArgs();
|
|
||||||
|
|
||||||
// reset git env tokens
|
|
||||||
resetEnvTokens();
|
|
||||||
|
|
||||||
// create CLI arguments parser
|
// create CLI arguments parser
|
||||||
parser = new CLIArgsParser();
|
parser = new CLIArgsParser();
|
||||||
|
|
||||||
|
@ -75,7 +67,13 @@ beforeEach(() => {
|
||||||
runner = new Runner(parser);
|
runner = new Runner(parser);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
// reset process.env variables
|
||||||
|
resetProcessArgs();
|
||||||
|
});
|
||||||
|
|
||||||
describe("cli runner", () => {
|
describe("cli runner", () => {
|
||||||
|
|
||||||
test("with dry run", async () => {
|
test("with dry run", async () => {
|
||||||
addProcessArgs([
|
addProcessArgs([
|
||||||
"-d",
|
"-d",
|
||||||
|
@ -96,17 +94,16 @@ describe("cli runner", () => {
|
||||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
|
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-9e15674");
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-9e15674ebd48e05c6e428a1fa31dbb60a778d644");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2");
|
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined, undefined);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledTimes(0);
|
expect(GitCLIService.prototype.push).toBeCalledTimes(0);
|
||||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(0);
|
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(0);
|
||||||
expect(GitLabClient.prototype.createPullRequestComment).toBeCalledTimes(0);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("dry run with relative folder", async () => {
|
test("dry run with relative folder", async () => {
|
||||||
|
@ -131,13 +128,13 @@ describe("cli runner", () => {
|
||||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
|
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-9e15674");
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-9e15674ebd48e05c6e428a1fa31dbb60a778d644");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2");
|
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined, undefined);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.addRemote).toBeCalledTimes(0);
|
expect(GitCLIService.prototype.addRemote).toBeCalledTimes(0);
|
||||||
expect(GitCLIService.prototype.addRemote).toBeCalledTimes(0);
|
expect(GitCLIService.prototype.addRemote).toBeCalledTimes(0);
|
||||||
|
@ -165,29 +162,28 @@ describe("cli runner", () => {
|
||||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
|
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-9e15674");
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-9e15674ebd48e05c6e428a1fa31dbb60a778d644");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2");
|
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined, undefined);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-9e15674");
|
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-9e15674ebd48e05c6e428a1fa31dbb60a778d644");
|
||||||
|
|
||||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
|
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
|
||||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
|
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
|
||||||
owner: "superuser",
|
owner: "superuser",
|
||||||
repo: "backporting-example",
|
repo: "backporting-example",
|
||||||
head: "bp-target-9e15674",
|
head: "bp-target-9e15674ebd48e05c6e428a1fa31dbb60a778d644",
|
||||||
base: "target",
|
base: "target",
|
||||||
title: "[target] Update test.txt opened",
|
title: "[target] Update test.txt opened",
|
||||||
body: expect.stringContaining("**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/2"),
|
body: expect.stringContaining("**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/2"),
|
||||||
reviewers: ["superuser"],
|
reviewers: ["superuser"],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: [],
|
labels: [],
|
||||||
comments: [],
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -200,8 +196,7 @@ describe("cli runner", () => {
|
||||||
"https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/3"
|
"https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/3"
|
||||||
]);
|
]);
|
||||||
|
|
||||||
await expect(() => runner.execute()).rejects.toThrow("Provided pull request is closed and not merged");
|
await expect(() => runner.execute()).rejects.toThrow("Provided pull request is closed and not merged!");
|
||||||
expect(GitLabClient.prototype.createPullRequestComment).toBeCalledTimes(0);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("merged pull request", async () => {
|
test("merged pull request", async () => {
|
||||||
|
@ -223,33 +218,31 @@ describe("cli runner", () => {
|
||||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
|
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-ebb1eca");
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||||
|
|
||||||
// 0 occurrences as the mr is already merged and the owner is the same for
|
// 0 occurrences as the mr is already merged and the owner is the same for
|
||||||
// both source and target repositories
|
// both source and target repositories
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(0);
|
expect(GitCLIService.prototype.fetch).toBeCalledTimes(0);
|
||||||
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e", undefined, undefined, undefined);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-ebb1eca");
|
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||||
|
|
||||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
|
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
|
||||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
|
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
|
||||||
owner: "superuser",
|
owner: "superuser",
|
||||||
repo: "backporting-example",
|
repo: "backporting-example",
|
||||||
head: "bp-target-ebb1eca",
|
head: "bp-target-ebb1eca696c42fd067658bd9b5267709f78ef38e",
|
||||||
base: "target",
|
base: "target",
|
||||||
title: "[target] Update test.txt",
|
title: "[target] Update test.txt",
|
||||||
body: expect.stringContaining("**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1"),
|
body: expect.stringContaining("**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1"),
|
||||||
reviewers: ["superuser"],
|
reviewers: ["superuser"],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: [],
|
labels: [],
|
||||||
comments: [],
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
expect(GitLabClient.prototype.createPullRequestComment).toBeCalledTimes(0);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -290,7 +283,7 @@ describe("cli runner", () => {
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2");
|
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined, undefined);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp_branch_name");
|
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp_branch_name");
|
||||||
|
@ -306,7 +299,6 @@ describe("cli runner", () => {
|
||||||
reviewers: ["user1", "user2"],
|
reviewers: ["user1", "user2"],
|
||||||
assignees: ["user3", "user4"],
|
assignees: ["user3", "user4"],
|
||||||
labels: [],
|
labels: [],
|
||||||
comments: [],
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -347,7 +339,7 @@ describe("cli runner", () => {
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2");
|
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined, undefined);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp_branch_name");
|
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp_branch_name");
|
||||||
|
@ -363,7 +355,6 @@ describe("cli runner", () => {
|
||||||
reviewers: [],
|
reviewers: [],
|
||||||
assignees: ["user3", "user4"],
|
assignees: ["user3", "user4"],
|
||||||
labels: [],
|
labels: [],
|
||||||
comments: [],
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -390,30 +381,29 @@ describe("cli runner", () => {
|
||||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
|
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-ebb1eca");
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||||
|
|
||||||
// 0 occurrences as the mr is already merged and the owner is the same for
|
// 0 occurrences as the mr is already merged and the owner is the same for
|
||||||
// both source and target repositories
|
// both source and target repositories
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(0);
|
expect(GitCLIService.prototype.fetch).toBeCalledTimes(0);
|
||||||
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e", undefined, undefined, undefined);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-ebb1eca");
|
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||||
|
|
||||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
|
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
|
||||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
|
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
|
||||||
owner: "superuser",
|
owner: "superuser",
|
||||||
repo: "backporting-example",
|
repo: "backporting-example",
|
||||||
head: "bp-target-ebb1eca",
|
head: "bp-target-ebb1eca696c42fd067658bd9b5267709f78ef38e",
|
||||||
base: "target",
|
base: "target",
|
||||||
title: "[target] Update test.txt",
|
title: "[target] Update test.txt",
|
||||||
body: expect.stringContaining("**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1"),
|
body: expect.stringContaining("**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1"),
|
||||||
reviewers: ["superuser"],
|
reviewers: ["superuser"],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: ["cherry-pick :cherries:", "another-label", "backport-prod"],
|
labels: ["cherry-pick :cherries:", "another-label", "gitlab-original-label"],
|
||||||
comments: [],
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -439,30 +429,29 @@ describe("cli runner", () => {
|
||||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
|
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-ebb1eca");
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||||
|
|
||||||
// 0 occurrences as the mr is already merged and the owner is the same for
|
// 0 occurrences as the mr is already merged and the owner is the same for
|
||||||
// both source and target repositories
|
// both source and target repositories
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(0);
|
expect(GitCLIService.prototype.fetch).toBeCalledTimes(0);
|
||||||
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e", undefined, undefined, undefined);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-ebb1eca");
|
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||||
|
|
||||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
|
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
|
||||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
|
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
|
||||||
owner: "superuser",
|
owner: "superuser",
|
||||||
repo: "backporting-example",
|
repo: "backporting-example",
|
||||||
head: "bp-target-ebb1eca",
|
head: "bp-target-ebb1eca696c42fd067658bd9b5267709f78ef38e",
|
||||||
base: "target",
|
base: "target",
|
||||||
title: "[target] Update test.txt",
|
title: "[target] Update test.txt",
|
||||||
body: expect.stringContaining("**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1"),
|
body: expect.stringContaining("**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1"),
|
||||||
reviewers: ["superuser"],
|
reviewers: ["superuser"],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: ["cherry-pick :cherries:", "another-label"],
|
labels: ["cherry-pick :cherries:", "another-label"],
|
||||||
comments: [],
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -484,74 +473,29 @@ describe("cli runner", () => {
|
||||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "prod");
|
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "prod");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-prod-ebb1eca");
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-prod-ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||||
|
|
||||||
// 0 occurrences as the mr is already merged and the owner is the same for
|
// 0 occurrences as the mr is already merged and the owner is the same for
|
||||||
// both source and target repositories
|
// both source and target repositories
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(0);
|
expect(GitCLIService.prototype.fetch).toBeCalledTimes(0);
|
||||||
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e", undefined, undefined, undefined);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-prod-ebb1eca");
|
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-prod-ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||||
|
|
||||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
|
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
|
||||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
|
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
|
||||||
owner: "superuser",
|
owner: "superuser",
|
||||||
repo: "backporting-example",
|
repo: "backporting-example",
|
||||||
head: "bp-prod-ebb1eca",
|
head: "bp-prod-ebb1eca696c42fd067658bd9b5267709f78ef38e",
|
||||||
base: "prod",
|
base: "prod",
|
||||||
title: "New Title",
|
title: "New Title",
|
||||||
body: expect.stringContaining("**This is a backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1"),
|
body: expect.stringContaining("**This is a backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1"),
|
||||||
reviewers: [],
|
reviewers: [],
|
||||||
assignees: ["user3", "user4"],
|
assignees: ["user3", "user4"],
|
||||||
labels: ["cli gitlab cherry pick :cherries:", "backport-prod"],
|
labels: ["cli gitlab cherry pick :cherries:", "gitlab-original-label"],
|
||||||
comments: [],
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("single commit without squash", async () => {
|
|
||||||
addProcessArgs([
|
|
||||||
"-tb",
|
|
||||||
"target",
|
|
||||||
"-pr",
|
|
||||||
"https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1",
|
|
||||||
"--no-squash",
|
|
||||||
]);
|
|
||||||
|
|
||||||
await runner.execute();
|
|
||||||
|
|
||||||
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(GitCLIService.prototype.clone).toBeCalledTimes(1);
|
|
||||||
expect(GitCLIService.prototype.clone).toBeCalledWith("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.cherryPick).toBeCalledTimes(1);
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "e4dd336a4a20f394df6665994df382fb1d193a11", undefined, undefined, undefined);
|
|
||||||
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-e4dd336");
|
|
||||||
|
|
||||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
|
|
||||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
|
|
||||||
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/1"),
|
|
||||||
reviewers: ["superuser"],
|
|
||||||
assignees: [],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -576,130 +520,30 @@ describe("cli runner", () => {
|
||||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
|
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-e4dd336-974519f");
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-e4dd336a4a20f394df6665994df382fb1d193a11-974519f65c9e0ed65277cd71026657a09fca05e7");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2");
|
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(2);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(2);
|
||||||
expect(GitCLIService.prototype.cherryPick).toHaveBeenNthCalledWith(1, cwd, "e4dd336a4a20f394df6665994df382fb1d193a11", undefined, undefined, undefined);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "e4dd336a4a20f394df6665994df382fb1d193a11");
|
||||||
expect(GitCLIService.prototype.cherryPick).toHaveBeenNthCalledWith(2, cwd, "974519f65c9e0ed65277cd71026657a09fca05e7", undefined, undefined, undefined);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "974519f65c9e0ed65277cd71026657a09fca05e7");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-e4dd336-974519f");
|
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-e4dd336a4a20f394df6665994df382fb1d193a11-974519f65c9e0ed65277cd71026657a09fca05e7");
|
||||||
|
|
||||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
|
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
|
||||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
|
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
|
||||||
owner: "superuser",
|
owner: "superuser",
|
||||||
repo: "backporting-example",
|
repo: "backporting-example",
|
||||||
head: "bp-target-e4dd336-974519f",
|
head: "bp-target-e4dd336a4a20f394df6665994df382fb1d193a11-974519f65c9e0ed65277cd71026657a09fca05e7",
|
||||||
base: "target",
|
base: "target",
|
||||||
title: "[target] Update test.txt opened",
|
title: "[target] Update test.txt opened",
|
||||||
body: expect.stringContaining("**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/2"),
|
body: expect.stringContaining("**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/2"),
|
||||||
reviewers: ["superuser"],
|
reviewers: ["superuser"],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: [],
|
labels: [],
|
||||||
comments: [],
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
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).toBeCalledTimes(1);
|
|
||||||
expect(GitClientFactory.getOrCreate).toBeCalledWith(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.createLocalBranch).toBeCalledTimes(1);
|
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-e4dd336");
|
|
||||||
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "e4dd336a4a20f394df6665994df382fb1d193a11", undefined, undefined, undefined);
|
|
||||||
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-e4dd336");
|
|
||||||
|
|
||||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
|
|
||||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
|
|
||||||
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";
|
|
||||||
addProcessArgs([
|
|
||||||
"-tb",
|
|
||||||
"target",
|
|
||||||
"-pr",
|
|
||||||
"https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/2"
|
|
||||||
]);
|
|
||||||
|
|
||||||
await runner.execute();
|
|
||||||
|
|
||||||
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
|
|
||||||
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITLAB, "mygitlabtoken", "https://my.gitlab.host.com/api/v4");
|
|
||||||
|
|
||||||
// Not interested in all subsequent calls, already tested in other test cases
|
|
||||||
});
|
|
||||||
|
|
||||||
test("auth arg takes precedence over GITLAB_TOKEN", async () => {
|
|
||||||
process.env[AuthTokenId.GITLAB_TOKEN] = "mygitlabtoken";
|
|
||||||
addProcessArgs([
|
|
||||||
"-tb",
|
|
||||||
"target",
|
|
||||||
"-pr",
|
|
||||||
"https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/2",
|
|
||||||
"-a",
|
|
||||||
"mytoken"
|
|
||||||
]);
|
|
||||||
|
|
||||||
await runner.execute();
|
|
||||||
|
|
||||||
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
|
|
||||||
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITLAB, "mytoken", "https://my.gitlab.host.com/api/v4");
|
|
||||||
|
|
||||||
// Not interested in all subsequent calls, already tested in other test cases
|
|
||||||
});
|
|
||||||
|
|
||||||
test("ignore env variables related to other git platforms", async () => {
|
|
||||||
process.env[AuthTokenId.GITHUB_TOKEN] = "mygithubtoken";
|
|
||||||
process.env[AuthTokenId.CODEBERG_TOKEN] = "mycodebergtoken";
|
|
||||||
addProcessArgs([
|
|
||||||
"-tb",
|
|
||||||
"target",
|
|
||||||
"-pr",
|
|
||||||
"https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/2"
|
|
||||||
]);
|
|
||||||
|
|
||||||
await runner.execute();
|
|
||||||
|
|
||||||
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
|
|
||||||
expect(GitClientFactory.getOrCreate).toBeCalledWith(GitClientType.GITLAB, undefined, "https://my.gitlab.host.com/api/v4");
|
|
||||||
|
|
||||||
// Not interested in all subsequent calls, already tested in other test cases
|
|
||||||
});
|
|
||||||
});
|
});
|
|
@ -3,7 +3,7 @@ import Runner from "@bp/service/runner/runner";
|
||||||
import GitCLIService from "@bp/service/git/git-cli";
|
import GitCLIService from "@bp/service/git/git-cli";
|
||||||
import GitHubClient from "@bp/service/git/github/github-client";
|
import GitHubClient from "@bp/service/git/github/github-client";
|
||||||
import GHAArgsParser from "@bp/service/args/gha/gha-args-parser";
|
import GHAArgsParser from "@bp/service/args/gha/gha-args-parser";
|
||||||
import { createTestFile, removeTestFile, resetEnvTokens, spyGetInput } from "../../support/utils";
|
import { createTestFile, removeTestFile, spyGetInput } from "../../support/utils";
|
||||||
import { mockGitHubClient } from "../../support/mock/git-client-mock-support";
|
import { mockGitHubClient } from "../../support/mock/git-client-mock-support";
|
||||||
import GitClientFactory from "@bp/service/git/git-client-factory";
|
import GitClientFactory from "@bp/service/git/git-client-factory";
|
||||||
import { GitClientType } from "@bp/service/git/git.types";
|
import { GitClientType } from "@bp/service/git/git.types";
|
||||||
|
@ -30,7 +30,6 @@ const GITHUB_MERGED_PR_W_OVERRIDES_CONFIG_FILE_CONTENT = {
|
||||||
|
|
||||||
jest.mock("@bp/service/git/git-cli");
|
jest.mock("@bp/service/git/git-cli");
|
||||||
jest.spyOn(GitHubClient.prototype, "createPullRequest");
|
jest.spyOn(GitHubClient.prototype, "createPullRequest");
|
||||||
jest.spyOn(GitHubClient.prototype, "createPullRequestComment");
|
|
||||||
jest.spyOn(GitClientFactory, "getOrCreate");
|
jest.spyOn(GitClientFactory, "getOrCreate");
|
||||||
|
|
||||||
let parser: ArgsParser;
|
let parser: ArgsParser;
|
||||||
|
@ -47,9 +46,6 @@ afterAll(() => {
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// reset git env tokens
|
|
||||||
resetEnvTokens();
|
|
||||||
|
|
||||||
mockGitHubClient();
|
mockGitHubClient();
|
||||||
|
|
||||||
// create GHA arguments parser
|
// create GHA arguments parser
|
||||||
|
@ -78,17 +74,16 @@ describe("gha runner", () => {
|
||||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");
|
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-28f63db");
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
|
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledTimes(0);
|
expect(GitCLIService.prototype.push).toBeCalledTimes(0);
|
||||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(0);
|
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(0);
|
||||||
expect(GitHubClient.prototype.createPullRequestComment).toBeCalledTimes(0);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("without dry run", async () => {
|
test("without dry run", async () => {
|
||||||
|
@ -108,32 +103,30 @@ describe("gha runner", () => {
|
||||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");
|
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-28f63db");
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
|
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-28f63db");
|
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc");
|
||||||
|
|
||||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1);
|
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1);
|
||||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
||||||
owner: "owner",
|
owner: "owner",
|
||||||
repo: "reponame",
|
repo: "reponame",
|
||||||
head: "bp-target-28f63db",
|
head: "bp-target-28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc",
|
||||||
base: "target",
|
base: "target",
|
||||||
title: "[target] PR Title",
|
title: "[target] PR Title",
|
||||||
body: "**Backport:** https://github.com/owner/reponame/pull/2368\r\n\r\nPlease review and merge",
|
body: expect.stringContaining("**Backport:** https://github.com/owner/reponame/pull/2368"),
|
||||||
reviewers: ["gh-user", "that-s-a-user"],
|
reviewers: ["gh-user", "that-s-a-user"],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: [],
|
labels: [],
|
||||||
comments: [],
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("closed and not merged pull request", async () => {
|
test("closed and not merged pull request", async () => {
|
||||||
|
@ -142,7 +135,7 @@ describe("gha runner", () => {
|
||||||
"pull-request": "https://github.com/owner/reponame/pull/6666"
|
"pull-request": "https://github.com/owner/reponame/pull/6666"
|
||||||
});
|
});
|
||||||
|
|
||||||
await expect(() => runner.execute()).rejects.toThrow("Provided pull request is closed and not merged");
|
await expect(() => runner.execute()).rejects.toThrow("Provided pull request is closed and not merged!");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("open pull request", async () => {
|
test("open pull request", async () => {
|
||||||
|
@ -162,32 +155,30 @@ describe("gha runner", () => {
|
||||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");
|
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-9174896");
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-91748965051fae1330ad58d15cf694e103267c87");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/4444/head:pr/4444");
|
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/4444/head:pr/4444");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "91748965051fae1330ad58d15cf694e103267c87", undefined, undefined, undefined);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "91748965051fae1330ad58d15cf694e103267c87");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-9174896");
|
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-91748965051fae1330ad58d15cf694e103267c87");
|
||||||
|
|
||||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1);
|
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1);
|
||||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
||||||
owner: "owner",
|
owner: "owner",
|
||||||
repo: "reponame",
|
repo: "reponame",
|
||||||
head: "bp-target-9174896",
|
head: "bp-target-91748965051fae1330ad58d15cf694e103267c87",
|
||||||
base: "target",
|
base: "target",
|
||||||
title: "[target] PR Title",
|
title: "[target] PR Title",
|
||||||
body: "**Backport:** https://github.com/owner/reponame/pull/4444\r\n\r\nPlease review and merge",
|
body: expect.stringContaining("**Backport:** https://github.com/owner/reponame/pull/4444"),
|
||||||
reviewers: ["gh-user"],
|
reviewers: ["gh-user"],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: [],
|
labels: [],
|
||||||
comments: [],
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("override backporting pr data", async () => {
|
test("override backporting pr data", async () => {
|
||||||
|
@ -196,7 +187,7 @@ describe("gha runner", () => {
|
||||||
"pull-request": "https://github.com/owner/reponame/pull/2368",
|
"pull-request": "https://github.com/owner/reponame/pull/2368",
|
||||||
"title": "New Title",
|
"title": "New Title",
|
||||||
"body": "New Body",
|
"body": "New Body",
|
||||||
"body-prefix": "New Body Prefix\\r\\n\\r\\n",
|
"body-prefix": "New Body Prefix - ",
|
||||||
"bp-branch-name": "bp_branch_name",
|
"bp-branch-name": "bp_branch_name",
|
||||||
"reviewers": "user1, user2",
|
"reviewers": "user1, user2",
|
||||||
"assignees": "user3, user4",
|
"assignees": "user3, user4",
|
||||||
|
@ -219,7 +210,7 @@ describe("gha runner", () => {
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
|
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp_branch_name");
|
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp_branch_name");
|
||||||
|
@ -231,14 +222,12 @@ describe("gha runner", () => {
|
||||||
head: "bp_branch_name",
|
head: "bp_branch_name",
|
||||||
base: "target",
|
base: "target",
|
||||||
title: "New Title",
|
title: "New Title",
|
||||||
body: "New Body Prefix\r\n\r\nNew Body",
|
body: "New Body Prefix - New Body",
|
||||||
reviewers: ["user1", "user2"],
|
reviewers: ["user1", "user2"],
|
||||||
assignees: ["user3", "user4"],
|
assignees: ["user3", "user4"],
|
||||||
labels: [],
|
labels: [],
|
||||||
comments: [],
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("set empty reviewers", async () => {
|
test("set empty reviewers", async () => {
|
||||||
|
@ -271,7 +260,7 @@ describe("gha runner", () => {
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
|
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp_branch_name");
|
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp_branch_name");
|
||||||
|
@ -287,10 +276,8 @@ describe("gha runner", () => {
|
||||||
reviewers: [],
|
reviewers: [],
|
||||||
assignees: ["user3", "user4"],
|
assignees: ["user3", "user4"],
|
||||||
labels: [],
|
labels: [],
|
||||||
comments: [],
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("set custom labels with inheritance", async () => {
|
test("set custom labels with inheritance", async () => {
|
||||||
|
@ -312,32 +299,30 @@ describe("gha runner", () => {
|
||||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");
|
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-28f63db");
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
|
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-28f63db");
|
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc");
|
||||||
|
|
||||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1);
|
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1);
|
||||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
||||||
owner: "owner",
|
owner: "owner",
|
||||||
repo: "reponame",
|
repo: "reponame",
|
||||||
head: "bp-target-28f63db",
|
head: "bp-target-28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc",
|
||||||
base: "target",
|
base: "target",
|
||||||
title: "[target] PR Title",
|
title: "[target] PR Title",
|
||||||
body: "**Backport:** https://github.com/owner/reponame/pull/2368\r\n\r\nPlease review and merge",
|
body: expect.stringContaining("**Backport:** https://github.com/owner/reponame/pull/2368"),
|
||||||
reviewers: ["gh-user", "that-s-a-user"],
|
reviewers: ["gh-user", "that-s-a-user"],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: ["cherry-pick :cherries:", "another-label", "backport prod"],
|
labels: ["cherry-pick :cherries:", "another-label", "original-label"],
|
||||||
comments: [],
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("set custom labels without inheritance", async () => {
|
test("set custom labels without inheritance", async () => {
|
||||||
|
@ -359,32 +344,30 @@ describe("gha runner", () => {
|
||||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");
|
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-28f63db");
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
|
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-28f63db");
|
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc");
|
||||||
|
|
||||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1);
|
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1);
|
||||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
||||||
owner: "owner",
|
owner: "owner",
|
||||||
repo: "reponame",
|
repo: "reponame",
|
||||||
head: "bp-target-28f63db",
|
head: "bp-target-28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc",
|
||||||
base: "target",
|
base: "target",
|
||||||
title: "[target] PR Title",
|
title: "[target] PR Title",
|
||||||
body: "**Backport:** https://github.com/owner/reponame/pull/2368\r\n\r\nPlease review and merge",
|
body: expect.stringContaining("**Backport:** https://github.com/owner/reponame/pull/2368"),
|
||||||
reviewers: ["gh-user", "that-s-a-user"],
|
reviewers: ["gh-user", "that-s-a-user"],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: ["cherry-pick :cherries:", "another-label"],
|
labels: ["cherry-pick :cherries:", "another-label"],
|
||||||
comments: [],
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("using config file with overrides", async () => {
|
test("using config file with overrides", async () => {
|
||||||
|
@ -409,7 +392,7 @@ describe("gha runner", () => {
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
|
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp_branch_name");
|
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp_branch_name");
|
||||||
|
@ -424,11 +407,9 @@ describe("gha runner", () => {
|
||||||
body: "New Body Prefix - New Body",
|
body: "New Body Prefix - New Body",
|
||||||
reviewers: [],
|
reviewers: [],
|
||||||
assignees: ["user3", "user4"],
|
assignees: ["user3", "user4"],
|
||||||
labels: ["gha github cherry pick :cherries:", "backport prod"],
|
labels: ["gha github cherry pick :cherries:", "original-label"],
|
||||||
comments: [],
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// to check: https://github.com/kiegroup/git-backporting/issues/52
|
// to check: https://github.com/kiegroup/git-backporting/issues/52
|
||||||
|
@ -449,32 +430,30 @@ describe("gha runner", () => {
|
||||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");
|
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-28f63db");
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
|
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "pull/2368/head:pr/2368");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc", undefined, undefined, undefined);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-28f63db");
|
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc");
|
||||||
|
|
||||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1);
|
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1);
|
||||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
||||||
owner: "owner",
|
owner: "owner",
|
||||||
repo: "reponame",
|
repo: "reponame",
|
||||||
head: "bp-target-28f63db",
|
head: "bp-target-28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc",
|
||||||
base: "target",
|
base: "target",
|
||||||
title: "[target] PR Title",
|
title: "[target] PR Title",
|
||||||
body: "**Backport:** https://github.com/owner/reponame/pull/2368\r\n\r\nPlease review and merge",
|
body: expect.stringContaining("**Backport:** https://github.com/owner/reponame/pull/2368"),
|
||||||
reviewers: ["gh-user", "that-s-a-user"],
|
reviewers: ["gh-user", "that-s-a-user"],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: [],
|
labels: [],
|
||||||
comments: [],
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("multiple commits pr", async () => {
|
test("multiple commits pr", async () => {
|
||||||
|
@ -495,344 +474,29 @@ describe("gha runner", () => {
|
||||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");
|
expect(GitCLIService.prototype.clone).toBeCalledWith("https://github.com/owner/reponame.git", cwd, "target");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-0404fb9-11da4e3");
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-0404fb922ab75c3a8aecad5c97d9af388df04695-11da4e38aa3e577ffde6d546f1c52e53b04d3151");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(0);
|
expect(GitCLIService.prototype.fetch).toBeCalledTimes(0);
|
||||||
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(2);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(2);
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "0404fb922ab75c3a8aecad5c97d9af388df04695", undefined, undefined, undefined);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "0404fb922ab75c3a8aecad5c97d9af388df04695");
|
||||||
expect(GitCLIService.prototype.cherryPick).toHaveBeenLastCalledWith(cwd, "11da4e38aa3e577ffde6d546f1c52e53b04d3151", undefined, undefined, undefined);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "11da4e38aa3e577ffde6d546f1c52e53b04d3151");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-0404fb9-11da4e3");
|
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-0404fb922ab75c3a8aecad5c97d9af388df04695-11da4e38aa3e577ffde6d546f1c52e53b04d3151");
|
||||||
|
|
||||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1);
|
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1);
|
||||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
||||||
owner: "owner",
|
owner: "owner",
|
||||||
repo: "reponame",
|
repo: "reponame",
|
||||||
head: "bp-target-0404fb9-11da4e3",
|
head: "bp-target-0404fb922ab75c3a8aecad5c97d9af388df04695-11da4e38aa3e577ffde6d546f1c52e53b04d3151",
|
||||||
base: "target",
|
base: "target",
|
||||||
title: "[target] PR Title",
|
title: "[target] PR Title",
|
||||||
body: "**Backport:** https://github.com/owner/reponame/pull/8632\r\n\r\nPlease review and merge",
|
body: expect.stringContaining("**Backport:** https://github.com/owner/reponame/pull/8632"),
|
||||||
reviewers: ["gh-user", "that-s-a-user"],
|
reviewers: ["gh-user", "that-s-a-user"],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: [],
|
labels: [],
|
||||||
comments: [],
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("using github api url and different strategy", async () => {
|
|
||||||
spyGetInput({
|
|
||||||
"target-branch": "target",
|
|
||||||
"pull-request": "https://api.github.com/repos/owner/reponame/pulls/2368",
|
|
||||||
"strategy": "ort",
|
|
||||||
"strategy-option": "ours",
|
|
||||||
});
|
|
||||||
|
|
||||||
await runner.execute();
|
|
||||||
|
|
||||||
const cwd = process.cwd() + "/bp";
|
|
||||||
|
|
||||||
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
|
|
||||||
expect(GitClientFactory.getOrCreate).toBeCalledWith(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.createLocalBranch).toBeCalledTimes(1);
|
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-28f63db");
|
|
||||||
|
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
|
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledWith(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.push).toBeCalledTimes(1);
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-28f63db");
|
|
||||||
|
|
||||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1);
|
|
||||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
|
||||||
owner: "owner",
|
|
||||||
repo: "reponame",
|
|
||||||
head: "bp-target-28f63db",
|
|
||||||
base: "target",
|
|
||||||
title: "[target] PR Title",
|
|
||||||
body: "**Backport:** https://github.com/owner/reponame/pull/2368\r\n\r\nPlease review and merge",
|
|
||||||
reviewers: ["gh-user", "that-s-a-user"],
|
|
||||||
assignees: [],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
}
|
|
||||||
);
|
|
||||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("using github api url and additional cherry-pick options", async () => {
|
|
||||||
spyGetInput({
|
|
||||||
"target-branch": "target",
|
|
||||||
"pull-request": "https://api.github.com/repos/owner/reponame/pulls/2368",
|
|
||||||
"cherry-pick-options": "-x --allow-empty",
|
|
||||||
});
|
|
||||||
|
|
||||||
await runner.execute();
|
|
||||||
|
|
||||||
const cwd = process.cwd() + "/bp";
|
|
||||||
|
|
||||||
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
|
|
||||||
expect(GitClientFactory.getOrCreate).toBeCalledWith(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.createLocalBranch).toBeCalledTimes(1);
|
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-28f63db");
|
|
||||||
|
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
|
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledWith(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.push).toBeCalledTimes(1);
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-28f63db");
|
|
||||||
|
|
||||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1);
|
|
||||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
|
||||||
owner: "owner",
|
|
||||||
repo: "reponame",
|
|
||||||
head: "bp-target-28f63db",
|
|
||||||
base: "target",
|
|
||||||
title: "[target] PR Title",
|
|
||||||
body: "**Backport:** https://github.com/owner/reponame/pull/2368\r\n\r\nPlease review and merge",
|
|
||||||
reviewers: ["gh-user", "that-s-a-user"],
|
|
||||||
assignees: [],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
}
|
|
||||||
);
|
|
||||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("additional pr comments", async () => {
|
|
||||||
spyGetInput({
|
|
||||||
"target-branch": "target",
|
|
||||||
"pull-request": "https://github.com/owner/reponame/pull/2368",
|
|
||||||
"comments": "first comment; second comment",
|
|
||||||
});
|
|
||||||
|
|
||||||
await runner.execute();
|
|
||||||
|
|
||||||
const cwd = process.cwd() + "/bp";
|
|
||||||
|
|
||||||
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
|
|
||||||
expect(GitClientFactory.getOrCreate).toBeCalledWith(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.createLocalBranch).toBeCalledTimes(1);
|
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-28f63db");
|
|
||||||
|
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
|
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledWith(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.push).toBeCalledTimes(1);
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-28f63db");
|
|
||||||
|
|
||||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledTimes(1);
|
|
||||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
|
||||||
owner: "owner",
|
|
||||||
repo: "reponame",
|
|
||||||
head: "bp-target-28f63db",
|
|
||||||
base: "target",
|
|
||||||
title: "[target] PR Title",
|
|
||||||
body: "**Backport:** https://github.com/owner/reponame/pull/2368\r\n\r\nPlease review and merge",
|
|
||||||
reviewers: ["gh-user", "that-s-a-user"],
|
|
||||||
assignees: [],
|
|
||||||
labels: [],
|
|
||||||
comments: ["first comment", "second comment"],
|
|
||||||
}
|
|
||||||
);
|
|
||||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("with multiple target branches", async () => {
|
|
||||||
spyGetInput({
|
|
||||||
"target-branch": "v1, v2, v3",
|
|
||||||
"pull-request": "https://github.com/owner/reponame/pull/2368",
|
|
||||||
"folder": "/tmp/folder",
|
|
||||||
});
|
|
||||||
|
|
||||||
await runner.execute();
|
|
||||||
|
|
||||||
const cwd = "/tmp/folder";
|
|
||||||
|
|
||||||
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
|
|
||||||
expect(GitClientFactory.getOrCreate).toBeCalledWith(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.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.fetch).toBeCalledTimes(3);
|
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledWith(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.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(GitHubClient.prototype.createPullRequest).toBeCalledTimes(3);
|
|
||||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
|
||||||
owner: "owner",
|
|
||||||
repo: "reponame",
|
|
||||||
head: "bp-v1-28f63db",
|
|
||||||
base: "v1",
|
|
||||||
title: "[v1] PR Title",
|
|
||||||
body: "**Backport:** https://github.com/owner/reponame/pull/2368\r\n\r\nPlease review and merge",
|
|
||||||
reviewers: ["gh-user", "that-s-a-user"],
|
|
||||||
assignees: [],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
});
|
|
||||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
|
||||||
owner: "owner",
|
|
||||||
repo: "reponame",
|
|
||||||
head: "bp-v2-28f63db",
|
|
||||||
base: "v2",
|
|
||||||
title: "[v2] PR Title",
|
|
||||||
body: "**Backport:** https://github.com/owner/reponame/pull/2368\r\n\r\nPlease review and merge",
|
|
||||||
reviewers: ["gh-user", "that-s-a-user"],
|
|
||||||
assignees: [],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
});
|
|
||||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
|
||||||
owner: "owner",
|
|
||||||
repo: "reponame",
|
|
||||||
head: "bp-v3-28f63db",
|
|
||||||
base: "v3",
|
|
||||||
title: "[v3] PR Title",
|
|
||||||
body: "**Backport:** https://github.com/owner/reponame/pull/2368\r\n\r\nPlease review and merge",
|
|
||||||
reviewers: ["gh-user", "that-s-a-user"],
|
|
||||||
assignees: [],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
});
|
|
||||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(3);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("with multiple target branches and single custom bp branch", async () => {
|
|
||||||
spyGetInput({
|
|
||||||
"target-branch": "v1, v2, v3",
|
|
||||||
"pull-request": "https://github.com/owner/reponame/pull/2368",
|
|
||||||
"folder": "/tmp/folder",
|
|
||||||
"bp-branch-name": "custom"
|
|
||||||
});
|
|
||||||
|
|
||||||
await runner.execute();
|
|
||||||
|
|
||||||
const cwd = "/tmp/folder";
|
|
||||||
|
|
||||||
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
|
|
||||||
expect(GitClientFactory.getOrCreate).toBeCalledWith(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.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.fetch).toBeCalledTimes(3);
|
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledWith(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.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(GitHubClient.prototype.createPullRequest).toBeCalledTimes(3);
|
|
||||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
|
||||||
owner: "owner",
|
|
||||||
repo: "reponame",
|
|
||||||
head: "custom-v1",
|
|
||||||
base: "v1",
|
|
||||||
title: "[v1] PR Title",
|
|
||||||
body: "**Backport:** https://github.com/owner/reponame/pull/2368\r\n\r\nPlease review and merge",
|
|
||||||
reviewers: ["gh-user", "that-s-a-user"],
|
|
||||||
assignees: [],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
});
|
|
||||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
|
||||||
owner: "owner",
|
|
||||||
repo: "reponame",
|
|
||||||
head: "custom-v2",
|
|
||||||
base: "v2",
|
|
||||||
title: "[v2] PR Title",
|
|
||||||
body: "**Backport:** https://github.com/owner/reponame/pull/2368\r\n\r\nPlease review and merge",
|
|
||||||
reviewers: ["gh-user", "that-s-a-user"],
|
|
||||||
assignees: [],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
});
|
|
||||||
expect(GitHubClient.prototype.createPullRequest).toBeCalledWith({
|
|
||||||
owner: "owner",
|
|
||||||
repo: "reponame",
|
|
||||||
head: "custom-v3",
|
|
||||||
base: "v3",
|
|
||||||
title: "[v3] PR Title",
|
|
||||||
body: "**Backport:** https://github.com/owner/reponame/pull/2368\r\n\r\nPlease review and merge",
|
|
||||||
reviewers: ["gh-user", "that-s-a-user"],
|
|
||||||
assignees: [],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
});
|
|
||||||
expect(GitHubClient.prototype.createPullRequest).toReturnTimes(3);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("explicitly set git client", async () => {
|
|
||||||
spyGetInput({
|
|
||||||
"target-branch": "target",
|
|
||||||
"pull-request": "https://api.github.com/repos/owner/reponame/pulls/2368",
|
|
||||||
"git-client": "codeberg",
|
|
||||||
});
|
|
||||||
|
|
||||||
await runner.execute();
|
|
||||||
|
|
||||||
const cwd = process.cwd() + "/bp";
|
|
||||||
|
|
||||||
expect(GitClientFactory.getOrCreate).toBeCalledTimes(1);
|
|
||||||
expect(GitClientFactory.getOrCreate).toBeCalledWith(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");
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
|
@ -3,7 +3,7 @@ import Runner from "@bp/service/runner/runner";
|
||||||
import GitCLIService from "@bp/service/git/git-cli";
|
import GitCLIService from "@bp/service/git/git-cli";
|
||||||
import GitLabClient from "@bp/service/git/gitlab/gitlab-client";
|
import GitLabClient from "@bp/service/git/gitlab/gitlab-client";
|
||||||
import GHAArgsParser from "@bp/service/args/gha/gha-args-parser";
|
import GHAArgsParser from "@bp/service/args/gha/gha-args-parser";
|
||||||
import { createTestFile, removeTestFile, resetEnvTokens, spyGetInput } from "../../support/utils";
|
import { createTestFile, removeTestFile, spyGetInput } from "../../support/utils";
|
||||||
import { getAxiosMocked } from "../../support/mock/git-client-mock-support";
|
import { getAxiosMocked } from "../../support/mock/git-client-mock-support";
|
||||||
import { MERGED_SQUASHED_MR } from "../../support/mock/gitlab-data";
|
import { MERGED_SQUASHED_MR } from "../../support/mock/gitlab-data";
|
||||||
import GitClientFactory from "@bp/service/git/git-client-factory";
|
import GitClientFactory from "@bp/service/git/git-client-factory";
|
||||||
|
@ -36,14 +36,13 @@ jest.mock("axios", () => {
|
||||||
iid: 1, // FIXME: I am not testing this atm
|
iid: 1, // FIXME: I am not testing this atm
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
put: async () => undefined, // make it async so that .catch doesn't throw an error
|
put: jest.fn(),
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
jest.mock("@bp/service/git/git-cli");
|
jest.mock("@bp/service/git/git-cli");
|
||||||
jest.spyOn(GitLabClient.prototype, "createPullRequest");
|
jest.spyOn(GitLabClient.prototype, "createPullRequest");
|
||||||
jest.spyOn(GitLabClient.prototype, "createPullRequestComment");
|
|
||||||
jest.spyOn(GitClientFactory, "getOrCreate");
|
jest.spyOn(GitClientFactory, "getOrCreate");
|
||||||
|
|
||||||
let parser: ArgsParser;
|
let parser: ArgsParser;
|
||||||
|
@ -60,9 +59,6 @@ afterAll(() => {
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// reset git env tokens
|
|
||||||
resetEnvTokens();
|
|
||||||
|
|
||||||
// create GHA arguments parser
|
// create GHA arguments parser
|
||||||
parser = new GHAArgsParser();
|
parser = new GHAArgsParser();
|
||||||
|
|
||||||
|
@ -89,17 +85,16 @@ describe("gha runner", () => {
|
||||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
|
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-9e15674");
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-9e15674ebd48e05c6e428a1fa31dbb60a778d644");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2");
|
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined, undefined);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledTimes(0);
|
expect(GitCLIService.prototype.push).toBeCalledTimes(0);
|
||||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(0);
|
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(0);
|
||||||
expect(GitLabClient.prototype.createPullRequestComment).toBeCalledTimes(0);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("without dry run", async () => {
|
test("without dry run", async () => {
|
||||||
|
@ -119,29 +114,28 @@ describe("gha runner", () => {
|
||||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
|
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-9e15674");
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-9e15674ebd48e05c6e428a1fa31dbb60a778d644");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2");
|
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined, undefined);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-9e15674");
|
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-9e15674ebd48e05c6e428a1fa31dbb60a778d644");
|
||||||
|
|
||||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
|
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
|
||||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
|
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
|
||||||
owner: "superuser",
|
owner: "superuser",
|
||||||
repo: "backporting-example",
|
repo: "backporting-example",
|
||||||
head: "bp-target-9e15674",
|
head: "bp-target-9e15674ebd48e05c6e428a1fa31dbb60a778d644",
|
||||||
base: "target",
|
base: "target",
|
||||||
title: "[target] Update test.txt opened",
|
title: "[target] Update test.txt opened",
|
||||||
body: expect.stringContaining("**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/2"),
|
body: expect.stringContaining("**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/2"),
|
||||||
reviewers: ["superuser"],
|
reviewers: ["superuser"],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: [],
|
labels: [],
|
||||||
comments: [],
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -152,7 +146,7 @@ describe("gha runner", () => {
|
||||||
"pull-request": "https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/3"
|
"pull-request": "https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/3"
|
||||||
});
|
});
|
||||||
|
|
||||||
await expect(() => runner.execute()).rejects.toThrow("Provided pull request is closed and not merged");
|
await expect(() => runner.execute()).rejects.toThrow("Provided pull request is closed and not merged!");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("merged pull request", async () => {
|
test("merged pull request", async () => {
|
||||||
|
@ -172,28 +166,27 @@ describe("gha runner", () => {
|
||||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
|
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-ebb1eca");
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(0);
|
expect(GitCLIService.prototype.fetch).toBeCalledTimes(0);
|
||||||
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e", undefined, undefined, undefined);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-ebb1eca");
|
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||||
|
|
||||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
|
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
|
||||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
|
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
|
||||||
owner: "superuser",
|
owner: "superuser",
|
||||||
repo: "backporting-example",
|
repo: "backporting-example",
|
||||||
head: "bp-target-ebb1eca",
|
head: "bp-target-ebb1eca696c42fd067658bd9b5267709f78ef38e",
|
||||||
base: "target",
|
base: "target",
|
||||||
title: "[target] Update test.txt",
|
title: "[target] Update test.txt",
|
||||||
body: expect.stringContaining("**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1"),
|
body: expect.stringContaining("**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1"),
|
||||||
reviewers: ["superuser"],
|
reviewers: ["superuser"],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: [],
|
labels: [],
|
||||||
comments: [],
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -227,7 +220,7 @@ describe("gha runner", () => {
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2");
|
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined, undefined);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp_branch_name");
|
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp_branch_name");
|
||||||
|
@ -243,7 +236,6 @@ describe("gha runner", () => {
|
||||||
reviewers: ["user1", "user2"],
|
reviewers: ["user1", "user2"],
|
||||||
assignees: ["user3", "user4"],
|
assignees: ["user3", "user4"],
|
||||||
labels: [],
|
labels: [],
|
||||||
comments: [],
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -278,7 +270,7 @@ describe("gha runner", () => {
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2");
|
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644", undefined, undefined, undefined);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "9e15674ebd48e05c6e428a1fa31dbb60a778d644");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp_branch_name");
|
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp_branch_name");
|
||||||
|
@ -294,7 +286,6 @@ describe("gha runner", () => {
|
||||||
reviewers: [],
|
reviewers: [],
|
||||||
assignees: ["user3", "user4"],
|
assignees: ["user3", "user4"],
|
||||||
labels: [],
|
labels: [],
|
||||||
comments: [],
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -318,28 +309,27 @@ describe("gha runner", () => {
|
||||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
|
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-ebb1eca");
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(0);
|
expect(GitCLIService.prototype.fetch).toBeCalledTimes(0);
|
||||||
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e", undefined, undefined, undefined);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-ebb1eca");
|
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||||
|
|
||||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
|
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
|
||||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
|
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
|
||||||
owner: "superuser",
|
owner: "superuser",
|
||||||
repo: "backporting-example",
|
repo: "backporting-example",
|
||||||
head: "bp-target-ebb1eca",
|
head: "bp-target-ebb1eca696c42fd067658bd9b5267709f78ef38e",
|
||||||
base: "target",
|
base: "target",
|
||||||
title: "[target] Update test.txt",
|
title: "[target] Update test.txt",
|
||||||
body: expect.stringContaining("**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1"),
|
body: expect.stringContaining("**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1"),
|
||||||
reviewers: ["superuser"],
|
reviewers: ["superuser"],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: ["cherry-pick :cherries:", "another-label", "backport-prod"],
|
labels: ["cherry-pick :cherries:", "another-label", "gitlab-original-label"],
|
||||||
comments: [],
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -362,28 +352,27 @@ describe("gha runner", () => {
|
||||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
|
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-ebb1eca");
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(0);
|
expect(GitCLIService.prototype.fetch).toBeCalledTimes(0);
|
||||||
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e", undefined, undefined, undefined);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-ebb1eca");
|
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||||
|
|
||||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
|
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
|
||||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
|
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
|
||||||
owner: "superuser",
|
owner: "superuser",
|
||||||
repo: "backporting-example",
|
repo: "backporting-example",
|
||||||
head: "bp-target-ebb1eca",
|
head: "bp-target-ebb1eca696c42fd067658bd9b5267709f78ef38e",
|
||||||
base: "target",
|
base: "target",
|
||||||
title: "[target] Update test.txt",
|
title: "[target] Update test.txt",
|
||||||
body: expect.stringContaining("**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1"),
|
body: expect.stringContaining("**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1"),
|
||||||
reviewers: ["superuser"],
|
reviewers: ["superuser"],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: ["cherry-pick :cherries:", "another-label"],
|
labels: ["cherry-pick :cherries:", "another-label"],
|
||||||
comments: [],
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -404,72 +393,29 @@ describe("gha runner", () => {
|
||||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "prod");
|
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "prod");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-prod-ebb1eca");
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-prod-ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||||
|
|
||||||
// 0 occurrences as the mr is already merged and the owner is the same for
|
// 0 occurrences as the mr is already merged and the owner is the same for
|
||||||
// both source and target repositories
|
// both source and target repositories
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(0);
|
expect(GitCLIService.prototype.fetch).toBeCalledTimes(0);
|
||||||
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e", undefined, undefined, undefined);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-prod-ebb1eca");
|
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-prod-ebb1eca696c42fd067658bd9b5267709f78ef38e");
|
||||||
|
|
||||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
|
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
|
||||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
|
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
|
||||||
owner: "superuser",
|
owner: "superuser",
|
||||||
repo: "backporting-example",
|
repo: "backporting-example",
|
||||||
head: "bp-prod-ebb1eca",
|
head: "bp-prod-ebb1eca696c42fd067658bd9b5267709f78ef38e",
|
||||||
base: "prod",
|
base: "prod",
|
||||||
title: "New Title",
|
title: "New Title",
|
||||||
body: expect.stringContaining("**This is a backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1"),
|
body: expect.stringContaining("**This is a backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1"),
|
||||||
reviewers: [],
|
reviewers: [],
|
||||||
assignees: ["user3", "user4"],
|
assignees: ["user3", "user4"],
|
||||||
labels: ["gha gitlab cherry pick :cherries:", "backport-prod"],
|
labels: ["gha gitlab cherry pick :cherries:", "gitlab-original-label"],
|
||||||
comments: [],
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("single commit without squash", async () => {
|
|
||||||
spyGetInput({
|
|
||||||
"target-branch": "target",
|
|
||||||
"pull-request": "https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/1",
|
|
||||||
"no-squash": "true",
|
|
||||||
});
|
|
||||||
|
|
||||||
await runner.execute();
|
|
||||||
|
|
||||||
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(GitCLIService.prototype.clone).toBeCalledTimes(1);
|
|
||||||
expect(GitCLIService.prototype.clone).toBeCalledWith("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.cherryPick).toBeCalledTimes(1);
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "e4dd336a4a20f394df6665994df382fb1d193a11", undefined, undefined, undefined);
|
|
||||||
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-e4dd336");
|
|
||||||
|
|
||||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
|
|
||||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
|
|
||||||
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/1"),
|
|
||||||
reviewers: ["superuser"],
|
|
||||||
assignees: [],
|
|
||||||
labels: [],
|
|
||||||
comments: [],
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -492,72 +438,29 @@ describe("gha runner", () => {
|
||||||
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
|
expect(GitCLIService.prototype.clone).toBeCalledWith("https://my.gitlab.host.com/superuser/backporting-example.git", cwd, "target");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-e4dd336-974519f");
|
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-e4dd336a4a20f394df6665994df382fb1d193a11-974519f65c9e0ed65277cd71026657a09fca05e7");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.fetch).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2");
|
expect(GitCLIService.prototype.fetch).toBeCalledWith(cwd, "merge-requests/2/head:pr/2");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(2);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(2);
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "e4dd336a4a20f394df6665994df382fb1d193a11", undefined, undefined, undefined);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "e4dd336a4a20f394df6665994df382fb1d193a11");
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "974519f65c9e0ed65277cd71026657a09fca05e7", undefined, undefined, undefined);
|
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "974519f65c9e0ed65277cd71026657a09fca05e7");
|
||||||
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
||||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-e4dd336-974519f");
|
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-e4dd336a4a20f394df6665994df382fb1d193a11-974519f65c9e0ed65277cd71026657a09fca05e7");
|
||||||
|
|
||||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
|
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
|
||||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
|
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
|
||||||
owner: "superuser",
|
owner: "superuser",
|
||||||
repo: "backporting-example",
|
repo: "backporting-example",
|
||||||
head: "bp-target-e4dd336-974519f",
|
head: "bp-target-e4dd336a4a20f394df6665994df382fb1d193a11-974519f65c9e0ed65277cd71026657a09fca05e7",
|
||||||
base: "target",
|
base: "target",
|
||||||
title: "[target] Update test.txt opened",
|
title: "[target] Update test.txt opened",
|
||||||
body: expect.stringContaining("**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/2"),
|
body: expect.stringContaining("**Backport:** https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/2"),
|
||||||
reviewers: ["superuser"],
|
reviewers: ["superuser"],
|
||||||
assignees: [],
|
assignees: [],
|
||||||
labels: [],
|
labels: [],
|
||||||
comments: [],
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
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).toBeCalledTimes(1);
|
|
||||||
expect(GitClientFactory.getOrCreate).toBeCalledWith(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.createLocalBranch).toBeCalledTimes(1);
|
|
||||||
expect(GitCLIService.prototype.createLocalBranch).toBeCalledWith(cwd, "bp-target-e4dd336");
|
|
||||||
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledTimes(1);
|
|
||||||
expect(GitCLIService.prototype.cherryPick).toBeCalledWith(cwd, "e4dd336a4a20f394df6665994df382fb1d193a11", undefined, undefined, undefined);
|
|
||||||
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledTimes(1);
|
|
||||||
expect(GitCLIService.prototype.push).toBeCalledWith(cwd, "bp-target-e4dd336");
|
|
||||||
|
|
||||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledTimes(1);
|
|
||||||
expect(GitLabClient.prototype.createPullRequest).toBeCalledWith({
|
|
||||||
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: [],
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
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
|
@ -1,12 +1,7 @@
|
||||||
import LoggerServiceFactory from "@bp/service/logger/logger-service-factory";
|
import LoggerServiceFactory from "@bp/service/logger/logger-service-factory";
|
||||||
import { Moctokit } from "@kie/mock-github";
|
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, GITHUB_GET_COMMIT } from "./github-data";
|
import { targetOwner, repo, mergedPullRequestFixture, openPullRequestFixture, notMergedPullRequestFixture, notFoundPullRequestNumber, multipleCommitsPullRequestFixture, multipleCommitsPullRequestCommits } 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 } from "./gitlab-data";
|
import { CLOSED_NOT_MERGED_MR, MERGED_SQUASHED_MR, OPEN_MR, OPEN_PR_COMMITS, PROJECT_EXAMPLE, SUPERUSER} 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
|
|
||||||
const REPEAT = 20;
|
|
||||||
|
|
||||||
const logger = LoggerServiceFactory.getLogger();
|
const logger = LoggerServiceFactory.getLogger();
|
||||||
|
|
||||||
|
@ -23,22 +18,12 @@ export const getAxiosMocked = (url: string) => {
|
||||||
data = OPEN_MR;
|
data = OPEN_MR;
|
||||||
} else if (url.endsWith("merge_requests/3")) {
|
} else if (url.endsWith("merge_requests/3")) {
|
||||||
data = CLOSED_NOT_MERGED_MR;
|
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("projects/76316")) {
|
} else if (url.endsWith("projects/76316")) {
|
||||||
data = PROJECT_EXAMPLE;
|
data = PROJECT_EXAMPLE;
|
||||||
} else if (url.endsWith("projects/1645")) {
|
|
||||||
data = NESTED_PROJECT_EXAMPLE;
|
|
||||||
} else if (url.endsWith("users?username=superuser")) {
|
} else if (url.endsWith("users?username=superuser")) {
|
||||||
data = [SUPERUSER];
|
data = [SUPERUSER];
|
||||||
} else if (url.endsWith("merge_requests/1/commits")) {
|
|
||||||
data = MERGED_SQUASHED_MR_COMMITS;
|
|
||||||
} else if (url.endsWith("merge_requests/2/commits")) {
|
} else if (url.endsWith("merge_requests/2/commits")) {
|
||||||
data = OPEN_PR_COMMITS;
|
data = OPEN_PR_COMMITS;
|
||||||
} else if (url.endsWith("merge_requests/5/commits")) {
|
|
||||||
data = MERGED_NOT_SQUASHED_MR_COMMITS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -49,24 +34,18 @@ export const getAxiosMocked = (url: string) => {
|
||||||
|
|
||||||
export const NEW_GITLAB_MR_ID = 999;
|
export const NEW_GITLAB_MR_ID = 999;
|
||||||
export const SECOND_NEW_GITLAB_MR_ID = 1000;
|
export const SECOND_NEW_GITLAB_MR_ID = 1000;
|
||||||
export const postAxiosMocked = async (url: string, data?: {source_branch: string,}) => {
|
export const postAxiosMocked = (_url: string, data?: {source_branch: string,}) => {
|
||||||
let responseData = undefined;
|
let responseData = undefined;
|
||||||
|
|
||||||
// gitlab
|
// gitlab
|
||||||
|
|
||||||
if (url.includes("notes")) {
|
if (data?.source_branch === "bp-branch") {
|
||||||
// creating comments
|
|
||||||
responseData = {
|
|
||||||
// we do not need the whole response
|
|
||||||
iid: NEW_GITLAB_MR_ID,
|
|
||||||
};
|
|
||||||
} else if (data?.source_branch === "bp-branch") {
|
|
||||||
responseData = {
|
responseData = {
|
||||||
// we do not need the whole response
|
// we do not need the whole response
|
||||||
iid: NEW_GITLAB_MR_ID,
|
iid: NEW_GITLAB_MR_ID,
|
||||||
web_url: "https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/" + NEW_GITLAB_MR_ID
|
web_url: "https://my.gitlab.host.com/superuser/backporting-example/-/merge_requests/" + NEW_GITLAB_MR_ID
|
||||||
};
|
};
|
||||||
} else if (data?.source_branch === "bp-branch-2") {
|
} if (data?.source_branch === "bp-branch-2") {
|
||||||
responseData = {
|
responseData = {
|
||||||
// we do not need the whole response
|
// we do not need the whole response
|
||||||
iid: SECOND_NEW_GITLAB_MR_ID,
|
iid: SECOND_NEW_GITLAB_MR_ID,
|
||||||
|
@ -80,7 +59,7 @@ export const postAxiosMocked = async (url: string, data?: {source_branch: string
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const putAxiosMocked = async (url: string, _data?: unknown) => {
|
export const putAxiosMocked = (url: string, _data?: unknown) => {
|
||||||
const responseData = undefined;
|
const responseData = undefined;
|
||||||
|
|
||||||
// gitlab
|
// gitlab
|
||||||
|
@ -100,7 +79,7 @@ export const putAxiosMocked = async (url: string, _data?: unknown) => {
|
||||||
// GITHUB - OCTOKIT
|
// GITHUB - OCTOKIT
|
||||||
|
|
||||||
export const mockGitHubClient = (apiUrl = "https://api.github.com"): Moctokit => {
|
export const mockGitHubClient = (apiUrl = "https://api.github.com"): Moctokit => {
|
||||||
logger.debug("Setting up moctokit..");
|
logger.debug("Setting up moctokit.");
|
||||||
|
|
||||||
const mock = new Moctokit(apiUrl);
|
const mock = new Moctokit(apiUrl);
|
||||||
|
|
||||||
|
@ -109,93 +88,76 @@ export const mockGitHubClient = (apiUrl = "https://api.github.com"): Moctokit =>
|
||||||
// valid requests
|
// valid requests
|
||||||
mock.rest.pulls
|
mock.rest.pulls
|
||||||
.get({
|
.get({
|
||||||
owner: TARGET_OWNER,
|
owner: targetOwner,
|
||||||
repo: REPO,
|
repo: repo,
|
||||||
pull_number: MERGED_PR_FIXTURE.number
|
pull_number: mergedPullRequestFixture.number
|
||||||
})
|
})
|
||||||
.reply({
|
.reply({
|
||||||
status: 200,
|
status: 200,
|
||||||
data: MERGED_PR_FIXTURE
|
data: mergedPullRequestFixture
|
||||||
});
|
});
|
||||||
|
|
||||||
mock.rest.pulls
|
mock.rest.pulls
|
||||||
.get({
|
.get({
|
||||||
owner: TARGET_OWNER,
|
owner: targetOwner,
|
||||||
repo: REPO,
|
repo: repo,
|
||||||
pull_number: MULT_COMMITS_PR_FIXTURE.number
|
pull_number: multipleCommitsPullRequestFixture.number
|
||||||
})
|
})
|
||||||
.reply({
|
.reply({
|
||||||
status: 200,
|
status: 200,
|
||||||
data: MULT_COMMITS_PR_FIXTURE
|
data: multipleCommitsPullRequestFixture
|
||||||
});
|
});
|
||||||
|
|
||||||
mock.rest.pulls
|
mock.rest.pulls
|
||||||
.get({
|
.get({
|
||||||
owner: TARGET_OWNER,
|
owner: targetOwner,
|
||||||
repo: REPO,
|
repo: repo,
|
||||||
pull_number: OPEN_PR_FIXTURE.number
|
pull_number: openPullRequestFixture.number
|
||||||
})
|
})
|
||||||
.reply({
|
.reply({
|
||||||
status: 200,
|
status: 200,
|
||||||
data: OPEN_PR_FIXTURE
|
data: openPullRequestFixture
|
||||||
});
|
});
|
||||||
|
|
||||||
mock.rest.pulls
|
mock.rest.pulls
|
||||||
.get({
|
.get({
|
||||||
owner: TARGET_OWNER,
|
owner: targetOwner,
|
||||||
repo: REPO,
|
repo: repo,
|
||||||
pull_number: NOT_MERGED_PR_FIXTURE.number
|
pull_number: notMergedPullRequestFixture.number
|
||||||
})
|
})
|
||||||
.reply({
|
.reply({
|
||||||
status: 200,
|
status: 200,
|
||||||
data: NOT_MERGED_PR_FIXTURE
|
data: notMergedPullRequestFixture
|
||||||
});
|
});
|
||||||
|
|
||||||
mock.rest.pulls
|
mock.rest.pulls
|
||||||
.listCommits({
|
.listCommits({
|
||||||
owner: TARGET_OWNER,
|
owner: targetOwner,
|
||||||
repo: REPO,
|
repo: repo,
|
||||||
pull_number: MULT_COMMITS_PR_FIXTURE.number
|
pull_number: multipleCommitsPullRequestFixture.number
|
||||||
})
|
})
|
||||||
.reply({
|
.reply({
|
||||||
status: 200,
|
status: 200,
|
||||||
data: MULT_COMMITS_PR_COMMITS
|
data: multipleCommitsPullRequestCommits
|
||||||
});
|
|
||||||
|
|
||||||
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
|
mock.rest.pulls
|
||||||
.create()
|
.create()
|
||||||
.reply({
|
.reply({
|
||||||
repeat: REPEAT,
|
|
||||||
status: 201,
|
status: 201,
|
||||||
data: {
|
data: mergedPullRequestFixture
|
||||||
number: NEW_PR_NUMBER,
|
|
||||||
html_url: NEW_PR_URL,
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
mock.rest.pulls
|
mock.rest.pulls
|
||||||
.requestReviewers()
|
.requestReviewers()
|
||||||
.reply({
|
.reply({
|
||||||
repeat: REPEAT,
|
|
||||||
status: 201,
|
status: 201,
|
||||||
data: MERGED_PR_FIXTURE
|
data: mergedPullRequestFixture
|
||||||
});
|
});
|
||||||
|
|
||||||
mock.rest.issues
|
mock.rest.issues
|
||||||
.addAssignees()
|
.addAssignees()
|
||||||
.reply({
|
.reply({
|
||||||
repeat: REPEAT,
|
|
||||||
status: 201,
|
status: 201,
|
||||||
data: {}
|
data: {}
|
||||||
});
|
});
|
||||||
|
@ -203,187 +165,18 @@ export const mockGitHubClient = (apiUrl = "https://api.github.com"): Moctokit =>
|
||||||
mock.rest.issues
|
mock.rest.issues
|
||||||
.addLabels()
|
.addLabels()
|
||||||
.reply({
|
.reply({
|
||||||
repeat: REPEAT,
|
|
||||||
status: 200,
|
status: 200,
|
||||||
data: {}
|
data: {}
|
||||||
});
|
});
|
||||||
|
|
||||||
mock.rest.issues
|
|
||||||
.createComment()
|
|
||||||
.reply({
|
|
||||||
repeat: REPEAT,
|
|
||||||
status: 201,
|
|
||||||
data: {}
|
|
||||||
});
|
|
||||||
|
|
||||||
mock.rest.git
|
|
||||||
.getCommit({
|
|
||||||
owner: TARGET_OWNER,
|
|
||||||
repo: REPO,
|
|
||||||
commit_sha: "28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc",
|
|
||||||
})
|
|
||||||
.reply({
|
|
||||||
status: 200,
|
|
||||||
data: GITHUB_GET_COMMIT,
|
|
||||||
});
|
|
||||||
|
|
||||||
// invalid requests
|
// invalid requests
|
||||||
mock.rest.pulls
|
mock.rest.pulls
|
||||||
.get({
|
.get({
|
||||||
owner: TARGET_OWNER,
|
owner: targetOwner,
|
||||||
repo: REPO,
|
repo: repo,
|
||||||
pull_number: NOT_FOUND_PR_NUMBER
|
pull_number: notFoundPullRequestNumber
|
||||||
})
|
})
|
||||||
.reply({
|
.reply({
|
||||||
repeat: REPEAT,
|
|
||||||
status: 404,
|
|
||||||
data: {
|
|
||||||
message: "Not found"
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
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,
|
status: 404,
|
||||||
data: {
|
data: {
|
||||||
message: "Not found"
|
message: "Not found"
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
export const TARGET_OWNER = "owner";
|
export const targetOwner = "owner";
|
||||||
export const SOURCE_OWNER = "fork";
|
export const sourceOwner = "fork";
|
||||||
export const REPO = "reponame";
|
export const repo = "reponame";
|
||||||
export const NOT_FOUND_PR_NUMBER = 1;
|
export const notFoundPullRequestNumber = 1;
|
||||||
export const NEW_PR_URL = "new_pr_url";
|
|
||||||
export const NEW_PR_NUMBER = 9999;
|
|
||||||
|
|
||||||
export const MERGED_PR_FIXTURE = {
|
export const mergedPullRequestFixture = {
|
||||||
"url": "https://api.github.com/repos/owner/reponame/pulls/2368",
|
"url": "https://api.github.com/repos/owner/reponame/pulls/2368",
|
||||||
"id": 1137188271,
|
"id": 1137188271,
|
||||||
"node_id": "PR_kwDOABTq6s5DyB2v",
|
"node_id": "PR_kwDOABTq6s5DyB2v",
|
||||||
|
@ -96,8 +94,8 @@ export const MERGED_PR_FIXTURE = {
|
||||||
{
|
{
|
||||||
"id": 4901021057,
|
"id": 4901021057,
|
||||||
"node_id": "LA_kwDOImgs2354988AAAABJB-lgQ",
|
"node_id": "LA_kwDOImgs2354988AAAABJB-lgQ",
|
||||||
"url": "https://api.github.com/repos/owner/reponame/labels/backport-prod",
|
"url": "https://api.github.com/repos/owner/reponame/labels/original-label",
|
||||||
"name": "backport prod",
|
"name": "original-label",
|
||||||
"color": "AB975B",
|
"color": "AB975B",
|
||||||
"default": false,
|
"default": false,
|
||||||
"description": ""
|
"description": ""
|
||||||
|
@ -476,7 +474,7 @@ export const MERGED_PR_FIXTURE = {
|
||||||
"changed_files": 2
|
"changed_files": 2
|
||||||
};
|
};
|
||||||
|
|
||||||
export const OPEN_PR_FIXTURE = {
|
export const openPullRequestFixture = {
|
||||||
"url": "https://api.github.com/repos/owner/reponame/pulls/4444",
|
"url": "https://api.github.com/repos/owner/reponame/pulls/4444",
|
||||||
"id": 1137188271,
|
"id": 1137188271,
|
||||||
"node_id": "PR_kwDOABTq6s5DyB2v",
|
"node_id": "PR_kwDOABTq6s5DyB2v",
|
||||||
|
@ -900,7 +898,7 @@ export const OPEN_PR_FIXTURE = {
|
||||||
"changed_files": 2
|
"changed_files": 2
|
||||||
};
|
};
|
||||||
|
|
||||||
export const NOT_MERGED_PR_FIXTURE = {
|
export const notMergedPullRequestFixture = {
|
||||||
"url": "https://api.github.com/repos/owner/reponame/pulls/6666",
|
"url": "https://api.github.com/repos/owner/reponame/pulls/6666",
|
||||||
"id": 1137188271,
|
"id": 1137188271,
|
||||||
"node_id": "PR_kwDOABTq6s5DyB2v",
|
"node_id": "PR_kwDOABTq6s5DyB2v",
|
||||||
|
@ -1343,7 +1341,7 @@ export const NOT_MERGED_PR_FIXTURE = {
|
||||||
"changed_files": 2
|
"changed_files": 2
|
||||||
};
|
};
|
||||||
|
|
||||||
export const MULT_COMMITS_PR_FIXTURE = {
|
export const multipleCommitsPullRequestFixture = {
|
||||||
"url": "https://api.github.com/repos/owner/reponame/pulls/8632",
|
"url": "https://api.github.com/repos/owner/reponame/pulls/8632",
|
||||||
"id": 1137188271,
|
"id": 1137188271,
|
||||||
"node_id": "PR_kwDOABTq6s5DyB2v",
|
"node_id": "PR_kwDOABTq6s5DyB2v",
|
||||||
|
@ -1431,33 +1429,7 @@ export const MULT_COMMITS_PR_FIXTURE = {
|
||||||
|
|
||||||
],
|
],
|
||||||
"labels": [
|
"labels": [
|
||||||
{
|
|
||||||
"id": 4901021057,
|
|
||||||
"node_id": "LA_kwDOImgs2354988AAAABJB-lgQ",
|
|
||||||
"url": "https://api.github.com/repos/owner/reponame/labels/backport-v1",
|
|
||||||
"name": "backport v1",
|
|
||||||
"color": "AB975B",
|
|
||||||
"default": false,
|
|
||||||
"description": ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 4901021057,
|
|
||||||
"node_id": "LA_kwDOImgs2354988AAAABJB-lgQ",
|
|
||||||
"url": "https://api.github.com/repos/owner/reponame/labels/backport-v2",
|
|
||||||
"name": "backport v2",
|
|
||||||
"color": "AB975B",
|
|
||||||
"default": false,
|
|
||||||
"description": ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 4901021057,
|
|
||||||
"node_id": "LA_kwDOImgs2354988AAAABJB-lgQ",
|
|
||||||
"url": "https://api.github.com/repos/owner/reponame/labels/backport-v3",
|
|
||||||
"name": "backport v3",
|
|
||||||
"color": "AB975B",
|
|
||||||
"default": false,
|
|
||||||
"description": ""
|
|
||||||
}
|
|
||||||
],
|
],
|
||||||
"milestone": null,
|
"milestone": null,
|
||||||
"draft": false,
|
"draft": false,
|
||||||
|
@ -1832,15 +1804,7 @@ export const MULT_COMMITS_PR_FIXTURE = {
|
||||||
"changed_files": 2
|
"changed_files": 2
|
||||||
};
|
};
|
||||||
|
|
||||||
export const GITHUB_GET_COMMIT = {
|
export const multipleCommitsPullRequestCommits = [
|
||||||
"parents": [
|
|
||||||
{
|
|
||||||
"sha": "SHA"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
export const MULT_COMMITS_PR_COMMITS = [
|
|
||||||
{
|
{
|
||||||
"sha": "0404fb922ab75c3a8aecad5c97d9af388df04695",
|
"sha": "0404fb922ab75c3a8aecad5c97d9af388df04695",
|
||||||
"node_id": "C_kwDOImgs99oAKDA0MDRmYjkyMmFiNzVjM2E4YWVjYWQ1Yzk3ZDlhZjM4OGRmMDQ2OTU",
|
"node_id": "C_kwDOImgs99oAKDA0MDRmYjkyMmFiNzVjM2E4YWVjYWQ1Yzk3ZDlhZjM4OGRmMDQ2OTU",
|
||||||
|
|
|
@ -161,166 +161,6 @@ export const PROJECT_EXAMPLE = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const NESTED_PROJECT_EXAMPLE = {
|
|
||||||
"id":1645,
|
|
||||||
"description":null,
|
|
||||||
"name":"Backporting Example",
|
|
||||||
"name_with_namespace":"Super User / Backporting Example",
|
|
||||||
"path":"backporting-example",
|
|
||||||
"path_with_namespace":"mysuperorg/6/mysuperproduct/mysuperunit/backporting-example",
|
|
||||||
"created_at":"2023-06-23T13:45:15.121Z",
|
|
||||||
"default_branch":"main",
|
|
||||||
"tag_list":[
|
|
||||||
|
|
||||||
],
|
|
||||||
"topics":[
|
|
||||||
|
|
||||||
],
|
|
||||||
"ssh_url_to_repo":"git@my.gitlab.host.com:mysuperorg/6/mysuperproduct/mysuperunit/backporting-example.git",
|
|
||||||
"http_url_to_repo":"https://my.gitlab.host.com/mysuperorg/6/mysuperproduct/mysuperunit/backporting-example.git",
|
|
||||||
"web_url":"https://my.gitlab.host.com/mysuperorg/6/mysuperproduct/mysuperunit/backporting-example",
|
|
||||||
"readme_url":"https://my.gitlab.host.com/mysuperorg/6/mysuperproduct/mysuperunit/backporting-example/-/blob/main/README.md",
|
|
||||||
"forks_count":0,
|
|
||||||
"avatar_url":null,
|
|
||||||
"star_count":0,
|
|
||||||
"last_activity_at":"2023-06-28T14:05:42.596Z",
|
|
||||||
"namespace":{
|
|
||||||
"id":70747,
|
|
||||||
"name":"Super User",
|
|
||||||
"path":"superuser",
|
|
||||||
"kind":"user",
|
|
||||||
"full_path":"superuser",
|
|
||||||
"parent_id":null,
|
|
||||||
"avatar_url":"/uploads/-/system/user/avatar/14041/avatar.png",
|
|
||||||
"web_url":"https://my.gitlab.host.com/superuser"
|
|
||||||
},
|
|
||||||
"_links":{
|
|
||||||
"self":"https://my.gitlab.host.com/api/v4/projects/1645",
|
|
||||||
"issues":"https://my.gitlab.host.com/api/v4/projects/1645/issues",
|
|
||||||
"merge_requests":"https://my.gitlab.host.com/api/v4/projects/1645/merge_requests",
|
|
||||||
"repo_branches":"https://my.gitlab.host.com/api/v4/projects/1645/repository/branches",
|
|
||||||
"labels":"https://my.gitlab.host.com/api/v4/projects/1645/labels",
|
|
||||||
"events":"https://my.gitlab.host.com/api/v4/projects/1645/events",
|
|
||||||
"members":"https://my.gitlab.host.com/api/v4/projects/1645/members",
|
|
||||||
"cluster_agents":"https://my.gitlab.host.com/api/v4/projects/1645/cluster_agents"
|
|
||||||
},
|
|
||||||
"packages_enabled":true,
|
|
||||||
"empty_repo":false,
|
|
||||||
"archived":false,
|
|
||||||
"visibility":"private",
|
|
||||||
"owner":{
|
|
||||||
"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"
|
|
||||||
},
|
|
||||||
"resolve_outdated_diff_discussions":false,
|
|
||||||
"container_expiration_policy":{
|
|
||||||
"cadence":"1d",
|
|
||||||
"enabled":false,
|
|
||||||
"keep_n":10,
|
|
||||||
"older_than":"90d",
|
|
||||||
"name_regex":".*",
|
|
||||||
"name_regex_keep":null,
|
|
||||||
"next_run_at":"2023-06-24T13:45:15.167Z"
|
|
||||||
},
|
|
||||||
"issues_enabled":true,
|
|
||||||
"merge_requests_enabled":true,
|
|
||||||
"wiki_enabled":true,
|
|
||||||
"jobs_enabled":true,
|
|
||||||
"snippets_enabled":true,
|
|
||||||
"container_registry_enabled":true,
|
|
||||||
"service_desk_enabled":false,
|
|
||||||
"service_desk_address":null,
|
|
||||||
"can_create_merge_request_in":true,
|
|
||||||
"issues_access_level":"enabled",
|
|
||||||
"repository_access_level":"enabled",
|
|
||||||
"merge_requests_access_level":"enabled",
|
|
||||||
"forking_access_level":"enabled",
|
|
||||||
"wiki_access_level":"enabled",
|
|
||||||
"builds_access_level":"enabled",
|
|
||||||
"snippets_access_level":"enabled",
|
|
||||||
"pages_access_level":"private",
|
|
||||||
"analytics_access_level":"enabled",
|
|
||||||
"container_registry_access_level":"enabled",
|
|
||||||
"security_and_compliance_access_level":"private",
|
|
||||||
"releases_access_level":"enabled",
|
|
||||||
"environments_access_level":"enabled",
|
|
||||||
"feature_flags_access_level":"enabled",
|
|
||||||
"infrastructure_access_level":"enabled",
|
|
||||||
"monitor_access_level":"enabled",
|
|
||||||
"emails_disabled":null,
|
|
||||||
"shared_runners_enabled":true,
|
|
||||||
"lfs_enabled":true,
|
|
||||||
"creator_id":14041,
|
|
||||||
"import_url":null,
|
|
||||||
"import_type":null,
|
|
||||||
"import_status":"none",
|
|
||||||
"import_error":null,
|
|
||||||
"open_issues_count":0,
|
|
||||||
"description_html":"",
|
|
||||||
"updated_at":"2023-06-28T14:05:42.596Z",
|
|
||||||
"ci_default_git_depth":20,
|
|
||||||
"ci_forward_deployment_enabled":true,
|
|
||||||
"ci_job_token_scope_enabled":false,
|
|
||||||
"ci_separated_caches":true,
|
|
||||||
"ci_allow_fork_pipelines_to_run_in_parent_project":true,
|
|
||||||
"build_git_strategy":"fetch",
|
|
||||||
"keep_latest_artifact":true,
|
|
||||||
"restrict_user_defined_variables":false,
|
|
||||||
"runners_token":"TOKEN",
|
|
||||||
"runner_token_expiration_interval":null,
|
|
||||||
"group_runners_enabled":true,
|
|
||||||
"auto_cancel_pending_pipelines":"enabled",
|
|
||||||
"build_timeout":3600,
|
|
||||||
"auto_devops_enabled":false,
|
|
||||||
"auto_devops_deploy_strategy":"continuous",
|
|
||||||
"ci_config_path":"",
|
|
||||||
"public_jobs":true,
|
|
||||||
"shared_with_groups":[
|
|
||||||
|
|
||||||
],
|
|
||||||
"only_allow_merge_if_pipeline_succeeds":false,
|
|
||||||
"allow_merge_on_skipped_pipeline":null,
|
|
||||||
"request_access_enabled":true,
|
|
||||||
"only_allow_merge_if_all_discussions_are_resolved":false,
|
|
||||||
"remove_source_branch_after_merge":true,
|
|
||||||
"printing_merge_request_link_enabled":true,
|
|
||||||
"merge_method":"merge",
|
|
||||||
"squash_option":"default_off",
|
|
||||||
"enforce_auth_checks_on_uploads":true,
|
|
||||||
"suggestion_commit_message":null,
|
|
||||||
"merge_commit_template":null,
|
|
||||||
"squash_commit_template":null,
|
|
||||||
"issue_branch_template":null,
|
|
||||||
"autoclose_referenced_issues":true,
|
|
||||||
"approvals_before_merge":0,
|
|
||||||
"mirror":false,
|
|
||||||
"external_authorization_classification_label":null,
|
|
||||||
"marked_for_deletion_at":null,
|
|
||||||
"marked_for_deletion_on":null,
|
|
||||||
"requirements_enabled":false,
|
|
||||||
"requirements_access_level":"enabled",
|
|
||||||
"security_and_compliance_enabled":true,
|
|
||||||
"compliance_frameworks":[
|
|
||||||
|
|
||||||
],
|
|
||||||
"issues_template":null,
|
|
||||||
"merge_requests_template":null,
|
|
||||||
"merge_pipelines_enabled":false,
|
|
||||||
"merge_trains_enabled":false,
|
|
||||||
"allow_pipeline_trigger_approve_deployment":false,
|
|
||||||
"permissions":{
|
|
||||||
"project_access":{
|
|
||||||
"access_level":50,
|
|
||||||
"notification_level":3
|
|
||||||
},
|
|
||||||
"group_access":null
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const MERGED_SQUASHED_MR = {
|
export const MERGED_SQUASHED_MR = {
|
||||||
"id":807106,
|
"id":807106,
|
||||||
"iid":1,
|
"iid":1,
|
||||||
|
@ -401,7 +241,7 @@ export const MERGED_SQUASHED_MR = {
|
||||||
"source_project_id":76316,
|
"source_project_id":76316,
|
||||||
"target_project_id":76316,
|
"target_project_id":76316,
|
||||||
"labels":[
|
"labels":[
|
||||||
"backport-prod"
|
"gitlab-original-label"
|
||||||
],
|
],
|
||||||
"draft":false,
|
"draft":false,
|
||||||
"work_in_progress":false,
|
"work_in_progress":false,
|
||||||
|
@ -689,29 +529,6 @@ export const CLOSED_NOT_MERGED_MR = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const MERGED_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 OPEN_PR_COMMITS = [
|
export const OPEN_PR_COMMITS = [
|
||||||
{
|
{
|
||||||
"id":"974519f65c9e0ed65277cd71026657a09fca05e7",
|
"id":"974519f65c9e0ed65277cd71026657a09fca05e7",
|
||||||
|
@ -755,29 +572,6 @@ 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 = {
|
export const SUPERUSER = {
|
||||||
"id":14041,
|
"id":14041,
|
||||||
"username":"superuser",
|
"username":"superuser",
|
||||||
|
@ -786,273 +580,3 @@ export const SUPERUSER = {
|
||||||
"avatar_url":"https://my.gitlab.host.com/uploads/-/system/user/avatar/14041/avatar.png",
|
"avatar_url":"https://my.gitlab.host.com/uploads/-/system/user/avatar/14041/avatar.png",
|
||||||
"web_url":"https://my.gitlab.host.com/superuser"
|
"web_url":"https://my.gitlab.host.com/superuser"
|
||||||
};
|
};
|
||||||
|
|
||||||
export const NESTED_NAMESPACE_MR = {
|
|
||||||
"id":807106,
|
|
||||||
"iid":1,
|
|
||||||
"project_id":1645,
|
|
||||||
"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":1645,
|
|
||||||
"target_project_id":1645,
|
|
||||||
"labels":[
|
|
||||||
"gitlab-original-label"
|
|
||||||
],
|
|
||||||
"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":"ebb1eca696c42fd067658bd9b5267709f78ef38e",
|
|
||||||
"discussion_locked":null,
|
|
||||||
"should_remove_source_branch":true,
|
|
||||||
"force_remove_source_branch":true,
|
|
||||||
"reference":"!2",
|
|
||||||
"references":{
|
|
||||||
"short":"!2",
|
|
||||||
"relative":"!2",
|
|
||||||
"full":"superuser/backporting-example!2"
|
|
||||||
},
|
|
||||||
"web_url":"https://my.gitlab.host.com/mysuperorg/6/mysuperproduct/mysuperunit/backporting-example/-/merge_requests/4",
|
|
||||||
"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
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,5 +1,4 @@
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import { AuthTokenId } from "@bp/service/configs/configs.types";
|
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
|
|
||||||
export const addProcessArgs = (args: string[]) => {
|
export const addProcessArgs = (args: string[]) => {
|
||||||
|
@ -10,13 +9,6 @@ export const resetProcessArgs = () => {
|
||||||
process.argv = ["node", "backporting"];
|
process.argv = ["node", "backporting"];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const resetEnvTokens = () => {
|
|
||||||
delete process.env[AuthTokenId.GITHUB_TOKEN];
|
|
||||||
delete process.env[AuthTokenId.GITLAB_TOKEN];
|
|
||||||
delete process.env[AuthTokenId.CODEBERG_TOKEN];
|
|
||||||
delete process.env[AuthTokenId.GIT_TOKEN];
|
|
||||||
};
|
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
export const spyGetInput = (obj: any) => {
|
export const spyGetInput = (obj: any) => {
|
||||||
const mock = jest.spyOn(core, "getInput");
|
const mock = jest.spyOn(core, "getInput");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue