Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conf: Add Pylint to CI. #16

Merged
merged 6 commits into from
Feb 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions .githooks/commit-msg

This file was deleted.

25 changes: 0 additions & 25 deletions .githooks/pre-commit

This file was deleted.

13 changes: 12 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,28 @@ jobs:
runs-on: ubuntu-latest

steps:
# Setup
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.10"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Lint with black

# Lint
- name: Lint with Black
run: |
pip install black
black --check .

- name: Lint with Pylint
run: |
pip install pylint
touch __init__.py
pylint `pwd` --fail-under=5 --disable=too-few-public-methods,fixme
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.env
.idea
venv
**__pycache__**
*.pyc
__init__.py
14 changes: 4 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,10 @@ $ pip install -r requirements.txt
```
Or, if your system contains both Python 2 and Python 3, use `pip3`.

#### 5. Enable Git hooks

```
$ git config --local --add core.hooksPath .githooks
```

#### 6. Get the environment variables from another contributor
#### 7. [Download and configure ngrok](https://betterprogramming.pub/ngrok-make-your-localhost-accessible-to-anyone-333b99e44b07)
#### 8. Send your generated URL to MDG org admins
#### 9. Run the bot
#### 5. Get the environment variables from another contributor
#### 6. [Download and configure ngrok](https://betterprogramming.pub/ngrok-make-your-localhost-accessible-to-anyone-333b99e44b07)
#### 7. Send your generated URL to MDG org admins
#### 8. Run the bot

```
$ python main.py
Expand Down
4 changes: 3 additions & 1 deletion github_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class GitHubPayloadParser:
@staticmethod
def parse(event_type, raw_json) -> GitHubEvent:
def parse(event_type, raw_json) -> GitHubEvent | None:
json: JSON = JSON(raw_json)
event_parsers: list[Type[EventParser]] = [
BranchCreateEventParser,
Expand Down Expand Up @@ -37,6 +37,8 @@ def parse(event_type, raw_json) -> GitHubEvent:
event_type=event_type,
json=json,
)
print(f"Undefined event: {raw_json}")
return None


# Helper classes:
Expand Down
14 changes: 6 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Optional

from bottle import post, run, request, get

from github_parsers import GitHubPayloadParser
Expand All @@ -22,18 +20,18 @@ def test_post():

@post("/github/events")
def manage_github_events():
event: GitHubEvent = GitHubPayloadParser.parse(
event: GitHubEvent | None = GitHubPayloadParser.parse(
event_type=request.headers["X-GitHub-Event"],
raw_json=request.json,
)
bot.inform(event)
if event is not None:
bot.inform(event)


@post("/slack/commands")
def manage_slack_commands():
response: Optional[dict] = bot.run(raw_json=request.forms)
if response is not None:
return response
def manage_slack_commands() -> dict | None:
response: dict | None = bot.run(raw_json=request.forms)
return response


bot: SlackBot = SlackBot()
Expand Down
31 changes: 16 additions & 15 deletions models/github.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import enum
from typing import Optional, Literal
from typing import Literal

from models.link import Link


class Commit:
def __init__(
self,
message: Optional[str] = None,
sha: Optional[str] = None,
link: Optional[str] = None,
message: str | None = None,
sha: str | None = None,
link: str | None = None,
):
self.message = message
self.sha = sha
Expand Down Expand Up @@ -55,14 +55,14 @@ def __init__(
**kwargs,
):
self.name = name
self.link: Optional[str] = kwargs.get("link", None)
self.link: str | None = kwargs.get("link", None)
self.type = ref_type


class Repository:
def __init__(self, name: str, **kwargs):
self.name = name
self.link: Optional[str] = kwargs.get("link", None)
self.link: str | None = kwargs.get("link", None)


class User:
Expand All @@ -71,21 +71,22 @@ def __init__(self, name: str, **kwargs):
self.link = kwargs.get("link", f"https://github.com/{name}")


# pylint: disable-next=too-many-instance-attributes
class GitHubEvent:
def __init__(self, event_type: EventType, repo: Repository, **kwargs):
self.type = event_type
self.repo = repo

self.number: Optional[int] = kwargs.get("number", None)
self.number: int | None = kwargs.get("number", None)

self.status: Optional[str] = kwargs.get("status", None)
self.title: Optional[str] = kwargs.get("title", None)
self.status: str | None = kwargs.get("status", None)
self.title: str | None = kwargs.get("title", None)

self.branch: Optional[Ref] = kwargs.get("branch", None)
self.user: Optional[User] = kwargs.get("user", None)
self.branch: Ref | None = kwargs.get("branch", None)
self.user: User | None = kwargs.get("user", None)

self.comments: Optional[list[str]] = kwargs.get("comments", None)
self.comments: list[str] | None = kwargs.get("comments", None)

self.commits: Optional[list[Commit]] = kwargs.get("commits", None)
self.links: Optional[list[Link]] = kwargs.get("links", None)
self.reviewers: Optional[list[User]] = kwargs.get("reviewers", None)
self.commits: list[Commit] | None = kwargs.get("commits", None)
self.links: list[Link] | None = kwargs.get("links", None)
self.reviewers: list[User] | None = kwargs.get("reviewers", None)
5 changes: 1 addition & 4 deletions models/link.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from typing import Optional


class Link:
def __init__(self, url: Optional[str] = None, text: Optional[str] = None):
def __init__(self, url: str | None = None, text: str | None = None):
self.url = url
self.text = text

Expand Down
Loading