Giter VIP home page Giter VIP logo

git-backporting's Introduction

Git Backporting
📤 📥

ci checks status npm version


Git Backporting is a NodeJS 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.

Table of content

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.

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.

Therefore this tools is for anybody who is working on projects where they have to maintain multiple active branches/versions at the same time. If you are actively cherry-picking many changes from your main branch to other ones, and you mainly do changes through pull requests or merge requests, maybe this tool may be right for you.

CLI tool

All instructions provided below pertain to version v4 of the tool. If you wish to use an earlier version, we strongly encourage you to consider migrating to version v4 as there are no valid reason to keep using older versions. Please refer to Migrating to v4 section for comprehensive details on how to properly migrate to version v4.

This tool is released on the public npm registry, therefore it can be easily installed using npm:

$ 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:

$ git-backporting -tb <branch> -pr <pull-request-url> -a <git-token>

A real example could be the following one:

$ git-backporting -tb develop -pr https://github.com/kiegroup/git-backporting-example/pull/47 -a *****

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 section.

Requirements

  • Node 16 or higher, more details on Node can be found here.
  • Git, see how to install if you need help.

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).

After that it clones the corresponding git repository, check out in the provided target branch and create a new branch from that (name automatically generated if not provided as option).

By default the tool will try to cherry-pick the single squashed/merged commit into the newly created branch (please consider using --no-squash option if you want to cherry-pick all commits belonging to the provided pull request).

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.

Default cherry-pick strategy

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:

$ git cherry-pick -m 1 --strategy=recursive --strategy-option=theirs <sha>

From version v4.2.0 we made both strategy and strategy-option fully configurable from CLI or GitHub action, so if users need a specific strategy which differs from the default one please consider using either --strategy or --strategy-option, or their equivalent GitHub action inputs, more details in inputs section.

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

This tool comes with some inputs that allow users to override the default behavior, here the full list of available inputs:

Name Command Required Description Default
Version -V, --version - Current version of the tool
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
Pull Request -pr, --pull-request N Original pull request url, the one that must be backported, e.g., #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
Auth -a, --auth N Git access/authorization token, if provided all token env variables will be ignored. See auth token section for more details ""
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
Git User -gu, --git-user N Local git user name "GitHub"
Git Email -ge, --git-email N Local git user email "[email protected]"
Title --title N Backporting pull request title "{original-pr-title}"
Body --body N Backporting pull request body "{original-pr-body}"
Body Prefix --body-prefix N Prefix to the backporting pull request body "Backport: {original-pr-link}"
Reviewers --reviewers N Backporting pull request comma-separated reviewers 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
Backport Branch Names --bp-branch-name N Comma separated lists of the backporting pull request branch names, if they exceeds 250 chars they will be truncated bp-{target-branch}-{sha1}...{shaN}
Labels --labels N Provide custom labels to be added to the backporting pull request []
Inherit labels --inherit-labels N If enabled inherit lables from the original pull request false
No squash --no-squash N If provided the backporting will try to backport all pull request commits without squashing false
Strategy --strategy N Cherry pick merging strategy, see git-merge doc for all possible values "recursive"
Strategy Option --strategy-option N Cherry pick merging strategy option, see git-merge doc for all possible values "theirs"
Additional comments --comments N Semicolon separated list of additional comments to be posted to the backported pull request []
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 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

This is an example of a configuration file that can be used.

{
  "pullRequest": "https://gitlab.com/<namespace>/<repo>/-/merge_requests/1",
  "targetBranch": "old",
  "folder": "/tmp/my-folder",
  "title": "Override Title",
  "auth": "*****"
}

Keep in mind that its structure MUST match the Args interface, which is actually a camel-case version of the CLI options.

Supported git services

Right now Git Backporting supports the following git management services:

  • GITHUB: Introduced since the first release of this tool (version 1.0.0). The interaction with this system is performed using octokit client library.

  • 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 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 platform. Thanks to the api compatibility with GitHub, the interaction with this service is performed using using octokit client library.

NOTE: by default, all gitlab requests are performed setting rejectUnauthorized=false, planning to make this configurable too.

GitHub action

This action can be used in any GitHub workflow, below you can find a simple example of manually triggered workflow backporting a specific pull request (provided as input).

name: Pull Request Backporting using Git Backporting

on: 
  workflow_dispatch:
    inputs:
      targetBranch:
        description: 'Target branch'
        required: true
        type: string
      pullRequest:
        description: 'Pull request'
        required: true 
        type: string
      dryRun:
        description: 'Dry run'
        required: false
        default: "true" 
        type: string

jobs:
  backporting:
    name: "Backporting"
    runs-on: ubuntu-latest
    steps:
      - name: Backporting
        uses: kiegroup/git-backporting@main
        with:
          target-branch: ${{ inputs.targetBranch }}
          pull-request: ${{ inputs.pullRequest }}
          auth: ${{ secrets.GITHUB_TOKEN }}
          dry-run: ${{ inputs.dryRun }}

You can also use this action with other events - you'll just need to specify target-branch and pull-request params.

For example, this configuration creates a pull request against branch v1 once the current one is merged, provided that the label backport-v1 is applied:

name: Pull Request Backporting using Git Backporting

on:
  pull_request_target:
    types:
      - closed
      - labeled

env:
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
  backporting:
    name: "Backporting"
    # Only react to merged PRs for security reasons.
    # See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target.
    if: >
      github.event.pull_request.merged
      && (
        github.event.action == 'closed'
          && contains(github.event.pull_request.labels.*.name, 'backport-v1')
        || (
          github.event.action == 'labeled'
          && contains(github.event.label.name, 'backport-v1')
        )
      )
    runs-on: ubuntu-latest
    steps:
      - name: Backporting
        uses: kiegroup/git-backporting@main
        with:
          target-branch: v1
          pull-request: ${{ github.event.pull_request.url }}

For a complete description of all inputs see Inputs section.

Future works

Git Backporting is still in development mode, this means that there are still many future works and extension that can be implemented. I'll try to summarize the most important ones:

  • Provide a way to backport single commit (or a set of them) if no original pull request is present.
  • Integrate this tool with other git management services (like Bitbucket) to make it as generic as possible.
  • Integrate it into other CI/CD services like gitlab CI.
  • Provide some reusable GitHub workflows.

Migrating to v4

From version v4 the project has been moved under @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 that these changes are madnatory to make the tool working.

NOTE: Versions v3.1.1 and v4.0.0 offer identical features; the only distinction lies in the project's renaming and organization movement.

Development

Package release

The release of this package is entirely based on release-it tool. I created some useful scripts that can make the release itself quite easy.

Automatic release

The first step is to prepare the changes for the next release, this is done by running:

$ npm run release:prepare:all

NOTE: running locally this requires npm login, please consider using .github/workflows/prepare-release.yml if you don't have permission on the npm package.

This script performs the following steps:

  1. Automatically computes the next version based on the last commits
  2. Create a new branch release/v${computed_version}
  3. Apply all changes, like version and changelog upgrade
  4. Commit those changes: chore: release v${compute_version}

After that you should just push the new branch and open the pull request.

NOTE: if you don't want to run this preparation from you local environment, there is already a workflow that does all these steps, including the pull request. See Prepare release workflow.

Once the release preparion pull request got merged, you can run Release package workflow that automatically performs the release itself, including npm publishing, git tag and github release.

Manual release

In case we would like to perform a manual release, it would be enough to open a pull request changing the following items:

  • Package version inside the package.json
  • Provide exhaustive changelog information inside CHANGELOG.md
  • Commit like chore: release v<version>

Once the release preparion pull request got merged, run Release package workflow.

Contributing

This is an open source project, and you are more than welcome to contribute ❤️!

Every change must be submitted through a GitHub pull request (PR). Backporting uses continuous integration (CI). The CI runs checks against your branch after you submit the PR to ensure that your PR doesn’t introduce errors. If the CI identifies a potential problem, our friendly PR maintainers will help you resolve it.

Note: this project follows git-conventional-commits standards, thanks to the commit-msg hook you are not allowed to use commits that do not follow those standards.

  1. Fork it (https://github.com/kiegroup/git-backporting).

  2. Create your feature branch: (git checkout -b feature).

  3. Commit your changes with a comment: (git commit -am 'Add some feature').

  4. Push to the branch to GitHub: (git push origin feature).

  5. Create a new pull request against main branch.

Note: you don't need to take care about typescript compilation and minifycation, there are automated git hooks taking care of that!

Hint: if you are still in a work in progress branch and you want to push your changes remotely, consider adding --no-verify for both commit and push, e.g., git push origin <feat-branch> --no-verify

License

Git backporting open source project is licensed under the MIT license.

git-backporting's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

git-backporting's Issues

Change default branch name

Right now the default branch name used to cherry-pick changes is formatted this way:

bp-<target-branch>-<sha>

Since pr #55 we introduced a new feature where users can backport all commits belonging to the provided pull request, this could end up having a very long branch as it will be formatted this way:

bp-<target-branch>-<sha1>-<sha2>-<sha3>....<shaN>

Furthermore git limits the branch name length to 250 chars.

Proposed solutions:

  1. Simply truncate the branch name to 250 chars (we can shorten the shas to include as much commits as possible)
  2. Keep one single commit representative of the whole backport, the last one?
  3. Keep first and last commit to identify the range of commmits that are going to be backported

Support Azure DevOps

It would be interesting that being a cli tool it would work with other widely used providers like Azure DevOps.

I have been analyzing of all the tools similar to this one and none of them support Azure DevOps, they all seem to be GitHub centric.

Thanks!

Override Backporting PR Fields

Give users the possibility to override pull requests fields, in particular:

  • title
  • body
  • body prefix (which default is backport: <pr-link>) ?
  • backporting branch name

These new params must be added for both CLI and GHA.

Tests Not Working With Node 18

Environment: node v18.12.1 (npm v9.6.7)

Running npm test ends up in the following results:

Test Suites: 4 failed, 3 passed, 7 total
Tests:       18 failed, 13 passed, 31 total

An example of errors is this one:

  ● cli runner › override backporting pr data

    HttpError: Not Found

      24 |   async getPullRequest(owner: string, repo: string, prNumber: number): Promise<GitPullRequest> {
      25 |     this.logger.info(`Getting pull request ${owner}/${repo}/${prNumber}.`);
    > 26 |     const { data } = await this.octokit.rest.pulls.get({
         |                      ^
      27 |       owner: owner,
      28 |       repo: repo,
      29 |       pull_number: prNumber

      at node_modules/@octokit/request/dist-src/fetch-wrapper.js:70:27
      at GitHubService.getPullRequest (src/service/git/github/github-service.ts:26:22)
      at PullRequestConfigsParser.parse (src/service/configs/pullrequest/pr-configs-parser.ts:18:32)
      at PullRequestConfigsParser.parseAndValidate (src/service/configs/configs-parser.ts:21:30)
      at Runner.execute (src/service/runner/runner.ts:78:30)
      at Object.<anonymous> (test/service/runner/cli-runner.test.ts:302:5)

Seems like the octokit requests are not mocked by mock-github.

NOTE: this does not happen using node v16.19.0 (npm v9.6.7)

Backport pull request not merged yet

Give the chance to backport pull request that are not merged yet.

This will require to checkout to the pull request branch in order to cherry pick that commit, because if the pr is not merged yet that commit can be found only there.

Migrating to v4: unresolved github.event.pull_request.url in workflow

While testing the migration to v4.0.0, the Github action doesn't seem to find any more the pull request referenced with github.event.pull_request.url.

Here's the workflow that stopped working:

name: Pull Request backporting

on:
  pull_request_target:
    types:
      - closed
      - labeled

jobs:
  backporting:
    name: "Backporting"
    # Only react to merged PRs for security reasons.
    # See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target.
    if: >
      github.event.pull_request.merged
      && (
        github.event.action == 'closed'
          && contains(github.event.pull_request.labels.*.name, 'backport-v1')
        || (
          github.event.action == 'labeled'
          && contains(github.event.label.name, 'backport-v1')
        )
      )
    runs-on: ubuntu-latest
    steps:
      - name: Backporting
        uses: kiegroup/git-backporting@573a83f114038bcc514e1766d3cfc5c240618eeb
        with:
          target-branch: v1
          pull-request: ${{ github.event.pull_request.url }}
          auth: ${{ secrets.GITHUB_TOKEN }}

It should be conform to what's documented in the README.

Here's the error I get from Github:

2023-07-10T09:40:39.0291834Z Requested labels: ubuntu-latest
2023-07-10T09:40:39.0292142Z Job defined at: pierreprinetti/gophtest2/.github/workflows/backport_v1.yaml@refs/heads/main
2023-07-10T09:40:39.0292235Z Waiting for a runner to pick up this job...
2023-07-10T09:40:39.2456559Z Job is waiting for a hosted runner to come online.
2023-07-10T09:40:42.0169714Z Job is about to start running on the hosted runner: GitHub Actions 2 (hosted)
2023-07-10T09:40:44.3904829Z Current runner version: '2.305.0'
2023-07-10T09:40:44.3935479Z ##[group]Operating System
2023-07-10T09:40:44.3936041Z Ubuntu
2023-07-10T09:40:44.3936451Z 22.04.2
2023-07-10T09:40:44.3936773Z LTS
2023-07-10T09:40:44.3937058Z ##[endgroup]
2023-07-10T09:40:44.3937413Z ##[group]Runner Image
2023-07-10T09:40:44.3937826Z Image: ubuntu-22.04
2023-07-10T09:40:44.3938137Z Version: 20230702.1.0
2023-07-10T09:40:44.3938718Z Included Software: https://github.com/actions/runner-images/blob/ubuntu22/20230702.1/images/linux/Ubuntu2204-Readme.md
2023-07-10T09:40:44.3939444Z Image Release: https://github.com/actions/runner-images/releases/tag/ubuntu22%2F20230702.1
2023-07-10T09:40:44.3939891Z ##[endgroup]
2023-07-10T09:40:44.3940313Z ##[group]Runner Image Provisioner
2023-07-10T09:40:44.3940701Z 2.0.238.1
2023-07-10T09:40:44.3940984Z ##[endgroup]
2023-07-10T09:40:44.3942088Z ##[group]GITHUB_TOKEN Permissions
2023-07-10T09:40:44.3942811Z Actions: write
2023-07-10T09:40:44.3943172Z Checks: write
2023-07-10T09:40:44.3943730Z Contents: write
2023-07-10T09:40:44.3944230Z Deployments: write
2023-07-10T09:40:44.3944561Z Discussions: write
2023-07-10T09:40:44.3944919Z Issues: write
2023-07-10T09:40:44.3945256Z Metadata: read
2023-07-10T09:40:44.3945556Z Packages: write
2023-07-10T09:40:44.3945944Z Pages: write
2023-07-10T09:40:44.3946295Z PullRequests: write
2023-07-10T09:40:44.3946642Z RepositoryProjects: write
2023-07-10T09:40:44.3947061Z SecurityEvents: write
2023-07-10T09:40:44.3947473Z Statuses: write
2023-07-10T09:40:44.3947817Z ##[endgroup]
2023-07-10T09:40:44.3951546Z Secret source: Actions
2023-07-10T09:40:44.3952301Z Prepare workflow directory
2023-07-10T09:40:44.4714748Z Prepare all required actions
2023-07-10T09:40:44.4909419Z Getting action download info
2023-07-10T09:40:44.7434418Z Download action repository 'kiegroup/git-backporting@573a83f114038bcc514e1766d3cfc5c240618eeb' (SHA:573a83f114038bcc514e1766d3cfc5c240618eeb)
2023-07-10T09:40:45.4685592Z Complete job name: Backporting
2023-07-10T09:40:45.5713630Z ##[group]Run kiegroup/git-backporting@573a83f114038bcc514e1766d3cfc5c240618eeb
2023-07-10T09:40:45.5714144Z with:
2023-07-10T09:40:45.5714390Z   target-branch: v1
2023-07-10T09:40:45.5714818Z   pull-request: https://api.github.com/repos/pierreprinetti/gophtest2/pulls/1
2023-07-10T09:40:45.5715526Z   auth: ***
2023-07-10T09:40:45.5715783Z   dry-run: false
2023-07-10T09:40:45.5716033Z   git-user: GitHub
2023-07-10T09:40:45.5716325Z   git-email: [email protected]
2023-07-10T09:40:45.5716648Z   no-inherit-reviewers: false
2023-07-10T09:40:45.5716924Z ##[endgroup]
2023-07-10T09:40:45.8624129Z [DEBUG] Setting up github client: apiUrl=https://api.github.com/api/v4, token=****
2023-07-10T09:40:45.8626763Z [INFO] Creating octokit instance.
2023-07-10T09:40:45.8647634Z [DEBUG] Parsing configs..
2023-07-10T09:40:45.8650623Z [INFO] Getting pull request pierreprinetti/gophtest2/1.
2023-07-10T09:40:46.0049751Z [ERROR] Something went wrong retrieving pull request
2023-07-10T09:40:46.0052191Z [ERROR] HttpError: Not Found
2023-07-10T09:40:46.0053125Z [INFO] Process failed!
2023-07-10T09:40:46.0383395Z Cleaning up orphan processes

And in particular:

2023-07-10T09:40:45.8650623Z [INFO] Getting pull request pierreprinetti/gophtest2/1.
2023-07-10T09:40:46.0049751Z [ERROR] Something went wrong retrieving pull request
2023-07-10T09:40:46.0052191Z [ERROR] HttpError: Not Found

Thank you!

Backport all commits from a PR without squashing

Right now the tool merge merge_commit_sha if present which is basically the squashed commit for that PR, but there may be situations where users would like to cherry-pick all commits in a specific pull request.

Proposal:

  1. Add new cli option squash (default set to true)
  2. If squash=true the behavior would exactly as it is now
  3. If squash=false retrieve all commits from that pr and backport all of them.

Improve README.md

Improved README.md adding the following information:

  • NPM tool installation
  • NPM tool usage
  • Inputs description
  • Future works and limitation
  • Contribution

When cherry-pick conflict cannot be resolved

It seems that there are cases where the conflict cannot be resolved with git cherry-pick -m 1 --strategy=recursive --strategy-option=theirs.
What I have experienced is that in the case of a commit that modifies a file that does not yet exist in the branch to be backported, a conflict occurs even with the theirs option.
How do you behave or handle these cases?

Handle multiple `target-branch`

Since there might be use cases where the same change should be backported to multiple changes, instead of iterating over those target branches calling the same CLI command (or GHA invocation), properly integrate this feature in the tool itself such that to apply backporting multiple times on different branches.

GITLAB_TOKEN environment variable not used for API call

Step to reproduce:

  1. Set GITLAB_TOKEN environment variable.
  2. Call git-backporting without --auth. Pulling and pushing Git branches will succeed, but the attempt to create a merge request will fail.

It seems like the environment variable is parsed in PullRequestConfigsParser.parseAndValidate(). However, this seems to happen before the GitClient is created, so it's not used inside it.

Log
[DEBUG] Setting up gitlab client: apiUrl=https://gitlab.com/api/v4, token=****
[DEBUG] Parsing configs..
[INFO ] Auth argument not provided, checking available tokens from env..
[DEBUG] [ubports/focal] Cloning repo..
[INFO ] [ubports/focal] Cloning repository https://gitlab.com/peat-psuwit/ut-declarative-camera.git to /builds/peat-psuwit/gitlab-auto-backporter/gitlab-auto-backporter-cOoDLk/bp
[DEBUG] [ubports/focal] Creating local branch..
[INFO ] [ubports/focal] Creating branch backports/mr-1/ubports/focal
[DEBUG] [ubports/focal] Cherry picking commits..
[INFO ] [ubports/focal] Cherry picking e6ba6be7b155b5aa86b0b2968f91cda9471ff50d
[INFO ] [ubports/focal] Pushing backports/mr-1/ubports/focal to origin
[INFO ] [ubports/focal] Creating pull request backports/mr-1/ubports/focal -> ubports/focal
[INFO ] [ubports/focal] {
  "owner": "peat-psuwit",
  "repo": "ut-declarative-camera",
  "head": "backports/mr-1/ubports/focal",
  "base": "ubports/focal",
  "title": "[ubports/focal] Personal/peat psuwit/test",
  "body": "**Backport:** https://gitlab.com/peat-psuwit/ut-declarative-camera/-/merge_requests/1\r\n\r\nTest\n\nX-UBports-Depends: !1 \nX-UBports-Depends: ubports/development/core/morph-browser!574 \nX-UBports-Depends: https://gitlab.com/ubports/development/core/morph-browser/-/merge_requests/574",
  "reviewers": [
    "peat-psuwit"
  ],
  "assignees": [],
  "labels": [],
  "comments": []
}
[ERROR] [ubports/focal] Something went wrong backporting to ubports/focal: AxiosError: Request failed with status code 401
[ERROR] [ubports/focal] Error: Failure occurred during one of the backports: [AxiosError: Request failed with status code 401]
[INFO ] [ubports/focal] Process failed

Git clone by default into temporary directory

It seems like right now it will be cloned into the current directory as bp. While searching something in my finder i found that folder and thought wtf is that.

I think in default it should be written to /tmp instead of CWD.

Create Pull Request from Forked Repo

Give the possibility to open the backporting pull request from the forked repository, obviously in this case we assume the provided token has proper permissions on the forked repository.

Steps need:

  • Parameterize this new feature, by default create PR from target repo
  • If this new feature is enabled:
    • Add new remote
    • Push branch to this remote
    • Create pr setting head has <fork-owner>:<branch-name>

Configuration File as Option

Since the number of CLI options is increasing more and more, give users the possibility to provide a json configuration file containing all those required options.

Option: ".option(--config <path-to-config>", "path to a configuration file containing all required options", undefined)

Config file example:

{
  "target-branch": "<branch>",
  "pull-request": "<pr-url>",
  "auth": "<token>",
  ...
}

Make merge strategy option configurable

The current theirs strategy option is not always desirable since it can result in surprising behavior as seen in gophercloud/gophercloud#2685.

We should provide a way to configure the merge strategy, or at a minimum disable the automatic conflict resolution, so that merge conflicts result in an error.

Setup e2e Test Suite

All tests are just unit tests where most of the git commands are mocked, a possible improvement could be to setup a full e2e test suite in order to concretely test both CLI and GHA.

Retrieve target branch from PR label(s)

There are use cases where the target branch is not always fixed, instead it is dynamically computed from the original PR label(s).
That is why we created this additional workflow step [1] to properly parse labels with a prefixed pattern and extracting the target branch from them, this could be hard to maintain and error-prone.

Proposal: integrate this step in the tool itself, in this way target-branch will become optional and you can provide the regex/pattern to use in order to extract the target branch from the original PR labels, if any.

[1] https://github.com/kiegroup/droolsjbpm-build-bootstrap/blob/main/.github/workflows/pr-backporting.yml#L12-L25

Tasks

  1. enhancement
    lampajr

Keep track of requested user ids on Gitlab client

In the Gitlab client we have to perform additional request to retrieve the user ids in order to correctly setup reviewers and assignees, since it could happen that an assignee is also a reviewers (especially if you consider that backporting is generally automatically executed by CI/CD tools) we could keep track of already requested user ids and check it before doing the rest call.

From a techincal point of view this could be implemented as simple key-value map where the key is the username and the value is the userId.

Fix CLI Fields Help Message

This PR #29 introduced new CLI fields [1] for which the helper method has NOT been correctly setup, the parameter value name is called <folder> for all of them. This results in the following help message:

❯ bper --help
Usage: @lampajr/bper [options]

BPer is a tool to execute automatic git backporting.

Options:
  -V, --version                  output the version number
  -tb, --target-branch <branch>  branch where changes must be backported to.
  -pr, --pull-request <pr url>   pull request url, e.g., https://github.com/lampajr/backporting/pull/1.
  -d, --dry-run                  if enabled the tool does not create any pull request nor push anything remotely (default: false)
  -a, --auth <auth>              git service authentication string, e.g., github token. (default: "")
  -f, --folder <folder>          local folder where the repo will be checked out, e.g., /tmp/folder.
  --title <folder>               backport pr title, default original pr title prefixed by target branch.
  --body <folder>                backport pr title, default original pr body prefixed by bodyPrefix.
  --body-prefix <folder>         backport pr body prefix, default `backport <original-pr-link>`.
  --bp-branch-name <folder>      backport pr branch name, default auto-generated by the commit.
  -h, --help                     display help for command

To Do: replace <folder> with an appropriate and meaningful name.

[1] https://github.com/lampajr/backporting/blob/main/src/service/args/cli/cli-args-parser.ts#L18-L21

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.