1
|
|
|
from changes.commands import info, note, highlight |
|
|
|
|
2
|
|
|
from changes.commands.init import init |
3
|
|
|
|
4
|
|
|
|
5
|
|
|
class Release: |
6
|
|
|
BREAKING_CHANGE = 1 |
7
|
|
|
FEATURE = 2 |
8
|
|
|
FIX = 3 |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
def changes_to_release_type(repository): |
12
|
|
|
pull_request_labels = set() |
13
|
|
|
changes = repository.changes_since_last_version |
14
|
|
|
|
15
|
|
|
for change in changes: |
16
|
|
|
for label in change.labels: |
17
|
|
|
pull_request_labels.add(label) |
18
|
|
|
|
19
|
|
|
change_descriptions = [ |
20
|
|
|
'\n'.join([change.title, change.description]) for change in changes |
21
|
|
|
] |
22
|
|
|
|
23
|
|
|
current_version = repository.latest_version |
24
|
|
|
if 'BREAKING CHANGE' in change_descriptions: |
25
|
|
|
return Release.BREAKING_CHANGE, current_version.next_major() |
26
|
|
|
elif 'enhancement' in pull_request_labels: |
27
|
|
|
return Release.BREAKING_CHANGE, current_version.next_minor() |
28
|
|
|
elif 'bug' in pull_request_labels: |
29
|
|
|
return Release.BREAKING_CHANGE, current_version.next_patch() |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
def status(): |
33
|
|
|
repository = init() |
34
|
|
|
|
35
|
|
|
info( |
36
|
|
|
'Repository: ' + |
37
|
|
|
highlight( |
38
|
|
|
'{}/{}'.format(repository.owner, repository.repo), |
39
|
|
|
) |
40
|
|
|
) |
41
|
|
|
|
42
|
|
|
info('Latest Version') |
43
|
|
|
note(repository.latest_version) |
44
|
|
|
|
45
|
|
|
info('Changes') |
46
|
|
|
note('{} changes found since {}'.format( |
47
|
|
|
len(repository.changes_since_last_version), |
48
|
|
|
repository.latest_version, |
49
|
|
|
)) |
50
|
|
|
|
51
|
|
|
for pull_request in repository.changes_since_last_version: |
52
|
|
|
note('#{} {} by @{}{}'.format( |
53
|
|
|
pull_request.number, |
54
|
|
|
pull_request.title, |
55
|
|
|
pull_request.author, |
56
|
|
|
' [{}] '.format( |
57
|
|
|
','.join(pull_request.labels) |
58
|
|
|
) if pull_request.labels else '', |
59
|
|
|
)) |
60
|
|
|
|
61
|
|
|
release_type, proposed_version = changes_to_release_type(repository) |
62
|
|
|
info('Computed release type {} from changes issue tags'.format(release_type)) |
|
|
|
|
63
|
|
|
info('Proposed version bump {} => {}'.format( |
64
|
|
|
repository.latest_version, proposed_version |
65
|
|
|
)) |
66
|
|
|
|
Cyclic imports may cause partly loaded modules to be returned. This might lead to unexpected runtime behavior which is hard to debug.