diff --git a/.github/workflows/create-pull-request-multi.yml b/.github/workflows/create-pull-request-multi.yml index a2788ec..389f35a 100644 --- a/.github/workflows/create-pull-request-multi.yml +++ b/.github/workflows/create-pull-request-multi.yml @@ -22,10 +22,12 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} COMMIT_MESSAGE: Add report file + COMMIT_AUTHOR_EMAIL: peter-evans@users.noreply.github.com + COMMIT_AUTHOR_NAME: Peter Evans + PULL_REQUEST_TITLE: '[Example] Add report file' PULL_REQUEST_BODY: > This PR is auto-generated by [create-pull-request](https://github.com/peter-evans/create-pull-request). - PULL_REQUEST_TITLE: '[Example] Add report file' PULL_REQUEST_LABELS: report, automated pr PULL_REQUEST_ASSIGNEES: peter-evans PULL_REQUEST_REVIEWERS: peter-evans diff --git a/.github/workflows/create-pull-request.yml b/.github/workflows/create-pull-request.yml index aade0c7..a4b8a84 100644 --- a/.github/workflows/create-pull-request.yml +++ b/.github/workflows/create-pull-request.yml @@ -14,10 +14,12 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} COMMIT_MESSAGE: Add report file + COMMIT_AUTHOR_EMAIL: peter-evans@users.noreply.github.com + COMMIT_AUTHOR_NAME: Peter Evans + PULL_REQUEST_TITLE: '[Example] Add report file' PULL_REQUEST_BODY: > This PR is auto-generated by [create-pull-request](https://github.com/peter-evans/create-pull-request). - PULL_REQUEST_TITLE: '[Example] Add report file' PULL_REQUEST_LABELS: report, automated pr PULL_REQUEST_ASSIGNEES: peter-evans PULL_REQUEST_REVIEWERS: peter-evans diff --git a/README.md b/README.md index 82c7b5f..5c8a79c 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Create Pull Request action will: Linux ```yml - name: Create Pull Request - uses: peter-evans/create-pull-request@v1.4.1 + uses: peter-evans/create-pull-request@v1.5.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ``` @@ -26,7 +26,7 @@ Linux Multi platform - Linux, MacOS, Windows (beta) ```yml - name: Create Pull Request - uses: peter-evans/create-pull-request@v1.4.1-multi + uses: peter-evans/create-pull-request@v1.5.0-multi env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ``` @@ -81,7 +81,7 @@ To use this strategy, set `BRANCH_SUFFIX` to the value `none`. The variable `PUL 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 +## Examples Here is an example that sets all the main environment variables. @@ -98,14 +98,14 @@ jobs: - name: Create report file run: date +%s > report.txt - name: Create Pull Request - uses: peter-evans/create-pull-request@v1.4.1 + uses: peter-evans/create-pull-request@v1.5.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} COMMIT_MESSAGE: Add report file + PULL_REQUEST_TITLE: '[Example] Add report file' PULL_REQUEST_BODY: > This PR is auto-generated by [create-pull-request](https://github.com/peter-evans/create-pull-request). - PULL_REQUEST_TITLE: '[Example] Add report file' PULL_REQUEST_LABELS: report, automated pr PULL_REQUEST_ASSIGNEES: peter-evans PULL_REQUEST_REVIEWERS: peter-evans @@ -118,7 +118,42 @@ jobs: This configuration will create pull requests that look like this: -![Pull Request Example](pull-request-example.png?raw=true) +![Pull Request Example](https://github.com/peter-evans/create-pull-request/blob/master/pull-request-example.png?raw=true) + +### Dynamic configuration using variables + +The following examples show how configuration for the action can be dynamically defined in a previous workflow step. + +The recommended method is to use `set-output`. Note that the step where output variables are defined must have an id. + +```yml + - name: Set output variables + id: vars + run: | + echo ::set-output name=pr_title::"[Test] Add report file $(date +%d-%m-%Y)" + echo ::set-output name=pr_body::"This PR was auto-generated on $(date +%d-%m-%Y) \ + by [create-pull-request](https://github.com/peter-evans/create-pull-request)." + - name: Create Pull Request + uses: peter-evans/create-pull-request@v1.5.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PULL_REQUEST_TITLE: ${{ steps.vars.outputs.pr_title }} + PULL_REQUEST_BODY: ${{ steps.vars.outputs.pr_body }} +``` + +Since the action reads environment variables from the system, it's technically not necessary to explicitly pass them as long as they exist in the environment. So the following method using `set-env` *also* works, but explicitly passing the configuration parameters using the previous method is perferred for its clarity. + +```yml + - name: Set environment variables + run: | + echo ::set-env name=PULL_REQUEST_TITLE::"[Test] Add report file $(date +%d-%m-%Y)" + echo ::set-env name=PULL_REQUEST_BODY::"This PR was auto-generated on $(date +%d-%m-%Y) \ + by [create-pull-request](https://github.com/peter-evans/create-pull-request)." + - name: Create Pull Request + uses: peter-evans/create-pull-request@v1.5.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +``` ## License diff --git a/create-pull-request.py b/create-pull-request.py index 0223f49..e5c0c33 100755 --- a/create-pull-request.py +++ b/create-pull-request.py @@ -52,7 +52,7 @@ def remote_branch_exists(repo, branch): return False -def get_head_author(event_name, event_data): +def get_author_default(event_name, event_data): if event_name == "push": email = "{head_commit[author][email]}".format(**event_data) name = "{head_commit[author][name]}".format(**event_data) @@ -203,8 +203,11 @@ if skip_ignore_event or not ignore_event(event_name, event_data): print("Pull request branch '%s' already exists for this commit. Skipping." % branch) sys.exit() - # Get the HEAD committer's email and name - author_email, author_name = get_head_author(event_name, event_data) + # Get the default for author email and name + author_email, author_name = get_author_default(event_name, event_data) + # Set commit author overrides + author_email = os.getenv('COMMIT_AUTHOR_EMAIL', author_email) + author_name = os.getenv('COMMIT_AUTHOR_NAME', author_name) # Set git configuration set_git_config(repo.git, author_email, author_name) # Checkout branch