Skip to content

Commit

Permalink
Accept GitHub token from file
Browse files Browse the repository at this point in the history
  • Loading branch information
dmikurube committed Dec 10, 2024
1 parent 8e9ea17 commit 53f2484
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion audit.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
# coding: utf-8
require 'octokit'
require 'minitest'
require 'pathname'
require 'yaml'

SCRIPT_PATH = Pathname.new(__dir__)

include Minitest::Assertions

class << self
attr_accessor :assertions
end
self.assertions = 0

def retrieve_github_token()
token_path = SCRIPT_PATH.join('github_token')
if File.exist?(token_path)
File.open(token_path) do |f|
puts "Found GitHub token file: github_token"
return f.gets
end
end

if ENV.has_key?('GITHUB_TOKEN')
puts "Not found GitHub token file. Using the env: GITHUB_TOKEN"
return ENV.fetch('GITHUB_TOKEN')
end

raise StandardError, "Not found GitHub token token."
end

def assert_repos(expected_repos, actual_repos)
expected_repo_names = expected_repos.map { |node| node[:name] }
actual_repo_names = actual_repos.map { |node| node[:name] }
Expand Down Expand Up @@ -46,7 +66,7 @@ def load_actual_repos(access_token)
end

expected_repos = load_expected_repos("repos.yaml")
actual_repos = load_actual_repos(ENV.fetch('GITHUB_TOKEN'))
actual_repos = load_actual_repos(retrieve_github_token())

puts actual_repos.inspect

Expand Down

0 comments on commit 53f2484

Please sign in to comment.