diff --git a/app/core/lib/slash_commands/__init__.py b/app/core/lib/slash_commands/__init__.py index 45a670a7..a4928ba1 100644 --- a/app/core/lib/slash_commands/__init__.py +++ b/app/core/lib/slash_commands/__init__.py @@ -1,10 +1,12 @@ import re from .duration import Duration +from .related_ticket import CommandRelatedTicket class SlashCommands( - Duration + Duration, + CommandRelatedTicket ): """Slash Commands Base Class @@ -13,6 +15,8 @@ class SlashCommands( - Ticket - TicketComment + + Testing of regex can be done at https://pythex.org/ """ @@ -34,4 +38,6 @@ class SlashCommands( markdown = re.sub(self.time_spent, self.command_duration, markdown) + markdown = re.sub(self.related_ticket, self.command_related_ticket, markdown) + return markdown diff --git a/app/core/lib/slash_commands/related_ticket.py b/app/core/lib/slash_commands/related_ticket.py new file mode 100644 index 00000000..97c926bb --- /dev/null +++ b/app/core/lib/slash_commands/related_ticket.py @@ -0,0 +1,98 @@ +import re + + +class CommandRelatedTicket: + # This summary is used for the user documentation + """Add to the current ticket a relationship to another ticket. Supports all ticket +relations: blocked by, blocks and related. +The command keywords are `relate`, `blocks` and `blocked_by` along with the ticket +reference, i.e. `#`. + +Valid commands are as follows: + +- /relate #1 + +- /blocks #1 + +- /blocked_by #1 + +For this command to process the following conditions must be met: + +- There is either a `` (`\\n`) or a `` char immediatly before the slash `/` + +- There is a `` char after the command keyword, i.e. `/relate#1` +""" + + + related_ticket: str = r'[\s|\n]\/(?P[relate|blocks|blocked_by]+)\s\#(?P\d+)[\s|\n]?' + + + def command_related_ticket(self, match) -> str: + """/relate, /blocks and /blocked_by processor + + Slash command usage within a ticket description will add an action comment with the + time spent. For a ticket comment, it's duration field is set to the duration valuee calculated. + + Args: + match (re.Match): Named group matches + + Returns: + str: The matched string if the duration calculation is `0` + None: On successfully processing the command + """ + + a = 'a' + + command = match.group('command') + ticket_id:int = str(match.group('ticket')) + + if ticket_id is not None: + + from core.models.ticket.ticket import RelatedTickets + + if command == 'relate': + + how_related = RelatedTickets.Related.RELATED.value + + elif command == 'blocks': + + how_related = RelatedTickets.Related.BLOCKS.value + + elif command == 'blocked_by': + + how_related = RelatedTickets.Related.BLOCKED_BY.value + + else: + + #ToDo: Add logging that the slash command could not be processed. + + return str(match.string[match.start():match.end()]) + + + if str(self._meta.verbose_name).lower() == 'ticket': + + from_ticket = self + + to_ticket = self.__class__.objects.get(pk = ticket_id) + + elif str(self._meta.verbose_name).lower() == 'comment': + + from_ticket = self.ticket + + to_ticket = self.ticket.__class__.objects.get(pk = ticket_id) + + + RelatedTickets.objects.create( + from_ticket_id = from_ticket, + how_related = how_related, + to_ticket_id = to_ticket, + organization = self.organization + ) + + else: + + #ToDo: Add logging that the slash command could not be processed. + + return str(match.string[match.start():match.end()]) + + return None diff --git a/docs/projects/centurion_erp/user/core/tickets.md b/docs/projects/centurion_erp/user/core/tickets.md index 5046c4da..b6c40e04 100644 --- a/docs/projects/centurion_erp/user/core/tickets.md +++ b/docs/projects/centurion_erp/user/core/tickets.md @@ -47,12 +47,13 @@ Comment types are: Slash commands are a quick action that is specified after a slash command. As the name implies, the command starts with a slash `/`. The following slash commands are available: +- Related `/blocked_by`, `/blocks` and `/relate` + - Time Spent `/spend`, `/spent` ### Time Spent - ::: app.core.lib.slash_commands.Duration options: inherited_members: false @@ -62,6 +63,17 @@ Slash commands are a quick action that is specified after a slash command. As th summary: true +### Related Tickets + +::: app.core.lib.slash_commands.CommandRelatedTicket + options: + inherited_members: false + members: [] + show_bases: false + show_submodules: false + summary: true + + ## Ticket Types ::: app.core.models.ticket.ticket.Ticket.TicketType diff --git a/makefile b/makefile index 31823164..461d7ef0 100644 --- a/makefile +++ b/makefile @@ -24,7 +24,7 @@ prepare: markdown-mkdocs-lint: - PATH=${PATH}:node_modules/.bin markdownlint-cli2 docs/*.md docs/**/*.md docs/**/**/*.md docs/**/**/**/*.md docs/**/**/**/**/**/*.md !CHANGELOG.md !gitlab-ci !website-template || true + PATH=${PATH}:node_modules/.bin markdownlint-cli2 docs/*.md docs/**/*.md docs/**/**/*.md docs/**/**/**/*.md docs/**/**/**/**/**/*.md !docs/pull_request_template.md !CHANGELOG.md !gitlab-ci !website-template || true docs-lint: markdown-mkdocs-lint