Completed
Push — fix-ci-failures ( 4b308a...3c0b05 )
by Michael
02:37
created

status()   B

Complexity

Conditions 4

Size

Total Lines 35

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 4

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 4
c 4
b 0
f 0
dl 0
loc 35
ccs 14
cts 14
cp 1
crap 4
rs 8.5806
1 3
from changes.commands import info, note, highlight
0 ignored issues
show
Bug introduced by
There seems to be a cyclic import (changes -> changes.cli).

Cyclic imports may cause partly loaded modules to be returned. This might lead to unexpected runtime behavior which is hard to debug.

Loading history...
2 3
from changes.commands.init import init
3
4
5 3
class Release:
6 3
    NO_CHANGE = 'nochanges'
7 3
    BREAKING_CHANGE = 'breaking'
8 3
    FEATURE = 'feature'
9 3
    FIX = 'fix'
10
11
12 3
def changes_to_release_type(repository):
13 3
    pull_request_labels = set()
14 3
    changes = repository.changes_since_last_version
15
16 3
    for change in changes:
17 3
        for label in change.labels:
18 3
            pull_request_labels.add(label)
19
20 3
    change_descriptions = [
21
        '\n'.join([change.title, change.description]) for change in changes
22
    ]
23
24 3
    current_version = repository.latest_version
25 3
    if 'BREAKING CHANGE' in change_descriptions:
26
        return Release.BREAKING_CHANGE, current_version.next_major()
27 3
    elif 'enhancement' in pull_request_labels:
28
        return Release.FEATURE, current_version.next_minor()
29 3
    elif 'bug' in pull_request_labels:
30 3
        return Release.FIX, current_version.next_patch()
31
    else:
32
        return Release.NO_CHANGE, current_version
33
34
    return None
35
36
37 3
def status():
38 3
    repository = init()
39
40 3
    info(
41
        'Repository: ' +
42
        highlight(
43
            '{}/{}'.format(repository.owner, repository.repo),
44
        )
45
    )
46
47 3
    info('Latest Version')
48 3
    note(repository.latest_version)
49
50 3
    info('Changes')
51 3
    unreleased_changes = repository.changes_since_last_version
52 3
    note('{} changes found since {}'.format(
53
        len(unreleased_changes),
54
        repository.latest_version,
55
    ))
56
57 3
    for pull_request in unreleased_changes:
58 3
        note('#{} {} by @{}{}'.format(
59
            pull_request.number,
60
            pull_request.title,
61
            pull_request.author,
62
            ' [{}]'.format(
63
                ','.join(pull_request.labels)
64
            ) if pull_request.labels else '',
65
        ))
66
67 3
    if unreleased_changes:
68 3
        release_type, proposed_version = changes_to_release_type(repository)
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are trying to unpack a non-sequence, which was defined at line 34.
Loading history...
69 3
        info('Computed release type {} from changes issue tags'.format(release_type))
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (85/79).

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

Loading history...
70 3
        info('Proposed version bump {} => {}'.format(
71
            repository.latest_version, proposed_version
72
        ))
73