diff --git a/app.py b/app.py index 97b089b..425d645 100644 --- a/app.py +++ b/app.py @@ -15,25 +15,15 @@ app = Flask(__name__) -slack_events_adapter = SlackEventAdapter( - os.environ["SIGNING_SECRET"], "/slack/events", app -) +slack_events_adapter = SlackEventAdapter(os.environ["SIGNING_SECRET"], "/slack/events", app) client = WebClient(token=os.environ["SLACK_TOKEN"]) -client.chat_postMessage( - channel=DEPLOYS_CHANNEL_NAME, text="bot started v1.8 24-05-28 top" -) +client.chat_postMessage(channel=DEPLOYS_CHANNEL_NAME, text="bot started v1.8 24-05-28 top") def fetch_github_data(owner, repo): - prs = requests.get( - f"{GITHUB_API_URL}/repos/{owner}/{repo}/pulls?state=closed" - ).json() - issues = requests.get( - f"{GITHUB_API_URL}/repos/{owner}/{repo}/issues?state=closed" - ).json() - comments = requests.get( - f"{GITHUB_API_URL}/repos/{owner}/{repo}/issues/comments" - ).json() + prs = requests.get(f"{GITHUB_API_URL}/repos/{owner}/{repo}/pulls?state=closed").json() + issues = requests.get(f"{GITHUB_API_URL}/repos/{owner}/{repo}/issues?state=closed").json() + comments = requests.get(f"{GITHUB_API_URL}/repos/{owner}/{repo}/issues/comments").json() return prs, issues, comments @@ -58,11 +48,12 @@ def format_data(prs, issues, comments): user_data[user] = {"prs": 0, "issues": 0, "comments": 0} user_data[user]["comments"] += 1 - table = "User | PRs Merged | Issues Resolved | Comments\n ---- | ---------- | --------------- | --------\n" + table = ( + "User | PRs Merged | Issues Resolved | Comments\n" + " ---- | ---------- | --------------- | --------\n" + ) for user, counts in user_data.items(): - table += ( - f"{user} | {counts['prs']} | {counts['issues']} | {counts['comments']}\n" - ) + table += f"{user} | {counts['prs']} | {counts['issues']} | {counts['comments']}\n" return table diff --git a/pyproject.toml b/pyproject.toml index 8dda73e..239e8ab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,7 +16,22 @@ slack-sdk = "^3.27.2" slackeventsapi = "^3.0.1" requests = "^2.32.3" - [build-system] requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" + +[tool.isort] +known_first_party = ["lettuce", "tests"] +line_length = 99 +multi_line_output = 3 +profile = "black" + +[tool.ruff] +line-length = 99 +target-version = "py311" + +[tool.ruff.lint] +select = ["E4", "E5", "E7", "E9", "F", "N"] + +[tool.ruff.lint.flake8-errmsg] +max-string-length = 99 diff --git a/src/sammich/plugins/contributors.py b/src/sammich/plugins/contributors.py index 1a592c0..9371f48 100644 --- a/src/sammich/plugins/contributors.py +++ b/src/sammich/plugins/contributors.py @@ -1,19 +1,27 @@ +import os + import requests +from dotenv import load_dotenv from machine.plugins.base import MachineBasePlugin from machine.plugins.decorators import command +load_dotenv() + GITHUB_API_URL = "https://api.github.com" +GITHUB_TOKEN = os.getenv("GITHUB_TOKEN") def fetch_github_data(owner, repo): + + headers = {"Authorization": f"token {GITHUB_TOKEN}"} prs = requests.get( - f"{GITHUB_API_URL}/repos/{owner}/{repo}/pulls?state=closed" + f"{GITHUB_API_URL}/repos/{owner}/{repo}/pulls?state=closed", headers=headers ).json() issues = requests.get( - f"{GITHUB_API_URL}/repos/{owner}/{repo}/issues?state=closed" + f"{GITHUB_API_URL}/repos/{owner}/{repo}/issues?state=closed", headers=headers ).json() comments = requests.get( - f"{GITHUB_API_URL}/repos/{owner}/{repo}/issues/comments" + f"{GITHUB_API_URL}/repos/{owner}/{repo}/issues/comments", headers=headers ).json() return prs, issues, comments @@ -42,17 +50,18 @@ def format_data(prs, issues, comments): max_name_length = max(len(user) for user in user_data.keys()) max_prs_length = max(len(str(counts["prs"])) for counts in user_data.values()) max_issues_length = max(len(str(counts["issues"])) for counts in user_data.values()) - max_comments_length = max( - len(str(counts["comments"])) for counts in user_data.values() - ) + max_comments_length = max(len(str(counts["comments"])) for counts in user_data.values()) table = [ f"| {'User':<{max_name_length}} | PRs Merged | Issues Resolved | Comments |", - f"|{'-' * (max_name_length + 2)}|:{'-' * (max_prs_length + 2)}:|:{'-' * (max_issues_length + 2)}:|:{'-' * (max_comments_length + 2)}:|", + f"|{'-' * (max_name_length + 2)}|:{'-' * (max_prs_length + 2)}:|" + f":{'-' * (max_issues_length + 2)}:|:{'-' * (max_comments_length + 2)}:|", ] for user, counts in user_data.items(): table.append( - f"| {user:<{max_name_length}} | {counts['prs']:>{max_prs_length}} | {counts['issues']:>{max_issues_length}} | {counts['comments']:>{max_comments_length}} |" + f"| {user:<{max_name_length}} | {counts['prs']:>{max_prs_length}} | " + f"{counts['issues']:>{max_issues_length}} | " + f"{counts['comments']:>{max_comments_length}} |" ) return "\n".join(table)