Create GitHub Pull Request

Action ID: publish:github:pull-request
NPM Package:

@backstage/plugin-scaffolder-backend-module-github

Description

Publishes a pull request to GitHub with specified changes, reviewers, and assignees.

Input Schema

PropertyTypeDescriptionRequired
draftbooleanCreate a draft pull request
titlestringThe name for the pull request
tokenstringThe token to use for authorization to GitHub
updatebooleanUpdate pull request if already exists
repoUrlstringAccepts the format `github.com?repo=reponame&owner=owner` where `reponame` is the repository name and `owner` is an organization or username
assigneesarrayThe users that will be added as assignees to the pull request
forceForkbooleanCreate pull request from a fork
reviewersarrayThe users that will be added as reviewers to the pull request
branchNamestringThe name for the branch
sourcePathstringSubdirectory of working directory to copy changes from
targetPathstringSubdirectory of repository to apply changes to
descriptionstringThe description of the pull request
commitMessagestringThe commit message for the pull request commit
filesToDeletearrayList of files that will be deleted
gitAuthorNamestringSets the default author name for the commit. The default value is the authenticated user or `Scaffolder`
teamReviewersarrayThe teams that will be added as reviewers to the pull request
gitAuthorEmailstringSets the default author email for the commit. The default value is the authenticated user or `[email protected]`
createWhenEmptybooleanSet whether to create pull request when there are no changes to commit. The default value is true. If set to false, remoteUrl is no longer a required output.
targetBranchNamestringThe target branch name of the pull request
forceEmptyGitAuthorbooleanForces the author to be empty. This is useful when using a Github App, it permit the commit to be verified on Github

Output Schema

PropertyTypeDescriptionRequired
remoteUrlstringLink to the pull request in Github
targetBranchNamestringTarget branch name of the merge request
pullRequestNumbernumberThe pull request number

Usage Examples

Open a feature PR with reviewers and assignees

Creates a pull request with generated changes and requests reviews from specific users. Use this when you are adding new files and want to route the review to specific maintainers after preparing changes with fetch:template.

Copy
steps:
  - id: fetch-template
    action: fetch:template
    input:
      url: ./skeleton
      targetPath: ./changes
      values:
        serviceName: ${{ parameters.serviceName }}

  - id: create-feature-pr
    action: publish:github:pull-request
    input:
      repoUrl: github.com?repo=${{ parameters.repoName }}&owner=${{ parameters.repoOwner }}
      branchName: feature/upgrade-java-17
      targetBranchName: main
      title: Upgrade service to Java 17
      description: Update runtime to Java 17 and adjust Dockerfile and CI workflow
      sourcePath: ./changes
      commitMessage: chore: upgrade to Java 17 and update CI
      reviewers:
        - dev1
        - dev2
      assignees:
        - release-manager
      draft: false

Create a draft PR from a fork with team reviewers

Opens a draft pull request from a fork using a GitHub App or personal token. Use this when write access is restricted and you need team based reviews after preparing changes with fetch:template.

Copy
steps:
  - id: fetch-template
    action: fetch:template
    input:
      url: ./ci-updates
      targetPath: ./changes
      values:
        pipeline: github-actions

  - id: pr-from-fork
    action: publish:github:pull-request
    input:
      repoUrl: github.com?repo=${{ parameters.repoName }}&owner=${{ parameters.repoOwner }}
      branchName: chore/update-ci-workflows
      targetBranchName: develop
      title: CI workflow improvements
      description: Migrate workflows to reusable actions and improve caching
      sourcePath: ./changes
      commitMessage: ci: refactor workflows and caching
      draft: true
      teamReviewers:
        - platform
        - security
      forceFork: true
      token: ${{ secrets.githubToken }}
      forceEmptyGitAuthor: true

Delete obsolete files and skip empty PRs

Proposes a cleanup that removes deprecated files and updates docs, and does not open a pull request if there are no changes. Use this for periodic maintenance prepared with fetch:template.

Copy
steps:
  - id: fetch-docs
    action: fetch:template
    input:
      url: ./docs-refresh
      targetPath: ./changes
      values:
        docOwner: ${{ parameters.repoOwner }}

  - id: cleanup-docs-pr
    action: publish:github:pull-request
    input:
      repoUrl: github.com?repo=${{ parameters.repoName }}&owner=${{ parameters.repoOwner }}
      branchName: docs/cleanup
      targetBranchName: main
      title: Remove legacy docs and refresh content
      description: Delete deprecated documentation and apply latest templates
      sourcePath: ./changes
      targetPath: docs/
      filesToDelete:
        - docs/legacy.md
        - docs/old-config.yml
      commitMessage: docs: refresh and remove legacy files
      reviewers:
        - tech-writer
      createWhenEmpty: false

Update an existing PR if the branch already exists

Ensures the same branch is reused and the pull request is updated on subsequent runs. Use this for recurring automation that regenerates files with fetch:template.

Copy
steps:
  - id: fetch-updates
    action: fetch:template
    input:
      url: ./dependency-bump
      targetPath: ./changes
      values:
        updatePolicy: minor

  - id: update-bump-pr
    action: publish:github:pull-request
    input:
      repoUrl: github.com?repo=${{ parameters.repoName }}&owner=${{ parameters.repoOwner }}
      branchName: chore/dependency-bump
      targetBranchName: main
      title: Dependency updates
      description: Apply automated dependency updates across the project
      sourcePath: ./changes
      commitMessage: chore: bump dependencies
      assignees:
        - build-cop
      update: true
      draft: false

Apply changes to a subdirectory in a monorepo with team review

Copies generated files into a specific package directory in a monorepo and requests review from a team and an owner. Use this when only part of the repository should be changed after preparing content with fetch:template.

Copy
steps:
  - id: fetch-service-config
    action: fetch:template
    input:
      url: ./service-config
      targetPath: ./changes/service-a
      values:
        serviceId: service-a
        language: node

  - id: service-config-pr
    action: publish:github:pull-request
    input:
      repoUrl: github.com?repo=platform-monorepo&owner=acme-org
      branchName: feat/service-a-ci
      targetBranchName: main
      title: Add CI config for service-a
      description: Introduce CI workflow and codeowners for service-a
      sourcePath: ./changes/service-a
      targetPath: services/service-a/
      commitMessage: feat(service-a): add CI workflow and codeowners
      reviewers:
        - alice
      teamReviewers:
        - service-owners
      gitAuthorName: Automation Bot
      gitAuthorEmail: [email protected]