File tree Expand file tree Collapse file tree 3 files changed +25
-36
lines changed
Expand file tree Collapse file tree 3 files changed +25
-36
lines changed Original file line number Diff line number Diff line change @@ -88,16 +88,23 @@ func (r Repository) ViewerCanTriage() bool {
8888
8989func GitHubRepo (client * Client , repo ghrepo.Interface ) (* Repository , error ) {
9090 query := `
91+ fragment repo on Repository {
92+ id
93+ name
94+ owner { login }
95+ hasIssuesEnabled
96+ description
97+ viewerPermission
98+ defaultBranchRef {
99+ name
100+ }
101+ }
102+
91103 query RepositoryInfo($owner: String!, $name: String!) {
92104 repository(owner: $owner, name: $name) {
93- id
94- name
95- owner { login }
96- hasIssuesEnabled
97- description
98- viewerPermission
99- defaultBranchRef {
100- name
105+ ...repo
106+ parent {
107+ ...repo
101108 }
102109 }
103110 }`
Original file line number Diff line number Diff line change @@ -126,8 +126,7 @@ func cloneRun(opts *CloneOptions) error {
126126
127127 // Load the repo from the API to get the username/repo name in its
128128 // canonical capitalization
129- var canonicalRepo ghrepo.Interface
130- canonicalRepo , err = api .GitHubRepo (apiClient , repo )
129+ canonicalRepo , err := api .GitHubRepo (apiClient , repo )
131130 if err != nil {
132131 return err
133132 }
@@ -139,18 +138,12 @@ func cloneRun(opts *CloneOptions) error {
139138 }
140139
141140 // If the repo is a fork, add the parent as an upstream
142- var parentRepo ghrepo.Interface
143- parentRepo , err = api .RepoParent (apiClient , canonicalRepo )
144- if err != nil {
145- return err
146- }
147-
148- if parentRepo != nil {
149- protocol , err := cfg .Get (parentRepo .RepoHost (), "git_protocol" )
141+ if canonicalRepo .Parent != nil {
142+ protocol , err := cfg .Get (canonicalRepo .Parent .RepoHost (), "git_protocol" )
150143 if err != nil {
151144 return err
152145 }
153- upstreamURL := ghrepo .FormatRemoteURL (parentRepo , protocol )
146+ upstreamURL := ghrepo .FormatRemoteURL (canonicalRepo . Parent , protocol )
154147
155148 err = git .AddUpstreamRemote (upstreamURL , cloneDir )
156149 if err != nil {
Original file line number Diff line number Diff line change @@ -103,13 +103,6 @@ func Test_RepoClone(t *testing.T) {
103103 }
104104 } } }
105105 ` ))
106- reg .Register (
107- httpmock .GraphQL (`query RepositoryFindParent\b` ),
108- httpmock .StringResponse (`
109- { "data": { "repository": {
110- "parent": null
111- } } }
112- ` ))
113106
114107 httpClient := & http.Client {Transport : reg }
115108
@@ -141,19 +134,15 @@ func Test_RepoClone_hasParent(t *testing.T) {
141134 "name": "REPO",
142135 "owner": {
143136 "login": "OWNER"
137+ },
138+ "parent": {
139+ "name": "ORIG",
140+ "owner": {
141+ "login": "hubot"
142+ }
144143 }
145144 } } }
146145 ` ))
147- reg .Register (
148- httpmock .GraphQL (`query RepositoryFindParent\b` ),
149- httpmock .StringResponse (`
150- { "data": { "repository": {
151- "parent": {
152- "owner": {"login": "hubot"},
153- "name": "ORIG"
154- }
155- } } }
156- ` ))
157146
158147 httpClient := & http.Client {Transport : reg }
159148
You can’t perform that action at this time.
0 commit comments