mirror of
https://github.com/tauri-apps/create-pull-request.git
synced 2026-01-31 00:35:18 +01:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1fc2947eb6 | ||
|
|
4e47f5e151 | ||
|
|
e543bbd98a | ||
|
|
4fb3c76ad7 | ||
|
|
fcc56736a6 | ||
|
|
014d447f0c |
25
README.md
25
README.md
@@ -19,15 +19,11 @@ This action is experimental and may not work well for repositories that have a v
|
||||
|
||||
## Usage
|
||||
|
||||
In addition to the default `GITHUB_TOKEN`, the action requires a `repo` scoped token in order to commit.
|
||||
Create one [here](https://github.com/settings/tokens) and pass that as a secret to the `REPO_ACCESS_TOKEN` environment variable.
|
||||
|
||||
```yml
|
||||
- name: Create Pull Request
|
||||
uses: peter-evans/create-pull-request@v1.1.4
|
||||
uses: peter-evans/create-pull-request@v1.2.0
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
REPO_ACCESS_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
|
||||
```
|
||||
|
||||
#### Environment variables
|
||||
@@ -38,6 +34,12 @@ These variables are all optional. If not set, a default value will be used.
|
||||
- `COMMIT_MESSAGE` - The message to use when committing changes.
|
||||
- `PULL_REQUEST_TITLE` - The title of the pull request.
|
||||
- `PULL_REQUEST_BODY` - The body of the pull request.
|
||||
- `BRANCH_SUFFIX` - Valid values are `short-commit-hash` and `timestamp`. See **Branch naming** below for details.
|
||||
|
||||
The following parameters are available for debugging and troubleshooting.
|
||||
|
||||
- `DEBUG_EVENT` - If present, outputs the event data that triggered the workflow.
|
||||
- `SKIP_IGNORE` - If present, the `ignore_event` function will be skipped.
|
||||
|
||||
#### Branch naming
|
||||
|
||||
@@ -50,20 +52,27 @@ create-pull-request/patch-fcdfb59
|
||||
create-pull-request/patch-394710b
|
||||
```
|
||||
|
||||
Alternatively, branches can be suffixed with a timestamp by setting the environment variable `BRANCH_SUFFIX` to the value `timestamp`. This option may be necessary if multiple pull requests will be created during the execution of a workflow.
|
||||
|
||||
e.g.
|
||||
```
|
||||
create-pull-request/patch-1569322532
|
||||
create-pull-request/patch-1569322552
|
||||
```
|
||||
|
||||
#### Ignoring files
|
||||
|
||||
If there are files or directories you want to ignore you can simply add them to a `.gitignore` file at the root of your repository. The action will respect this file.
|
||||
|
||||
## Example
|
||||
|
||||
Here is an example that sets all the environment variables.
|
||||
Here is an example that sets all the main environment variables.
|
||||
|
||||
```yml
|
||||
- name: Create Pull Request
|
||||
uses: peter-evans/create-pull-request@v1.1.4
|
||||
uses: peter-evans/create-pull-request@v1.2.0
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
REPO_ACCESS_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
|
||||
PULL_REQUEST_BRANCH: my-patches
|
||||
COMMIT_MESSAGE: Auto-modify files by my-file-modifier-action
|
||||
PULL_REQUEST_TITLE: Changes from my-file-modifier-action
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
''' Create Pull Request '''
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
from git import Repo
|
||||
from github import Github
|
||||
|
||||
@@ -9,7 +10,7 @@ from github import Github
|
||||
def get_github_event(github_event_path):
|
||||
with open(github_event_path) as f:
|
||||
github_event = json.load(f)
|
||||
if os.environ.get('DEBUG_EVENT') is not None:
|
||||
if bool(os.environ.get('DEBUG_EVENT')):
|
||||
print(os.environ['GITHUB_EVENT_NAME'])
|
||||
print(json.dumps(github_event, sort_keys=True, indent=2))
|
||||
return github_event
|
||||
@@ -122,7 +123,8 @@ def process_event(event_name, event_data, repo, branch, base):
|
||||
event_name = os.environ['GITHUB_EVENT_NAME']
|
||||
event_data = get_github_event(os.environ['GITHUB_EVENT_PATH'])
|
||||
# Check if this event should be ignored
|
||||
if not ignore_event(event_name, event_data):
|
||||
skip_ignore_event = bool(os.environ.get('SKIP_IGNORE'))
|
||||
if skip_ignore_event or not ignore_event(event_name, event_data):
|
||||
# Set the repo to the working directory
|
||||
repo = Repo(os.getcwd())
|
||||
|
||||
@@ -133,8 +135,14 @@ if not ignore_event(event_name, event_data):
|
||||
|
||||
# Skip if the current branch is a PR branch created by this action
|
||||
if not base.startswith(branch):
|
||||
# Suffix with the short SHA1 hash
|
||||
branch = "%s-%s" % (branch, get_head_short_sha1(repo))
|
||||
# Fetch an optional environment variable to determine the branch suffix
|
||||
branch_suffix = os.getenv('BRANCH_SUFFIX', 'short-commit-hash')
|
||||
if branch_suffix == "timestamp":
|
||||
# Suffix with the current timestamp
|
||||
branch = "%s-%s" % (branch, int(time.time()))
|
||||
else:
|
||||
# Suffix with the short SHA1 hash
|
||||
branch = "%s-%s" % (branch, get_head_short_sha1(repo))
|
||||
|
||||
# Check if a PR branch already exists for this HEAD commit
|
||||
if not pr_branch_exists(repo, branch):
|
||||
|
||||
Reference in New Issue
Block a user