Skip to content

Commit

Permalink
Enable github issues
Browse files Browse the repository at this point in the history
closes #206
  • Loading branch information
fao89 committed Sep 20, 2021
1 parent 6a49995 commit f78cf97
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
22 changes: 10 additions & 12 deletions .ci/scripts/validate_commit_message.py
Expand Up @@ -8,29 +8,27 @@
import glob
import os
import re
import requests
import subprocess
import sys

from github import Github

KEYWORDS = ["fixes", "closes", "re", "ref"]
NO_ISSUE = "[noissue]"
STATUSES = ["NEW", "ASSIGNED", "POST", "MODIFIED"]
CHANGELOG_EXTS = [".feature", ".bugfix", ".doc", ".removal", ".misc"]

sha = sys.argv[1]
message = subprocess.check_output(["git", "log", "--format=%B", "-n 1", sha]).decode("utf-8")
g = Github(os.environ.get("GITHUB_TOKEN"))
repo = g.get_repo("pulp/pulp-operator")


def __check_status(issue):
response = requests.get("https://pulp.plan.io/issues/{}.json".format(issue))
response.raise_for_status()
bug_json = response.json()
status = bug_json["issue"]["status"]["name"]
if status not in STATUSES:
sys.exit(
"Error: issue #{issue} has invalid status of {status}. Status must be one of "
"{statuses}.".format(issue=issue, status=status, statuses=", ".join(STATUSES))
)
gi = repo.get_issue(int(issue))
if gi.pull_request:
sys.exit(f"Error: issue #{issue} is a pull request.")
if gi.closed_at:
sys.exit(f"Error: issue #{issue} is closed.")


def __check_changelog(issue):
Expand All @@ -50,7 +48,7 @@ def __check_changelog(issue):
print("Commit {sha} has no issue attached. Skipping issue check".format(sha=sha[0:7]))
else:
regex = r"(?:{keywords})[\s:]+#(\d+)".format(keywords=("|").join(KEYWORDS))
pattern = re.compile(regex)
pattern = re.compile(regex, re.IGNORECASE)

issues = pattern.findall(message)

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Expand Up @@ -33,7 +33,7 @@ jobs:
GITHUB_CONTEXT: ${{ github.event.pull_request.commits_url }}
run: |
echo ::group::REQUESTS
pip install requests
pip install pygithub
echo ::endgroup::
for sha in $(curl $GITHUB_CONTEXT | jq '.[].sha' | sed 's/"//g')
do
Expand Down
1 change: 1 addition & 0 deletions CHANGES/206.misc
@@ -0,0 +1 @@
Enable github issues

0 comments on commit f78cf97

Please sign in to comment.