Skip to content

Commit

Permalink
add filter to GitHub repos query
Browse files Browse the repository at this point in the history
this change excludes archived repos by default
  • Loading branch information
christeredvartsen committed Mar 7, 2024
1 parent 52a7c91 commit 5c161ba
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 20 deletions.
36 changes: 28 additions & 8 deletions internal/graph/gengql/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions internal/graph/github_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@ import (
"github.com/nais/api/internal/slug"
)

func toGraphGitHubRepositories(teamSlug slug.Slug, r *database.ReconcilerState) ([]*model.GitHubRepository, error) {
repos, err := database.GetGitHubRepos(r.Value)
func toGraphGitHubRepositories(teamSlug slug.Slug, state *database.ReconcilerState, filter *model.GitHubRepositoriesFilter) ([]*model.GitHubRepository, error) {
repos, err := database.GetGitHubRepos(state.Value)
if err != nil {
return nil, err
}

ret := make([]*model.GitHubRepository, len(repos))
for i, repo := range repos {
ret[i] = toGraphGitHubRepository(teamSlug, repo)
excludeArchived := filter == nil || filter.IncludeArchivedRepositories == nil || !*filter.IncludeArchivedRepositories

ret := make([]*model.GitHubRepository, 0)
for _, repo := range repos {
if repo.Archived && excludeArchived {
continue
}
ret = append(ret, toGraphGitHubRepository(teamSlug, repo))
}

return ret, nil
Expand Down
4 changes: 2 additions & 2 deletions internal/graph/graphqls/github_repo.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ type GitHubRepositoryPermission {

"Input for filtering GitHub repositories."
input GitHubRepositoriesFilter {
"Include archived repositories or not. Default is false."
includeArchivedRepositories: Boolean!
"Whether or not to include archived repositories. Defaults to false."
includeArchivedRepositories: Boolean
}
5 changes: 4 additions & 1 deletion internal/graph/graphqls/teams.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extend type Query {
"Limit the number of teams to return. Default is 20."
limit: Int

"Filter teams by GitHub repository permissions."
"Filter teams."
filter: TeamsFilter
): TeamList! @auth

Expand Down Expand Up @@ -283,6 +283,9 @@ type Team {

"Limit the number of repositories to return. Default is 20."
limit: Int

"Filter the repositories."
filter: GitHubRepositoriesFilter
): GitHubRepositoryList!

"Slack channel for the team."
Expand Down
4 changes: 2 additions & 2 deletions internal/graph/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions internal/graph/teams.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5c161ba

Please sign in to comment.