Skip to content
This repository was archived by the owner on Aug 25, 2024. It is now read-only.

Commit e62ac8c

Browse files
author
john-s-andersen
committed
alice: please: contribute: util: gh: Body from tempfile
Signed-off-by: john-s-andersen <[email protected]>
1 parent af48fd1 commit e62ac8c

File tree

1 file changed

+45
-35
lines changed
  • entities/alice/alice/please/contribute/util

1 file changed

+45
-35
lines changed

entities/alice/alice/please/contribute/util/gh.py

+45-35
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import json
2+
import pathlib
23
import logging
4+
import tempfile
35
from typing import Optional
46

57
import dffml
@@ -11,24 +13,28 @@ async def gh_issue_create(
1113
body: str,
1214
logger: Optional[logging.Logger] = None,
1315
) -> str:
14-
async for event, result in dffml.run_command_events(
15-
[
16-
"gh",
17-
"issue",
18-
"create",
19-
"-R",
20-
repo_url,
21-
"--title",
22-
title,
23-
"--body",
24-
body,
25-
],
26-
logger=logger,
27-
events=[dffml.Subprocess.STDOUT],
28-
):
29-
if event is dffml.Subprocess.STDOUT:
30-
# The URL of the issue created
31-
return result.strip().decode()
16+
# Create tempdir to avoid issue body to long
17+
with tempfile.TemporaryDirectory() as tempdir:
18+
body_path = pathlib.Path(tempdir, "issue_body.txt")
19+
body_path.write_text(body)
20+
async for event, result in dffml.run_command_events(
21+
[
22+
"gh",
23+
"issue",
24+
"create",
25+
"-R",
26+
repo_url,
27+
"--title",
28+
title,
29+
"--body-file",
30+
str(body_path),
31+
],
32+
logger=logger,
33+
events=[dffml.Subprocess.STDOUT],
34+
):
35+
if event is dffml.Subprocess.STDOUT:
36+
# The URL of the issue created
37+
return result.strip().decode()
3238

3339

3440
async def gh_issue_update(
@@ -38,23 +44,27 @@ async def gh_issue_update(
3844
*,
3945
logger: Optional[logging.Logger] = None,
4046
) -> str:
41-
async for event, result in dffml.run_command_events(
42-
[
43-
"gh",
44-
"issue",
45-
"edit",
46-
issue_url,
47-
"--title",
48-
title,
49-
"--body",
50-
body,
51-
],
52-
logger=logger,
53-
events=[dffml.Subprocess.STDOUT],
54-
):
55-
if event is dffml.Subprocess.STDOUT:
56-
# The URL of the issue created
57-
return result.strip().decode()
47+
# Create tempdir to avoid issue body to long
48+
with tempfile.TemporaryDirectory() as tempdir:
49+
body_path = pathlib.Path(tempdir, "issue_body.txt")
50+
body_path.write_text(body)
51+
async for event, result in dffml.run_command_events(
52+
[
53+
"gh",
54+
"issue",
55+
"edit",
56+
issue_url,
57+
"--title",
58+
title,
59+
"--body-file",
60+
str(body_path),
61+
],
62+
logger=logger,
63+
events=[dffml.Subprocess.STDOUT],
64+
):
65+
if event is dffml.Subprocess.STDOUT:
66+
# The URL of the issue created
67+
return result.strip().decode()
5868

5969

6070
async def gh_issue_search_by_title(

0 commit comments

Comments
 (0)