Class: GitHubGitDownloadStrategy
- Inherits:
-
GitDownloadStrategy
- Object
- AbstractDownloadStrategy
- VCSDownloadStrategy
- GitDownloadStrategy
- GitHubGitDownloadStrategy
- 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
Attributes inherited from AbstractDownloadStrategy
#cache, #cached_location, #source_modified_time, #url
Instance Method Summary collapse
-
#commit_outdated?(commit) ⇒ Boolean
-
#default_branch ⇒ String
-
#default_refspec ⇒ String
-
#github_last_commit ⇒ Object
-
#initialize(url, name, version, **meta) ⇒ GitHubGitDownloadStrategy
constructor
A new instance of GitHubGitDownloadStrategy.
-
#multiple_short_commits_exist?(commit) ⇒ Boolean
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.
1022 1023 1024 1025 1026 1027 1028 1029 |
# File 'download_strategy.rb', line 1022 def initialize(url, name, version, **) super return unless %r{^https?://github\.com/(?<user>[^/]+)/(?<repo>[^/]+)\.git$} =~ @url @user = user @repo = repo end |
Instance Method Details
#commit_outdated?(commit) ⇒ Boolean
1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 |
# File 'download_strategy.rb', line 1061 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 |
#default_branch ⇒ String
1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 |
# File 'download_strategy.rb', line 1088 def default_branch return @default_branch if defined?(@default_branch) command! "git", args: ["remote", "set-head", "origin", "--auto"], chdir: cached_location result = command! "git", args: ["symbolic-ref", "refs/remotes/origin/HEAD"], chdir: cached_location @default_branch = result.stdout[%r{^refs/remotes/origin/(.*)$}, 1] end |
#default_refspec ⇒ String
1079 1080 1081 1082 1083 1084 1085 |
# File 'download_strategy.rb', line 1079 def default_refspec if default_branch "+refs/heads/#{default_branch}:refs/remotes/origin/#{default_branch}" else super end end |
#github_last_commit ⇒ Object
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 |
# File 'download_strategy.rb', line 1031 def github_last_commit # TODO: move to Utils::GitHub 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
1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 |
# File 'download_strategy.rb', line 1048 def multiple_short_commits_exist?(commit) # TODO: move to Utils::GitHub 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 |