Skip to content

Commit

Permalink
Consider collaborators, and dump the actual values to actual.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
dmikurube committed Dec 19, 2024
1 parent 0a0cf5f commit 9142f8d
Show file tree
Hide file tree
Showing 3 changed files with 1,228 additions and 88 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/actual.yaml
/github_token

*.gem
Expand Down
28 changes: 27 additions & 1 deletion audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ class << self
end
self.assertions = 0

def sym_to_s(value)
if value.is_a?(Hash)
value.map { |k, v| [ k.to_s, sym_to_s(v) ] }.to_h
elsif value.is_a?(Array)
value.map { |e| sym_to_s(e) }
elsif value.is_a?(Symbol)
value.to_s
else
value
end
end

def retrieve_github_token()
token_path = SCRIPT_PATH.join('github_token')
if File.exist?(token_path)
Expand Down Expand Up @@ -51,6 +63,12 @@ def load_actual_repos(access_token)
repositories(visibility: PUBLIC, first: 100, orderBy: {field: NAME, direction: ASC}, after: $cursor) {
nodes {
name
collaborators {
totalCount
nodes {
login
}
}
visibility
}
pageInfo {
Expand All @@ -66,12 +84,20 @@ def load_actual_repos(access_token)
repositories_array = response_sawyer.data.to_h[:organization][:repositories][:nodes]
repositories = {}
repositories_array.each do |repository|
repositories[repository[:name]] = {}
repositories[repository[:name]] = sym_to_s(repository)
end
return repositories
end

def dump_actual_repos(actual_repos, io)
YAML.dump(actual_repos, io)
end

expected_repos = load_expected_repos("repos.yaml")
actual_repos = load_actual_repos(retrieve_github_token())

File.open("actual.yaml", "w") do |f|
dump_actual_repos(actual_repos, f)
end

assert_repos(expected_repos, actual_repos)
Loading

0 comments on commit 9142f8d

Please sign in to comment.