Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions github/github-accessors_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ type Client struct {
Search *SearchService
SecretScanning *SecretScanningService
SecurityAdvisories *SecurityAdvisoriesService
SubIssue *SubIssueService
Teams *TeamsService
Users *UsersService
}
Expand Down Expand Up @@ -458,6 +459,7 @@ func (c *Client) initialize() {
c.Search = (*SearchService)(&c.common)
c.SecretScanning = (*SecretScanningService)(&c.common)
c.SecurityAdvisories = (*SecurityAdvisoriesService)(&c.common)
c.SubIssue = (*SubIssueService)(&c.common)
c.Teams = (*TeamsService)(&c.common)
c.Users = (*UsersService)(&c.common)
}
Expand Down
1 change: 1 addition & 0 deletions github/strings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func TestString(t *testing.T) {
{Hook{ID: Ptr(int64(1))}, `github.Hook{ID:1}`},
{IssueComment{ID: Ptr(int64(1))}, `github.IssueComment{ID:1}`},
{Issue{Number: Ptr(1)}, `github.Issue{Number:1}`},
{SubIssue{ID: Ptr(int64(1))}, `github.SubIssue{ID:1}`},
{Key{ID: Ptr(int64(1))}, `github.Key{ID:1}`},
{Label{ID: Ptr(int64(1)), Name: Ptr("l")}, `github.Label{ID:1, Name:"l"}`},
{Organization{ID: Ptr(int64(1))}, `github.Organization{ID:1}`},
Expand Down
140 changes: 140 additions & 0 deletions github/sub_issue.go
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
}
Loading
Loading