Class: GitHubGitDownloadStrategy

Inherits:
GitDownloadStrategy show all
Defined in:
download_strategy.rb

Overview

Strategy for downloading a Git repository from GitHub.

Constant Summary

Constants inherited from VCSDownloadStrategy

VCSDownloadStrategy::REF_TYPES

Instance Attribute Summary

Attributes inherited from VCSDownloadStrategy

#last_commit

Attributes inherited from AbstractDownloadStrategy

#cache, #cached_location, #source_modified_time, #url

Instance Method Summary collapse

Methods inherited from GitDownloadStrategy

#last_commit, #source_modified_time

Methods inherited from VCSDownloadStrategy

#fetch, #fetch_last_commit, #head?

Methods inherited from AbstractDownloadStrategy

#basename, #clear_cache, #fetch, #quiet?, #shutup!, #stage

Methods included from Context

current, current=, #debug?, #quiet?, #verbose?, #with_context

Constructor Details

#initialize(url, name, version, **meta) ⇒ GitHubGitDownloadStrategy

Returns a new instance of GitHubGitDownloadStrategy.



993
994
995
996
997
998
999
1000
# File 'download_strategy.rb', line 993

def initialize(url, name, version, **meta)
  super

  return unless %r{^https?://github\.com/(?<user>[^/]+)/(?<repo>[^/]+)\.git$} =~ @url

  @user = user
  @repo = repo
end

Instance Method Details

#commit_outdated?(commit) ⇒ Boolean

Returns:

  • (Boolean)


1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
# File 'download_strategy.rb', line 1030

def commit_outdated?(commit)
  @last_commit ||= github_last_commit
  if @last_commit
    return true unless commit
    return true unless @last_commit.start_with?(commit)

    if multiple_short_commits_exist?(commit)
      true
    else
      version.update_commit(commit)
      false
    end
  else
    super
  end
end

#github_last_commitObject



1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
# File 'download_strategy.rb', line 1002

def github_last_commit
  return if Homebrew::EnvConfig.no_github_api?

  output, _, status = curl_output(
    "--silent", "--head", "--location",
    "-H", "Accept: application/vnd.github.v3.sha",
    "https://api.github.com/repos/#{@user}/#{@repo}/commits/#{@ref}"
  )

  return unless status.success?

  commit = output[/^ETag: "(\h+)"/, 1]
  version.update_commit(commit) if commit
  commit
end

#multiple_short_commits_exist?(commit) ⇒ Boolean

Returns:

  • (Boolean)


1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
# File 'download_strategy.rb', line 1018

def multiple_short_commits_exist?(commit)
  return if Homebrew::EnvConfig.no_github_api?

  output, _, status = curl_output(
    "--silent", "--head", "--location",
    "-H", "Accept: application/vnd.github.v3.sha",
    "https://api.github.com/repos/#{@user}/#{@repo}/commits/#{commit}"
  )

  !(status.success? && output && output[/^Status: (200)/, 1] == "200")
end