-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy path__init__.py
More file actions
88 lines (66 loc) · 2.55 KB
/
__init__.py
File metadata and controls
88 lines (66 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
"""Generates a github changelog, tags and uploads your python library"""
from datetime import date
from pathlib import Path
from changes.config import Changes, Project
from changes.models import Release, ReleaseType
from changes.models.repository import GitHubRepository
__version__ = '0.7.0'
__url__ = 'https://github.com/michaeljoseph/changes'
__author__ = 'Michael Joseph'
__email__ = '[email protected]'
settings = None
project_settings = None
def initialise():
"""
Detects, prompts and initialises the project.
Stores project and tool configuration in the `changes` module.
"""
global settings, project_settings
# Global changes settings
settings = Changes.load()
# Project specific settings
project_settings = Project.load(GitHubRepository(auth_token=settings.auth_token))
def release_from_pull_requests():
global project_settings
repository = project_settings.repository
pull_requests = repository.pull_requests_since_latest_version
labels = set(
[
label_name
for pull_request in pull_requests
for label_name in pull_request.label_names
]
)
descriptions = [
'\n'.join([pull_request.title, pull_request.description])
for pull_request in pull_requests
]
bumpversion_part, release_type, proposed_version = determine_release(
repository.latest_version, descriptions, labels
)
releases_directory = Path(project_settings.releases_directory)
if not releases_directory.exists():
releases_directory.mkdir(parents=True)
release = Release(
release_date=date.today().isoformat(),
version=str(proposed_version),
bumpversion_part=bumpversion_part,
release_type=release_type,
)
release_files = [release_file for release_file in releases_directory.glob('*.md')]
if release_files:
release_file = release_files[0]
release.release_file_path = Path(project_settings.releases_directory).joinpath(
release_file.name
)
release.description = release_file.read_text()
return release
def determine_release(latest_version, descriptions, labels):
if 'BREAKING CHANGE' in descriptions:
return 'major', ReleaseType.BREAKING_CHANGE, latest_version.next_major()
elif 'enhancement' in labels:
return 'minor', ReleaseType.FEATURE, latest_version.next_minor()
elif 'bug' in labels:
return 'patch', ReleaseType.FIX, latest_version.next_patch()
else:
return None, ReleaseType.NO_CHANGE, latest_version