1
|
3 |
|
from changes.commands import info, note, highlight |
|
|
|
|
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) |
|
|
|
|
69
|
3 |
|
info('Computed release type {} from changes issue tags'.format(release_type)) |
|
|
|
|
70
|
3 |
|
info('Proposed version bump {} => {}'.format( |
71
|
|
|
repository.latest_version, proposed_version |
72
|
|
|
)) |
73
|
|
|
|
Cyclic imports may cause partly loaded modules to be returned. This might lead to unexpected runtime behavior which is hard to debug.