Completed
Push — init-test ( 3e12e7 )
by Michael
07:46 queued 07:14
created

PullRequest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 15
ccs 12
cts 12
cp 1
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A __init__() 0 9 2
1 3
import re
2 3
import shlex
3
4 3
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...
5 3
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...
6 3
import requests
7 3
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...
8 3
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...
9
10 3
MERGED_PULL_REQUEST = re.compile(
11
    r'^([0-9a-f]{5,40}) Merge pull request #(\w+)'
12
)
13
14 3
PULL_REQUEST_API = 'https://api.github.com/repos{/owner}{/repo}/pulls{/number}'
15
16
17 3
class PullRequest:
18 3
    title = None
19 3
    description = None
20 3
    author = None
21 3
    labels = []
22
23 3
    def __init__(self, pr_number, committish, **kwargs):
24 3
        self.number = pr_number
25 3
        self.committish = committish
26 3
        self.title = kwargs['title']
27 3
        self.description = kwargs['body']
28 3
        self.author = kwargs['user']['login']
29 3
        self.labels = [
30
            label['name']
31
            for label in kwargs['labels']
32
        ]
33
34
35 3
class GitRepository:
36 3
    auth_token = None
37
38 3
    def __init__(self, url=None):
39 3
        self.parsed_repo = url or giturlparse.parse(
40
            git(shlex.split('config --get remote.origin.url'))
41
        )
42 3
        self.commit_history = git(shlex.split(
43
            'log --oneline --merges --no-color'
44
        )).split('\n')
45
46 3
        self.tags = git(shlex.split('tag --list')).split('\n')
47
48 3
        self.versions = sorted([
49
            semantic_version.Version(tag)
50
            for tag in self.tags
51
            if tag
52
        ])
53
54 3
    @property
55
    def latest_version(self):
56 3
        return self.versions[-1] if self.versions else semantic_version.Version('0.0.0')
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (88/79).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
57
58 3
    def get_pull_request(self, pr_num):
59 3
        return requests.get(
60
            uritemplate.expand(
61
                PULL_REQUEST_API,
62
                dict(
63
                    owner=self.owner,
64
                    repo=self.repo,
65
                    number=pr_num
66
                ),
67
            ),
68
            headers={
69
                'Authorization': 'token {}'.format(self.auth_token)
70
            },
71
        ).json()
72
73 3
    @property
74
    def pull_requests(self):
75 3
        pull_requests = []
76
77 3
        for index, commit_msg in enumerate(self.commit_history):
78 3
            matches = MERGED_PULL_REQUEST.findall(commit_msg)
79 3
            if matches:
80 3
                committish, pr_number = matches[0]
81
82 3
                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...
83
84 3
                pull_requests.append(
85
                    PullRequest(
86
                        pr_number,
87
                        committish,
88
                        **pr
89
                    )
90
                )
91
92 3
        return pull_requests
93
94 3
    @property
95
    def repo(self):
96 3
        return self.parsed_repo.repo
97
98 3
    @property
99
    def owner(self):
100 3
        return self.parsed_repo.owner
101
102 3
    @property
103
    def github(self):
104 3
        return self.parsed_repo.github
105
106 3
    @property
107
    def bitbucket(self):
108
        return self.parsed_repo.bitbucket
109