Completed
Push — init ( dbeaa1...a47ce7 )
by Michael
06:52
created

GitRepository.get_pull_request()   A

Complexity

Conditions 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
dl 0
loc 12
rs 9.4285
1
import re
2
import shlex
3
4
import uritemplate
0 ignored issues
show
Configuration introduced by
The import uritemplate could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
5
import requests
6
import giturlparse
0 ignored issues
show
Configuration introduced by
The import giturlparse could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
7
from plumbum.cmd import git
0 ignored issues
show
Configuration introduced by
The import plumbum.cmd could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
8
9
MERGED_PULL_REQUEST = re.compile(
10
    r'^([0-9a-f]{5,40}) Merge pull request #(\w+)'
11
)
12
13
PULL_REQUEST_API = 'https://api.github.com/repos{/owner}{/repo}/pulls{/number}'
14
15
16
class PullRequest:
17
    title = None
18
    description = None
19
    author = None
20
    labels = []
21
22
    def __init__(self, pr_number, committish, title, description, author):
23
        self.number = pr_number
24
        self.committish = committish
25
        self.title = title
26
        self.description = description
27
        self.author = author
28
29
30
class GitRepository:
31
    auth_token = None
32
33
    def __init__(self, url=None):
34
        self.parsed_repo = url or giturlparse.parse(
35
            git(shlex.split('config --get remote.origin.url'))
36
        )
37
        self.commit_history = git(shlex.split(
38
            'log --oneline --merges --no-color'
39
        )).split('\n')
40
41
        self.tags = git(shlex.split('tag --list')).split('\n')
42
        print(self.tags)
43
        import semantic_version
0 ignored issues
show
Configuration introduced by
The import semantic_version could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
44
        self.versions = sorted([
45
            semantic_version.Version(tag)
46
            for tag in self.tags
47
            if tag
48
        ])
49
50
    def get_pull_request(self, pr_num):
51
        return requests.get(
52
            uritemplate.expand(
53
                PULL_REQUEST_API,
54
                dict(
55
                    owner=self.owner,
56
                    repo=self.repo,
57
                    number=pr_num
58
                ),
59
            ),
60
            headers={
61
                'Authorization': 'token {}'.format(self.auth_token)
62
            },
63
        ).json()
64
65
    @property
66
    def pull_requests(self):
67
        pull_requests = []
68
69
        for index, commit_msg in enumerate(self.commit_history):
70
            matches = MERGED_PULL_REQUEST.findall(commit_msg)
71
            if matches:
72
                committish, pr_number = matches[0]
73
                title = description = author = None
74
                if self.auth_token:
75
                    pr = self.get_pull_request(pr_number)
0 ignored issues
show
Coding Style Naming introduced by
The name pr does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
76
                    title = pr['title']
77
                    description = pr['body']
78
                    author = pr['user']['login']
79
80
                pull_requests.append(
81
                    PullRequest(
82
                        pr_number,
83
                        committish,
84
                        title,
85
                        description,
86
                        author,
87
                    )
88
                )
89
90
        return pull_requests
91
92
    @property
93
    def repo(self):
94
        return self.parsed_repo.repo
95
96
    @property
97
    def owner(self):
98
        return self.parsed_repo.owner
99
100
    @property
101
    def github(self):
102
        return self.parsed_repo.github
103
104
    @property
105
    def bitbucket(self):
106
        return self.parsed_repo.bitbucket
107