qctrl-release-noter 0.1.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- qctrl_release_noter-0.1.3.dist-info/LICENSE +174 -0
- qctrl_release_noter-0.1.3.dist-info/METADATA +73 -0
- qctrl_release_noter-0.1.3.dist-info/RECORD +8 -0
- qctrl_release_noter-0.1.3.dist-info/WHEEL +4 -0
- qctrl_release_noter-0.1.3.dist-info/entry_points.txt +3 -0
- qctrlreleasenoter/__init__.py +20 -0
- qctrlreleasenoter/cli.py +101 -0
- qctrlreleasenoter/generate_release_notes.py +445 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: qctrl-release-noter
|
|
3
|
+
Version: 0.1.3
|
|
4
|
+
Summary: Q-CTRL Release Noter
|
|
5
|
+
Home-page: https://q-ctrl.com
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Keywords: black opal,boulder opal,fire opal,nisq,open controls,q control,q ctrl,q-control,q-ctrl,qcontrol,qctrl,quantum,quantum algorithms,quantum circuits,quantum coding,quantum coding software,quantum computing,quantum control,quantum control software,quantum control theory,quantum engineering,quantum error correction,quantum firmware,quantum fundamentals,quantum sensing,qubit,qudit
|
|
8
|
+
Author: Q-CTRL
|
|
9
|
+
Author-email: support@q-ctrl.com
|
|
10
|
+
Maintainer: Q-CTRL
|
|
11
|
+
Maintainer-email: support@q-ctrl.com
|
|
12
|
+
Requires-Python: >=3.8,<3.12
|
|
13
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
14
|
+
Classifier: Environment :: Console
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Intended Audience :: Education
|
|
17
|
+
Classifier: Intended Audience :: Science/Research
|
|
18
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
19
|
+
Classifier: Natural Language :: English
|
|
20
|
+
Classifier: Operating System :: OS Independent
|
|
21
|
+
Classifier: Programming Language :: Python :: 3
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
26
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
27
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
28
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
29
|
+
Classifier: Topic :: Software Development :: Embedded Systems
|
|
30
|
+
Classifier: Topic :: System :: Distributed Computing
|
|
31
|
+
Requires-Dist: click (>=8.0,<9.0)
|
|
32
|
+
Requires-Dist: gitpython (>=3.1.37,<4.0.0)
|
|
33
|
+
Requires-Dist: packaging (>=23.0,<24.0)
|
|
34
|
+
Requires-Dist: pyinflect (>=0.5.1,<0.6.0)
|
|
35
|
+
Project-URL: Facebook, https://www.facebook.com/qctrl
|
|
36
|
+
Project-URL: GitHub, https://github.com/qctrl
|
|
37
|
+
Project-URL: LinkedIn, https://www.linkedin.com/company/q-ctrl/
|
|
38
|
+
Project-URL: Twitter, https://twitter.com/qctrlHQ
|
|
39
|
+
Project-URL: YouTube, https://www.youtube.com/qctrl
|
|
40
|
+
Description-Content-Type: text/markdown
|
|
41
|
+
|
|
42
|
+
# Q-CTRL Release Noter
|
|
43
|
+
|
|
44
|
+
The Q-CTRL Release Noter Python package provides a command line tool that generates the recommended release notes for a GitHub package from Q-CTRL.
|
|
45
|
+
|
|
46
|
+
## Installation
|
|
47
|
+
|
|
48
|
+
Install the Q-CTRL Release Noter with:
|
|
49
|
+
|
|
50
|
+
```shell
|
|
51
|
+
pip install qctrl-release-noter
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Usage
|
|
55
|
+
|
|
56
|
+
In the repository whose release notes you want to generate, run:
|
|
57
|
+
|
|
58
|
+
```shell
|
|
59
|
+
release_noter
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
You can also specify the path of the repository:
|
|
63
|
+
|
|
64
|
+
```shell
|
|
65
|
+
release_noter /path/to/repository
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
To prefill the information on the GitHub release page, use:
|
|
69
|
+
|
|
70
|
+
```shell
|
|
71
|
+
release_noter --github
|
|
72
|
+
```
|
|
73
|
+
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
qctrlreleasenoter/__init__.py,sha256=_ILHRUBvdylLWCj5mkWYk6PwtY6JdnFEOghxoAaqqt4,707
|
|
2
|
+
qctrlreleasenoter/cli.py,sha256=k1Q-heR6mE3gujB-zI5bktS-hg4Qc1Xw3ZZMgJCETEA,2814
|
|
3
|
+
qctrlreleasenoter/generate_release_notes.py,sha256=gZPkJ5_5yjwvNT6g2mTIDsGkDrrLiorDVh12qGGAnm4,14121
|
|
4
|
+
qctrl_release_noter-0.1.3.dist-info/LICENSE,sha256=zE1N4JILDTkSIDtdmqdnKKxKEQh_VdqeoAV2230eNOI,10141
|
|
5
|
+
qctrl_release_noter-0.1.3.dist-info/METADATA,sha256=brQ0W-HEbehw_R7zJky5joNkAcGIbX9DikLbq93o8NU,2607
|
|
6
|
+
qctrl_release_noter-0.1.3.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
|
|
7
|
+
qctrl_release_noter-0.1.3.dist-info/entry_points.txt,sha256=0mgRjKS9temLQZVvEL_0eXL2wU65nZ4eM3ixTA3lCKI,60
|
|
8
|
+
qctrl_release_noter-0.1.3.dist-info/RECORD,,
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Copyright 2024 Q-CTRL
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""
|
|
16
|
+
A Python package for generating the recommended release notes.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
__version__ = "0.1.3"
|
|
20
|
+
__author__ = "Q-CTRL <support@q-ctrl.com>"
|
qctrlreleasenoter/cli.py
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# Copyright 2024 Q-CTRL
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
"""
|
|
15
|
+
The CLI tool to generate release note.
|
|
16
|
+
"""
|
|
17
|
+
import click
|
|
18
|
+
from git import (
|
|
19
|
+
InvalidGitRepositoryError,
|
|
20
|
+
Repo,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
from qctrlreleasenoter.generate_release_notes import (
|
|
24
|
+
generate_note,
|
|
25
|
+
pull_latest_changes,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@click.command(
|
|
30
|
+
help="""
|
|
31
|
+
Prints release notes for the commits between the latest tag and `branch`
|
|
32
|
+
for the specified repository.
|
|
33
|
+
|
|
34
|
+
Commits are expected to follow the Conventional Commits specification
|
|
35
|
+
(https://www.conventionalcommits.org/en/v1.0.0/). That is, messages are
|
|
36
|
+
typically expected to be of the form:
|
|
37
|
+
|
|
38
|
+
\b
|
|
39
|
+
<kind>: <title>
|
|
40
|
+
|
|
41
|
+
\b
|
|
42
|
+
<description>
|
|
43
|
+
|
|
44
|
+
The valid types and the release type they lead to are defined in the
|
|
45
|
+
contributing guidelines (https://code.q-ctrl.com/contributing).
|
|
46
|
+
|
|
47
|
+
Messages for commits introducing breaking changes are expected to be of
|
|
48
|
+
the form:
|
|
49
|
+
|
|
50
|
+
\b
|
|
51
|
+
<kind>!: <title>
|
|
52
|
+
|
|
53
|
+
\b
|
|
54
|
+
<description>
|
|
55
|
+
|
|
56
|
+
\b
|
|
57
|
+
BREAKING CHANGE: <explanation of the breaking change>
|
|
58
|
+
"""
|
|
59
|
+
)
|
|
60
|
+
@click.option(
|
|
61
|
+
"--branch",
|
|
62
|
+
default="master",
|
|
63
|
+
help="Branch on which the release will be made (defaults to master).",
|
|
64
|
+
)
|
|
65
|
+
@click.option(
|
|
66
|
+
"--github",
|
|
67
|
+
is_flag=True,
|
|
68
|
+
default=False,
|
|
69
|
+
help="Open GitHub with the release notes prefilled.",
|
|
70
|
+
)
|
|
71
|
+
@click.option(
|
|
72
|
+
"--phase",
|
|
73
|
+
type=click.Choice(["stable", "alpha", "beta"]),
|
|
74
|
+
default="stable",
|
|
75
|
+
help="Select the phase for the release (defaults to stable).",
|
|
76
|
+
)
|
|
77
|
+
@click.option(
|
|
78
|
+
"--pull/--no-pull",
|
|
79
|
+
default=True,
|
|
80
|
+
help="Pull the latest changes from remote for the specified --branch (defaults to --pull).",
|
|
81
|
+
)
|
|
82
|
+
@click.option(
|
|
83
|
+
"--allow-empty",
|
|
84
|
+
is_flag=True,
|
|
85
|
+
default=False,
|
|
86
|
+
help="Create a release notes template even if the release notes would be empty otherwise.",
|
|
87
|
+
)
|
|
88
|
+
@click.argument("path", default=".", type=click.Path(exists=True))
|
|
89
|
+
def main(branch, github, path, phase, allow_empty, pull):
|
|
90
|
+
"""
|
|
91
|
+
Main entry to generate the release note.
|
|
92
|
+
"""
|
|
93
|
+
try:
|
|
94
|
+
repo = Repo(path)
|
|
95
|
+
except InvalidGitRepositoryError as err:
|
|
96
|
+
raise RuntimeError("The current directory is not a valid repository.") from err
|
|
97
|
+
|
|
98
|
+
if pull:
|
|
99
|
+
pull_latest_changes(branch, repo)
|
|
100
|
+
|
|
101
|
+
generate_note(branch, github, phase, repo, allow_empty)
|
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
# Copyright 2024 Q-CTRL
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""
|
|
16
|
+
Generates release notes based on the commit history since the last release.
|
|
17
|
+
"""
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import re
|
|
21
|
+
import webbrowser
|
|
22
|
+
from dataclasses import (
|
|
23
|
+
dataclass,
|
|
24
|
+
field,
|
|
25
|
+
fields,
|
|
26
|
+
)
|
|
27
|
+
from enum import Enum
|
|
28
|
+
from functools import partial
|
|
29
|
+
from itertools import islice
|
|
30
|
+
from pathlib import Path
|
|
31
|
+
from typing import (
|
|
32
|
+
Iterator,
|
|
33
|
+
Optional,
|
|
34
|
+
)
|
|
35
|
+
from urllib.parse import quote_plus
|
|
36
|
+
|
|
37
|
+
import click
|
|
38
|
+
import pyinflect
|
|
39
|
+
from git.objects import Commit
|
|
40
|
+
from git.refs.tag import TagReference
|
|
41
|
+
from packaging.version import (
|
|
42
|
+
VERSION_PATTERN,
|
|
43
|
+
Version,
|
|
44
|
+
parse,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class _PrType(Enum):
|
|
49
|
+
MINOR = ("feat",)
|
|
50
|
+
PATCH = ("fix", "perf", "revert", "build")
|
|
51
|
+
IGNORED = ("refactor", "chore", "ci", "docs", "style", "test")
|
|
52
|
+
# Using an empty tuple here seems to cause issue in Python 3.11.1,
|
|
53
|
+
# as it's treated as an object instead of an iterable.
|
|
54
|
+
# Therefore, in `_classify_commit_type` we exclude the UNKNOWN item.
|
|
55
|
+
UNKNOWN = ()
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _classify_commit_type(kind: str) -> _PrType:
|
|
59
|
+
"""
|
|
60
|
+
Classify the PR type for a commit based on its kind.
|
|
61
|
+
This could be a classmethod of _PrType, but it's convenient for type-checking as
|
|
62
|
+
a private function.
|
|
63
|
+
"""
|
|
64
|
+
# Classify the types for valid PRs in the release note.
|
|
65
|
+
for type_ in islice(_PrType, len(_PrType) - 1):
|
|
66
|
+
if kind in type_.value:
|
|
67
|
+
return type_
|
|
68
|
+
# Label the invalid PR.
|
|
69
|
+
return _PrType.UNKNOWN
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@dataclass
|
|
73
|
+
class _CommitInfo:
|
|
74
|
+
title: str
|
|
75
|
+
kind: _PrType
|
|
76
|
+
sha: Optional[str]
|
|
77
|
+
breaking_change_message: Optional[str]
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class _ReleasePhase(Enum):
|
|
81
|
+
ALPHA = "alpha"
|
|
82
|
+
BETA = "beta"
|
|
83
|
+
STABLE = "stable"
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
@dataclass
|
|
87
|
+
class NoteBody:
|
|
88
|
+
"""
|
|
89
|
+
Dataclass to hold the body of release note.
|
|
90
|
+
"""
|
|
91
|
+
|
|
92
|
+
major: list[str] = field(default_factory=list)
|
|
93
|
+
minor: list[str] = field(default_factory=list)
|
|
94
|
+
patch: list[str] = field(default_factory=list)
|
|
95
|
+
unknown: list[str] = field(default_factory=list)
|
|
96
|
+
|
|
97
|
+
def is_empty(self) -> bool:
|
|
98
|
+
"""
|
|
99
|
+
Check whether the note body is empty.
|
|
100
|
+
"""
|
|
101
|
+
return (
|
|
102
|
+
sum(
|
|
103
|
+
map(
|
|
104
|
+
len, (getattr(self, field.name) for field in fields(self.__class__))
|
|
105
|
+
)
|
|
106
|
+
)
|
|
107
|
+
== 0
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
def add_item(self, item: _CommitInfo) -> None:
|
|
111
|
+
"""
|
|
112
|
+
Update note body from a commit item.
|
|
113
|
+
"""
|
|
114
|
+
# Handle the breaking change first since
|
|
115
|
+
# any valid PR could be a breaking one.
|
|
116
|
+
if item.breaking_change_message is not None:
|
|
117
|
+
self.major.append(item.breaking_change_message)
|
|
118
|
+
|
|
119
|
+
if item.kind is _PrType.IGNORED:
|
|
120
|
+
return
|
|
121
|
+
if item.kind is _PrType.UNKNOWN:
|
|
122
|
+
print_warning(
|
|
123
|
+
f"Commit {item.sha} has unknown kind {item.kind!r}, "
|
|
124
|
+
"appending to unknown changes."
|
|
125
|
+
)
|
|
126
|
+
self.unknown.append(convert_to_past_tense(item.title))
|
|
127
|
+
else:
|
|
128
|
+
pr_type = getattr(self, item.kind.name.lower())
|
|
129
|
+
pr_type.append(convert_to_past_tense(item.title))
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def pull_latest_changes(branch, repo):
|
|
133
|
+
"""
|
|
134
|
+
Pulls the latest changes from remote for the specified `branch`.
|
|
135
|
+
"""
|
|
136
|
+
repo.git.checkout(branch)
|
|
137
|
+
repo.remotes.origin.pull()
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def is_version(tag: TagReference) -> bool:
|
|
141
|
+
"""
|
|
142
|
+
Use packaging.version's regex to determine if a tag name is a valid version.
|
|
143
|
+
See also: https://packaging.pypa.io/en/stable/version.html
|
|
144
|
+
"""
|
|
145
|
+
return (
|
|
146
|
+
re.match(VERSION_PATTERN, tag.name, flags=re.VERBOSE | re.IGNORECASE)
|
|
147
|
+
is not None
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def generate_note(branch, github, phase, repo, allow_empty):
|
|
152
|
+
"""
|
|
153
|
+
Generate release notes for the commits between the latest tag and `branch`.
|
|
154
|
+
"""
|
|
155
|
+
|
|
156
|
+
# Filter to tags that look like versions, and then find the most recent.
|
|
157
|
+
tags = filter(is_version, repo.tags)
|
|
158
|
+
latest_tag = max(tags, key=lambda tag: tag.commit.committed_date, default=None)
|
|
159
|
+
if latest_tag is not None:
|
|
160
|
+
latest_tag_name = latest_tag.name
|
|
161
|
+
commits = repo.iter_commits(f"{latest_tag_name}..{branch}", reverse=True)
|
|
162
|
+
else:
|
|
163
|
+
# Meaning this is the first release of the target repo.
|
|
164
|
+
latest_tag_name = None
|
|
165
|
+
commits = repo.iter_commits(reverse=True)
|
|
166
|
+
|
|
167
|
+
note_body = generate_note_from_commits(commits)
|
|
168
|
+
if note_body.is_empty():
|
|
169
|
+
if not allow_empty:
|
|
170
|
+
print_warning(
|
|
171
|
+
"No correctly formatted changes detected. "
|
|
172
|
+
"You can use --allow-empty to create a release notes template."
|
|
173
|
+
)
|
|
174
|
+
return
|
|
175
|
+
note_body = generate_empty_note()
|
|
176
|
+
print_warning(
|
|
177
|
+
"No correctly formatted changes detected. "
|
|
178
|
+
"Remember to update the template before releasing the new version."
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
# Suggest a new version number based on the changes we found.
|
|
182
|
+
# If this is the first release, starting from "0.0.0".
|
|
183
|
+
version = Version("0.0.0") if latest_tag_name is None else parse(latest_tag_name)
|
|
184
|
+
assert isinstance(version, Version)
|
|
185
|
+
project_name = None
|
|
186
|
+
# Attempts to fetch the name of the project from the README title.
|
|
187
|
+
readme_locations = [
|
|
188
|
+
f"{repo.working_dir}/.github/README.md",
|
|
189
|
+
f"{repo.working_dir}/README.md",
|
|
190
|
+
]
|
|
191
|
+
for filepath in readme_locations:
|
|
192
|
+
if Path(filepath).is_file():
|
|
193
|
+
with open(filepath, "r", encoding="utf8") as file:
|
|
194
|
+
header = re.search(
|
|
195
|
+
"^(?: *)#(?: *)(.+)(?: *)$", file.read(), re.MULTILINE
|
|
196
|
+
)
|
|
197
|
+
if header is not None:
|
|
198
|
+
project_name = header.group(1)
|
|
199
|
+
break
|
|
200
|
+
|
|
201
|
+
if project_name is None:
|
|
202
|
+
print_warning("No project name found. Release name will not be suggested.")
|
|
203
|
+
|
|
204
|
+
try:
|
|
205
|
+
release_phase = _ReleasePhase[phase.upper()]
|
|
206
|
+
except KeyError as err:
|
|
207
|
+
raise RuntimeError(f"Unknown release phase: {phase}.") from err
|
|
208
|
+
|
|
209
|
+
query_parameters = {
|
|
210
|
+
"tag": get_new_version_tag(
|
|
211
|
+
release_phase=release_phase,
|
|
212
|
+
current_version=version,
|
|
213
|
+
has_major_changes=len(note_body.major) > 0,
|
|
214
|
+
has_minor_changes=len(note_body.minor) > 0,
|
|
215
|
+
)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
click.echo(f"Suggested version: {query_parameters['tag']}")
|
|
219
|
+
if project_name is not None:
|
|
220
|
+
query_parameters["title"] = f"{project_name} {query_parameters['tag']}"
|
|
221
|
+
click.echo(f"Suggested title: {query_parameters['title']}")
|
|
222
|
+
click.echo("")
|
|
223
|
+
|
|
224
|
+
# Create summary of changes.
|
|
225
|
+
change_list = []
|
|
226
|
+
for items, title in [
|
|
227
|
+
(note_body.unknown, "UNKNOWN CHANGES"),
|
|
228
|
+
(note_body.major, "Major changes"),
|
|
229
|
+
(note_body.minor, "Minor changes"),
|
|
230
|
+
(note_body.patch, "Patch changes"),
|
|
231
|
+
]:
|
|
232
|
+
if not items:
|
|
233
|
+
continue
|
|
234
|
+
change_list += [title]
|
|
235
|
+
formatted_items = [format_list_item(item) for item in items]
|
|
236
|
+
change_list += ["\n".join(formatted_items)]
|
|
237
|
+
query_parameters["body"] = "\n\n".join(change_list)
|
|
238
|
+
|
|
239
|
+
click.echo(query_parameters["body"])
|
|
240
|
+
click.echo("")
|
|
241
|
+
|
|
242
|
+
if github:
|
|
243
|
+
if len(repo.remotes) == 0:
|
|
244
|
+
print_warning("No remote repo found, cannot redirect to GitHub.")
|
|
245
|
+
return
|
|
246
|
+
if len(repo.remotes) > 1:
|
|
247
|
+
print_warning("More than one remote repo found, cannot redirect to GitHub.")
|
|
248
|
+
return
|
|
249
|
+
match = re.search(
|
|
250
|
+
"^https://github.com/(.*).git$|^git@github.com:(.*).git$",
|
|
251
|
+
repo.remotes.origin.url,
|
|
252
|
+
)
|
|
253
|
+
if match is None:
|
|
254
|
+
print_warning("Remote repository is not on GitHub, cannot redirect.")
|
|
255
|
+
return
|
|
256
|
+
repo_url = f"https://github.com/{match.groups()[0] or match.groups()[1]}"
|
|
257
|
+
parsed_parameters = "&".join(
|
|
258
|
+
[f"{key}={quote_plus(value)}" for key, value in query_parameters.items()]
|
|
259
|
+
)
|
|
260
|
+
if project_name is None:
|
|
261
|
+
print_warning("Project name not found, cannot redirect to GitHub.")
|
|
262
|
+
return
|
|
263
|
+
webbrowser.open(f"{repo_url}/releases/new?{parsed_parameters}")
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def _get_commit_info(commit: Commit) -> Optional[_CommitInfo]:
|
|
267
|
+
"""
|
|
268
|
+
Extract relevant parts from the commit message.
|
|
269
|
+
"""
|
|
270
|
+
message = commit.message
|
|
271
|
+
assert isinstance(message, str)
|
|
272
|
+
|
|
273
|
+
title_match = re.match("(?:(?P<kind>[a-z]*)(?P<break>!)?: )?(?P<title>.*)", message)
|
|
274
|
+
|
|
275
|
+
# For now, this branch is never triggered since the title group in the
|
|
276
|
+
# regex pattern above will match any string. This mainly serves as
|
|
277
|
+
# a type-checking for mypy at the moment. We can revise this if we
|
|
278
|
+
# change the regex pattern later.
|
|
279
|
+
if title_match is None:
|
|
280
|
+
print_warning(
|
|
281
|
+
f"Commit {commit.hexsha} has incorrectly formatted "
|
|
282
|
+
f"title {message.splitlines()[0]}, ignoring."
|
|
283
|
+
)
|
|
284
|
+
return None
|
|
285
|
+
|
|
286
|
+
kind = title_match.groupdict()["kind"]
|
|
287
|
+
title = title_match.groupdict()["title"]
|
|
288
|
+
|
|
289
|
+
assert isinstance(title, str)
|
|
290
|
+
|
|
291
|
+
# See whether this commit is a breaking change. We need to check both
|
|
292
|
+
# the title for an exclamation mark and the description for BREAKING
|
|
293
|
+
# CHANGE (we check for BREAKING-CHANGE too, as per Conventional
|
|
294
|
+
# Commits).
|
|
295
|
+
breaking_change_message = None
|
|
296
|
+
breaking_description_match = re.search("BREAKING(?: |-)CHANGE:", message)
|
|
297
|
+
if breaking_description_match:
|
|
298
|
+
breaking_change_message = message[breaking_description_match.end() :]
|
|
299
|
+
elif title_match.groupdict()["break"]:
|
|
300
|
+
print_warning(
|
|
301
|
+
f"Commit {commit.hexsha} is missing a breaking change "
|
|
302
|
+
"description, using commit title instead."
|
|
303
|
+
)
|
|
304
|
+
breaking_change_message = convert_to_past_tense(title)
|
|
305
|
+
|
|
306
|
+
return _CommitInfo(
|
|
307
|
+
title=title,
|
|
308
|
+
kind=_classify_commit_type(kind),
|
|
309
|
+
sha=commit.hexsha,
|
|
310
|
+
breaking_change_message=breaking_change_message,
|
|
311
|
+
)
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
def generate_note_from_commits(commits: Iterator[Commit]) -> NoteBody:
|
|
315
|
+
"""
|
|
316
|
+
Iterate through commits, collecting information about major, minor, and patch changes.
|
|
317
|
+
"""
|
|
318
|
+
|
|
319
|
+
note_body = NoteBody()
|
|
320
|
+
for commit in commits:
|
|
321
|
+
commit_info = _get_commit_info(commit)
|
|
322
|
+
if commit_info is None:
|
|
323
|
+
continue
|
|
324
|
+
note_body.add_item(commit_info)
|
|
325
|
+
return note_body
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
def generate_empty_note() -> NoteBody:
|
|
329
|
+
"""
|
|
330
|
+
Create a template for empty release note.
|
|
331
|
+
"""
|
|
332
|
+
note_body = NoteBody()
|
|
333
|
+
title = (
|
|
334
|
+
"No changes found. Add a description of the changes that require the release"
|
|
335
|
+
)
|
|
336
|
+
note_body.add_item(
|
|
337
|
+
_CommitInfo(
|
|
338
|
+
title=title, kind=_PrType.PATCH, sha=None, breaking_change_message=None
|
|
339
|
+
)
|
|
340
|
+
)
|
|
341
|
+
return note_body
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
def get_new_version_tag(
|
|
345
|
+
release_phase: _ReleasePhase,
|
|
346
|
+
current_version: Version,
|
|
347
|
+
has_major_changes: bool,
|
|
348
|
+
has_minor_changes: bool,
|
|
349
|
+
) -> str:
|
|
350
|
+
"""
|
|
351
|
+
Get the version tag for the next release.
|
|
352
|
+
"""
|
|
353
|
+
if release_phase is _ReleasePhase.STABLE:
|
|
354
|
+
_release_func = _stable_release
|
|
355
|
+
else:
|
|
356
|
+
_release_func = partial(_pre_release, phase=release_phase)
|
|
357
|
+
return _release_func(
|
|
358
|
+
current_version,
|
|
359
|
+
has_major_changes=has_major_changes,
|
|
360
|
+
has_minor_changes=has_minor_changes,
|
|
361
|
+
)
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
def _pre_release(
|
|
365
|
+
current_version: Version,
|
|
366
|
+
has_major_changes: bool,
|
|
367
|
+
has_minor_changes: bool,
|
|
368
|
+
phase: _ReleasePhase,
|
|
369
|
+
) -> str:
|
|
370
|
+
if current_version.is_prerelease:
|
|
371
|
+
assert current_version.pre is not None # for mypy
|
|
372
|
+
current_pre_version, pre_version_num = current_version.pre
|
|
373
|
+
if current_pre_version == "b" and phase is _ReleasePhase.ALPHA:
|
|
374
|
+
print_warning(
|
|
375
|
+
"Releasing an alpha version after a beta version means "
|
|
376
|
+
"a stable version is skipped."
|
|
377
|
+
)
|
|
378
|
+
# Jumping between pre release phases would reset the pre version number.
|
|
379
|
+
_num = 0 if current_pre_version != phase.value[0] else pre_version_num + 1
|
|
380
|
+
return f"{current_version.base_version}-{phase.value}.{_num}"
|
|
381
|
+
return f"{_stable_release(current_version, has_major_changes, has_minor_changes)}-{phase.value}"
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
def _stable_release(
|
|
385
|
+
current_version: Version, has_major_changes: bool, has_minor_changes: bool
|
|
386
|
+
) -> str:
|
|
387
|
+
# pre -> stable
|
|
388
|
+
if current_version.is_prerelease:
|
|
389
|
+
return current_version.base_version
|
|
390
|
+
|
|
391
|
+
# stable -> stable
|
|
392
|
+
major, minor, patch = current_version.release
|
|
393
|
+
if has_major_changes:
|
|
394
|
+
if major > 0:
|
|
395
|
+
major += 1
|
|
396
|
+
minor = 0
|
|
397
|
+
patch = 0
|
|
398
|
+
else:
|
|
399
|
+
minor += 1
|
|
400
|
+
patch = 0
|
|
401
|
+
elif has_minor_changes:
|
|
402
|
+
minor += 1
|
|
403
|
+
patch = 0
|
|
404
|
+
else:
|
|
405
|
+
patch += 1
|
|
406
|
+
return f"{major}.{minor}.{patch}"
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
def convert_to_past_tense(text: str) -> str:
|
|
410
|
+
"""
|
|
411
|
+
Tries to convert the given text to past tense.
|
|
412
|
+
"""
|
|
413
|
+
# Convert the first word to past tense if possible, otherwise just leave the
|
|
414
|
+
# text unchanged.
|
|
415
|
+
parts = text.split(" ", 1)
|
|
416
|
+
past_tense = pyinflect.getInflection(parts[0], "VBD")
|
|
417
|
+
if past_tense:
|
|
418
|
+
parts[0] = past_tense[0]
|
|
419
|
+
return " ".join(parts)
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
def format_list_item(text: str) -> str:
|
|
423
|
+
"""
|
|
424
|
+
Formats text (which might contain newlines) into a Markdown list item.
|
|
425
|
+
"""
|
|
426
|
+
text = text.strip()
|
|
427
|
+
|
|
428
|
+
# Capitalize first word and add period if necessary.
|
|
429
|
+
parts = text.split(" ", 1)
|
|
430
|
+
parts[0] = parts[0].capitalize()
|
|
431
|
+
text = " ".join(parts)
|
|
432
|
+
if text[-1] not in ".?!":
|
|
433
|
+
text += "."
|
|
434
|
+
|
|
435
|
+
# Indent subsequent lines.
|
|
436
|
+
indented = "\n ".join([line.strip() for line in text.splitlines()])
|
|
437
|
+
|
|
438
|
+
return f"- {indented}"
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
def print_warning(message: str):
|
|
442
|
+
"""
|
|
443
|
+
Prints a warning message to stderr.
|
|
444
|
+
"""
|
|
445
|
+
click.echo(click.style(message, fg="red"), err=True)
|