Skip to content
This repository has been archived by the owner on Sep 30, 2022. It is now read-only.

Commit

Permalink
Merge pull request #7 from KevinDeJong-TomTom/check-pull-request-title
Browse files Browse the repository at this point in the history
feat: check pull request title
  • Loading branch information
KevinDeJong-TomTom authored Sep 23, 2020
2 parents 0cbff5e + a9fd3eb commit 47b16a2
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/commisery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
name: Commisery
on:
pull_request:
types: [opened, synchronize, reopened]
types: [edited, opened, synchronize, reopened]

jobs:
commit-message:
Expand Down
106 changes: 53 additions & 53 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
===============================================================
Check your commits against Conventional Commits using Commisery
===============================================================

Using this GitHub action, scan your commits in your Pull Request against the `Conventional Commits`_ standard
using `Commisery`_

.. _`Conventional Commits`: https://www.conventionalcommits.org/en/v1.0.0/
.. _`Commisery`: https://pypi.org/project/commisery/

Usage
-----

The workflow, usually declared in `.github/workflows/build.yml`, looks like:

.. code-block:: yaml
name: Commisery
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
commit-message:
name: Conventional Commit Message Checker (Commisery)
runs-on: ubuntu-latest
steps:
- name: Check-out the repo under $GITHUB_WORKSPACE
uses: actions/checkout@v2
with:
# ensure we retrieve the full history as we need to check all commits in the provided Pull Request
fetch-depth: 0
- name: Run Commisery
uses: KevinDeJong-TomTom/commisery-action@master
with:
token: ${{ secrets.GITHUB_TOKEN }}
pull_request: ${{ github.event.number }}
Inputs
^^^^^^

- **token**: GitHub Token provided by GitHub, see `Authenticating with the GITHUB_TOKEN`_
- **pull_request**: Pull Request number, provided by the `GitHub context`_.

.. _`Authenticating with the GITHUB_TOKEN`: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/authenticating-with-the-github_token
.. _`GitHub context`: https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#github-context


Example of Conventional Commit check results
--------------------------------------------

.. image:: resources/example.png
===============================================================
Check your commits against Conventional Commits using Commisery
===============================================================

Using this GitHub action, scan your Pull Request title and all commits in your Pull Request against
the `Conventional Commits`_ standard using `Commisery`_

.. _`Conventional Commits`: https://www.conventionalcommits.org/en/v1.0.0/
.. _`Commisery`: https://pypi.org/project/commisery/

Usage
-----

The workflow, usually declared in `.github/workflows/build.yml`, looks like:

.. code-block:: yaml
name: Commisery
on:
pull_request:
types: [edited, opened, synchronize, reopened]
jobs:
commit-message:
name: Conventional Commit Message Checker (Commisery)
runs-on: ubuntu-latest
steps:
- name: Check-out the repo under $GITHUB_WORKSPACE
uses: actions/checkout@v2
with:
# ensure we retrieve the full history as we need to check all commits in the provided Pull Request
fetch-depth: 0
- name: Run Commisery
uses: KevinDeJong-TomTom/commisery-action@master
with:
token: ${{ secrets.GITHUB_TOKEN }}
pull_request: ${{ github.event.number }}
Inputs
^^^^^^

- **token**: GitHub Token provided by GitHub, see `Authenticating with the GITHUB_TOKEN`_
- **pull_request**: Pull Request number, provided by the `GitHub context`_.

.. _`Authenticating with the GITHUB_TOKEN`: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/authenticating-with-the-github_token
.. _`GitHub context`: https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#github-context


Example of Conventional Commit check results
--------------------------------------------

.. image:: resources/example.png
47 changes: 30 additions & 17 deletions commisery_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,34 @@ def strip_ansicolors(text: str) -> str:
return re.sub('\x1b\\[(K|.*?m)', '', text)


def error_message(message: str, options: dict = {}):
error = '::error '
def error_message(message: str):
message = strip_ansicolors(convert_to_multiline(message))
print(f'::error ::{message}')

for key, value in options.items():
error += f'{key}={value},'

error = error[:-1]
message = strip_ansicolors(convert_to_multiline(message))
error += f'::{message}'
def create_pr_file(pull_request: object) -> str:
filename = 'commit_message'

f = open(filename, 'w+')
f.write(pull_request.title)
f.close()

return filename


print(error)
def check_message(argument: str) -> bool:
proc = subprocess.Popen(
["commisery-verify-msg", argument],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
stdout, stderr = proc.communicate()

if proc.returncode > 0:
error_message(stderr.decode("utf-8"))
return False

return True


@click.command()
Expand All @@ -54,18 +71,14 @@ def main(token: str, repository: str, pull_request_id: int) -> int:

repo = Github(token).get_repo(repository)
pr = repo.get_pull(int(pull_request_id))

if not check_message(create_pr_file(pr)):
errors += 1

commits = pr.get_commits()

for commit in commits:
proc = subprocess.Popen(
["commisery-verify-msg", commit.sha],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
stdout, stderr = proc.communicate()

if proc.returncode > 0:
error_message(stderr.decode("utf-8"))
if not check_message(commit.sha):
errors += 1

exit(1 if errors else 0)
Expand Down
Binary file modified resources/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 47b16a2

Please sign in to comment.