Class: Match::Storage::GitStorage
- Defined in:
- match/lib/match/storage/git_storage.rb
Overview
Store the code signing identities in a git repo
Constant Summary
Constants inherited from Interface
Interface::MATCH_VERSION_FILE_NAME
Instance Attribute Summary collapse
-
#branch ⇒ Object
Returns the value of attribute branch.
-
#clone_branch_directly ⇒ Object
Returns the value of attribute clone_branch_directly.
-
#git_basic_authorization ⇒ Object
Returns the value of attribute git_basic_authorization.
-
#git_bearer_authorization ⇒ Object
Returns the value of attribute git_bearer_authorization.
-
#git_full_name ⇒ Object
Returns the value of attribute git_full_name.
-
#git_private_key ⇒ Object
Returns the value of attribute git_private_key.
-
#git_url ⇒ Object
User provided values.
-
#git_user_email ⇒ Object
Returns the value of attribute git_user_email.
-
#platform ⇒ Object
Returns the value of attribute platform.
-
#shallow_clone ⇒ Object
Returns the value of attribute shallow_clone.
-
#skip_docs ⇒ Object
Returns the value of attribute skip_docs.
-
#type ⇒ Object
Returns the value of attribute type.
Attributes inherited from Interface
Class Method Summary collapse
Instance Method Summary collapse
- #command_from_private_key(command) ⇒ Object
- #delete_files(files_to_delete: [], custom_message: nil) ⇒ Object
- #download ⇒ Object
-
#generate_commit_message ⇒ Object
Generate the commit message based on the user’s parameters.
- #generate_matchfile_content ⇒ Object
- #human_readable_description ⇒ Object
-
#initialize(type: nil, platform: nil, git_url: nil, shallow_clone: nil, skip_docs: false, branch: "master", git_full_name: nil, git_user_email: nil, clone_branch_directly: false, git_basic_authorization: nil, git_bearer_authorization: nil, git_private_key: nil) ⇒ GitStorage
constructor
A new instance of GitStorage.
- #list_files(file_name: "", file_ext: "") ⇒ Object
- #prefixed_working_directory ⇒ Object
- #upload_files(files_to_upload: [], custom_message: nil) ⇒ Object
Methods inherited from Interface
#clear_changes, #configure, #save_changes!
Constructor Details
#initialize(type: nil, platform: nil, git_url: nil, shallow_clone: nil, skip_docs: false, branch: "master", git_full_name: nil, git_user_email: nil, clone_branch_directly: false, git_basic_authorization: nil, git_bearer_authorization: nil, git_private_key: nil) ⇒ GitStorage
Returns a new instance of GitStorage.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'match/lib/match/storage/git_storage.rb', line 41 def initialize(type: nil, platform: nil, git_url: nil, shallow_clone: nil, skip_docs: false, branch: "master", git_full_name: nil, git_user_email: nil, clone_branch_directly: false, git_basic_authorization: nil, git_bearer_authorization: nil, git_private_key: nil) self.git_url = git_url self.shallow_clone = shallow_clone self.skip_docs = skip_docs self.branch = branch self.git_full_name = git_full_name self.git_user_email = git_user_email self.clone_branch_directly = clone_branch_directly self. = self. = self.git_private_key = git_private_key self.type = type if type self.platform = platform if platform end |
Instance Attribute Details
#branch ⇒ Object
Returns the value of attribute branch.
14 15 16 |
# File 'match/lib/match/storage/git_storage.rb', line 14 def branch @branch end |
#clone_branch_directly ⇒ Object
Returns the value of attribute clone_branch_directly.
17 18 19 |
# File 'match/lib/match/storage/git_storage.rb', line 17 def clone_branch_directly @clone_branch_directly end |
#git_basic_authorization ⇒ Object
Returns the value of attribute git_basic_authorization.
20 21 22 |
# File 'match/lib/match/storage/git_storage.rb', line 20 def @git_basic_authorization end |
#git_bearer_authorization ⇒ Object
Returns the value of attribute git_bearer_authorization.
21 22 23 |
# File 'match/lib/match/storage/git_storage.rb', line 21 def @git_bearer_authorization end |
#git_full_name ⇒ Object
Returns the value of attribute git_full_name.
15 16 17 |
# File 'match/lib/match/storage/git_storage.rb', line 15 def git_full_name @git_full_name end |
#git_private_key ⇒ Object
Returns the value of attribute git_private_key.
22 23 24 |
# File 'match/lib/match/storage/git_storage.rb', line 22 def git_private_key @git_private_key end |
#git_url ⇒ Object
User provided values
11 12 13 |
# File 'match/lib/match/storage/git_storage.rb', line 11 def git_url @git_url end |
#git_user_email ⇒ Object
Returns the value of attribute git_user_email.
16 17 18 |
# File 'match/lib/match/storage/git_storage.rb', line 16 def git_user_email @git_user_email end |
#platform ⇒ Object
Returns the value of attribute platform.
19 20 21 |
# File 'match/lib/match/storage/git_storage.rb', line 19 def platform @platform end |
#shallow_clone ⇒ Object
Returns the value of attribute shallow_clone.
12 13 14 |
# File 'match/lib/match/storage/git_storage.rb', line 12 def shallow_clone @shallow_clone end |
#skip_docs ⇒ Object
Returns the value of attribute skip_docs.
13 14 15 |
# File 'match/lib/match/storage/git_storage.rb', line 13 def skip_docs @skip_docs end |
#type ⇒ Object
Returns the value of attribute type.
18 19 20 |
# File 'match/lib/match/storage/git_storage.rb', line 18 def type @type end |
Class Method Details
.configure(params) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'match/lib/match/storage/git_storage.rb', line 24 def self.configure(params) return self.new( type: params[:type].to_s, platform: params[:platform].to_s, git_url: params[:git_url], shallow_clone: params[:shallow_clone], skip_docs: params[:skip_docs], branch: params[:git_branch], git_full_name: params[:git_full_name], git_user_email: params[:git_user_email], clone_branch_directly: params[:clone_branch_directly], git_basic_authorization: params[:git_basic_authorization], git_bearer_authorization: params[:git_bearer_authorization], git_private_key: params[:git_private_key] ) end |
Instance Method Details
#command_from_private_key(command) ⇒ Object
165 166 167 168 169 170 171 172 173 |
# File 'match/lib/match/storage/git_storage.rb', line 165 def command_from_private_key(command) if File.file?(self.git_private_key) ssh_add = File.(self.git_private_key).shellescape.to_s else UI.("Private key file does not exist, will continue by using it as a raw key.") ssh_add = "- <<< \"#{self.git_private_key}\"" end return "ssh-agent bash -c 'ssh-add #{ssh_add}; #{command}'" end |
#delete_files(files_to_delete: [], custom_message: nil) ⇒ Object
129 130 131 132 133 |
# File 'match/lib/match/storage/git_storage.rb', line 129 def delete_files(files_to_delete: [], custom_message: nil) # No specific list given, e.g. this happens on `fastlane match nuke` # We just want to run `git add -A` to commit everything git_push(commands: ["git add -A"], commit_message: ) end |
#download ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'match/lib/match/storage/git_storage.rb', line 72 def download # Check if we already have a functional working_directory return if @working_directory # No existing working directory, creating a new one now self.working_directory = Dir.mktmpdir command = "git clone #{self.git_url.shellescape} #{self.working_directory.shellescape}" # HTTP headers are supposed to be be case insensitive but # Bitbucket requires `Authorization: Basic` and `Authorization Bearer` to work # https://github.com/fastlane/fastlane/pull/15928 command << " -c http.extraheader='Authorization: Basic #{self.}'" unless self..nil? command << " -c http.extraheader='Authorization: Bearer #{self.}'" unless self..nil? if self.shallow_clone command << " --depth 1 --no-single-branch" elsif self.clone_branch_directly command += " -b #{self.branch.shellescape} --single-branch" end command = command_from_private_key(command) unless self.git_private_key.nil? UI.("Cloning remote git repo...") if self.branch && !self.clone_branch_directly UI.("If cloning the repo takes too long, you can use the `clone_branch_directly` option in match.") end begin # GIT_TERMINAL_PROMPT will fail the `git clone` command if user credentials are missing Helper.with_env_values('GIT_TERMINAL_PROMPT' => '0') do FastlaneCore::CommandExecutor.execute(command: command, print_all: FastlaneCore::Globals.verbose?, print_command: FastlaneCore::Globals.verbose?) end rescue UI.error("Error cloning certificates repo, please make sure you have read access to the repository you want to use") if self.branch && self.clone_branch_directly UI.error("You passed '#{self.branch}' as branch in combination with the `clone_branch_directly` flag. Please remove `clone_branch_directly` flag on the first run for _match_ to create the branch.") end UI.error("Run the following command manually to make sure you're properly authenticated:") UI.command(command) UI.user_error!("Error cloning certificates git repo, please make sure you have access to the repository - see instructions above") end add_user_config(self.git_full_name, self.git_user_email) unless File.directory?(self.working_directory) UI.user_error!("Error cloning repo, make sure you have access to it '#{self.git_url}'") end checkout_branch end |
#generate_commit_message ⇒ Object
Generate the commit message based on the user’s parameters
144 145 146 147 148 149 150 151 152 |
# File 'match/lib/match/storage/git_storage.rb', line 144 def [ "[fastlane]", "Updated", self.type, "and platform", self.platform ].join(" ") end |
#generate_matchfile_content ⇒ Object
154 155 156 157 158 159 |
# File 'match/lib/match/storage/git_storage.rb', line 154 def generate_matchfile_content UI.important("Please create a new, private git repository to store the certificates and profiles there") url = UI.input("URL of the Git Repo: ") return "git_url(\"#{url}\")" end |
#human_readable_description ⇒ Object
125 126 127 |
# File 'match/lib/match/storage/git_storage.rb', line 125 def human_readable_description "Git Repo [#{self.git_url}]" end |
#list_files(file_name: "", file_ext: "") ⇒ Object
161 162 163 |
# File 'match/lib/match/storage/git_storage.rb', line 161 def list_files(file_name: "", file_ext: "") Dir[File.join(working_directory, "**", file_name, "*.#{file_ext}")] end |
#prefixed_working_directory ⇒ Object
68 69 70 |
# File 'match/lib/match/storage/git_storage.rb', line 68 def prefixed_working_directory return working_directory end |
#upload_files(files_to_upload: [], custom_message: nil) ⇒ Object
135 136 137 138 139 140 141 |
# File 'match/lib/match/storage/git_storage.rb', line 135 def upload_files(files_to_upload: [], custom_message: nil) commands = files_to_upload.map do |current_file| "git add #{current_file.shellescape}" end git_push(commands: commands, commit_message: ) end |