@@ -209,20 +209,19 @@ public override async Task<List<string>> GetPullRequestsBetweenTagsAsync(Version
209209 /// <returns>List of issue IDs.</returns>
210210 public override async Task < List < string > > GetIssuesForPullRequestAsync ( string pullRequestId )
211211 {
212- // Validate and fetch PR body using GitHub CLI
213- // Arguments: --json body (get body field), --jq .body (extract body value)
214- // Output: raw PR description text which may contain issue references
212+ // Use GitHub API to get issues that are actually linked to close when PR merges
213+ // This is more reliable than parsing PR body text which could contain any #numbers
214+ // Arguments: --json closingIssuesReferences (get linked issues), --jq to extract numbers
215+ // Output: issue numbers (one per line)
215216 var validatedId = ValidateId ( pullRequestId , nameof ( pullRequestId ) ) ;
216- var output = await RunCommandAsync ( "gh" , $ "pr view { validatedId } --json body --jq .body ") ;
217+ var output = await RunCommandAsync ( "gh" , $ "pr view { validatedId } --json closingIssuesReferences --jq .closingIssuesReferences[].number ") ;
217218
218- // Extract issue references (e.g., #123, #456) from PR body text
219- var issues = new List < string > ( ) ;
220- var regex = NumberReferenceRegex ( ) ;
221-
222- foreach ( Match match in regex . Matches ( output ) )
223- {
224- issues . Add ( match . Groups [ 1 ] . Value ) ;
225- }
219+ // Parse output to get issue numbers
220+ var issues = output
221+ . Split ( '\n ' , StringSplitOptions . RemoveEmptyEntries )
222+ . Select ( n => n . Trim ( ) )
223+ . Where ( n => ! string . IsNullOrEmpty ( n ) )
224+ . ToList ( ) ;
226225
227226 return issues ;
228227 }
@@ -326,11 +325,4 @@ public override async Task<List<string>> GetOpenIssuesAsync()
326325 /// <returns>Compiled regular expression.</returns>
327326 [ GeneratedRegex ( @"^\d+$" , RegexOptions . Compiled ) ]
328327 private static partial Regex NumericIdRegex ( ) ;
329-
330- /// <summary>
331- /// Regular expression to match number references (#123).
332- /// </summary>
333- /// <returns>Compiled regular expression.</returns>
334- [ GeneratedRegex ( @"#(\d+)" , RegexOptions . Compiled ) ]
335- private static partial Regex NumberReferenceRegex ( ) ;
336328}
0 commit comments