Skip to content

Commit e5efd10

Browse files
authored
Merge pull request #12 from thehedgefrog/main
Allow custom commit message and pull request title
2 parents 8cd5087 + c47c62f commit e5efd10

3 files changed

Lines changed: 27 additions & 9 deletions

File tree

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/saadmk11/github-actions-version-updater/Changelog%20CI?label=Changelog%20CI&style=flat-square)
88

99
**GitHub Actions Version Updater** is GitHub Action that is used to **update other GitHub Actions** in a Repository
10-
and create a **pull request** with the updates. It is an automated dependency updater similar to GitHub's **Dependabot**,
10+
and create a **pull request** with the updates. It is an automated dependency updater similar to GitHub's **Dependabot**,
1111
but for GitHub Actions.
1212

1313
### How Does It Work:
@@ -24,16 +24,16 @@ but for GitHub Actions.
2424

2525
### Usage:
2626

27-
We recommend running this action on a [`schedule`](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#schedule)
27+
We recommend running this action on a [`schedule`](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#schedule)
2828
event or a [`workflow_dispatch`](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#workflow_dispatch) event.
2929

30-
To integrate `GitHub Actions Version Updater` on your repository, create a `YAML` file
30+
To integrate `GitHub Actions Version Updater` on your repository, create a `YAML` file
3131
inside `.github/workflows/` directory (`.github/workflows/updater.yaml`) add the following into the file:
3232

3333
```yaml
3434
name: GitHub Actions Version Updater
3535

36-
# Controls when the action will run.
36+
# Controls when the action will run.
3737
on:
3838
# can be used to run workflow manually
3939
workflow_dispatch:
@@ -44,7 +44,7 @@ on:
4444
jobs:
4545
build:
4646
runs-on: ubuntu-latest
47-
47+
4848
steps:
4949
- uses: actions/checkout@v2
5050
with:
@@ -58,6 +58,10 @@ jobs:
5858
# defaults to `github-actions[bot]` if not provided
5959
committer_username: 'test'
6060
committer_email: 'test@test.com'
61+
# Optional, allows customizing the commit message and pull request title
62+
# Both default to 'Update GitHub Action Versions'
63+
commit_message: 'Commit Message'
64+
pull_request_title: 'Pull Request Title'
6165
# Access token with `workflow` scope is required
6266
token: ${{ secrets.WORKFLOW_SECRET }}
6367
# Do not update these actions (Optional)

action.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ inputs:
1313
description: 'Email Address of that user who will commit'
1414
required: false
1515
default: 'github-actions[bot]@users.noreply.github.com'
16+
commit_message:
17+
description: 'Commit message for the commits by the action'
18+
required: false
19+
default: 'Update GitHub Action Versions'
20+
pull_request_title:
21+
description: 'Title for the pull requests generated by the action'
22+
required: false
23+
default: 'Update GitHub Action Versions'
1624
ignore:
1725
description: 'A JSON array which denotes the actions that should not be updated'
1826
required: false

main.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ class GitHubActionsVersionUpdater:
1515
github_url = 'https://github.com/'
1616
action_label = 'uses'
1717

18-
def __init__(self, repository, base_branch, token, ignore_actions=None):
18+
def __init__(self, repository, base_branch, token, commit_message=None, pr_title=None, ignore_actions=None):
1919
self.repository = repository
2020
self.base_branch = base_branch
2121
self.token = token
22+
self.commit_message = commit_message or 'Update GitHub Action Versions'
23+
self.pr_title = pr_title or 'Update GitHub Action Versions'
2224
self.ignore_actions = self.get_ignored_actions(ignore_actions)
2325
self.workflow_updated = False
2426

@@ -183,7 +185,7 @@ def create_new_branch(self):
183185
)
184186
subprocess.run(['git', 'add', '.'])
185187
subprocess.run(
186-
['git', 'commit', '-m', 'Update GitHub Action Versions']
188+
['git', 'commit', '-m', self.commit_message]
187189
)
188190

189191
subprocess.run(['git', 'push', '-u', 'origin', new_branch])
@@ -196,7 +198,7 @@ def create_pull_request(self, branch_name, body):
196198
"""Create pull request on GitHub"""
197199
url = f'{self.github_api_url}/repos/{self.repository}/pulls'
198200
payload = {
199-
'title': 'Update GitHub Action Versions',
201+
'title': self.pr_title,
200202
'head': branch_name,
201203
'base': self.base_branch,
202204
'body': body,
@@ -312,6 +314,10 @@ def print_message(message, message_type=None):
312314
email = os.environ['INPUT_COMMITTER_EMAIL']
313315
# Actions that should not be updated
314316
ignore = os.environ['INPUT_IGNORE']
317+
# Commit message
318+
commit_message = os.environ['INPUT_COMMIT_MESSAGE']
319+
# Pull Request Title
320+
pr_title = os.environ['INPUT_PULL_REQUEST_TITLE']
315321

316322
# Group: Configure Git
317323
print_message('Configure Git', message_type='group')
@@ -326,7 +332,7 @@ def print_message(message, message_type=None):
326332

327333
# Initialize GitHubActionsVersionUpdater
328334
actions_version_updater = GitHubActionsVersionUpdater(
329-
repository, base_branch, token, ignore_actions=ignore
335+
repository, base_branch, token, commit_message=commit_message, pr_title=pr_title, ignore_actions=ignore
330336
)
331337
actions_version_updater.run()
332338

0 commit comments

Comments
 (0)