@@ -11,6 +11,8 @@ import (
1111 "strings"
1212 "time"
1313
14+ "github.com/cli/cli/v2/internal/ghinstance"
15+
1416 "github.com/cli/cli/v2/internal/ghrepo"
1517 "github.com/shurcooL/githubv4"
1618)
@@ -524,6 +526,37 @@ func ForkRepo(client *Client, repo ghrepo.Interface, org string) (*Repository, e
524526 }, nil
525527}
526528
529+ // RenameRepo renames the repository on GitHub and returns the renamed repository
530+ func RenameRepo (client * Client , repo ghrepo.Interface , newRepoName string ) (* Repository , error ) {
531+ input := map [string ]string {"name" : newRepoName }
532+ body := & bytes.Buffer {}
533+ enc := json .NewEncoder (body )
534+ if err := enc .Encode (input ); err != nil {
535+ return nil , err
536+ }
537+
538+ path := fmt .Sprintf ("%srepos/%s" ,
539+ ghinstance .RESTPrefix (repo .RepoHost ()),
540+ ghrepo .FullName (repo ))
541+
542+ result := repositoryV3 {}
543+ err := client .REST (repo .RepoHost (), "PATCH" , path , body , & result )
544+ if err != nil {
545+ return nil , err
546+ }
547+
548+ return & Repository {
549+ ID : result .NodeID ,
550+ Name : result .Name ,
551+ CreatedAt : result .CreatedAt ,
552+ Owner : RepositoryOwner {
553+ Login : result .Owner .Login ,
554+ },
555+ ViewerPermission : "WRITE" ,
556+ hostname : repo .RepoHost (),
557+ }, nil
558+ }
559+
527560func LastCommit (client * Client , repo ghrepo.Interface ) (* Commit , error ) {
528561 var responseData struct {
529562 Repository struct {
@@ -983,6 +1016,15 @@ func RepoAndOrgProjects(client *Client, repo ghrepo.Interface) ([]RepoProject, e
9831016type RepoAssignee struct {
9841017 ID string
9851018 Login string
1019+ Name string
1020+ }
1021+
1022+ // DisplayName returns a formatted string that uses Login and Name to be displayed e.g. 'Login (Name)' or 'Login'
1023+ func (ra RepoAssignee ) DisplayName () string {
1024+ if ra .Name != "" {
1025+ return fmt .Sprintf ("%s (%s)" , ra .Login , ra .Name )
1026+ }
1027+ return ra .Login
9861028}
9871029
9881030// RepoAssignableUsers fetches all the assignable users for a repository
@@ -1128,46 +1170,6 @@ func RepoMilestones(client *Client, repo ghrepo.Interface, state string) ([]Repo
11281170 return milestones , nil
11291171}
11301172
1131- func MilestoneByTitle (client * Client , repo ghrepo.Interface , state , title string ) (* RepoMilestone , error ) {
1132- milestones , err := RepoMilestones (client , repo , state )
1133- if err != nil {
1134- return nil , err
1135- }
1136-
1137- for i := range milestones {
1138- if strings .EqualFold (milestones [i ].Title , title ) {
1139- return & milestones [i ], nil
1140- }
1141- }
1142- return nil , fmt .Errorf ("no milestone found with title %q" , title )
1143- }
1144-
1145- func MilestoneByNumber (client * Client , repo ghrepo.Interface , number int32 ) (* RepoMilestone , error ) {
1146- var query struct {
1147- Repository struct {
1148- Milestone * RepoMilestone `graphql:"milestone(number: $number)"`
1149- } `graphql:"repository(owner: $owner, name: $name)"`
1150- }
1151-
1152- variables := map [string ]interface {}{
1153- "owner" : githubv4 .String (repo .RepoOwner ()),
1154- "name" : githubv4 .String (repo .RepoName ()),
1155- "number" : githubv4 .Int (number ),
1156- }
1157-
1158- gql := graphQLClient (client .http , repo .RepoHost ())
1159-
1160- err := gql .QueryNamed (context .Background (), "RepositoryMilestoneByNumber" , & query , variables )
1161- if err != nil {
1162- return nil , err
1163- }
1164- if query .Repository .Milestone == nil {
1165- return nil , fmt .Errorf ("no milestone found with number '%d'" , number )
1166- }
1167-
1168- return query .Repository .Milestone , nil
1169- }
1170-
11711173func ProjectNamesToPaths (client * Client , repo ghrepo.Interface , projectNames []string ) ([]string , error ) {
11721174 var paths []string
11731175 projects , err := RepoAndOrgProjects (client , repo )
0 commit comments