Issue.is_pull_request: Bool vs richer pull_request type #55
SeanTAllen
started this conversation in
Research
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The GitHub Issues API (
GET /repos/{owner}/{repo}/issues) returns both issues and pull requests. PRs are distinguishable by the presence of apull_requestobject in the JSON response:{ "number": 42, "title": "Fix the thing", "pull_request": { "url": "https://api.github.com/repos/owner/repo/pulls/42", "html_url": "https://github.com/owner/repo/pull/42", "diff_url": "https://github.com/owner/repo/pull/42.diff", "patch_url": "https://github.com/owner/repo/pull/42.patch", "merged_at": "2024-01-15T10:30:00Z" } }For non-PR issues, this field is absent entirely.
The current implementation (PR #54) adds
is_pull_request: Boolto theIssuemodel. This discussion explores whether that's the right long-term representation.Current approach:
is_pull_request: BoolThe
IssueJsonConverterchecksobj.contains("pull_request")and sets the boolean.How to work around the boolean when you need more
If a caller needs PR details (URLs, merge status), they can use the issue number to fetch the full pull request:
This requires an additional API call per PR, but gives access to the complete
PullRequestmodel.Pros
PullRequestmodel already exists for when full details are neededCons
merged_at,url,html_url,diff_url,patch_urlmerged_atis particularly notable: it's the only way to check merge status without a separate API callGetPullRequestcallAlternative:
pull_request: (PullRequestLinks | None)Checking if an issue is a PR
Pros
merged_atavailable without extra API call(PullRequestLinks | None)naturally handles the "is it a PR?" questionCons
PullRequestLinks) and its converterIssueJsonConverteris_pull_requestboolean check becomes a match expression (slightly more verbose at the call site)Hybrid: both boolean and full type
Could add both
is_pull_request: Bool(convenience) andpull_request: (PullRequestLinks | None)(full data). But this violates DRY sinceis_pull_requestis always equivalent topull_request isnt None.Questions
merged_atan acceptable tradeoff, or is that field important enough to preserve?match issue.pull_request | let _: PullRequestLinks => ...too verbose compared toif issue.is_pull_request then?pull_requestdata?Beta Was this translation helpful? Give feedback.
All reactions