Commit fff0d568 authored by Vamshi Krishna's avatar Vamshi Krishna

Repository: Filter issues by label, assignee

parent c0253111
Pipeline #26252756 passed with stages
in 36 seconds
......@@ -399,13 +399,22 @@ class GitHubRepository(GitHubMixin, Repository):
"""
return self.filter_merge_requests(state='opened')
def filter_issues(self, state: str='opened') -> set:
def filter_issues(self, state: str='opened',
label: Optional[str]=None,
assignee: Optional[str]=None
) -> set:
"""
Filters the issues from the repository based on properties.
:param state: 'opened' or 'closed' or 'all'.
:param label: Label of the issue
:param assignee: username of issue assignee
"""
params = {'state': GH_ISSUE_STATE_TRANSLATION[state]}
if label:
params['labels'] = label
if assignee:
params['assignee'] = assignee
return {GitHubIssue.from_data(res, self._token,
self.full_name, res['number'])
for res in get(self._token, self.url + '/issues', params)
......
......@@ -14,6 +14,7 @@ from IGitt.GitLab import GitLabMixin
from IGitt.GitLab import GitLabOAuthToken, GitLabPrivateToken
from IGitt.GitLab.GitLabIssue import GitLabIssue
from IGitt.GitLab.GitLabOrganization import GitLabOrganization
from IGitt.GitLab.GitLabUser import GitLabUser
from IGitt.Interfaces import delete, get, post
from IGitt.Interfaces import BasicAuthorizationToken
from IGitt.Interfaces import AccessLevel
......@@ -418,17 +419,28 @@ class GitLabRepository(GitLabMixin, Repository):
"""
return self.filter_merge_requests(state='opened')
def filter_issues(self, state: str='opened') -> set:
def filter_issues(self, state: str='opened',
label: Optional[str]=None,
assignee: Optional[str]=None
) -> set:
"""
Filters the issues from the repository based on properties.
:param state: 'opened' or 'closed' or 'all'.
"""
:param label: Label of the issue.
:param assignee: username of issue assignee.
"""
params = {'state': state}
if label:
params['labels'] = label
if assignee:
params['assignee_id'] = GitLabUser(self._token,
assignee).identifier
return {GitLabIssue.from_data(res, self._token,
self.full_name, res['iid'])
for res in get(self._token,
self.url + '/issues',
{'state': state})}
params)}
@property
def issues(self) -> set:
......
......@@ -250,11 +250,17 @@ class Repository(IGittObject):
"""
raise NotImplementedError
def filter_issues(self, state: str='opened') -> set:
def filter_issues(self,
state: str='opened',
label: Optional[str]=None,
assignee: Optional[str]=None
) -> set:
"""
Filters the issues from the repository based on properties.
:param state: 'opened' or 'closed' or 'all'.
:param label: Label of the issue
:param assignee: username of issue assignee
"""
raise NotImplementedError
......
......@@ -79,6 +79,14 @@ class GitHubRepositoryTest(IGittTestCase):
def test_get_mr(self):
self.assertEqual(self.repo.get_mr(11).title, 'testpr closing/opening')
def test_filter_issues(self):
self.assertEqual(len(self.repo.filter_issues(state='opened')), 97)
self.assertEqual(len(self.repo.filter_issues(state='closed')), 17)
self.assertEqual(len(self.repo.filter_issues(label='a')), 1)
self.assertEqual(
len(self.repo.filter_issues(assignee='gitmate-test-user')), 0
)
def test_issues(self):
self.assertEqual(len(self.repo.issues), 89)
......
......@@ -97,6 +97,15 @@ class GitLabRepositoryTest(IGittTestCase):
def test_merge_requests(self):
self.assertEqual(len(self.repo.merge_requests), 13)
def test_filter_issues(self):
self.assertEqual(len(self.repo.filter_issues(state='all')), 22)
self.assertEqual(len(self.repo.filter_issues(state='opened')), 20)
self.assertEqual(len(self.repo.filter_issues(state='closed')), 2)
self.assertEqual(len(self.repo.filter_issues(label='dem')), 2)
self.assertEqual(
len(self.repo.filter_issues(assignee='gitmate-test-user')), 3
)
def test_issues(self):
self.assertEqual(len(self.repo.issues), 14)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment