Skip to content

Commit

Permalink
add function for adding assignees to issues
Browse files Browse the repository at this point in the history
  • Loading branch information
KPostOffice committed May 25, 2021
1 parent 49053ef commit a838229
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ogr/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,14 @@ def add_label(self, *labels: str) -> None:
"""
raise NotImplementedError()

def add_assignee(self, *assignees: str) -> None:
"""
Assign users to an issue.
:param assignees: [str]
"""
raise NotImplementedError()


class PRStatus(IntEnum):
open = 1
Expand Down
3 changes: 3 additions & 0 deletions ogr/services/github/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,6 @@ def close(self) -> "Issue":
def add_label(self, *labels: str) -> None:
for label in labels:
self._raw_issue.add_to_labels(label)

def add_assignee(self, *assignees: str) -> None:
self._raw_issue.add_to_assignees(*assignees)
10 changes: 10 additions & 0 deletions ogr/services/gitlab/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,13 @@ def add_label(self, *labels: str) -> None:
for label in labels:
self._raw_issue.labels.append(label)
self._raw_issue.save()

def add_assignee(self, *assignees: str) -> None:
for assignee in assignees:
users = self.project.service.gitlab_instance.users.list( # type: ignore
username=assignee
)
if not users:
raise GitlabAPIException(f"Unable to find '{assignee}' username")
self._raw_issue.assignees.append(str(users[0].id))
self._raw_issue.save()
8 changes: 8 additions & 0 deletions ogr/services/pagure/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,11 @@ def close(self) -> "PagureIssue":
)
self.__dirty = True
return self

def add_assignee(self, *assignees: str) -> None:
if len(assignees) > 1:
raise PagureAPIException("Pagure does not support multiple assignees")
payload = {"assignee": assignees[0]}
self.project._call_project_api(
"issue", str(self.id), "assignee", data=payload, method="POST"
)
15 changes: 15 additions & 0 deletions tests/integration/github/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,21 @@ def test_issue_labels(self):
assert labels[0].name == "test_lb1"
assert labels[1].name == "test_lb2"

def test_issue_assignees(self):
"""
Remove the assignees from this issue before regenerating the response files:
https://github.com/packit/ogr/issues/4
"""

issue = self.ogr_project.get_issue(4)
assignees = issue.assignees

assert not assignees
issue.add_assignee("lachmanfrantisek")
assignees = self.ogr_project.get_issue(4).assignees
assert len(assignees) == 1
assert assignees[0].login == "lachmanfrantisek"

def test_list_contains_only_issues(self):
issue_list_all = self.ogr_project.get_issue_list(status=IssueStatus.all)
issue_ids = [issue.id for issue in issue_list_all]
Expand Down
15 changes: 15 additions & 0 deletions tests/integration/gitlab/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,21 @@ def test_issue_labels(self):
assert labels[0] == "test_lb1"
assert labels[1] == "test_lb2"

def test_issue_assignees(self):
"""
Remove the assignees from this issue before regenerating the response files:
https://github.com/packit-service/ogr-tests/issues/1
"""

issue = self.project.get_issue(1)
assignees = issue.assignees

assert not assignees
issue.add_assignee("lachmanfrantisek")
assignees = self.project.get_issue(1).assignees
assert len(assignees) == 1
assert assignees[0]["username"] == "lachmanfrantisek"

def test_issue_list_labels(self):
issue_list = self.project.get_issue_list(
status=IssueStatus.all, labels=["testing-label-for-test-issue-list-labels"]
Expand Down
16 changes: 16 additions & 0 deletions tests/integration/pagure/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@ def test_create_issue_with_assignees(self):
assert issue.description == random_str
assert issue.assignee == assignee[0]

def test_issue_assignees(self):
"""
Remove the assignees from this issue before regenerating the response files:
https://pagure.io/testing/hello-112111/issue/4
"""

project = self.service.get_project(repo="hello-112111", namespace="testing")
issue = project.get_issue(4)

assignee = issue.assignee

assert not assignee
issue.add_assignee("lachmanfrantisek")
assignee = project.get_issue(4).assignee
assert assignee == "lachmanfrantisek"

def test_issue_without_label(self):
title = "This is an issue"
description = "Example of Issue description"
Expand Down

0 comments on commit a838229

Please sign in to comment.