-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: Add support for sub-issue #3580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
f2ab5e6
duplicate issue
e7217 f45993e
feat: support sub-issue
e7217 d310482
Merge branch 'master' into feat/add-subissue
e7217 a22cf85
fix: aapply fmt and lint
e7217 7c48809
Update github/sub_issue.go
e7217 5562069
Update github/sub_issue.go
e7217 42e1772
Update github/sub_issue.go
e7217 8c3d97c
Update github/sub_issue.go
e7217 36a4697
Update github/sub_issue.go
e7217 c090164
Update github/sub_issue.go
e7217 4b795b0
Update github/sub_issue.go
e7217 b04e778
Update github/sub_issue_test.go
e7217 42c6b67
fix: update test case
e7217 7d03490
Apply suggestions from code review
e7217 d977c43
fix: update test cases
e7217 f0a4204
fix: remove a header item
e7217 fde3e4b
fix: apply lint
e7217 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| // Copyright 2025 The go-github AUTHORS. All rights reserved. | ||
| // | ||
| // Use of this source code is governed by a BSD-style | ||
| // license that can be found in the LICENSE file. | ||
|
|
||
| package github | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| ) | ||
|
|
||
| // SubIssueService handles communication with the sub-issue related | ||
| // methods of the GitHub API. | ||
| // | ||
| // Sub-issues help you group and manage your issues with a parent/child relationship. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/rest/issues/sub-issues | ||
| type SubIssueService service | ||
|
|
||
| // SubIssue represents a GitHub sub-issue on a repository. | ||
| // Note: As far as the GitHub API is concerned, every pull request is an issue, | ||
| // but not every issue is a pull request. Some endpoints, events, and webhooks | ||
| // may also return pull requests via this struct. If PullRequestLinks is nil, | ||
| // this is an issue, and if PullRequestLinks is not nil, this is a pull request. | ||
| // The IsPullRequest helper method can be used to check that. | ||
| type SubIssue Issue | ||
|
|
||
| func (i SubIssue) String() string { | ||
| return Stringify(i) | ||
| } | ||
|
|
||
| // SubIssueListByIssueOptions specifies the optional parameters to the | ||
| // SubIssueService.ListByIssue method. | ||
| type SubIssueListByIssueOptions struct { | ||
| IssueListByRepoOptions | ||
| } | ||
|
|
||
| // SubIssueRequest represents a request to add, remove, or reprioritize sub-issues. | ||
| type SubIssueRequest struct { | ||
| SubIssueID int64 `json:"sub_issue_id"` // Required: The ID of the sub-issue | ||
| AfterID *int64 `json:"after_id,omitempty"` // Optional: Position after this sub-issue ID | ||
| BeforeID *int64 `json:"before_id,omitempty"` // Optional: Position before this sub-issue ID | ||
| ReplaceParent *bool `json:"replace_parent,omitempty"` // Optional: Whether to replace the existing parent | ||
| } | ||
|
|
||
| // Remove a sub-issue from the specified repository. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/rest/issues/sub-issues#remove-sub-issue | ||
| // | ||
| //meta:operation DELETE /repos/{owner}/{repo}/issues/{issue_number}/sub_issue | ||
| func (s *SubIssueService) Remove(ctx context.Context, owner, repo string, subIssueNumber int64, subIssue SubIssueRequest) (*SubIssue, *Response, error) { | ||
| u := fmt.Sprintf("repos/%v/%v/issues/%v/sub_issues", owner, repo, subIssueNumber) | ||
|
|
||
| req, err := s.client.NewRequest("DELETE", u, subIssue) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| si := new(SubIssue) | ||
| resp, err := s.client.Do(ctx, req, si) | ||
| if err != nil { | ||
| return nil, resp, err | ||
| } | ||
|
|
||
| return si, resp, nil | ||
| } | ||
|
|
||
| // ListByIssue lists all sub-issues for the specified issue. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/rest/issues/sub-issues#list-sub-issues | ||
| // | ||
| //meta:operation GET /repos/{owner}/{repo}/issues/{issue_number}/sub_issues | ||
| func (s *SubIssueService) ListByIssue(ctx context.Context, owner, repo string, issueNumber int64, opts *IssueListOptions) ([]*SubIssue, *Response, error) { | ||
| u := fmt.Sprintf("repos/%v/%v/issues/%v/sub_issues", owner, repo, issueNumber) | ||
| u, err := addOptions(u, opts) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| req, err := s.client.NewRequest("GET", u, nil) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| var subIssues []*SubIssue | ||
| resp, err := s.client.Do(ctx, req, &subIssues) | ||
| if err != nil { | ||
| return nil, resp, err | ||
| } | ||
|
|
||
| return subIssues, resp, nil | ||
| } | ||
|
|
||
| // Add adds a sub-issue to the specified issue. | ||
| // | ||
| // The sub-issue to be added must belong to the same repository owner as the parent issue. | ||
| // To replace the existing parent of a sub-issue, set replaceParent to true. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/rest/issues/sub-issues#add-sub-issue | ||
| // | ||
| //meta:operation POST /repos/{owner}/{repo}/issues/{issue_number}/sub_issues | ||
| func (s *SubIssueService) Add(ctx context.Context, owner, repo string, issueNumber int64, subIssue SubIssueRequest) (*SubIssue, *Response, error) { | ||
| u := fmt.Sprintf("repos/%v/%v/issues/%v/sub_issues", owner, repo, issueNumber) | ||
| req, err := s.client.NewRequest("POST", u, subIssue) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| si := new(SubIssue) | ||
| resp, err := s.client.Do(ctx, req, si) | ||
| if err != nil { | ||
| return nil, resp, err | ||
| } | ||
|
|
||
| return si, resp, nil | ||
| } | ||
|
|
||
| // Reprioritize changes a sub-issue's priority to a different position in the parent list. | ||
| // | ||
| // Either afterId or beforeId must be specified to determine the new position of the sub-issue. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/rest/issues/sub-issues#reprioritize-sub-issue | ||
| // | ||
| //meta:operation PATCH /repos/{owner}/{repo}/issues/{issue_number}/sub_issues/priority | ||
| func (s *SubIssueService) Reprioritize(ctx context.Context, owner, repo string, issueNumber int64, subIssue SubIssueRequest) (*SubIssue, *Response, error) { | ||
| u := fmt.Sprintf("repos/%v/%v/issues/%v/sub_issues/priority", owner, repo, issueNumber) | ||
| req, err := s.client.NewRequest("PATCH", u, subIssue) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| si := new(SubIssue) | ||
| resp, err := s.client.Do(ctx, req, si) | ||
| if err != nil { | ||
| return nil, resp, err | ||
| } | ||
|
|
||
| return si, resp, nil | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.