Skip to content

Commit b7c2865

Browse files
committed
Remove archived filter from repo list
1 parent 9a149d7 commit b7c2865

File tree

2 files changed

+35
-99
lines changed

2 files changed

+35
-99
lines changed

pkg/cmd/repo/list/http.go

Lines changed: 29 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package list
22

33
import (
4-
"fmt"
54
"strings"
65

76
"github.com/cli/cli/api"
@@ -14,35 +13,21 @@ type RepositoryList struct {
1413
}
1514

1615
func listRepos(client *api.Client, hostname string, limit int, owner string, filter FilterOptions) (*RepositoryList, error) {
17-
type reposBlock struct {
18-
TotalCount int
19-
RepositoryCount int
20-
Nodes []Repository
21-
PageInfo struct {
22-
HasNextPage bool
23-
EndCursor string
24-
}
25-
}
26-
2716
type response struct {
2817
RepositoryOwner struct {
29-
Repositories reposBlock
18+
Repositories struct {
19+
TotalCount int
20+
RepositoryCount int
21+
Nodes []Repository
22+
PageInfo struct {
23+
HasNextPage bool
24+
EndCursor string
25+
}
26+
}
3027
}
31-
Search reposBlock
3228
}
3329

34-
fragment := `
35-
fragment repo on Repository {
36-
nameWithOwner
37-
description
38-
isFork
39-
isPrivate
40-
isArchived
41-
updatedAt
42-
}`
43-
44-
// If `--archived` wasn't specified, use `repositoryOwner.repositores`
45-
query := fragment + `
30+
query := `
4631
query RepoList($owner: String!, $per_page: Int!, $endCursor: String, $fork: Boolean, $privacy: RepositoryPrivacy) {
4732
repositoryOwner(login: $owner) {
4833
repositories(
@@ -54,7 +39,12 @@ func listRepos(client *api.Client, hostname string, limit int, owner string, fil
5439
orderBy: { field: UPDATED_AT, direction: DESC }) {
5540
totalCount
5641
nodes {
57-
...repo
42+
nameWithOwner
43+
description
44+
isFork
45+
isPrivate
46+
isArchived
47+
updatedAt
5848
}
5949
pageInfo {
6050
hasNextPage
@@ -70,59 +60,23 @@ func listRepos(client *api.Client, hostname string, limit int, owner string, fil
7060
}
7161

7262
variables := map[string]interface{}{
63+
"owner": githubv4.String(owner),
7364
"per_page": githubv4.Int(perPage),
7465
"endCursor": (*githubv4.String)(nil),
7566
}
7667

77-
hasArchivedFilter := filter.Archived
78-
79-
if hasArchivedFilter {
80-
// If `--archived` was specified, use the `search` API rather than
81-
// `repositoryOwner.repositories`
82-
query = fragment + `
83-
query RepoList($per_page: Int!, $endCursor: String, $query: String!) {
84-
search(first: $per_page, after:$endCursor, type: REPOSITORY, query: $query) {
85-
repositoryCount
86-
nodes {
87-
... on Repository {
88-
...repo
89-
}
90-
}
91-
pageInfo {
92-
hasNextPage
93-
endCursor
94-
}
95-
}
96-
}`
97-
98-
search := []string{fmt.Sprintf("user:%s archived:true fork:true sort:updated-desc", owner)}
99-
100-
switch filter.Visibility {
101-
case "private":
102-
search = append(search, "is:private")
103-
case "public":
104-
search = append(search, "is:public")
105-
default:
106-
search = append(search, "is:all")
107-
}
108-
109-
variables["query"] = strings.Join(search, " ")
68+
if filter.Visibility != "" {
69+
variables["privacy"] = githubv4.RepositoryPrivacy(strings.ToUpper(filter.Visibility))
11070
} else {
111-
variables["owner"] = githubv4.String(owner)
112-
113-
if filter.Visibility != "" {
114-
variables["privacy"] = githubv4.RepositoryPrivacy(strings.ToUpper(filter.Visibility))
115-
} else {
116-
variables["privacy"] = (*githubv4.RepositoryPrivacy)(nil)
117-
}
71+
variables["privacy"] = (*githubv4.RepositoryPrivacy)(nil)
72+
}
11873

119-
if filter.Fork {
120-
variables["fork"] = githubv4.Boolean(true)
121-
} else if filter.Source {
122-
variables["fork"] = githubv4.Boolean(false)
123-
} else {
124-
variables["fork"] = (*githubv4.Boolean)(nil)
125-
}
74+
if filter.Fork {
75+
variables["fork"] = githubv4.Boolean(true)
76+
} else if filter.Source {
77+
variables["fork"] = githubv4.Boolean(false)
78+
} else {
79+
variables["fork"] = (*githubv4.Boolean)(nil)
12680
}
12781

12882
var repos []Repository
@@ -137,11 +91,7 @@ pagination:
13791
return nil, err
13892
}
13993

140-
if hasArchivedFilter {
141-
repos = append(repos, result.Search.Nodes...)
142-
} else {
143-
repos = append(repos, result.RepositoryOwner.Repositories.Nodes...)
144-
}
94+
repos = append(repos, result.RepositoryOwner.Repositories.Nodes...)
14595

14696
if len(repos) >= limit {
14797
if len(repos) > limit {
@@ -151,21 +101,13 @@ pagination:
151101
}
152102

153103
if !result.RepositoryOwner.Repositories.PageInfo.HasNextPage {
154-
if !result.Search.PageInfo.HasNextPage {
155-
break
156-
}
104+
break
157105
}
158106

159107
variables["endCursor"] = githubv4.String(result.RepositoryOwner.Repositories.PageInfo.EndCursor)
160-
if hasArchivedFilter {
161-
variables["endCursor"] = githubv4.String(result.Search.PageInfo.EndCursor)
162-
}
163108
}
164109

165110
totalCount = result.RepositoryOwner.Repositories.TotalCount
166-
if hasArchivedFilter {
167-
totalCount = result.Search.RepositoryCount
168-
}
169111

170112
listResult := &RepositoryList{
171113
Repositories: repos,

pkg/cmd/repo/list/list.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ type FilterOptions struct {
2020
Visibility string // private, public
2121
Fork bool
2222
Source bool
23-
Archived bool
2423
}
2524

2625
type ListOptions struct {
@@ -33,7 +32,6 @@ type ListOptions struct {
3332
Visibility string
3433
Fork bool
3534
Source bool
36-
Archived bool
3735
}
3836

3937
func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Command {
@@ -43,11 +41,10 @@ func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Comman
4341
}
4442

4543
var (
46-
flagPublic bool
47-
flagPrivate bool
48-
flagSource bool
49-
flagFork bool
50-
flagArchived bool
44+
flagPublic bool
45+
flagPrivate bool
46+
flagSource bool
47+
flagFork bool
5148
)
5249

5350
cmd := &cobra.Command{
@@ -72,7 +69,6 @@ func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Comman
7269
opts.Visibility = "public"
7370
}
7471

75-
opts.Archived = flagArchived
7672
opts.Fork = flagFork
7773
opts.Source = flagSource
7874

@@ -91,7 +87,6 @@ func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Comman
9187
cmd.Flags().BoolVar(&flagPrivate, "private", false, "Show only private repositories")
9288
cmd.Flags().BoolVar(&flagPublic, "public", false, "Show only public repositories")
9389
cmd.Flags().BoolVar(&flagSource, "source", false, "Show only source repositories")
94-
cmd.Flags().BoolVar(&flagArchived, "archived", false, "Show only archived repositories")
9590
cmd.Flags().BoolVar(&flagFork, "fork", false, "Show only forks")
9691

9792
return cmd
@@ -119,7 +114,6 @@ func listRun(opts *ListOptions) error {
119114
Visibility: opts.Visibility,
120115
Fork: opts.Fork,
121116
Source: opts.Source,
122-
Archived: opts.Archived,
123117
}
124118

125119
listResult, err := listRepos(apiClient, ghinstance.OverridableDefault(), opts.Limit, owner, filter)
@@ -131,7 +125,7 @@ func listRun(opts *ListOptions) error {
131125

132126
tp := utils.NewTablePrinter(opts.IO)
133127

134-
notArchived := (filter.Fork || filter.Source) && !filter.Archived
128+
notArchived := filter.Fork || filter.Source
135129

136130
matchCount := len(listResult.Repositories)
137131
now := time.Now()
@@ -172,7 +166,7 @@ func listRun(opts *ListOptions) error {
172166
}
173167

174168
if isTerminal {
175-
hasFilters := filter.Visibility != "" || filter.Fork || filter.Source || filter.Archived
169+
hasFilters := filter.Visibility != "" || filter.Fork || filter.Source
176170
title := listHeader(owner, matchCount, listResult.TotalCount, hasFilters)
177171
fmt.Fprintf(opts.IO.Out, "\n%s\n\n", title)
178172
}

0 commit comments

Comments
 (0)