Skip to content

Commit

Permalink
Support temporary private fork creation via API (#3025)
Browse files Browse the repository at this point in the history
Fixes: #3007.
  • Loading branch information
Kiyo510 authored Dec 15, 2023
1 parent 2cc47f9 commit 37f1826
Show file tree
Hide file tree
Showing 2 changed files with 501 additions and 4 deletions.
31 changes: 31 additions & 0 deletions github/security_advisories.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package github

import (
"context"
"encoding/json"
"fmt"
)

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

// CreateTemporaryPrivateFork creates a temporary private fork to collaborate on fixing a security vulnerability in your repository.
// The ghsaID is the GitHub Security Advisory identifier of the advisory.
//
// GitHub API docs: https://docs.github.com/rest/security-advisories/repository-advisories#create-a-temporary-private-fork
//
//meta:operation POST /repos/{owner}/{repo}/security-advisories/{ghsa_id}/forks
func (s *SecurityAdvisoriesService) CreateTemporaryPrivateFork(ctx context.Context, owner, repo, ghsaID string) (*Repository, *Response, error) {
url := fmt.Sprintf("repos/%v/%v/security-advisories/%v/forks", owner, repo, ghsaID)

req, err := s.client.NewRequest("POST", url, nil)
if err != nil {
return nil, nil, err
}

fork := new(Repository)
resp, err := s.client.Do(ctx, req, fork)
if err != nil {
if aerr, ok := err.(*AcceptedError); ok {
if err := json.Unmarshal(aerr.Raw, fork); err != nil {
return fork, resp, err
}

return fork, resp, err
}
return nil, resp, err
}

return fork, resp, nil
}

// ListRepositorySecurityAdvisoriesForOrg lists the repository security advisories for an organization.
//
// GitHub API docs: https://docs.github.com/rest/security-advisories/repository-advisories#list-repository-security-advisories-for-an-organization
Expand Down
Loading

0 comments on commit 37f1826

Please sign in to comment.