Skip to content

Commit

Permalink
manage tags
Browse files Browse the repository at this point in the history
  • Loading branch information
honzajavorek committed Apr 16, 2024
1 parent 6f09ca8 commit 4a05d5d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
19 changes: 12 additions & 7 deletions jg/chick/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
find_github_url,
find_linkedin_url,
format_summary,
prepare_tags,
)
from jg.chick.lib.threads import (
add_members_with_role,
Expand Down Expand Up @@ -204,12 +205,13 @@ async def handle_review_thread(
f"<:github:842685206095724554> Zavětřilo jsem GitHub profil {github_url}, jdu se v tom pohrabat…",
suppress=True,
)
logger.debug(f"{'Using' if GITHUB_API_KEY else 'Not using'} GitHub API key")
summary = await check_profile_url(github_url, github_api_key=GITHUB_API_KEY)
logger.info(f"Done reviewing {github_url}: {summary.status}")
for message in format_summary(summary):
await thread.send(**message)
await thread.send("✨ Hotovo!")
async with thread.typing():
logger.debug(f"{'Using' if GITHUB_API_KEY else 'Not using'} GitHub API key")
summary = await check_profile_url(github_url, github_api_key=GITHUB_API_KEY)
logger.info(f"Done reviewing {github_url}: {summary.status}")
for message in format_summary(summary):
await thread.send(**message)
await thread.send("✨ Hotovo!")

if linkedin_url := find_linkedin_url(starting_message.content):
logger.info(f"Found {linkedin_url} in {thread.name!r}, reviewing…")
Expand All @@ -222,7 +224,10 @@ async def handle_review_thread(
suppress=True,
)

if not (github_url or linkedin_url):
tags = prepare_tags(thread, github=bool(github_url), linkedin=bool(linkedin_url))
await thread.edit(applied_tags=tags)

if not github_url and not linkedin_url:
await starting_message.reply(
"Nenašlo jsem žádný GitHub ani LinkedIn profil. "
"Pokud nějaký máš a chceš jej zkontrolovat, přidej sem zprávu, "
Expand Down
21 changes: 19 additions & 2 deletions jg/chick/lib/reviews.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import os
import re
from typing import Any, Generator
from typing import Any, Generator, TypedDict
from urllib.parse import quote, unquote

from discord import Color, Embed
from discord import Color, Embed, ForumTag, Thread
from jg.hen.core import ResultType, Summary


Expand Down Expand Up @@ -39,6 +39,23 @@ def find_linkedin_url(text: str) -> str | None:
return ""


def prepare_tags(
thread: Thread,
cv: bool = False,
github: bool = False,
linkedin: bool = False,
) -> list[ForumTag]:
available_tags = {tag.name: tag for tag in thread.parent.available_tags}
applied_tags = set(thread.applied_tags)
if cv:
applied_tags.add(available_tags.pop("zpětná vazba na CV"))
if github:
applied_tags.add(available_tags.pop("zpětná vazba na GH"))
if linkedin:
applied_tags.add(available_tags.pop("zpětná vazba na LI"))
return list(applied_tags)


def format_summary(summary: Summary) -> Generator[dict[str, Any], None, None]:
if summary.status == "error":
yield dict(
Expand Down

0 comments on commit 4a05d5d

Please sign in to comment.