-
Notifications
You must be signed in to change notification settings - Fork 237
/
repo_w_no_tags.py
283 lines (241 loc) · 10.2 KB
/
repo_w_no_tags.py
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
from __future__ import annotations
from copy import deepcopy
from typing import TYPE_CHECKING
import pytest
from git import Repo
from tests.const import EXAMPLE_HVCS_DOMAIN
from tests.util import copy_dir_tree, temporary_working_directory
if TYPE_CHECKING:
from pathlib import Path
from semantic_release.hvcs import HvcsBase
from tests.conftest import TeardownCachedDirFn
from tests.fixtures.example_project import ExProjectDir
from tests.fixtures.git_repo import (
BaseRepoVersionDef,
BuildRepoFn,
CommitConvention,
ExProjectGitRepoFn,
GetRepoDefinitionFn,
GetVersionStringsFn,
RepoDefinition,
SimulateChangeCommitsNReturnChangelogEntryFn,
SimulateDefaultChangelogCreationFn,
TomlSerializableTypes,
VersionStr,
)
@pytest.fixture(scope="session")
def get_commits_for_trunk_only_repo_w_no_tags() -> GetRepoDefinitionFn:
base_definition: dict[str, BaseRepoVersionDef] = {
"Unreleased": {
"changelog_sections": {
# ORDER matters here since greater than 1 commit, changelogs sections are alphabetized
# But value is ultimately defined by the commits, which means the commits are
# referenced by index value
"angular": [
{"section": "Feature", "i_commits": [2]},
{"section": "Fix", "i_commits": [3, 1]},
{"section": "Unknown", "i_commits": [0]},
],
"emoji": [
{"section": ":bug:", "i_commits": [3, 1]},
{"section": ":sparkles:", "i_commits": [2]},
{"section": "Other", "i_commits": [0]},
],
"scipy": [
{"section": "Feature", "i_commits": [2]},
{"section": "Fix", "i_commits": [3, 1]},
{"section": "Unknown", "i_commits": [0]},
],
"tag": [
{"section": "Feature", "i_commits": [2]},
{"section": "Fix", "i_commits": [3, 1]},
{"section": "Unknown", "i_commits": [0]},
],
},
"commits": [
{
"angular": "Initial commit",
"emoji": "Initial commit",
"scipy": "Initial commit",
"tag": "Initial commit",
},
{
"angular": "fix: add some more text",
"emoji": ":bug: add some more text",
"scipy": "MAINT: add some more text",
"tag": ":nut_and_bolt: add some more text",
},
{
"angular": "feat: add much more text",
"emoji": ":sparkles: add much more text",
"scipy": "ENH: add much more text",
"tag": ":sparkles: add much more text",
},
{
"angular": "fix: more text",
"emoji": ":bug: more text",
"scipy": "MAINT: more text",
"tag": ":nut_and_bolt: more text",
},
],
},
}
def _get_commits_for_trunk_only_repo_w_no_tags(
commit_type: CommitConvention = "angular",
) -> RepoDefinition:
definition: RepoDefinition = {}
for version, version_def in base_definition.items():
definition[version] = {
# Extract the correct changelog section header for the commit type
"changelog_sections": deepcopy(
version_def["changelog_sections"][commit_type]
),
"commits": [
# Extract the correct commit message for the commit type
message_variants[commit_type]
for message_variants in version_def["commits"]
],
}
return definition
return _get_commits_for_trunk_only_repo_w_no_tags
@pytest.fixture(scope="session")
def get_versions_for_trunk_only_repo_w_no_tags(
get_commits_for_trunk_only_repo_w_no_tags: GetRepoDefinitionFn,
) -> GetVersionStringsFn:
def _get_versions_for_trunk_only_repo_w_no_tags() -> list[VersionStr]:
return list(get_commits_for_trunk_only_repo_w_no_tags().keys())
return _get_versions_for_trunk_only_repo_w_no_tags
@pytest.fixture(scope="session")
def build_trunk_only_repo_w_no_tags(
get_commits_for_trunk_only_repo_w_no_tags: GetRepoDefinitionFn,
build_configured_base_repo: BuildRepoFn,
changelog_md_file: Path,
simulate_change_commits_n_rtn_changelog_entry: SimulateChangeCommitsNReturnChangelogEntryFn,
simulate_default_changelog_creation: SimulateDefaultChangelogCreationFn,
) -> BuildRepoFn:
def _build_trunk_only_repo_w_no_tags(
dest_dir: Path | str,
commit_type: CommitConvention = "angular",
hvcs_client_name: str = "github",
hvcs_domain: str = EXAMPLE_HVCS_DOMAIN,
tag_format_str: str | None = None,
extra_configs: dict[str, TomlSerializableTypes] | None = None,
) -> tuple[Path, HvcsBase]:
repo_dir, hvcs = build_configured_base_repo(
dest_dir,
commit_type=commit_type,
hvcs_client_name=hvcs_client_name,
hvcs_domain=hvcs_domain,
tag_format_str=tag_format_str,
extra_configs=extra_configs,
)
repo_def = get_commits_for_trunk_only_repo_w_no_tags(commit_type)
versions = (key for key in repo_def)
next_version = next(versions)
next_version_def = repo_def[next_version]
with temporary_working_directory(repo_dir), Repo(".") as git_repo:
# Run set up commits
next_version_def["commits"] = simulate_change_commits_n_rtn_changelog_entry(
git_repo, next_version_def["commits"], hvcs
)
# write expected changelog (should match template changelog)
simulate_default_changelog_creation(
repo_def,
repo_dir.joinpath(changelog_md_file),
)
return repo_dir, hvcs
return _build_trunk_only_repo_w_no_tags
# --------------------------------------------------------------------------- #
# Session-level fixtures to use to set up cached repositories on first use #
# --------------------------------------------------------------------------- #
@pytest.fixture(scope="session")
def cached_repo_with_no_tags_angular_commits(
build_trunk_only_repo_w_no_tags: BuildRepoFn,
cached_files_dir: Path,
teardown_cached_dir: TeardownCachedDirFn,
) -> Path:
cached_repo_path = cached_files_dir.joinpath(
cached_repo_with_no_tags_angular_commits.__name__
)
build_trunk_only_repo_w_no_tags(cached_repo_path, "angular")
return teardown_cached_dir(cached_repo_path)
@pytest.fixture(scope="session")
def cached_repo_with_no_tags_emoji_commits(
build_trunk_only_repo_w_no_tags: BuildRepoFn,
cached_files_dir: Path,
teardown_cached_dir: TeardownCachedDirFn,
) -> Path:
cached_repo_path = cached_files_dir.joinpath(
cached_repo_with_no_tags_emoji_commits.__name__
)
build_trunk_only_repo_w_no_tags(cached_repo_path, "emoji")
return teardown_cached_dir(cached_repo_path)
@pytest.fixture(scope="session")
def cached_repo_with_no_tags_scipy_commits(
build_trunk_only_repo_w_no_tags: BuildRepoFn,
cached_files_dir: Path,
teardown_cached_dir: TeardownCachedDirFn,
) -> Path:
cached_repo_path = cached_files_dir.joinpath(
cached_repo_with_no_tags_scipy_commits.__name__
)
build_trunk_only_repo_w_no_tags(cached_repo_path, "scipy")
return teardown_cached_dir(cached_repo_path)
@pytest.fixture(scope="session")
def cached_repo_with_no_tags_tag_commits(
build_trunk_only_repo_w_no_tags: BuildRepoFn,
cached_files_dir: Path,
teardown_cached_dir: TeardownCachedDirFn,
) -> Path:
cached_repo_path = cached_files_dir.joinpath(
cached_repo_with_no_tags_tag_commits.__name__
)
build_trunk_only_repo_w_no_tags(cached_repo_path, "tag")
return teardown_cached_dir(cached_repo_path)
# --------------------------------------------------------------------------- #
# Test-level fixtures to use to set up temporary test directory #
# --------------------------------------------------------------------------- #
@pytest.fixture
def repo_with_no_tags_angular_commits(
cached_repo_with_no_tags_angular_commits: Path,
example_project_git_repo: ExProjectGitRepoFn,
example_project_dir: ExProjectDir,
change_to_ex_proj_dir: None,
) -> Repo:
if not cached_repo_with_no_tags_angular_commits.exists():
raise RuntimeError("Unable to find cached repo!")
copy_dir_tree(cached_repo_with_no_tags_angular_commits, example_project_dir)
return example_project_git_repo()
@pytest.fixture
def repo_with_no_tags_emoji_commits(
cached_repo_with_no_tags_emoji_commits: Path,
example_project_git_repo: ExProjectGitRepoFn,
example_project_dir: ExProjectDir,
change_to_ex_proj_dir: None,
) -> Repo:
if not cached_repo_with_no_tags_emoji_commits.exists():
raise RuntimeError("Unable to find cached repo!")
copy_dir_tree(cached_repo_with_no_tags_emoji_commits, example_project_dir)
return example_project_git_repo()
@pytest.fixture
def repo_with_no_tags_scipy_commits(
cached_repo_with_no_tags_scipy_commits: Path,
example_project_git_repo: ExProjectGitRepoFn,
example_project_dir: ExProjectDir,
change_to_ex_proj_dir: None,
) -> Repo:
if not cached_repo_with_no_tags_scipy_commits.exists():
raise RuntimeError("Unable to find cached repo!")
copy_dir_tree(cached_repo_with_no_tags_scipy_commits, example_project_dir)
return example_project_git_repo()
@pytest.fixture
def repo_with_no_tags_tag_commits(
cached_repo_with_no_tags_tag_commits: Path,
example_project_git_repo: ExProjectGitRepoFn,
example_project_dir: ExProjectDir,
change_to_ex_proj_dir: None,
) -> Repo:
if not cached_repo_with_no_tags_tag_commits.exists():
raise RuntimeError("Unable to find cached repo!")
copy_dir_tree(cached_repo_with_no_tags_tag_commits, example_project_dir)
return example_project_git_repo()