Sha256: 624d59bdf29c11f25350b284d45fc9846402e354ca880111ba478df91d8a78d2
Contents?: true
Size: 996 Bytes
Versions: 4
Compression:
Stored size: 996 Bytes
Contents
require 'git' require 'open-uri' module OpenStax::Aws module GitHelper def self.sha_for_branch_name(org_slash_repo:, branch:) ::Git.ls_remote("https://github.com/#{org_slash_repo}")["branches"][branch][:sha] end 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 def self.local_repo_sha(path: nil) path ||= Dir.pwd ::Git.open(path).revparse('HEAD') end end end
Version data entries
4 entries across 4 versions & 1 rubygems