10
10
11
11
After that, it will create a release using the `release` tox environment, and push a new PR.
12
12
13
- **Token**: currently the token from the GitHub Actions is used, pushed with
14
- `pytest bot <[email protected] >` commit author.
13
+ Note: the script uses the `gh` command-line tool, so `GH_TOKEN` must be set in the environment.
15
14
"""
16
15
17
16
from __future__ import annotations
25
24
26
25
from colorama import Fore
27
26
from colorama import init
28
- from github3 .repos import Repository
29
27
30
28
31
29
class InvalidFeatureRelease (Exception ):
@@ -54,17 +52,7 @@ class InvalidFeatureRelease(Exception):
54
52
"""
55
53
56
54
57
- def login (token : str ) -> Repository :
58
- import github3
59
-
60
- github = github3 .login (token = token )
61
- owner , repo = SLUG .split ("/" )
62
- return github .repository (owner , repo )
63
-
64
-
65
- def prepare_release_pr (
66
- base_branch : str , is_major : bool , token : str , prerelease : str
67
- ) -> None :
55
+ def prepare_release_pr (base_branch : str , is_major : bool , prerelease : str ) -> None :
68
56
print ()
69
57
print (f"Processing release for branch { Fore .CYAN } { base_branch } " )
70
58
@@ -131,22 +119,25 @@ def prepare_release_pr(
131
119
check = True ,
132
120
)
133
121
134
- oauth_url = f"https://{ token } :[email protected] /{ SLUG } .git"
135
122
run (
136
- ["git" , "push" , oauth_url , f"HEAD:{ release_branch } " , "--force" ],
123
+ ["git" , "push" , f"HEAD:{ release_branch } " , "--force" ],
137
124
check = True ,
138
125
)
139
126
print (f"Branch { Fore .CYAN } { release_branch } { Fore .RESET } pushed." )
140
127
141
128
body = PR_BODY .format (version = version )
142
- repo = login (token )
143
- pr = repo .create_pull (
144
- f"Prepare release { version } " ,
145
- base = base_branch ,
146
- head = release_branch ,
147
- body = body ,
129
+ run (
130
+ [
131
+ "gh" ,
132
+ "pr" ,
133
+ "new" ,
134
+ f"--base={ base_branch } " ,
135
+ f"--head={ release_branch } " ,
136
+ f"--title=Release { version } " ,
137
+ f"--body={ body } " ,
138
+ ],
139
+ check = True ,
148
140
)
149
- print (f"Pull request { Fore .CYAN } { pr .url } { Fore .RESET } created." )
150
141
151
142
152
143
def find_next_version (
@@ -163,7 +154,7 @@ def find_next_version(
163
154
last_version = valid_versions [- 1 ]
164
155
165
156
if is_major :
166
- return f"{ last_version [0 ]+ 1 } .0.0{ prerelease } "
157
+ return f"{ last_version [0 ] + 1 } .0.0{ prerelease } "
167
158
elif is_feature_release :
168
159
return f"{ last_version [0 ]} .{ last_version [1 ] + 1 } .0{ prerelease } "
169
160
else :
@@ -174,14 +165,12 @@ def main() -> None:
174
165
init (autoreset = True )
175
166
parser = argparse .ArgumentParser ()
176
167
parser .add_argument ("base_branch" )
177
- parser .add_argument ("token" )
178
168
parser .add_argument ("--major" , action = "store_true" , default = False )
179
169
parser .add_argument ("--prerelease" , default = "" )
180
170
options = parser .parse_args ()
181
171
prepare_release_pr (
182
172
base_branch = options .base_branch ,
183
173
is_major = options .major ,
184
- token = options .token ,
185
174
prerelease = options .prerelease ,
186
175
)
187
176
0 commit comments