MCPcopy Create free account
hub / github.com/cli/cli / RenameRepo

Function RenameRepo

api/queries_repo.go:645–674  ·  view source on GitHub ↗

RenameRepo renames the repository on GitHub and returns the renamed repository

(client *Client, repo ghrepo.Interface, newRepoName string)

Source from the content-addressed store, hash-verified

643
644// RenameRepo renames the repository on GitHub and returns the renamed repository
645func RenameRepo(client *Client, repo ghrepo.Interface, newRepoName string) (*Repository, error) {
646 input := map[string]string{"name": newRepoName}
647 body := &bytes.Buffer{}
648 enc := json.NewEncoder(body)
649 if err := enc.Encode(input); err != nil {
650 return nil, err
651 }
652
653 path, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName())
654 if err != nil {
655 return nil, err
656 }
657
658 result := repositoryV3{}
659 err = client.REST(repo.RepoHost(), http.MethodPatch, path.String(), body, &result)
660 if err != nil {
661 return nil, err
662 }
663
664 return &Repository{
665 ID: result.NodeID,
666 Name: result.Name,
667 CreatedAt: result.CreatedAt,
668 Owner: RepositoryOwner{
669 Login: result.Owner.Login,
670 },
671 ViewerPermission: "WRITE",
672 hostname: repo.RepoHost(),
673 }, nil
674}
675
676func LastCommit(client *Client, repo ghrepo.Interface) (*Commit, error) {
677 var responseData struct {

Callers 2

forkRunFunction · 0.92
renameRunFunction · 0.92

Calls 6

JoinPathFunction · 0.92
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
RESTMethod · 0.65
RepoHostMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected