From ebdefe2d3dc32775b77df59ad978afff1128ee99 Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Sun, 17 May 2020 14:57:20 +0200 Subject: [PATCH] Fix GA behavior on pull request (#576) * Add missing pull request event to gihub actions * Fix towncrier-check whe running in GA on pull requests --- .github/workflows/test.yml | 2 +- changes/575.bugfix | 1 + tasks.py | 15 +++++++++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 changes/575.bugfix diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 314e13c0..174e56ac 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,6 @@ name: Linting - Tests -on: [push] +on: [push, pull_request] jobs: lint: diff --git a/changes/575.bugfix b/changes/575.bugfix new file mode 100644 index 00000000..b83f40d2 --- /dev/null +++ b/changes/575.bugfix @@ -0,0 +1 @@ +Fix GA on pull request diff --git a/tasks.py b/tasks.py index d0645d33..d58be1a8 100644 --- a/tasks.py +++ b/tasks.py @@ -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)