Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom commit messages #9

Merged
merged 2 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)