{"id":13474275,"url":"https://github.com/vsoch/pull-request-action","last_synced_at":"2025-04-05T01:08:11.882Z","repository":{"id":35408041,"uuid":"168611951","full_name":"vsoch/pull-request-action","owner":"vsoch","description":"open a pull request when a branch is pushed or updated","archived":false,"fork":false,"pushed_at":"2024-06-10T15:58:48.000Z","size":192,"stargazers_count":173,"open_issues_count":1,"forks_count":62,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-29T22:33:17.532Z","etag":null,"topics":["branches","github-action","github-actions","hacktoberfest","pull-request"],"latest_commit_sha":null,"homepage":"https://github.com/marketplace/actions/pull-request-action","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vsoch.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-01-31T23:21:34.000Z","updated_at":"2024-07-29T17:18:55.000Z","dependencies_parsed_at":"2023-12-08T03:29:14.546Z","dependency_job_id":"adf79405-97b5-4336-8ef2-e3d52bb7f133","html_url":"https://github.com/vsoch/pull-request-action","commit_stats":{"total_commits":82,"total_committers":16,"mean_commits":5.125,"dds":"0.24390243902439024","last_synced_commit":"882391869b75196e039a732df05085312c456995"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vsoch%2Fpull-request-action","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vsoch%2Fpull-request-action/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vsoch%2Fpull-request-action/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vsoch%2Fpull-request-action/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vsoch","download_url":"https://codeload.github.com/vsoch/pull-request-action/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247271530,"owners_count":20911587,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["branches","github-action","github-actions","hacktoberfest","pull-request"],"created_at":"2024-07-31T16:01:10.963Z","updated_at":"2025-04-05T01:08:11.863Z","avatar_url":"https://github.com/vsoch.png","language":"Python","readme":"# Automated Branch Pull Requests\n\nThis action will open a pull request to master branch (or otherwise specified)\nwhenever a branch with some prefix is pushed to. The idea is that you can\nset up some workflow that pushes content to branches of the repostory,\nand you would then want this push reviewed for merge to master.\n\nHere is an example of what to put in your `.github/workflows/pull-request.yml` file to\ntrigger the action.\n\n```yaml\nname: Pull Request on Branch Push\non:\n  push:\n    branches-ignore:\n      - staging\n      - launchpad\n      - production\njobs:\n  auto-pull-request:\n    name: PullRequestAction\n    runs-on: ubuntu-latest\n    steps:\n      - name: pull-request-action\n        uses: vsoch/pull-request-action@master\n        env:\n          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n          BRANCH_PREFIX: \"update/\"\n          PULL_REQUEST_BRANCH: \"master\"\n```\n\n**Important**: Make sure to use a stable [release](https://github.com/vsoch/pull-request-action/releases) instead of a branch for your workflow.\n\n\n## Environment Variable Inputs\n\nUnlike standard actions, this action just uses variables from the environment.\n\n| Name | Description | Required | Default |\n|------|-------------|----------|---------|\n| BRANCH_PREFIX | the prefix to filter to. If the branch doesn't start with the prefix, it will be ignored | false | \"\" |\n| PULL_REQUEST_REPOSITORY | Choose another repository instead of default GITHUB_REPOSITORY for the PR  | false | |\n| PULL_REQUEST_TOKEN | [Personal Access Token(PAT)](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) only if you define a different repository with PULL_REQUEST_REPOSITORY | false | |\n| PULL_REQUEST_BRANCH | open pull request against this branch | false | master |\n| PULL_REQUEST_FROM_BRANCH | if a branch isn't found in your GitHub payload, use this branch | false | |\n| PULL_REQUEST_BODY | the body for the pull request | false | |\n| PULL_REQUEST_TITLE | the title for the pull request | false | |\n| PULL_REQUEST_DRAFT | should this be a draft PR? | false | unset |\n| MAINTAINER_CANT_MODIFY | Do not allow the maintainer to modify the PR | false | unset |\n| PULL_REQUEST_ASSIGNEES | A list (string with spaces) of users to assign | false | unset |\n| PULL_REQUEST_REVIEWERS | A list (string with spaces) of users to assign review | false | unset |\n| PULL_REQUEST_TEAM_REVIEWERS | A list (string with spaces) of teams to assign review | false | unset |\n| PASS_ON_ERROR | Instead of failing on an error response, pass | false | unset |\n| PASS_IF_EXISTS | Instead of failing if the pull request already exists, pass | false | unset |\n| PULL_REQUEST_UPDATE | If the pull request already exists, update it | false | unset |\n| PULL_REQUEST_STATE | If `PULL_REQUEST_UPDATE` is true, update to this state (open, closed) | false |open |\n\nFor `PULL_REQUEST_DRAFT`, `PASS_ON_ERROR`, `PASS_IF_EXISTS`, and `MAINTAINER_CANT_MODIFY`, these are\ntreated as environment booleans. If they are defined in the environment, they trigger the\n\"true\" condition. E.g.,:\n\n - Define `MAINTAINER_CANT_MODIFY` if you don't want the maintainer to be able to modify the pull request.\n - Define `PULL_REQUEST_DRAFT` if you want the PR to be a draft.\n - Define `PASS_ON_ERROR` if you want the PR to not exit given any non 200/201 response.\n - Define `PASS_IF_EXISTS` if you want the PR to not exit given the pull request is already open.\n - Define `PULL_REQUEST_UPDATE` if you want the pull request to be updated if it already exits.\n\nFor `PULL_REQUEST_ASSIGNEES`, `PULL_REQUEST_REVIEWERS`, and `PULL_REQUEST_TEAM_REVIEWERS` \nyou can provide a string of one or more GitHub usernames (or team names) to\nassign to the issue. Note that only users with push access can add assigness to \nan issue or PR, they are ignored otherwise.\n\nThe `GITHUB_TOKEN` secret is required to interact and authenticate with the GitHub API to open\nthe pull request. The example is [deployed here](https://github.com/vsoch/pull-request-action-example) with an example opened (and merged) [pull request here](https://github.com/vsoch/pull-request-action-example/pull/1) if needed.\n\nIf you want to create a pull request to another repository, for example, a pull request to the upstream repository, you need to define PULL_REQUEST_REPOSITORY and PULL_REQUEST_TOKEN. The PULL_REQUEST_TOKEN is one [Personal Access Token(PAT)](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token), which can be save in the [encrypted secrets](https://docs.github.com/en/actions/reference/encrypted-secrets#creating-encrypted-secrets-for-a-repository)\n\n## Outputs\n\nThe action sets a few useful output and environment variables. An output can\nbe referenced later as `${{ steps.\u003cstepname\u003e.outputs.\u003coutput-name\u003e }}`.\nAn environment variable of course can be referenced as you usually would.\n\n| Name | Description | Environment | \n|------|-------------|-------------|\n| pull_request_number |If the pull request is opened, this is the number for it. | PULL_REQUEST_NUMBER |\n| pull_request_url |If the pull request is opened, the html url for it. | PULL_REQUEST_URL |\n| pull_request_return_code | Return code for the pull request | PULL_REQUEST_RETURN_CODE |\n| assignees_return_code | Return code for the assignees request | ASSIGNEES_RETURN_CODE |\n| reviewers_return_code | Return code for the reviewers request | REVIEWERS_RETURN_CODE |\n\nSee the [examples/outputs-example.yml](examples/outputs-example.yml) for how this works. \nIn this example, we can reference `${{ steps.pull_request.outputs.pull_request_url }}`\nin either another environment variable declaration, or within a run statement to access\nour variable `pull_request_url` that was generated in a step with id `pull_request`.\nThe screenshot below shows the example in action to interact with outputs in several ways.\n\n![img/outputs.png](img/outputs.png)\n\n## Examples\n\nExample workflows are provided in [examples](examples), and please contribute any\nexamples that you might have to help other users! You can get the same commit hashes\nand commented tags if you use the [action-updater](https://github.com/vsoch/action-updater)\nalso maintained by @vsoch. We will walk through a basic\nexample here for a niche case. Let's say that we are opening a pull request on the release event. This would mean\nthat the payload's branch variable would be null. We would need to define `PULL_REQUEST_FROM`. How would\nwe do that? We can [set environment variables](https://github.com/actions/toolkit/blob/main/docs/commands.md#environment-files) for next steps. Here is an example:\n\n```yaml\nname: Pull Request on Branch Push\non: [release]\njobs:\n  pull-request-on-release:\n    name: PullRequestAction\n    runs-on: ubuntu-latest\n    steps:\n      - name: Checkout Code\n        uses: actions/checkout@v2\n      - name: Derive from branch name\n        run: |\n            # do custom parsing of your code / date to derive a branch from\n            PR_BRANCH_FROM=release-v$(cat VERSION)\n            echo \"PULL_REQUEST_FROM_BRANCH=${PR_BRANCH_FROM}\" \u003e\u003e $GITHUB_ENV\n      - name: pull-request-action\n        uses: vsoch/pull-request-action@master\n        env:\n          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n          PULL_REQUEST_BRANCH: \"master\"\n```\n\nThe above workflow is triggered on a release, so the branch will be null in the GItHub\npayload. Since we want the release PR to come from a special branch, we derive it\nin the second step, and then set the `PULL_REQUEST_FROM_BRANCH` variable in the environment\nfor the next step. In the Pull Request Action step, the pull request\nwill be opened from `PULL_REQUEST_FROM_BRANCH` against `PULL_REQUEST_BRANCH`, which is\nmaster. If we do not set this variable, the job will exit in an error,\nas it is not clear what action to take.\n\n\n## Example use Case: Update Registry\n\nAs an example, I created this action to be intended for an \n[organizational static registry](https://www.github.com/singularityhub/registry-org) for container builds. \nSpecifically, you have modular repositories building container recipes, and then opening pull requests to the \nregistry to update it. \n\n - the container collection content should be generated from a separate GitHub repository, including the folder structure (manifests, tags, collection README) that are expected.\n - the container collection metadata is pushed to a new branch on the registry repository, with namespace matching the GitHub repository, meaning that each GitHub repository always has a unique branch for its content.\n - pushing this branch that starts with the prefix (update/\u003cnamespace\u003e) triggers the GitHub actions to open the pull request.\n\nIf the branch is already open for PR, it updates it. Take a look at [this example](https://github.com/singularityhub/registry-org/pull/8)\nfor the pull request opened when we updated the previous GitHub syntax to the new yaml syntax. Although this\ndoesn't describe the workflow above, it works equivalently in terms of the triggers.\n","funding_links":[],"categories":["Community Resources","Uncategorized","Python"],"sub_categories":["Pull Requests","Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvsoch%2Fpull-request-action","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvsoch%2Fpull-request-action","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvsoch%2Fpull-request-action/lists"}