Completed
Push — refactor-and-polish ( 03473b...062128 )
by Michael
09:35
created

PullRequest.label_names()   A

Complexity

Conditions 2

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
1
from enum import Enum
2
3
import attr
4
5
6
def changes_to_release_type(repository):
7
    pull_requests = repository.pull_requests_since_latest_version
8
9
    labels = set([
10
        label_name
11
        for pull_request in pull_requests
12
        for label_name in pull_request.label_names
13
    ])
14
15
    descriptions = [
16
        '\n'.join([
17
            pull_request.title, pull_request.description
18
        ])
19
        for pull_request in pull_requests
20
    ]
21
22
    return determine_release(
23
        repository.latest_version,
24
        descriptions,
25
        labels
26
    )
27
28
29
def determine_release(latest_version, descriptions, labels):
30
    if 'BREAKING CHANGE' in descriptions:
31
        return 'major', ReleaseType.BREAKING_CHANGE, latest_version.next_major()
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (80/79).

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

Loading history...
32
    elif 'enhancement' in labels:
33
        return 'minor', ReleaseType.FEATURE, latest_version.next_minor()
34
    elif 'bug' in labels:
35
        return 'patch', ReleaseType.FIX, latest_version.next_patch()
36
    else:
37
        return None, ReleaseType.NO_CHANGE, latest_version
38
39
40
class ReleaseType(str, Enum):
41
    NO_CHANGE = 'no-changes'
42
    BREAKING_CHANGE = 'breaking'
43
    FEATURE = 'feature'
44
    FIX = 'fix'
45
46
47
@attr.s
48
class Release(object):
49
50
    release_date = attr.ib()
51
    version = attr.ib()
52
    description = attr.ib(default=attr.Factory(str))
53
    name = attr.ib(default=attr.Factory(str))
54
    changes = attr.ib(default=attr.Factory(dict))
55
56
    @property
57
    def title(self):
58
        return '{version} ({release_date})'.format(
59
            version=self.version,
60
            release_date=self.release_date
61
        ) + (' ' + self.name) if self.name else ''
62
63
64
@attr.s
65
class PullRequest(object):
66
    number = attr.ib()
67
    title = attr.ib()
68
    description = attr.ib()
69
    author = attr.ib()
70
    body = attr.ib()
71
    user = attr.ib()
72
    labels = attr.ib(default=attr.Factory(list))
73
74
    @property
75
    def description(self):
76
        return self.body
77
78
    @property
79
    def author(self):
80
        return self.user['login']
81
82
    @property
83
    def label_names(self):
84
        return [
85
            label['name']
86
            for label in self.labels
87
        ]
88
89
    @classmethod
90
    def from_github(cls, api_response):
91
        return cls(**api_response)
92
93
    @classmethod
94
    def from_number(cls, number):
95
        pass
96
97
# def gitx(args):
98
#     if changes.debug:
99
#         print('git {}'.format(args))
100
#     return git(shlex.split(args))
101