devopsinfra/action-pull-request

Sponsored OSS

By DevOps Infra

Updated about 22 hours ago

GitHub Action that will create a pull request from the current branch

Image
0

1M+

devopsinfra/action-pull-request repository overview

🚀 GitHub Action for creating Pull Requests

GitHub Action that will create a pull request from the currently selected branch.

📦 Available on

✨ Features

  • Creates pull request if triggered from a current branch or any specified by source_branch to a target_branch
  • Title and body of a pull request can be specified with title and body
  • Can assign assignee, reviewer, one or more label, a milestone or mark it as a draft
  • Can replace any old_string inside a pull request template with a new_string. Or put commits' subjects in place of old_string
  • When get_diff is true will add list of commits in place of <!-- Diff commits --> and list of modified files in place of <!-- Diff files --> in a pull request template
  • When allow_no_diff is set to true will continue execution and create pull request even if both branches have no differences, e.g. having only a merge commit
  • Supports both amd64 and arm64 architectures

Useful in combination with my other action devops-infra/action-commit-push.

📊 Badges

GitHub repo GitHub last commit GitHub code size in bytes GitHub license
DockerHub Docker version Image size Docker Pulls

🏷️ Version Tags: vX, vX.Y, vX.Y.Z

This action supports three tag levels for flexible versioning:

  • vX: latest patch of the major version (e.g., v1).
  • vX.Y: latest patch of the minor version (e.g., v1.2).
  • vX.Y.Z: fixed to a specific release (e.g., v1.2.3).

📖 API Reference

    - name: Run the Action
      uses: devops-infra/[email protected]
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
        source_branch: development
        target_branch: master
        title: My pull request
        template: .github/PULL_REQUEST_TEMPLATE.md
        body: "**Automated pull request**"
        reviewer: octocat
        assignee: octocat
        label: enhancement
        milestone: My milestone
        draft: true
        old_string: "<!-- Add your description here -->"
        new_string: "** Automatic pull request**"
        get_diff: true
        ignore_users: "dependabot"
        allow_no_diff: false
🔧 Input Parameters
Input VariableRequiredDefaultDescription
github_tokenYes""GitHub token ${{ secrets.GITHUB_TOKEN }}
source_branchNocurrent branchName of the source branch
target_branchNomasterName of the target branch. Change it if you use main
titleNosubject of the first commitPull request title
templateNo""Template file location
bodyNolist of commitsPull request body
reviewerNo""Reviewer's username
assigneeNo""Assignee's usernames
labelNo""Labels to apply, comma separated
milestoneNo""Milestone
draftNofalseWhether to mark it as a draft
old_stringNo""Old string for the replacement in the template
new_stringNo""New string for the replacement in the template. If not specified, but old_string was, it will gather commits subjects
get_diffNofalseWhether to replace predefined comments with differences between branches - see details below
ignore_usersNo"dependabot"List of users to ignore, comma separated
allow_no_diffNofalseAllows to continue on merge commits with no diffs
📤 Outputs Parameters
OutputDescription
urlPull request URL
pr_numberNumber of GitHub pull request
➿ How get_diff works

In previous versions occurrences of following strings in a template result with replacing them with list of commits and list of modified files (<!-- Diff commits --> and <!-- Diff files -->).

Now this action will expect to have three types of comment blocks. Meaning anything between START and END comment will get replaced. This is especially important when updating pull request with new commits.

  • <!-- Diff summary - START --> and <!-- Diff summary - END --> - show first lines of each commit in the pull request
  • <!-- Diff commits - START --> and <!-- Diff commits - END --> - show graph of commits in the pull request, with authors' info and time
  • <!-- Diff files - START --> and <!-- Diff files - END --> - show list of modified files

If your template uses old comment strings it will try to adjust them in the pull request body to a new standard when pull request is created. It will not modify the template.

CAUTION: Remember to not use default fetch-depth for actions/checkout action. Rather set it to 0 - see example below.

💻 Usage Examples

Red areas show fields that can be dynamically expanded based on commits to the current branch. Blue areas show fields that can be set in action configuration.

Example screenshot

📝 Basic Example

Create pull request for non-master branches:

name: Run the Action
on:
  push:
    branches-ignore: master
jobs:
  action-pull-request:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v5

      - name: Create pull request
        uses: devops-infra/[email protected]
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          title: Automatic pull request
🔀 Advanced Example

Use first commit as a title and part of body, add a label based on a branch name, add git differences in the template:

name: Run the Action
on:
  push:
    branches-ignore: master
jobs:
  action-pull-request:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v5
        with:
          fetch-depth: 0

      - name: Run the Action
        if: startsWith(github.ref, 'refs/heads/feature')
        uses: devops-infra/[email protected]
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          title: ${{ github.event.commits[0].message }}
          assignee: ${{ github.actor }}
          label: automatic,feature
          template: .github/PULL_REQUEST_TEMPLATE/FEATURE.md
          old_string: "**Write your description here**"
          new_string: ${{ github.event.commits[0].message }}
          get_diff: true
🎯 Use specific version

Run the Action with a specific version tag.

name: Run the Action
on:
  push:
    branches-ignore: master
jobs:
  action-pull-request:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5

      - uses: devops-infra/[email protected]
        id: Pin patch version

      - uses: devops-infra/[email protected]
        id: Pin minor version

      - uses: devops-infra/action-pull-request@v1
        id: Pin major version

🤝 Contributing

Contributions are welcome! See CONTRIBUTING. This project is licensed under the MIT License - see the LICENSE file for details.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

💬 Support

If you have any questions or need help, please:

  • 📝 Create an issue
  • 🌟 Star this repository if you find it useful!

Tag summary

Content type

Image

Digest

sha256:7d512d9b2

Size

109.1 MB

Last updated

about 22 hours ago

Requires Docker Desktop 4.37.1 or later.

This week's pulls

Pulls:

6,529

Feb 23 to Mar 1