Completed
Pull Request — master (#460)
by Manas
02:32
created

ListIssuesAction   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 33
Duplicated Lines 0 %
Metric Value
dl 0
loc 33
rs 10
wmc 8

1 Method

Rating   Name   Duplication   Size   Complexity  
D run() 0 32 8
1
import datetime
2
3
from lib.base import BaseGithubAction
4
from lib.formatters import issue_to_dict
5
6
__all__ = [
7
    'ListIssuesAction'
8
]
9
10
11
class ListIssuesAction(BaseGithubAction):
12
    def run(self, user, repo, filter=None, state=None, sort=None,
13
            direction=None, since=None, limit=20):
14
        user = self._client.get_user(user)
15
        repo = user.get_repo(repo)
16
17
        kwargs = {}
18
        if filter:
19
            kwargs['filter'] = filter
20
        if state:
21
            kwargs['state'] = state
22
        if sort:
23
            kwargs['sort'] = sort
24
        if direction:
25
            kwargs['direction'] = direction
26
        if since:
27
            kwargs['since'] = datetime.datetime.fromtimestamp(since)
28
29
        # Note: PyGithub library introduces an abstraction for paginated lists
30
        # which doesn't conform to Python's iterator spec so we can't use
31
        # array slicing to exhaust the list :/
32
        issues = repo.get_issues(**kwargs)
33
        issues = list(issues)
34
35
        result = []
36
        for index, issue in enumerate(issues):
37
            issue = issue_to_dict(issue=issue)
38
            result.append(issue)
39
40
            if (index + 1) >= limit:
41
                break
42
43
        return result
44