Skip to content

Commit

Permalink
Fix GA behavior on pull request (nephila#576)
Browse files Browse the repository at this point in the history
* Add missing pull request event to gihub actions

* Fix towncrier-check whe running in GA on pull requests
  • Loading branch information
yakky authored May 17, 2020
1 parent c5bb3cd commit ebdefe2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Linting - Tests

on: [push]
on: [push, pull_request]

jobs:
lint:
Expand Down
1 change: 1 addition & 0 deletions changes/575.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix GA on pull request
15 changes: 13 additions & 2 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,20 @@ def towncrier_check(c): # NOQA
""" Check towncrier files. """
output = io.StringIO()
c.run("git branch -a --contains HEAD", out_stream=output)
branches = [branch.replace("remotes/origin/", "") for branch in output.getvalue().strip("*").split()]
towncrier_file = None
skipped_branch_prefix = ["pull/", "develop", "master", "HEAD"]
# cleanup branch names by removing PR-only names in local, remote and disconnected branches to ensure the current
# (i.e. user defined) branch name is used
branches = list(
filter(
lambda x: x and all(not x.startswith(part) for part in skipped_branch_prefix),
(branch.replace("remotes/", "").strip("* (") for branch in output.getvalue().split("\n")),
)
)
if not branches:
# if no branch name matches, we are in one of the excluded branches above, so we just exit
return
branch = branches[0]
towncrier_file = None
for branch in branches:
if any(branch.startswith(prefix) for prefix in SPECIAL_BRANCHES):
sys.exit(0)
Expand Down

0 comments on commit ebdefe2

Please sign in to comment.