Skip to content

Commit

Permalink
Create Thoth schema updated command (AICoE#185)
Browse files Browse the repository at this point in the history
* Add missing known commands

* Create Thoth schema updated command

Co-authored-by: Harshad Reddy Nalla <hnalla@redhat.com>
  • Loading branch information
fridex and harshad16 committed Jun 3, 2022
1 parent 653be97 commit 433951f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
48 changes: 47 additions & 1 deletion aicoe/sesheta/actions/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,27 @@
"xtuchyna",
]

_THOTH_STORAGE_REPOS = [
"adviser",
"cve-update-job",
"graph-backup-job",
"graph-metrics-exporter",
"graph-refresh-job",
"graph-sync-job",
"init-job",
"investigator",
"management-api",
"metrics-exporter",
"package-releases-job",
"package-update-job",
"prescriptions-refresh-job",
"pulp-pypi-sync-job",
"revsolver",
"slo-reporter",
"user-api",
"workflow-helpers",
]

CHATBOT = ChatBot("Sesheta", read_only=True)
_TRAINER = ChatterBotCorpusTrainer(CHATBOT)
_TRAINER.train("chatterbot.corpus.english")
Expand All @@ -76,6 +97,22 @@ async def make_release_issue(request: dict):
return f"Creating the issue failed. \n Log - {resp_text}"


async def make_kebechet_update_issue(repo_name: str) -> str:
web_url = f"https://api.github.com/repos/thoth-station/{repo_name}/issues"
json_payload = {"title": "Kebechet update", "assignees": ["sesheta"], "labels": ["bot"]}
async with aiohttp.ClientSession() as session:
async with session.post(
web_url, headers={f"Authorization": f"token {_GITHUB_TOKEN}"}, json=json_payload,
) as resp:
status = resp.status
resp_text = await resp.json()
_LOGGER.debug(status, resp_text)
if resp.status == 201:
issue_link = resp_text.get("html_url")
return f"Kebechet update issue is successfully created for {repo_name} at - <{issue_link}|Link>"
return f"Creating the issue failed. \n Log - {resp_text}"


async def get_intent(text: str,) -> (str, float, dict):
"""Get the Intent of the provided text, and assign it a score."""
repo_name = None
Expand Down Expand Up @@ -108,6 +145,9 @@ async def get_intent(text: str,) -> (str, float, dict):
if text.lower().startswith(("grti", "get random thoth inhabitant")):
return ("grti", 1.0, {})

if text.lower().startswith("schema updated"):
return ("tsu", 1.0, {})

return (None, 0.0, {})


Expand Down Expand Up @@ -160,7 +200,13 @@ async def process_user_text(thread_id: str, text: str) -> str:
return " 🔗 ".join(inhabitants)

if intent[0] == "grti":
return f"⭐ In this Universe, based on relative position of planets and all the galaxies I picked {hangouts_userid(random.choice(_THOTH_INHABITANTS))} ⭐"
return f"⭐ In this Universe, based on relative position of planets and all the galaxies I picked {hangouts_userid(random.choice(_THOTH_INHABITANTS))} ⭐"

if intent[0] == "tsu":
text = ""
for repo_name in _THOTH_STORAGE_REPOS:
text += f"{make_kebechet_update_issue(repo_name)}\n"
return text

chatterbox_response = CHATBOT.get_response(text[len("@sesheta ") :])
return str(chatterbox_response)
2 changes: 2 additions & 0 deletions aicoe/sesheta/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@
- Get one Thoth inhabitant, randomly
- `get random thoth inhabitant` to randomly pick one Thoth inhabitant
- `grti` is the abbreviated form
- Trigger Kebechet updates for all the Thoth repositories that depend on thoth-storages
- `schema updated` to open "Kebechet update" on all the repositories that use thoth-storages
"""

0 comments on commit 433951f

Please sign in to comment.