Skip to content

Commit 1fc2947

Browse files
authored
Merge pull request #42 from peter-evans/new-params
New parameters
2 parents 014d447 + 4e47f5e commit 1fc2947

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ These variables are all optional. If not set, a default value will be used.
3434
- `COMMIT_MESSAGE` - The message to use when committing changes.
3535
- `PULL_REQUEST_TITLE` - The title of the pull request.
3636
- `PULL_REQUEST_BODY` - The body of the pull request.
37+
- `BRANCH_SUFFIX` - Valid values are `short-commit-hash` and `timestamp`. See **Branch naming** below for details.
38+
39+
The following parameters are available for debugging and troubleshooting.
40+
41+
- `DEBUG_EVENT` - If present, outputs the event data that triggered the workflow.
42+
- `SKIP_IGNORE` - If present, the `ignore_event` function will be skipped.
3743

3844
#### Branch naming
3945

@@ -46,13 +52,21 @@ create-pull-request/patch-fcdfb59
4652
create-pull-request/patch-394710b
4753
```
4854
55+
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.
56+
57+
e.g.
58+
```
59+
create-pull-request/patch-1569322532
60+
create-pull-request/patch-1569322552
61+
```
62+
4963
#### Ignoring files
5064
5165
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.
5266
5367
## Example
5468
55-
Here is an example that sets all the environment variables.
69+
Here is an example that sets all the main environment variables.
5670
5771
```yml
5872
- name: Create Pull Request

create-pull-request.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
''' Create Pull Request '''
33
import json
44
import os
5+
import time
56
from git import Repo
67
from github import Github
78

89

910
def get_github_event(github_event_path):
1011
with open(github_event_path) as f:
1112
github_event = json.load(f)
12-
if os.environ.get('DEBUG_EVENT') is not None:
13+
if bool(os.environ.get('DEBUG_EVENT')):
1314
print(os.environ['GITHUB_EVENT_NAME'])
1415
print(json.dumps(github_event, sort_keys=True, indent=2))
1516
return github_event
@@ -122,7 +123,8 @@ def process_event(event_name, event_data, repo, branch, base):
122123
event_name = os.environ['GITHUB_EVENT_NAME']
123124
event_data = get_github_event(os.environ['GITHUB_EVENT_PATH'])
124125
# Check if this event should be ignored
125-
if not ignore_event(event_name, event_data):
126+
skip_ignore_event = bool(os.environ.get('SKIP_IGNORE'))
127+
if skip_ignore_event or not ignore_event(event_name, event_data):
126128
# Set the repo to the working directory
127129
repo = Repo(os.getcwd())
128130

@@ -133,8 +135,14 @@ def process_event(event_name, event_data, repo, branch, base):
133135

134136
# Skip if the current branch is a PR branch created by this action
135137
if not base.startswith(branch):
136-
# Suffix with the short SHA1 hash
137-
branch = "%s-%s" % (branch, get_head_short_sha1(repo))
138+
# Fetch an optional environment variable to determine the branch suffix
139+
branch_suffix = os.getenv('BRANCH_SUFFIX', 'short-commit-hash')
140+
if branch_suffix == "timestamp":
141+
# Suffix with the current timestamp
142+
branch = "%s-%s" % (branch, int(time.time()))
143+
else:
144+
# Suffix with the short SHA1 hash
145+
branch = "%s-%s" % (branch, get_head_short_sha1(repo))
138146

139147
# Check if a PR branch already exists for this HEAD commit
140148
if not pr_branch_exists(repo, branch):

0 commit comments

Comments
 (0)