Skip to content

Commit dd0d236

Browse files
committed
Merge remote-tracking branch 'origin' into ghe-api
2 parents 8763279 + 9035418 commit dd0d236

File tree

14 files changed

+647
-560
lines changed

14 files changed

+647
-560
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@ Install and upgrade:
139139

140140
### Arch Linux
141141

142-
Arch Linux users can install from the AUR: https://aur.archlinux.org/packages/github-cli/
142+
Arch Linux users can install from the community repo: https://www.archlinux.org/packages/community/x86_64/github-cli/
143143

144144
```bash
145-
yay -S github-cli
145+
pacman -S github-cli
146146
```
147147

148148
### Other platforms

api/queries_org.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,11 @@ package api
22

33
import (
44
"context"
5-
"fmt"
65

7-
"github.com/cli/cli/internal/ghinstance"
86
"github.com/cli/cli/internal/ghrepo"
97
"github.com/shurcooL/githubv4"
108
)
119

12-
// using API v3 here because the equivalent in GraphQL needs `read:org` scope
13-
func resolveOrganization(client *Client, orgName string) (string, error) {
14-
var response struct {
15-
NodeID string `json:"node_id"`
16-
}
17-
// TODO: GHE support
18-
err := client.REST(ghinstance.Default(), "GET", fmt.Sprintf("users/%s", orgName), nil, &response)
19-
return response.NodeID, err
20-
}
21-
22-
// using API v3 here because the equivalent in GraphQL needs `read:org` scope
23-
func resolveOrganizationTeam(client *Client, orgName, teamSlug string) (string, string, error) {
24-
var response struct {
25-
NodeID string `json:"node_id"`
26-
Organization struct {
27-
NodeID string `json:"node_id"`
28-
}
29-
}
30-
// TODO: GHE support
31-
err := client.REST(ghinstance.Default(), "GET", fmt.Sprintf("orgs/%s/teams/%s", orgName, teamSlug), nil, &response)
32-
return response.Organization.NodeID, response.NodeID, err
33-
}
34-
3510
// OrganizationProjects fetches all open projects for an organization
3611
func OrganizationProjects(client *Client, repo ghrepo.Interface) ([]RepoProject, error) {
3712
var query struct {

api/queries_repo.go

Lines changed: 4 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"strings"
1111
"time"
1212

13-
"github.com/cli/cli/internal/ghinstance"
1413
"github.com/cli/cli/internal/ghrepo"
1514
"github.com/shurcooL/githubv4"
1615
)
@@ -110,7 +109,7 @@ func GitHubRepo(client *Client, repo ghrepo.Interface) (*Repository, error) {
110109
return nil, err
111110
}
112111

113-
return initRepoHostname(&result.Repository, repo.RepoHost()), nil
112+
return InitRepoHostname(&result.Repository, repo.RepoHost()), nil
114113
}
115114

116115
func RepoDefaultBranch(client *Client, repo ghrepo.Interface) (string, error) {
@@ -251,15 +250,15 @@ func RepoNetwork(client *Client, repos []ghrepo.Interface) (RepoNetworkResult, e
251250
if err := decoder.Decode(&repo); err != nil {
252251
return result, err
253252
}
254-
result.Repositories = append(result.Repositories, initRepoHostname(&repo, hostname))
253+
result.Repositories = append(result.Repositories, InitRepoHostname(&repo, hostname))
255254
} else {
256255
return result, fmt.Errorf("unknown GraphQL result key %q", name)
257256
}
258257
}
259258
return result, nil
260259
}
261260

262-
func initRepoHostname(repo *Repository, hostname string) *Repository {
261+
func InitRepoHostname(repo *Repository, hostname string) *Repository {
263262
repo.hostname = hostname
264263
if repo.Parent != nil {
265264
repo.Parent.hostname = hostname
@@ -339,74 +338,11 @@ func RepoFindFork(client *Client, repo ghrepo.Interface) (*Repository, error) {
339338
// `affiliations` condition, to guard against versions of GitHub with a
340339
// faulty `affiliations` implementation
341340
if len(forks) > 0 && forks[0].ViewerCanPush() {
342-
return initRepoHostname(&forks[0], repo.RepoHost()), nil
341+
return InitRepoHostname(&forks[0], repo.RepoHost()), nil
343342
}
344343
return nil, &NotFoundError{errors.New("no fork found")}
345344
}
346345

347-
// RepoCreateInput represents input parameters for RepoCreate
348-
type RepoCreateInput struct {
349-
Name string `json:"name"`
350-
Visibility string `json:"visibility"`
351-
HomepageURL string `json:"homepageUrl,omitempty"`
352-
Description string `json:"description,omitempty"`
353-
354-
OwnerID string `json:"ownerId,omitempty"`
355-
TeamID string `json:"teamId,omitempty"`
356-
357-
HasIssuesEnabled bool `json:"hasIssuesEnabled"`
358-
HasWikiEnabled bool `json:"hasWikiEnabled"`
359-
}
360-
361-
// RepoCreate creates a new GitHub repository
362-
func RepoCreate(client *Client, input RepoCreateInput) (*Repository, error) {
363-
var response struct {
364-
CreateRepository struct {
365-
Repository Repository
366-
}
367-
}
368-
369-
if input.TeamID != "" {
370-
orgID, teamID, err := resolveOrganizationTeam(client, input.OwnerID, input.TeamID)
371-
if err != nil {
372-
return nil, err
373-
}
374-
input.TeamID = teamID
375-
input.OwnerID = orgID
376-
} else if input.OwnerID != "" {
377-
orgID, err := resolveOrganization(client, input.OwnerID)
378-
if err != nil {
379-
return nil, err
380-
}
381-
input.OwnerID = orgID
382-
}
383-
384-
variables := map[string]interface{}{
385-
"input": input,
386-
}
387-
388-
// TODO: GHE support
389-
hostname := ghinstance.Default()
390-
391-
err := client.GraphQL(hostname, `
392-
mutation RepositoryCreate($input: CreateRepositoryInput!) {
393-
createRepository(input: $input) {
394-
repository {
395-
id
396-
name
397-
owner { login }
398-
url
399-
}
400-
}
401-
}
402-
`, variables, &response)
403-
if err != nil {
404-
return nil, err
405-
}
406-
407-
return initRepoHostname(&response.CreateRepository.Repository, hostname), nil
408-
}
409-
410346
type RepoMetadataResult struct {
411347
AssignableUsers []RepoAssignee
412348
Labels []RepoLabel

api/queries_repo_test.go

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,12 @@
11
package api
22

33
import (
4-
"bytes"
5-
"encoding/json"
6-
"io/ioutil"
74
"testing"
85

96
"github.com/cli/cli/internal/ghrepo"
107
"github.com/cli/cli/pkg/httpmock"
118
)
129

13-
func Test_RepoCreate(t *testing.T) {
14-
http := &httpmock.Registry{}
15-
client := NewClient(ReplaceTripper(http))
16-
17-
http.StubResponse(200, bytes.NewBufferString(`{}`))
18-
19-
input := RepoCreateInput{
20-
Description: "roasted chesnuts",
21-
HomepageURL: "http://example.com",
22-
}
23-
24-
_, err := RepoCreate(client, input)
25-
if err != nil {
26-
t.Fatalf("unexpected error: %v", err)
27-
}
28-
29-
if len(http.Requests) != 1 {
30-
t.Fatalf("expected 1 HTTP request, seen %d", len(http.Requests))
31-
}
32-
33-
var reqBody struct {
34-
Query string
35-
Variables struct {
36-
Input map[string]interface{}
37-
}
38-
}
39-
40-
bodyBytes, _ := ioutil.ReadAll(http.Requests[0].Body)
41-
_ = json.Unmarshal(bodyBytes, &reqBody)
42-
if description := reqBody.Variables.Input["description"].(string); description != "roasted chesnuts" {
43-
t.Errorf("expected description to be %q, got %q", "roasted chesnuts", description)
44-
}
45-
if homepage := reqBody.Variables.Input["homepageUrl"].(string); homepage != "http://example.com" {
46-
t.Errorf("expected homepageUrl to be %q, got %q", "http://example.com", homepage)
47-
}
48-
}
4910
func Test_RepoMetadata(t *testing.T) {
5011
http := &httpmock.Registry{}
5112
client := NewClient(ReplaceTripper(http))

0 commit comments

Comments
 (0)