Skip to content

Commit

Permalink
Merge pull request #9 from jtpio/pr-script-commit-message
Browse files Browse the repository at this point in the history
Add support for custom commit messages
  • Loading branch information
blink1073 authored Nov 17, 2021
2 parents 5ec14f7 + c8ef091 commit 90bc268
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/pr_script.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ on:
pre_commit:
description: Whether to run the pre-commit script
required: false
commit_message:
description: Optional commit message
required: false
jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -35,5 +38,6 @@ jobs:
TARGET: ${{ github.event.inputs.target }}
SCRIPT: ${{ github.event.inputs.script }}
PRE_COMMIT: ${{ github.event.inputs.pre_commit }}
COMMIT_MESSAGE: ${{ github.event.inputs.commit_message }}
run: |
python pr_script.py
8 changes: 5 additions & 3 deletions pr_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def run(cmd, **kwargs):
raise e


def run_script(target, script):
def run_script(target, script, commit_message=''):
"""Run a script on the target pull request URL"""
# e.g. https://github.com/foo/bar/pull/81
owner, repo = target.replace("https://github.com/", "").split('/')[:2]
Expand Down Expand Up @@ -62,14 +62,16 @@ def run_script(target, script):
'git config user.email "41898282+github-actions[bot]@users.noreply.github.com"'
)
run('git config user.name "GitHub Action"')
run(f"git commit -a -m 'Run maintainer script' -m 'by {maintainer}' -m '{json.dumps(script)}'")
message = commit_message or "Run maintainer script"
run(f"git commit -a -m '{message}' -m 'by {maintainer}' -m '{json.dumps(script)}'")
run(f"git push origin {branch}")


if __name__ == '__main__':
# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#inputs
target = os.environ.get('TARGET')
maintainer = os.environ['MAINTAINER']
commit_message = os.environ.get('COMMIT_MESSAGE', '')
try:
script = json.loads(os.environ.get('SCRIPT', '[]'))
except Exception:
Expand All @@ -80,4 +82,4 @@ def run_script(target, script):
script += ['pre-commit run --all-files']
print(f'Running script on {target}:')
print(f' {script}')
run_script(target, script)
run_script(target, script, commit_message)

0 comments on commit 90bc268

Please sign in to comment.