Skip to content
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
24 changes: 23 additions & 1 deletion commanderbot/ext/jira/jira_client.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import re
from datetime import datetime

import aiohttp

from commanderbot.ext.jira.jira_issue import JiraIssue, StatusColor
from commanderbot.lib.responsive_exception import ResponsiveException

ISSUE_ID_PATTERN = re.compile(r"\w+-\d+")


class JiraException(ResponsiveException):
pass
Expand All @@ -16,6 +19,17 @@ def __init__(self, issue_id: str):
super().__init__(f"`{self.issue_id}` does not exist or it may be private")


class IssueHasNoFields(JiraException):
def __init__(self, issue_id: str):
self.issue_id = issue_id
super().__init__(f"`{self.issue_id}` does not have any fields")


class InvalidIssueFormat(JiraException):
def __init__(self):
super().__init__("Jira issues must use the `<project>-<id>` format")


class ConnectionError(JiraException):
def __init__(self, url: str):
self.url = url
Expand Down Expand Up @@ -49,9 +63,17 @@ async def _request_issue_data(self, issue_id: str) -> dict:
raise RequestError(issue_id)

async def get_issue(self, issue_id: str) -> JiraIssue:
# Check if issue ID is using the correct format
if not ISSUE_ID_PATTERN.match(issue_id):
raise InvalidIssueFormat

# Request issue data and get its fields
data: dict = await self._request_issue_data(issue_id)
fields: dict = data["fields"]
fields: dict = data.get("fields", {})
if not fields:
raise IssueHasNoFields(issue_id)

# Extract data from fields and construct an issue
assignee: str = "Unassigned"
if user := fields.get("assignee"):
assignee = user["displayName"]
Expand Down
2 changes: 1 addition & 1 deletion commanderbot/ext/jira/jira_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, bot: Bot, **options):

# Create the Jira client
self.jira_client: JiraClient = JiraClient(url)

@command(name="jira", aliases=["bug"])
async def cmd_jira(self, ctx: Context, issue_id: str):
# Extract the issue ID if the command was given a URL. Issue IDs given
Expand Down