autopub 1.0.0a32__py3-none-any.whl → 1.0.0a34__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.
- autopub/plugin_loader.py +1 -2
- autopub/plugins/github.py +81 -36
- {autopub-1.0.0a32.dist-info → autopub-1.0.0a34.dist-info}/METADATA +1 -1
- {autopub-1.0.0a32.dist-info → autopub-1.0.0a34.dist-info}/RECORD +7 -7
- {autopub-1.0.0a32.dist-info → autopub-1.0.0a34.dist-info}/LICENSE +0 -0
- {autopub-1.0.0a32.dist-info → autopub-1.0.0a34.dist-info}/WHEEL +0 -0
- {autopub-1.0.0a32.dist-info → autopub-1.0.0a34.dist-info}/entry_points.txt +0 -0
autopub/plugin_loader.py
CHANGED
autopub/plugins/github.py
CHANGED
@@ -8,6 +8,7 @@ from typing import Optional, TypedDict
|
|
8
8
|
from github import Github
|
9
9
|
from github.PullRequest import PullRequest
|
10
10
|
from github.Repository import Repository
|
11
|
+
from pydantic import BaseModel
|
11
12
|
|
12
13
|
from autopub.exceptions import AutopubException
|
13
14
|
from autopub.plugins import AutopubPlugin
|
@@ -25,19 +26,65 @@ class Sponsors(TypedDict):
|
|
25
26
|
private_sponsors: int
|
26
27
|
|
27
28
|
|
29
|
+
class GithubConfig(BaseModel):
|
30
|
+
comment_template_success: str = textwrap.dedent(
|
31
|
+
"""
|
32
|
+
Thanks for adding the `RELEASE.md` file!
|
33
|
+
|
34
|
+
Here's a preview of the changelog:
|
35
|
+
|
36
|
+
{changelog}
|
37
|
+
""",
|
38
|
+
)
|
39
|
+
|
40
|
+
comment_template_error: str = textwrap.dedent(
|
41
|
+
"""
|
42
|
+
Something went wrong while checking the release file.
|
43
|
+
|
44
|
+
Here's the error:
|
45
|
+
|
46
|
+
{error}
|
47
|
+
""",
|
48
|
+
description="Template for release note validation errors",
|
49
|
+
)
|
50
|
+
|
51
|
+
comment_template_missing_release: str = textwrap.dedent("""
|
52
|
+
Hi, thanks for contributing to this project!
|
53
|
+
|
54
|
+
We noticed that this PR is missing a `RELEASE.md` file. We use that to automatically do releases here on GitHub and, most importantly, to PyPI!
|
55
|
+
|
56
|
+
So as soon as this PR is merged, a release will be made 🚀.
|
57
|
+
|
58
|
+
Here's an example of `RELEASE.md`:
|
59
|
+
|
60
|
+
```markdown
|
61
|
+
---
|
62
|
+
release type: patch
|
63
|
+
---
|
64
|
+
|
65
|
+
Description of the changes, ideally with some examples, if adding a new feature.
|
66
|
+
|
67
|
+
Release type can be one of patch, minor or major. We use [semver](https://semver.org/), so make sure to pick the appropriate type. If in doubt feel free to ask :)
|
68
|
+
```
|
69
|
+
""")
|
70
|
+
|
71
|
+
|
28
72
|
class GithubPlugin(AutopubPlugin):
|
29
|
-
|
73
|
+
id = "github"
|
74
|
+
Config = GithubConfig
|
75
|
+
|
30
76
|
def __init__(self) -> None:
|
31
77
|
super().__init__()
|
32
|
-
|
78
|
+
|
33
79
|
self.github_token = os.environ.get("GITHUB_TOKEN")
|
34
|
-
|
80
|
+
|
35
81
|
if not self.github_token:
|
36
82
|
raise AutopubException("GITHUB_TOKEN environment variable is required")
|
37
83
|
|
38
84
|
self.repository_name = os.environ.get("GITHUB_REPOSITORY")
|
39
|
-
|
40
|
-
|
85
|
+
self.discussion_category_name = os.environ.get(
|
86
|
+
"DISCUSSION_CATEGORY_NAME", "Announcements"
|
87
|
+
)
|
41
88
|
|
42
89
|
@cached_property
|
43
90
|
def _github(self) -> Github:
|
@@ -57,9 +104,9 @@ class GithubPlugin(AutopubPlugin):
|
|
57
104
|
return self._github.get_repo(self.repository_name)
|
58
105
|
|
59
106
|
@cached_property
|
60
|
-
def pull_request(self) -> Optional[PullRequest]:
|
107
|
+
def pull_request(self) -> Optional[PullRequest]:
|
61
108
|
pr_number = self._get_pr_number()
|
62
|
-
|
109
|
+
|
63
110
|
if pr_number is None:
|
64
111
|
return None
|
65
112
|
|
@@ -95,7 +142,9 @@ class GithubPlugin(AutopubPlugin):
|
|
95
142
|
self, text: str, marker: str = "<!-- autopub-comment -->"
|
96
143
|
) -> None:
|
97
144
|
"""Update or create a comment on the current PR with the given text."""
|
98
|
-
print(
|
145
|
+
print(
|
146
|
+
f"Updating or creating comment on PR {self.pull_request} in {self.repository}"
|
147
|
+
)
|
99
148
|
|
100
149
|
# Look for existing autopub comment
|
101
150
|
comment_body = f"{marker}\n{text}"
|
@@ -162,19 +211,24 @@ class GithubPlugin(AutopubPlugin):
|
|
162
211
|
"""
|
163
212
|
|
164
213
|
# TODO: there might be some permission issues in some cases
|
214
|
+
# TODO: this needs a PAT (check security implications)
|
165
215
|
if self.repository.organization:
|
166
216
|
_, response = self._github.requester.graphql_query(
|
167
217
|
query_organisation, {"organization": self.repository.organization.login}
|
168
218
|
)
|
219
|
+
|
220
|
+
data = response["data"]["organization"]["sponsorshipsAsMaintainer"]["nodes"]
|
169
221
|
else:
|
170
222
|
_, response = self._github.requester.graphql_query(
|
171
223
|
query_user, {"user": self.repository.owner.login}
|
172
224
|
)
|
173
225
|
|
226
|
+
data = response["data"]["user"]["sponsorshipsAsMaintainer"]["nodes"]
|
227
|
+
|
174
228
|
sponsors = set()
|
175
229
|
private_sponsors = 0
|
176
230
|
|
177
|
-
for node in
|
231
|
+
for node in data:
|
178
232
|
if node["privacyLevel"] == "PUBLIC":
|
179
233
|
sponsors.add(node["sponsorEntity"]["login"])
|
180
234
|
else:
|
@@ -186,7 +240,6 @@ class GithubPlugin(AutopubPlugin):
|
|
186
240
|
)
|
187
241
|
|
188
242
|
def _get_discussion_category_id(self) -> str:
|
189
|
-
|
190
243
|
query = """
|
191
244
|
query GetDiscussionCategoryId($owner: String!, $repositoryName: String!) {
|
192
245
|
repository(owner: $owner, name: $repositoryName) {
|
@@ -212,7 +265,9 @@ class GithubPlugin(AutopubPlugin):
|
|
212
265
|
if node["name"] == self.discussion_category_name:
|
213
266
|
return node["id"]
|
214
267
|
|
215
|
-
raise AutopubException(
|
268
|
+
raise AutopubException(
|
269
|
+
f"Discussion category {self.discussion_category_name} not found"
|
270
|
+
)
|
216
271
|
|
217
272
|
def _create_discussion(self, release_info: ReleaseInfo) -> None:
|
218
273
|
mutation = """
|
@@ -264,36 +319,21 @@ class GithubPlugin(AutopubPlugin):
|
|
264
319
|
|
265
320
|
return pr_contributors
|
266
321
|
|
267
|
-
def on_release_notes_valid(
|
268
|
-
self, release_info: ReleaseInfo
|
269
|
-
) -> None: # pragma: no cover
|
322
|
+
def on_release_notes_valid(self, release_info: ReleaseInfo) -> None:
|
270
323
|
assert self.pull_request is not None
|
271
324
|
|
272
|
-
|
273
|
-
sponsors = self._get_sponsors()
|
274
|
-
discussion_category_id = self._get_discussion_category_id()
|
275
|
-
|
276
|
-
message = textwrap.dedent(
|
277
|
-
f"""
|
278
|
-
## {release_info.version}
|
279
|
-
|
280
|
-
{release_info.release_notes}
|
281
|
-
|
282
|
-
This release was contributed by {contributors} in #{self.pull_request.number}
|
325
|
+
changelog = self._get_release_message(release_info)
|
283
326
|
|
284
|
-
|
285
|
-
|
286
|
-
Discussion: {discussion_category_id}
|
287
|
-
"""
|
327
|
+
message = self.configuration.comment_template_success.format(
|
328
|
+
changelog=changelog
|
288
329
|
)
|
289
330
|
|
290
331
|
self._update_or_create_comment(message)
|
291
332
|
|
292
|
-
def on_release_notes_invalid(
|
293
|
-
self
|
294
|
-
|
295
|
-
|
296
|
-
self._update_or_create_comment(str(exception))
|
333
|
+
def on_release_notes_invalid(self, exception: AutopubException) -> None:
|
334
|
+
message = self.configuration.comment_template_error.format(error=str(exception))
|
335
|
+
|
336
|
+
self._update_or_create_comment(message)
|
297
337
|
|
298
338
|
def _get_release_message(self, release_info: ReleaseInfo) -> str:
|
299
339
|
assert self.pull_request is not None
|
@@ -312,8 +352,13 @@ class GithubPlugin(AutopubPlugin):
|
|
312
352
|
)
|
313
353
|
|
314
354
|
if contributors["additional_contributors"]:
|
315
|
-
additional_contributors = [
|
316
|
-
|
355
|
+
additional_contributors = [
|
356
|
+
f"@{contributor}"
|
357
|
+
for contributor in contributors["additional_contributors"]
|
358
|
+
]
|
359
|
+
message += (
|
360
|
+
f"\n\nAdditional contributors: {', '.join(additional_contributors)}"
|
361
|
+
)
|
317
362
|
|
318
363
|
if contributors["reviewers"]:
|
319
364
|
reviewers = [f"@{reviewer}" for reviewer in contributors["reviewers"]]
|
@@ -1,19 +1,19 @@
|
|
1
1
|
autopub/__init__.py,sha256=mJ7Ai6ygc43IuiaKbVBcLGj8oHMuZmJ3Bxq3rPgKmf8,7130
|
2
2
|
autopub/cli/__init__.py,sha256=77rx1yYi8adLUZAW7Rs48CNVyYe4HgSMZ7pZyIxD1iQ,3894
|
3
3
|
autopub/exceptions.py,sha256=gNUbiG3_fVmNjhk2kyueQHPSifNgQf0Bl6IDNvkVhxQ,1534
|
4
|
-
autopub/plugin_loader.py,sha256=
|
4
|
+
autopub/plugin_loader.py,sha256=2ysITgpHGUmcb1mP1Qvs-iBX2wZxmfP9obnebThwUMA,1809
|
5
5
|
autopub/plugins/__init__.py,sha256=57ewn1lhZYKKuVL49l3cgqAN9LQfCRzdsgSZimIAkls,2030
|
6
6
|
autopub/plugins/bump_version.py,sha256=-tTGQR0v8K3Bto1Y8UcmkEs4WnExeF1QyHKHPUKgll8,1565
|
7
7
|
autopub/plugins/git.py,sha256=d0SMLc6hwuk0eymj8aHyu3_cEd-7x4fhkwu35wPPV4k,1054
|
8
|
-
autopub/plugins/github.py,sha256=
|
8
|
+
autopub/plugins/github.py,sha256=LKO6bS7gw3BqJOEj3qryKd5AFCZDzJ32018f7CGuVys,12873
|
9
9
|
autopub/plugins/pdm.py,sha256=Pczye06fKg8_HMJDkEfMXQyvao9rZ7sqzTHFd6lLEpU,532
|
10
10
|
autopub/plugins/poetry.py,sha256=d2LvW9RI7ZB3reBOXbcp1mqWmzQ06Uyg_T-MxTvlSBg,517
|
11
11
|
autopub/plugins/update_changelog.py,sha256=g_6flOP5wocZbjOaYSayWxobL3ld8f0wT78nFtAIkFc,1586
|
12
12
|
autopub/plugins/uv.py,sha256=goo8QxaD3FVJ1c3xOSmN1hikZTCUXN8jWNac1S5uDDY,1089
|
13
13
|
autopub/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
14
14
|
autopub/types.py,sha256=gY1WR93XZVFS7vf5JMSmL_h5z7zO51-rtmZ6MYsh3so,1043
|
15
|
-
autopub-1.0.
|
16
|
-
autopub-1.0.
|
17
|
-
autopub-1.0.
|
18
|
-
autopub-1.0.
|
19
|
-
autopub-1.0.
|
15
|
+
autopub-1.0.0a34.dist-info/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
|
16
|
+
autopub-1.0.0a34.dist-info/METADATA,sha256=gdk2lNOdyVIs-i7jTckdrmgg85TVYR291pQrbSXiVLc,992
|
17
|
+
autopub-1.0.0a34.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
18
|
+
autopub-1.0.0a34.dist-info/entry_points.txt,sha256=oeTav5NgCxif6mcZ_HeVGgGv5LzS4DwdI01nr4bO1IM,43
|
19
|
+
autopub-1.0.0a34.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|