Skip to content

Commit

Permalink
Merge branch 'OWASP-BLT:main' into adding_slash_commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarthak5598 authored Jun 16, 2024
2 parents acd24bc + f495912 commit 3e6f5e2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 28 deletions.
29 changes: 10 additions & 19 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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

Expand Down
17 changes: 16 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 17 additions & 8 deletions src/sammich/plugins/contributors.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3e6f5e2

Please sign in to comment.