@@ -131,10 +131,14 @@ def resolve_parent_issue(metadata, repo, sha):
131131
132132
133133def create_github_issue (repo , title , body , labels , assignees , milestone ):
134- """Create a GitHub issue via the GitHub API. Return (issue_number, issue_url).
134+ """Create a GitHub issue via the GitHub API. Return (issue_number, issue_id, issue_url).
135135
136136 Uses ``gh api`` so the JSON response can be parsed reliably, avoiding any
137137 dependency on the URL format printed by ``gh issue create``.
138+
139+ Returns a 3-tuple: (issue_number, issue_id, issue_url).
140+ ``issue_id`` is the internal integer ID required by the sub-issues API.
141+ ``issue_number`` is the human-readable number shown in the URL.
138142 """
139143 fields = ["-f" , f"title={ title } " , "-f" , f"body={ body } " ]
140144
@@ -156,24 +160,29 @@ def create_github_issue(repo, title, body, labels, assignees, milestone):
156160 f"repos/{ repo } /issues" ,
157161 * fields ,
158162 "--jq" ,
159- ".number,.html_url" ,
163+ ".number,.id,. html_url" ,
160164 )
161165
162166 lines = result .stdout .strip ().splitlines ()
163- if len (lines ) < 2 :
167+ if len (lines ) < 3 :
164168 raise RuntimeError (f"Unexpected response from issues API: { result .stdout !r} " )
165169
166170 issue_number = int (lines [0 ])
167- issue_url = lines [1 ]
168- return issue_number , issue_url
171+ issue_id = int (lines [1 ])
172+ issue_url = lines [2 ]
173+ return issue_number , issue_id , issue_url
169174
170175
171- def add_sub_issue (repo , parent_number , child_number ):
172- """Register child_number as a sub-issue of parent_number.
176+ def add_sub_issue (repo , parent_number , child_issue_id ):
177+ """Register the issue identified by child_issue_id as a sub-issue of parent_number.
173178
174179 Uses the GitHub sub-issues REST API endpoint:
175180 POST /repos/{owner}/{repo}/issues/{issue_number}/sub_issues
176181
182+ ``child_issue_id`` must be the internal integer ID of the issue (the ``.id``
183+ field in the GitHub API response), **not** the human-readable issue number.
184+ See https://docs.github.com/en/rest/issues/sub-issues
185+
177186 This endpoint requires the repository to have the Sub-issues feature
178187 enabled (available on GitHub Team and Enterprise plans, and as a public
179188 beta on some Free plans). If the endpoint is unavailable, a warning is
@@ -187,11 +196,7 @@ def add_sub_issue(repo, parent_number, child_number):
187196 "Accept: application/vnd.github+json" ,
188197 f"repos/{ repo } /issues/{ parent_number } /sub_issues" ,
189198 "-f" ,
190- # The GitHub sub-issues API uses "sub_issue_id" as the field name but
191- # accepts the public issue number (the integer shown in the URL), not
192- # an internal database ID. See:
193- # https://docs.github.com/en/rest/issues/sub-issues
194- f"sub_issue_id={ child_number } " ,
199+ f"sub_issue_id={ child_issue_id } " ,
195200 check = False ,
196201 )
197202 if result .returncode != 0 :
@@ -265,7 +270,7 @@ def main():
265270 milestone = metadata .get ("milestone" )
266271
267272 try :
268- issue_number , issue_url = create_github_issue (
273+ issue_number , issue_id , issue_url = create_github_issue (
269274 repo , title , body , labels , assignees , milestone
270275 )
271276 except RuntimeError as exc :
@@ -276,7 +281,7 @@ def main():
276281 print (f" Created: #{ issue_number } — { issue_url } " )
277282
278283 # --- Sub-issue link ---
279- linked = add_sub_issue (repo , parent_issue , issue_number )
284+ linked = add_sub_issue (repo , parent_issue , issue_id )
280285 if linked :
281286 print (f" Linked as sub-issue of #{ parent_issue } " )
282287
0 commit comments