Skip to content

Commit

Permalink
Merge pull request #28 from mozilla-services/check-if-repos-are-archived
Browse files Browse the repository at this point in the history
Check if repos are archived 🧟
  • Loading branch information
hackebrot authored Nov 19, 2024
2 parents 7341791 + 1ab871f commit 7dd7fc5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
25 changes: 19 additions & 6 deletions ciplatforms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ service,repository
monitor,mozilla/blurts-server
autoconnect,mozilla-services/autopush-rs
autoendpoint,mozilla-services/autopush-rs
contile,mozilla-services/contile
```

Example JSON output format (`services_ciplatforms.json`):
Expand All @@ -111,32 +112,44 @@ Example JSON output format (`services_ciplatforms.json`):
"circle_ci": false,
"gh_actions": true,
"taskcluster": false,
"accessible": true
"accessible": true,
"archived": false
},
{
"service": "autoconnect",
"repository": "mozilla-services/autopush-rs",
"circle_ci": true,
"gh_actions": true,
"taskcluster": false,
"accessible": true
"accessible": true,
"archived": false
},
{
"service": "autoendpoint",
"repository": "mozilla-services/autopush-rs",
"circle_ci": true,
"gh_actions": true,
"taskcluster": false,
"accessible": true
"accessible": true,
"archived": false
},
{
"service": "contile",
"repository": "mozilla-services/contile",
"circle_ci": true,
"gh_actions": false,
"taskcluster": false,
"accessible": true,
"archived": true
}
]
```

This output provides details about the CI platform configuration status of each
repository, including its accessibility (a repository may be inaccessible if it
does not exist or if the provided authentication token lacks access), and flags
indicating the presence of CircleCI, GitHub Actions, and Taskcluster
configuration files.
does not exist or if the provided authentication token lacks access), whether it
has been archived, and flags indicating the presence of CircleCI, GitHub
Actions, and Taskcluster configuration files.

## Docker

Expand Down
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 7dd7fc5

Please sign in to comment.