Module: OpenStax::Aws::GitHelper

Defined in:
lib/openstax/aws/git_helper.rb

Class Method Summary collapse

Class Method Details

.file_content_at_sha(org_slash_repo:, sha:, path:, github_token: nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/openstax/aws/git_helper.rb', line 10

def self.file_content_at_sha(org_slash_repo:, sha:, path:, github_token: nil )
  if github_token.blank?
    location = "https://raw.githubusercontent.com/#{org_slash_repo}/#{sha}/#{path}"
    file = URI.open(location)
    file.read
  else
    uri = URI("https://raw.githubusercontent.com/#{org_slash_repo}/#{sha}/#{path}")
    Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
      request = Net::HTTP::Get.new uri.request_uri
       request.basic_auth 'token', github_token
       response = http.request request
       response.body
    end
  end
end

.local_repo_sha(path: nil) ⇒ Object



26
27
28
29
# File 'lib/openstax/aws/git_helper.rb', line 26

def self.local_repo_sha(path: nil)
  path ||= Dir.pwd
  ::Git.open(path).revparse('HEAD')
end

.sha_for_branch_name(org_slash_repo:, branch:) ⇒ Object



6
7
8
# File 'lib/openstax/aws/git_helper.rb', line 6

def self.sha_for_branch_name(org_slash_repo:, branch:)
  ::Git.ls_remote("https://github.com/#{org_slash_repo}")["branches"][branch][:sha]
end