"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "pkg/cmd/repo/create/http.go" between
gh-cli-1.12.0.tar.gz and gh-cli-1.12.1.tar.gz

About: GitHub CLI is GitHub’s official command line tool.

http.go  (gh-cli-1.12.0):http.go  (gh-cli-1.12.1)
package create package create
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"strings"
"github.com/cli/cli/api" "github.com/cli/cli/api"
) )
// repoCreateInput represents input parameters for repoCreate // repoCreateInput represents input parameters for repoCreate
type repoCreateInput struct { type repoCreateInput struct {
Name string `json:"name"` Name string `json:"name"`
Visibility string `json:"visibility"` Visibility string `json:"visibility"`
HomepageURL string `json:"homepageUrl,omitempty"` HomepageURL string `json:"homepageUrl,omitempty"`
Description string `json:"description,omitempty"` Description string `json:"description,omitempty"`
skipping to change at line 41 skipping to change at line 42
OwnerID string `json:"ownerId,omitempty"` OwnerID string `json:"ownerId,omitempty"`
RepositoryID string `json:"repositoryId,omitempty"` RepositoryID string `json:"repositoryId,omitempty"`
Description string `json:"description,omitempty"` Description string `json:"description,omitempty"`
} }
// repoCreate creates a new GitHub repository // repoCreate creates a new GitHub repository
func repoCreate(client *http.Client, hostname string, input repoCreateInput, tem plateRepositoryID string) (*api.Repository, error) { func repoCreate(client *http.Client, hostname string, input repoCreateInput, tem plateRepositoryID string) (*api.Repository, error) {
apiClient := api.NewClientFromHTTP(client) apiClient := api.NewClientFromHTTP(client)
ownerName := input.OwnerID
isOrg := false
if input.TeamID != "" { if input.TeamID != "" {
orgID, teamID, err := resolveOrganizationTeam(apiClient, hostname , input.OwnerID, input.TeamID) orgID, teamID, err := resolveOrganizationTeam(apiClient, hostname , input.OwnerID, input.TeamID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
input.TeamID = teamID input.TeamID = teamID
input.OwnerID = orgID input.OwnerID = orgID
} else if input.OwnerID != "" { } else if input.OwnerID != "" {
orgID, err := resolveOrganization(apiClient, hostname, input.Owne var orgID string
rID) var err error
orgID, isOrg, err = resolveOrganization(apiClient, hostname, inpu
t.OwnerID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
input.OwnerID = orgID input.OwnerID = orgID
} }
if templateRepositoryID != "" { if templateRepositoryID != "" {
var response struct { var response struct {
CloneTemplateRepository struct { CloneTemplateRepository struct {
Repository api.Repository Repository api.Repository
skipping to change at line 112 skipping to change at line 118
CreateRepository struct { CreateRepository struct {
Repository api.Repository Repository api.Repository
} }
} }
variables := map[string]interface{}{ variables := map[string]interface{}{
"input": input, "input": input,
} }
if input.GitIgnoreTemplate != "" || input.LicenseTemplate != "" { if input.GitIgnoreTemplate != "" || input.LicenseTemplate != "" {
input.Visibility = strings.ToLower(input.Visibility)
body := &bytes.Buffer{} body := &bytes.Buffer{}
enc := json.NewEncoder(body) enc := json.NewEncoder(body)
if err := enc.Encode(input); err != nil { if err := enc.Encode(input); err != nil {
return nil, err return nil, err
} }
repo, err := api.CreateRepoTransformToV4(apiClient, hostname, "PO
ST", "user/repos", body) path := "user/repos"
if isOrg {
path = fmt.Sprintf("orgs/%s/repos", ownerName)
}
repo, err := api.CreateRepoTransformToV4(apiClient, hostname, "PO
ST", path, body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return api.InitRepoHostname(repo, hostname), nil return api.InitRepoHostname(repo, hostname), nil
} }
err := apiClient.GraphQL(hostname, ` err := apiClient.GraphQL(hostname, `
mutation RepositoryCreate($input: CreateRepositoryInput!) { mutation RepositoryCreate($input: CreateRepositoryInput!) {
createRepository(input: $input) { createRepository(input: $input) {
repository { repository {
skipping to change at line 144 skipping to change at line 157
} }
`, variables, &response) `, variables, &response)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return api.InitRepoHostname(&response.CreateRepository.Repository, hostna me), nil return api.InitRepoHostname(&response.CreateRepository.Repository, hostna me), nil
} }
// using API v3 here because the equivalent in GraphQL needs `read:org` scope // using API v3 here because the equivalent in GraphQL needs `read:org` scope
func resolveOrganization(client *api.Client, hostname, orgName string) (string, error) { func resolveOrganization(client *api.Client, hostname, orgName string) (string, bool, error) {
var response struct { var response struct {
NodeID string `json:"node_id"` NodeID string `json:"node_id"`
Type string
} }
err := client.REST(hostname, "GET", fmt.Sprintf("users/%s", orgName), nil , &response) err := client.REST(hostname, "GET", fmt.Sprintf("users/%s", orgName), nil , &response)
return response.NodeID, err return response.NodeID, response.Type == "Organization", err
} }
// using API v3 here because the equivalent in GraphQL needs `read:org` scope // using API v3 here because the equivalent in GraphQL needs `read:org` scope
func resolveOrganizationTeam(client *api.Client, hostname, orgName, teamSlug str ing) (string, string, error) { func resolveOrganizationTeam(client *api.Client, hostname, orgName, teamSlug str ing) (string, string, error) {
var response struct { var response struct {
NodeID string `json:"node_id"` NodeID string `json:"node_id"`
Organization struct { Organization struct {
NodeID string `json:"node_id"` NodeID string `json:"node_id"`
} }
} }
 End of changes. 8 change blocks. 
6 lines changed or deleted 20 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)