Skip to content

Commit

Permalink
feat: Add archived status check to GraphQL query
Browse files Browse the repository at this point in the history
  • Loading branch information
hackebrot committed Nov 19, 2024
1 parent 7341791 commit e77dd25
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions ciplatforms/internal/github/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Repository struct {
GitHubActions bool `json:"gh_actions"`
Taskcluster bool `json:"taskcluster"`
Accessible bool `json:"accessible"`
Archived bool `json:"archived"`
}

// Define the GraphQL query template for batch queries for multiple repos.
Expand All @@ -34,6 +35,7 @@ query {
repo{{ $i }}: repository(owner: "{{ $repo.Owner }}", name: "{{ $repo.Name }}") {
name
owner { login }
isArchived
circleci: object(expression: "HEAD:.circleci/config.yml") {
... on Blob { id }
}
Expand Down Expand Up @@ -162,6 +164,12 @@ func updateRepos(batch []*Repository, data map[string]interface{}) error {
return fmt.Errorf("invalid data format for alias %s (%s/%s): expected a map but got %T", alias, repo.Owner, repo.Name, repoData)
}

if archived, ok := repoDataMap["isArchived"].(bool); ok {
repo.Archived = archived
} else {
log.Printf("[WARNING] 'isArchived' field missing or invalid for repository %s/%s", repo.Owner, repo.Name)
}

// Check if CircleCI configuration file is present
repo.CircleCI = repoDataMap["circleci"] != nil

Expand Down
3 changes: 2 additions & 1 deletion ciplatforms/internal/io/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (c CSVResultWriter) WriteResults(filename string, services []github.Service
defer writer.Flush()

// Write header row
header := []string{"service", "repo", "circleci", "github_actions", "taskcluster", "accessible"}
header := []string{"service", "repo", "circleci", "github_actions", "taskcluster", "accessible", "archived"}
if err := writer.Write(header); err != nil {
return fmt.Errorf("error writing header to CSV file: %w", err)
}
Expand All @@ -52,6 +52,7 @@ func (c CSVResultWriter) WriteResults(filename string, services []github.Service
fmt.Sprintf("%t", service.Repository.GitHubActions),
fmt.Sprintf("%t", service.Repository.Taskcluster),
fmt.Sprintf("%t", service.Repository.Accessible),
fmt.Sprintf("%t", service.Repository.Archived),
}
if err := writer.Write(row); err != nil {
return fmt.Errorf("error writing row to CSV file: %w", err)
Expand Down

0 comments on commit e77dd25

Please sign in to comment.