Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configurable pagure issue aliases #14

Merged
merged 1 commit into from
Oct 12, 2023
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
4 changes: 4 additions & 0 deletions base-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
fasjson_url: https://fasjson.fedoraproject.org
pagureio_url: https://pagure.io
pagureio_issue_aliases:
fpc: "packaging-committee"
epel: "epel"
fesco: "fesco"
paguredistgit_url: https://src.fedoraproject.org
bodhi_url: https://bodhi.fedoraproject.org
controlroom: ''
1 change: 1 addition & 0 deletions fedora/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Config(BaseProxyConfig):
def do_update(self, helper: ConfigUpdateHelper) -> None:
helper.copy("fasjson_url")
helper.copy("pagureio_url")
helper.copy("pagureio_issue_aliases")
helper.copy("paguredistgit_url")
helper.copy("bodhi_url")
helper.copy("controlroom")
50 changes: 6 additions & 44 deletions fedora/pagureio.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,47 +37,9 @@ async def pagureissue(self, evt: MessageEvent, project: str, issue_id: str) -> N
"""
await self._get_pagure_issue(evt, project, issue_id)

# these were done in supybot / limnoria with the alias plugin. need to find a better way to
# do this so they can be defined, but for now, lets just define the commands here.
@command.new(help="Get a Summary of a ticket from the packaging-committee ticket tracker")
@command.argument("issue_id", required=True)
async def fpc(self, evt: MessageEvent, issue_id: str) -> None:
"""
Show a summary of an issue in the `packaging-committee` pagure.io project

#### Arguments ####

* `issue_id`: the issue number

"""
await self._get_pagure_issue(evt, "packaging-committee", issue_id)

# these were done in supybot / limnoria with the alias plugin. need to find a better way to
# do this so they can be defined, but for now, lets just define the commands here.
@command.new(help="Get a Summary of a ticket from the epel ticket tracker")
@command.argument("issue_id", required=True)
async def epel(self, evt: MessageEvent, issue_id: str) -> None:
"""
Show a summary of an issue in the `epel` pagure.io project

#### Arguments ####

* `issue_id`: the issue number

"""
await self._get_pagure_issue(evt, "epel", issue_id)

# these were done in supybot / limnoria with the alias plugin. need to find a better way to
# do this so they can be defined, but for now, lets just define the commands here.
@command.new(help="Get a Summary of a ticket from the fesco ticket tracker")
@command.argument("issue_id", required=True)
async def fesco(self, evt: MessageEvent, issue_id: str) -> None:
"""
Show a summary of an issue in the `fesco` pagure.io project

#### Arguments ####

* `issue_id`: the issue number

"""
await self._get_pagure_issue(evt, "fesco", issue_id)
@command.passive(r"^!(\S+)(?:\s+|$)(.*)")
async def aliases(self, evt: MessageEvent, match) -> None:
msg, cmd, arguments = match
defined_aliases = self.plugin.config.get("pagureio_issue_aliases", {})
if cmd in defined_aliases:
await self._get_pagure_issue(evt, defined_aliases[cmd], arguments)
4 changes: 0 additions & 4 deletions tests/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ async def test_help(bot, plugin):
expected = (
"● `!help [commandname]` - list commands\n"
"● `!version ` - return information about this bot\n"
"● `!epel <issue_id>` - Get a Summary of a ticket from the epel ticket tracker\n"
"● `!fesco <issue_id>` - Get a Summary of a ticket from the fesco ticket tracker\n"
"● `!fpc <issue_id>` - Get a Summary of a ticket from the packaging-committee "
"ticket tracker\n"
ryanlerch marked this conversation as resolved.
Show resolved Hide resolved
"● `!pagureissue <project> <issue_id>` - return a pagure issue\n"
"● `!whoowns <package>` - Retrieve the owner of a given package\n"
"● `!group <subcommand> [...]` - Query information about Fedora Accounts groups\n"
Expand Down
28 changes: 28 additions & 0 deletions tests/test_pagure.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from unittest import mock

import httpx
import pytest

import fedora


@pytest.mark.parametrize(
"command,project",
Expand Down Expand Up @@ -32,6 +36,30 @@ async def test_pagureissue(bot, plugin, respx_mock, command, project):
assert bot.sent[0].content.formatted_body == expected_html


@pytest.mark.parametrize(
"command,result",
[
("!fpc", ["packaging-committee", ""]),
("!fpc 1234", ["packaging-committee", "1234"]),
("!fpcd 1234", []),
("a!fpcd 1234", []),
("!fpc 1234 1234", ["packaging-committee", "1234 1234"]),
],
)
async def test_pagureissue_regex(bot, plugin, monkeypatch, command, result):
mocked_get_pagure_issue = mock.AsyncMock()
monkeypatch.setattr(
fedora.pagureio.PagureIOHandler, "_get_pagure_issue", mocked_get_pagure_issue
)
await bot.send(command)
if result == []:
mocked_get_pagure_issue.assert_not_called()
else:
mocked_get_pagure_issue.assert_called_once()
assert mocked_get_pagure_issue.call_args[0][1] == result[0]
assert mocked_get_pagure_issue.call_args[0][2] == result[1]


async def test_whoowns(bot, plugin, respx_mock):
respx_mock.get("http://src.example.com/api/0/rpms/dummy-package").mock(
return_value=httpx.Response(
Expand Down