Skip to content
This repository was archived by the owner on Jun 10, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- `--all-repos` option to audit all repositories in the organisation (not just the current repo)
- `--all` option to audit all repositories in the organisation (not only the current repo)
- `--topic` option to filter repositories by GitHub topics (e.g., way-of-working)
- `--name` option to filter repositories by name (supports multiple names)
- `--public` option to filter to only public repositories
- `--fix` option to automatically fix issues where possible (passed to individual rules)

## [1.0.1] - 2025-01-24
Expand Down
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,37 @@ Then to run the GitHub audit for your project, use:
way_of_working exec audit_github
```

By default, the audit runs only against repositories that are configured as git remotes in your current project. To audit all repositories in your organisation, use the `--all-repos` flag:
By default, the audit runs only against repositories that are configured as git remotes in your current project. To audit all repositories in your organisation, use the `--all` flag:

```bash
way_of_working exec audit_github --all-repos
way_of_working exec audit_github --all
```

You can filter repositories by topic using the `--topic` flag. This accepts a single topic and will only audit repositories that have that topic:

```bash
# Audit all repos with the 'way-of-working' topic
way_of_working exec audit_github --all-repos --topic way-of-working
way_of_working exec audit_github --all --topic way-of-working

# Audit all repos with the 'indoor-mapping' topic
way_of_working exec audit_github --all-repos --topic indoor-mapping
way_of_working exec audit_github --all --topic indoor-mapping
```

You can filter repositories by name using the `--name` flag. This accepts one or more repository names and automatically audits all repositories in the organisation (you don't need to specify `--all`):

```bash
# Audit a single repository by name
way_of_working exec audit_github --name structured_store

# Audit multiple repositories by name
way_of_working exec audit_github --name structured_store other_repo
```

You can filter to only public repositories using the `--public` flag:

```bash
# Audit all public repos
way_of_working exec audit_github --all --public
```

To automatically fix issues where possible, use the `--fix` flag:
Expand All @@ -61,7 +78,7 @@ To automatically fix issues where possible, use the `--fix` flag:
way_of_working exec audit_github --fix

# Audit and fix issues in all repos with a specific topic
way_of_working exec audit_github --all-repos --topic way-of-working --fix
way_of_working exec audit_github --all --topic way-of-working --fix
```

Note: The `--fix` flag is passed to individual rules, which may implement automatic fixes for their specific checks. Not all rules support automatic fixing.
Expand Down
56 changes: 39 additions & 17 deletions lib/way_of_working/audit/github/generators/exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,21 @@ module Github
module Generators
# This generator runs the github audit
class Exec < Thor::Group
# argument :all_repos, type: :string, required: false, desc: 'Optional repo to test'
class_option :all, type: :boolean, default: false,
desc: 'Audit all repositories in the organisation (not just this repo)'

class_option :all_repos, type: :boolean, default: false,
desc: 'Audit all repositories in the organisation (not just this repo)'
class_option :fix, type: :boolean, default: false,
desc: 'Attempt to automatically fix issues where possible'

class_option :name, type: :array, default: nil,
desc: 'Filter repositories by name (e.g., structured_store)'

class_option :public, type: :boolean, default: false,
desc: 'Filter to only public repositories'

class_option :topic, type: :string, default: nil,
desc: 'Filter repositories by topic (e.g., way-of-working)'

class_option :fix, type: :boolean, default: false,
desc: 'Attempt to automatically fix issues where possible'

desc 'This runs the github audit on this project'

def check_for_github_token_environment_variables
Expand Down Expand Up @@ -55,20 +59,38 @@ def prep_audit

# Loop though all the repos
@repositories = @auditor.repositories
unless options[:all_repos]
@repositories = @repositories.select do |repo|
github_organisation_remotes.include?(repo.name)
end
rescue Octokit::Unauthorized
abort(Rainbow("\nGITHUB_TOKEN has expired or does not have sufficient permission").red)
end

def filter_all_if_specified
return if options[:all] || options[:name]

@repositories = @repositories.select do |repo|
github_organisation_remotes.include?(repo.name)
end
end

# Filter by topic if specified
if options[:topic]
@repositories = @repositories.select do |repo|
repo.topics.include?(options[:topic])
end
def filter_by_name_array_if_specified
return unless options[:name]

@repositories = @repositories.select do |repo|
options[:name].include?(repo.name)
end
rescue Octokit::Unauthorized
abort(Rainbow("\nGITHUB_TOKEN has expired or does not have sufficient permission").red)
end

def filter_by_topic_if_specified
return unless options[:topic]

@repositories = @repositories.select do |repo|
repo.topics.include?(options[:topic])
end
end

def filter_by_visibility_if_specified
return unless options[:public]

@repositories = @repositories.reject(&:private?)
end

def run_audit
Expand Down
Loading
Loading