Skip to content

Commit

Permalink
WIP check
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick91 committed Aug 22, 2019
1 parent 0a22c05 commit 1e5e7cc
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .github/release-check-action/Dockerfile
@@ -0,0 +1,7 @@
FROM python:3.7-alpine

RUN pip install httpx

COPY . /action

ENTRYPOINT ["python", "/action/check.py"]
31 changes: 31 additions & 0 deletions .github/release-check-action/check.py
@@ -0,0 +1,31 @@
import json
import os
import pathlib
import sys

from github import add_release_check_comment, get_comments, is_release_check_comment


RELEASE_FILE_PATH = "RELEASE.md"
GITHUB_SHA = os.environ["GITHUB_SHA"]
GITHUB_EVENT_PATH = os.environ["GITHUB_EVENT_PATH"]
GITHUB_WORKSPACE = os.environ["GITHUB_WORKSPACE"]

with open(GITHUB_EVENT_PATH) as f:
event_data = json.load(f)

current_comments = get_comments(event_data)

release_file = pathlib.Path(GITHUB_WORKSPACE) / RELEASE_FILE_PATH

if not release_file.exists():
print("release file does not exist")

has_release_check_comment = any(
is_release_check_comment(comment) for comment in current_comments
)

if not has_release_check_comment:
add_release_check_comment(event_data)

sys.exit(1)
53 changes: 53 additions & 0 deletions .github/release-check-action/github.py
@@ -0,0 +1,53 @@
import os
import sys
import textwrap
import typing

import httpx


GITHUB_TOKEN = os.environ["GITHUB_TOKEN"]
SIGNATURE = "<!-- action-check: release-file -->"


def is_release_check_comment(comment: dict) -> bool:
return (
comment["user"]["login"] == "github-actions[bot]"
and SIGNATURE in comment["body"]
)


def get_comments(github_event_data: dict) -> typing.List[dict]:
comments_link = github_event_data["pull_request"]["_links"]["comments"]["href"]

comments_request = httpx.get(comments_link)

return comments_request.json()


def add_release_check_comment(github_event_data: dict):
comments_link = github_event_data["pull_request"]["_links"]["comments"]["href"]

body = f"""Nice change
multiline and code
```md
release type: patch
Description of issue
```
{SIGNATURE}
"""

request = httpx.post(
comments_link,
headers={"Authorization": f"token {GITHUB_TOKEN}"},
json={"body": textwrap.dedent(body)},
)

if request.status_code != 200:
print(request.text)
print(request.status_code)

sys.exit(1)
18 changes: 18 additions & 0 deletions .github/workflows/release-check.yml
@@ -0,0 +1,18 @@
name: Release file check

on:
pull_request:
branches:
- master

jobs:
release-file-check:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1

- name: Release file check
uses: ./.github/release-check-action
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .isort.cfg
Expand Up @@ -11,5 +11,5 @@ known_pytest=pytest
known_future_library=future
known_standard_library=types,requests
default_section=THIRDPARTY
known_third_party = base,click,github_release,graphql,hupper,pygments,starlette,uvicorn
known_third_party = base,click,github,github_release,graphql,httpx,hupper,pygments,starlette,uvicorn
sections=FUTURE,STDLIB,PYTEST,DJANGO,THIRDPARTY,FIRSTPARTY,LOCALFOLDER

0 comments on commit 1e5e7cc

Please sign in to comment.