Skip to content

Commit 37f1826

Browse files
authored
Support temporary private fork creation via API (#3025)
Fixes: #3007.
1 parent 2cc47f9 commit 37f1826

File tree

2 files changed

+501
-4
lines changed

2 files changed

+501
-4
lines changed

github/security_advisories.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package github
77

88
import (
99
"context"
10+
"encoding/json"
1011
"fmt"
1112
)
1213

@@ -148,6 +149,36 @@ func (s *SecurityAdvisoriesService) RequestCVE(ctx context.Context, owner, repo,
148149
return resp, nil
149150
}
150151

152+
// CreateTemporaryPrivateFork creates a temporary private fork to collaborate on fixing a security vulnerability in your repository.
153+
// The ghsaID is the GitHub Security Advisory identifier of the advisory.
154+
//
155+
// GitHub API docs: https://docs.github.com/rest/security-advisories/repository-advisories#create-a-temporary-private-fork
156+
//
157+
//meta:operation POST /repos/{owner}/{repo}/security-advisories/{ghsa_id}/forks
158+
func (s *SecurityAdvisoriesService) CreateTemporaryPrivateFork(ctx context.Context, owner, repo, ghsaID string) (*Repository, *Response, error) {
159+
url := fmt.Sprintf("repos/%v/%v/security-advisories/%v/forks", owner, repo, ghsaID)
160+
161+
req, err := s.client.NewRequest("POST", url, nil)
162+
if err != nil {
163+
return nil, nil, err
164+
}
165+
166+
fork := new(Repository)
167+
resp, err := s.client.Do(ctx, req, fork)
168+
if err != nil {
169+
if aerr, ok := err.(*AcceptedError); ok {
170+
if err := json.Unmarshal(aerr.Raw, fork); err != nil {
171+
return fork, resp, err
172+
}
173+
174+
return fork, resp, err
175+
}
176+
return nil, resp, err
177+
}
178+
179+
return fork, resp, nil
180+
}
181+
151182
// ListRepositorySecurityAdvisoriesForOrg lists the repository security advisories for an organization.
152183
//
153184
// GitHub API docs: https://docs.github.com/rest/security-advisories/repository-advisories#list-repository-security-advisories-for-an-organization

0 commit comments

Comments
 (0)