auto-optimize 1.0.0__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.
- auto_optimize/__init__.py +3 -0
- auto_optimize/__main__.py +5 -0
- auto_optimize/cli.py +651 -0
- auto_optimize/skills/auto-optimize-code/LICENSE +21 -0
- auto_optimize/skills/auto-optimize-code/SKILL.md +251 -0
- auto_optimize/skills/auto-optimize-code/VERSION +1 -0
- auto_optimize/skills/auto-optimize-code/references/algorithm.md +182 -0
- auto_optimize/skills/auto-optimize-code/references/changes.md +146 -0
- auto_optimize/skills/auto-optimize-code/references/cli.md +206 -0
- auto_optimize/skills/auto-optimize-code/references/dashboard.md +203 -0
- auto_optimize/skills/auto-optimize-code/references/documents.md +55 -0
- auto_optimize/skills/auto-optimize-code/references/extending.md +87 -0
- auto_optimize/skills/auto-optimize-code/references/external-validation.md +98 -0
- auto_optimize/skills/auto-optimize-code/references/glossary.md +134 -0
- auto_optimize/skills/auto-optimize-code/references/idea-miner.md +108 -0
- auto_optimize/skills/auto-optimize-code/references/issue-bugs.md +182 -0
- auto_optimize/skills/auto-optimize-code/references/layout.md +300 -0
- auto_optimize/skills/auto-optimize-code/references/main-session.md +45 -0
- auto_optimize/skills/auto-optimize-code/references/measuring.md +208 -0
- auto_optimize/skills/auto-optimize-code/references/pr-optimization.md +127 -0
- auto_optimize/skills/auto-optimize-code/references/pr-tests.md +254 -0
- auto_optimize/skills/auto-optimize-code/references/promotion.md +133 -0
- auto_optimize/skills/auto-optimize-code/references/reading-a-search.md +65 -0
- auto_optimize/skills/auto-optimize-code/references/repo-mode.md +224 -0
- auto_optimize/skills/auto-optimize-code/references/resume.md +81 -0
- auto_optimize/skills/auto-optimize-code/references/shared-knowledge.md +114 -0
- auto_optimize/skills/auto-optimize-code/references/step0-interview.md +298 -0
- auto_optimize/skills/auto-optimize-code/references/step1-unit-tests.md +136 -0
- auto_optimize/skills/auto-optimize-code/references/step2-baseline.md +708 -0
- auto_optimize/skills/auto-optimize-code/references/step3-rounds.md +350 -0
- auto_optimize/skills/auto-optimize-code/references/step4-final.md +121 -0
- auto_optimize/skills/auto-optimize-code/references/step5-ship.md +220 -0
- auto_optimize/skills/auto-optimize-code/references/step6-finish.md +67 -0
- auto_optimize/skills/auto-optimize-code/references/subagent.md +467 -0
- auto_optimize/skills/auto-optimize-code/references/symptoms.md +67 -0
- auto_optimize/skills/auto-optimize-code/references/writing-briefs.md +117 -0
- auto_optimize/skills/auto-optimize-code/scripts/attribution.py +156 -0
- auto_optimize/skills/auto-optimize-code/scripts/autoopt.py +12863 -0
- auto_optimize/skills/auto-optimize-code/scripts/check_seeding.py +334 -0
- auto_optimize/skills/auto-optimize-code/scripts/cold.py +90 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/README.md +165 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/autoopt_monitor.py +850 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/gpu_scan.py +954 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/monitor_writer.py +684 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/scan.py +1030 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/static/dashboard.css +775 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/static/dashboard.js +3652 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/static/index.html +191 -0
- auto_optimize/skills/auto-optimize-code/scripts/issue_body.py +2118 -0
- auto_optimize/skills/auto-optimize-code/scripts/lint_text.py +448 -0
- auto_optimize/skills/auto-optimize-code/scripts/opt_pr_body.py +894 -0
- auto_optimize/skills/auto-optimize-code/scripts/opt_pr_tables.py +367 -0
- auto_optimize/skills/auto-optimize-code/scripts/paired.py +188 -0
- auto_optimize/skills/auto-optimize-code/scripts/preflight.py +280 -0
- auto_optimize/skills/auto-optimize-code/scripts/probe_run.py +72 -0
- auto_optimize/skills/auto-optimize-code/scripts/publish.py +385 -0
- auto_optimize/skills/auto-optimize-code/scripts/run_iteration.py +1382 -0
- auto_optimize/skills/auto-optimize-code/scripts/ship.py +1193 -0
- auto_optimize/skills/auto-optimize-code/scripts/stages.py +651 -0
- auto_optimize/skills/auto-optimize-code/scripts/tests_pr_body.py +1267 -0
- auto_optimize/skills/auto-optimize-code/scripts/tests_pr_push.py +426 -0
- auto_optimize/skills/auto-optimize-code/scripts/tests_pr_tables.py +779 -0
- auto_optimize-1.0.0.dist-info/METADATA +610 -0
- auto_optimize-1.0.0.dist-info/RECORD +67 -0
- auto_optimize-1.0.0.dist-info/WHEEL +4 -0
- auto_optimize-1.0.0.dist-info/entry_points.txt +2 -0
- auto_optimize-1.0.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
"""What the scripts that write and post a document share: `issue_body.py`,
|
|
2
|
+
`tests_pr_body.py`, `tests_pr_push.py`, `opt_pr_body.py`, `ship.py` and
|
|
3
|
+
`autoopt.py pr`. Not run on its own.
|
|
4
|
+
|
|
5
|
+
Writing a file whole or not at all, a body with its title beside it, the
|
|
6
|
+
title a body was last rendered with, the bug report's and the unit-test PR's
|
|
7
|
+
numbers filled into a rendered body, a refusal that lists every problem, a
|
|
8
|
+
`gh` call returning (exit code, stdout, stderr), filling a stand-in such as
|
|
9
|
+
`#<tests PR>` into documents, and the check that a repository belongs to the
|
|
10
|
+
account `gh` is logged in as. Standard library only.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import os
|
|
14
|
+
import re
|
|
15
|
+
import sys
|
|
16
|
+
import json
|
|
17
|
+
import shutil
|
|
18
|
+
import hashlib
|
|
19
|
+
import subprocess
|
|
20
|
+
|
|
21
|
+
import attribution
|
|
22
|
+
|
|
23
|
+
# The folder of each document under `<work>/ship/`, and the record that holds
|
|
24
|
+
# its number once posted. The same table as `autoopt.SHIP_FOLDERS`, kept
|
|
25
|
+
# here so a renderer runs without importing the search's scripts.
|
|
26
|
+
FOLDERS = {'bugs': 'issue-bugs', 'tests': 'pr-tests',
|
|
27
|
+
'optimization': 'pr-optimization'}
|
|
28
|
+
RECORDS = {'bugs': 'filed.json', 'tests': 'pr.json', 'optimization': 'pr.json'}
|
|
29
|
+
|
|
30
|
+
# The stand-in each posted document fills into the others.
|
|
31
|
+
STAND_INS = {'bugs': attribution.PLACEHOLDERS[0],
|
|
32
|
+
'tests': attribution.PLACEHOLDERS[1]}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def series(items):
|
|
36
|
+
"""`a`, `a and b`, `a, b and c`."""
|
|
37
|
+
|
|
38
|
+
items = [str(item) for item in items]
|
|
39
|
+
|
|
40
|
+
if len(items) < 2:
|
|
41
|
+
return ''.join(items)
|
|
42
|
+
|
|
43
|
+
return ', '.join(items[:-1]) + ' and ' + items[-1]
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def cell(text):
|
|
47
|
+
"""A Markdown table cell: a pipe would end it."""
|
|
48
|
+
|
|
49
|
+
return text.replace('|', '\\|')
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def table(header, rows, align=None):
|
|
53
|
+
"""Markdown table lines. `align` is one delimiter cell per column
|
|
54
|
+
(`---`, `---:`), `---` by default."""
|
|
55
|
+
|
|
56
|
+
align = align or ['---'] * len(header)
|
|
57
|
+
|
|
58
|
+
return ['| ' + ' | '.join(header) + ' |', '|' + '|'.join(align) + '|'] + [
|
|
59
|
+
'| ' + ' | '.join(cell(str(value)) for value in row) + ' |'
|
|
60
|
+
for row in rows]
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def digest(title, body):
|
|
64
|
+
"""What a document's title and body were when they were posted."""
|
|
65
|
+
|
|
66
|
+
return hashlib.sha256((title + '\n' + body).encode('utf-8')).hexdigest()
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def stored_title(out):
|
|
70
|
+
"""The title `out`'s body was last rendered with (`<out stem>.title`), or
|
|
71
|
+
None."""
|
|
72
|
+
|
|
73
|
+
try:
|
|
74
|
+
with open(os.path.splitext(out)[0] + '.title', encoding='utf-8') as handle:
|
|
75
|
+
return handle.read().strip() or None
|
|
76
|
+
except OSError:
|
|
77
|
+
return None
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def write_titled(out, title, text):
|
|
81
|
+
"""The body at `out` and its title beside it, each whole or not at all."""
|
|
82
|
+
|
|
83
|
+
write(out, text)
|
|
84
|
+
write(os.path.splitext(out)[0] + '.title', title.strip() + '\n')
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def sibling(directory, document):
|
|
88
|
+
"""The record of `document` (`bugs`, `tests`) in the ship folder beside
|
|
89
|
+
`directory`, the folder of another document."""
|
|
90
|
+
|
|
91
|
+
return os.path.join(os.path.dirname(os.path.abspath(directory)),
|
|
92
|
+
FOLDERS[document], RECORDS[document])
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def chosen(directory):
|
|
96
|
+
"""The documents chosen at step 5 (`after.ship_documents`), read from the
|
|
97
|
+
search's `config.json` two folders above `directory`
|
|
98
|
+
(`<work>/ship/<document>/`); every document when there is none, as for a
|
|
99
|
+
document rendered on its own."""
|
|
100
|
+
|
|
101
|
+
config = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(
|
|
102
|
+
directory))), 'autooptimize', 'config.json')
|
|
103
|
+
|
|
104
|
+
try:
|
|
105
|
+
with open(config, encoding='utf-8') as handle:
|
|
106
|
+
documents = (json.load(handle).get('after') or {}).get(
|
|
107
|
+
'ship_documents')
|
|
108
|
+
except (OSError, ValueError):
|
|
109
|
+
documents = None
|
|
110
|
+
|
|
111
|
+
return list(documents) if documents else list(FOLDERS)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def fill_numbers(text, directory, problems):
|
|
115
|
+
"""`text` with `#<bug issue>` replaced by the number in the bug report's
|
|
116
|
+
`filed.json` and `#<tests PR>` by the one in the unit-test PR's
|
|
117
|
+
`pr.json`, in the folders beside `directory`, where those files exist. An
|
|
118
|
+
unreadable record is added to `problems`."""
|
|
119
|
+
|
|
120
|
+
for document, placeholder in STAND_INS.items():
|
|
121
|
+
path = sibling(directory, document)
|
|
122
|
+
|
|
123
|
+
if not os.path.exists(path):
|
|
124
|
+
continue
|
|
125
|
+
|
|
126
|
+
try:
|
|
127
|
+
with open(path, encoding='utf-8') as handle:
|
|
128
|
+
number = json.load(handle)['number']
|
|
129
|
+
|
|
130
|
+
text = text.replace(placeholder, '#{}'.format(number))
|
|
131
|
+
except (OSError, ValueError, KeyError, TypeError) as error:
|
|
132
|
+
problems.add('{}: cannot read the number ({})'.format(path, error))
|
|
133
|
+
|
|
134
|
+
return text
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def write(path, text):
|
|
138
|
+
"""Write `path` whole or not at all."""
|
|
139
|
+
|
|
140
|
+
temporary = path + '.tmp'
|
|
141
|
+
|
|
142
|
+
with open(temporary, 'w', encoding='utf-8', newline='\n') as out:
|
|
143
|
+
out.write(text)
|
|
144
|
+
|
|
145
|
+
os.replace(temporary, path)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def write_json(path, data):
|
|
149
|
+
"""`data` as sorted, indented JSON with a final newline, whole or not at
|
|
150
|
+
all; a missing folder is made."""
|
|
151
|
+
|
|
152
|
+
os.makedirs(os.path.dirname(path), exist_ok=True)
|
|
153
|
+
write(path, json.dumps(data, indent=1, sort_keys=True) + '\n')
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def read(path):
|
|
157
|
+
with open(path, encoding='utf-8') as handle:
|
|
158
|
+
return handle.read()
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def refuse(tool, problems, left='nothing done'):
|
|
162
|
+
"""Print every problem on stderr; the exit code to return."""
|
|
163
|
+
|
|
164
|
+
sys.stderr.write('{}: refused, {}:\n'.format(tool, left)
|
|
165
|
+
+ ''.join(' ' + problem + '\n' for problem in problems))
|
|
166
|
+
|
|
167
|
+
return 1
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def split_nodeid(nodeid):
|
|
171
|
+
"""(module, qualified function name) of a pytest node id, the
|
|
172
|
+
parametrization dropped: `a/test_b.py::TestC::test_d[x-1]` gives
|
|
173
|
+
(`a/test_b.py`, `TestC.test_d`)."""
|
|
174
|
+
|
|
175
|
+
base = nodeid.split('[', 1)[0]
|
|
176
|
+
parts = base.split('::')
|
|
177
|
+
|
|
178
|
+
return parts[0], '.'.join(parts[1:])
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def fail(prefix, message):
|
|
182
|
+
"""Print `prefix: message` on stderr and exit 1."""
|
|
183
|
+
|
|
184
|
+
sys.stderr.write('{}: {}\n'.format(prefix, message))
|
|
185
|
+
raise SystemExit(1)
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def run(command, cwd=None):
|
|
189
|
+
"""(exit code, stdout, stderr) of a command, stdout and stderr stripped."""
|
|
190
|
+
|
|
191
|
+
done = subprocess.run(command, capture_output=True, text=True, cwd=cwd,
|
|
192
|
+
stdin=subprocess.DEVNULL)
|
|
193
|
+
|
|
194
|
+
return done.returncode, done.stdout.strip(), done.stderr.strip()
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def run_gh(arguments):
|
|
198
|
+
return run(['gh'] + arguments)
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def link_files(paths, placeholder, value):
|
|
202
|
+
"""Replace `placeholder` with `value` in each file; the count in each."""
|
|
203
|
+
|
|
204
|
+
counts = {}
|
|
205
|
+
|
|
206
|
+
for path in paths:
|
|
207
|
+
with open(path, encoding='utf-8') as handle:
|
|
208
|
+
text = handle.read()
|
|
209
|
+
|
|
210
|
+
counts[path] = text.count(placeholder)
|
|
211
|
+
|
|
212
|
+
if counts[path]:
|
|
213
|
+
write(path, text.replace(placeholder, value))
|
|
214
|
+
|
|
215
|
+
return counts
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def account_problem(repo, other_owner):
|
|
219
|
+
"""Why `repo` (OWNER/REPO) may not be posted to yet, or None: `gh` must
|
|
220
|
+
answer, and an owner other than the logged-in account needs `other_owner`,
|
|
221
|
+
set once the user has confirmed it."""
|
|
222
|
+
|
|
223
|
+
if not shutil.which('gh'):
|
|
224
|
+
return 'gh is not installed'
|
|
225
|
+
|
|
226
|
+
code, login_name, err = run_gh(['api', 'user', '-q', '.login'])
|
|
227
|
+
|
|
228
|
+
if code != 0:
|
|
229
|
+
return 'gh api user failed: {}'.format(err)
|
|
230
|
+
|
|
231
|
+
if repo.split('/')[0] != login_name and not other_owner:
|
|
232
|
+
return ('{} is not {}\'s own account ({}); show the user, then pass '
|
|
233
|
+
'--other-owner'.format(repo.split('/')[0], login_name, repo))
|
|
234
|
+
|
|
235
|
+
return None
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def login():
|
|
239
|
+
"""The account `gh` is logged in as, or None (gh missing or not logged
|
|
240
|
+
in). A read-only call."""
|
|
241
|
+
|
|
242
|
+
if not shutil.which('gh'):
|
|
243
|
+
return None
|
|
244
|
+
|
|
245
|
+
code, out, _ = run_gh(['api', 'user', '-q', '.login'])
|
|
246
|
+
|
|
247
|
+
return out if code == 0 and out else None
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
def can_push(repo):
|
|
251
|
+
"""True, False, or None when unknown: whether the logged-in account may
|
|
252
|
+
push to `repo` (OWNER/REPO), from GitHub's own answer. Read-only."""
|
|
253
|
+
|
|
254
|
+
if not shutil.which('gh'):
|
|
255
|
+
return None
|
|
256
|
+
|
|
257
|
+
code, out, _ = run_gh(['api', 'repos/{}'.format(repo), '-q',
|
|
258
|
+
'.permissions.push'])
|
|
259
|
+
|
|
260
|
+
if code != 0 or out not in ('true', 'false'):
|
|
261
|
+
return None
|
|
262
|
+
|
|
263
|
+
return out == 'true'
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def post_needs(owner_repo, push, fills=()):
|
|
267
|
+
"""The lines a preview prints under `post needs:`, so the user sees what
|
|
268
|
+
the real post will ask for: `--other-owner` when OWNER of `owner_repo`
|
|
269
|
+
(OWNER/REPO, the repository the push lands on) is not the logged-in
|
|
270
|
+
account, the push target (`push`, one line), and what it will fill (a
|
|
271
|
+
list of `(placeholder, path, count)`)."""
|
|
272
|
+
|
|
273
|
+
who = login()
|
|
274
|
+
owner = owner_repo.split('/')[0]
|
|
275
|
+
lines = ['post needs:']
|
|
276
|
+
|
|
277
|
+
if who is None:
|
|
278
|
+
lines.append(' --other-owner: not checked (gh is missing or not '
|
|
279
|
+
'logged in); {} must be your own account or the post needs it'
|
|
280
|
+
.format(owner))
|
|
281
|
+
elif owner != who:
|
|
282
|
+
lines.append(' --other-owner: yes, {} is not {}\'s account; confirm '
|
|
283
|
+
'the repository with the user first'.format(owner, who))
|
|
284
|
+
else:
|
|
285
|
+
lines.append(' --other-owner: no, {} is your account'.format(owner))
|
|
286
|
+
|
|
287
|
+
lines.append(' push: ' + push)
|
|
288
|
+
|
|
289
|
+
for placeholder, path, count in fills:
|
|
290
|
+
lines.append(' fills {} in {}: {} place{}'.format(placeholder, path,
|
|
291
|
+
count, '' if count == 1 else 's'))
|
|
292
|
+
|
|
293
|
+
if not fills:
|
|
294
|
+
lines.append(' fills: no stand-in number in another document')
|
|
295
|
+
|
|
296
|
+
return lines
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
def emit(tool, text, problems, title, out, dropped=(), unused=(), labels=None):
|
|
300
|
+
"""The end of a body renderer: with `out`, the body and its title beside
|
|
301
|
+
it (`title`, else the one stored there), otherwise the body on stdout.
|
|
302
|
+
`problems` (with `.add`) are checked together with the title and, by
|
|
303
|
+
`lint_text.py`, the vocabulary of the body and title; any problem
|
|
304
|
+
writes nothing and returns 1. `dropped` and `unused` are noted on stderr."""
|
|
305
|
+
|
|
306
|
+
title = title or (stored_title(out) if out else None)
|
|
307
|
+
|
|
308
|
+
if out and not title:
|
|
309
|
+
problems.add('--out needs --title: the body is not written without the '
|
|
310
|
+
'title it will be opened with, and none is stored beside it')
|
|
311
|
+
|
|
312
|
+
if title:
|
|
313
|
+
for problem in attribution.title_problems(title):
|
|
314
|
+
problems.add('title: ' + problem)
|
|
315
|
+
|
|
316
|
+
import lint_text
|
|
317
|
+
|
|
318
|
+
for problem in lint_text.problems(text, 'body', labels):
|
|
319
|
+
problems.add(problem)
|
|
320
|
+
|
|
321
|
+
if title:
|
|
322
|
+
for problem in lint_text.problems(title, 'title', labels):
|
|
323
|
+
problems.add(problem)
|
|
324
|
+
|
|
325
|
+
if problems:
|
|
326
|
+
return refuse(tool, problems, 'nothing written')
|
|
327
|
+
|
|
328
|
+
for reason in dropped:
|
|
329
|
+
sys.stderr.write('{}: dropped {}\n'.format(tool, reason))
|
|
330
|
+
|
|
331
|
+
if unused:
|
|
332
|
+
sys.stderr.write('{}: prose fields no rendered section uses: {}\n'.format(
|
|
333
|
+
tool, ', '.join(unused)))
|
|
334
|
+
|
|
335
|
+
if out:
|
|
336
|
+
write_titled(out, title, text)
|
|
337
|
+
|
|
338
|
+
sys.stderr.write('{}: wrote {}\n'.format(tool, out))
|
|
339
|
+
else:
|
|
340
|
+
sys.stdout.write(text)
|
|
341
|
+
|
|
342
|
+
return 0
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
PULL_URL = re.compile(r'https://\S+/(?:pull|issues)/(\d+)')
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
def new_record(repo, url, branch, title, body, **more):
|
|
349
|
+
"""The record of a document just posted: its repository, URL, number,
|
|
350
|
+
branch, title, a digest of title and body, the time, and `more`."""
|
|
351
|
+
|
|
352
|
+
import datetime
|
|
353
|
+
|
|
354
|
+
found = PULL_URL.search(url)
|
|
355
|
+
record = {'repo': repo, 'url': url, 'number': int(found.group(1)) if found
|
|
356
|
+
else None, 'branch': branch, 'title': title, 'digest': digest(title,
|
|
357
|
+
body), 'date': datetime.datetime.now(datetime.timezone.utc).strftime(
|
|
358
|
+
'%Y-%m-%dT%H:%MZ')}
|
|
359
|
+
record.update(more)
|
|
360
|
+
return record
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
def write_record(path, record):
|
|
364
|
+
write(path, json.dumps(record, indent=1) + '\n')
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
def edit_pull(path, record, title, body, body_path, other_owner):
|
|
368
|
+
"""Replace the title and body of the PR `record` (the `pr.json`
|
|
369
|
+
at `path`) describes, and record the new digest. Returns what went wrong,
|
|
370
|
+
or None."""
|
|
371
|
+
|
|
372
|
+
problem = account_problem(record['repo'], other_owner)
|
|
373
|
+
|
|
374
|
+
if problem:
|
|
375
|
+
return problem
|
|
376
|
+
|
|
377
|
+
code, out, err = run_gh(['pr', 'edit', str(record['number']), '--repo',
|
|
378
|
+
record['repo'], '--title', title, '--body-file', body_path])
|
|
379
|
+
|
|
380
|
+
if code != 0:
|
|
381
|
+
return 'gh pr edit failed ({}): {}{}'.format(code, out, err)
|
|
382
|
+
|
|
383
|
+
record.update(title=title, digest=digest(title, body))
|
|
384
|
+
write_record(path, record)
|
|
385
|
+
return None
|