Class: Match::Storage::GitStorage

Inherits:
Interface
  • Object
show all
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

Attributes inherited from Interface

#working_directory

Class Method Summary collapse

Instance Method Summary collapse

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) ⇒ GitStorage

Returns a new instance of GitStorage.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'match/lib/match/storage/git_storage.rb', line 39

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)
  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.git_basic_authorization = git_basic_authorization
  self.git_bearer_authorization = git_bearer_authorization

  self.type = type if type
  self.platform = platform if platform
end

Instance Attribute Details

#branchObject

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_directlyObject

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_authorizationObject

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
  @git_basic_authorization
end

#git_bearer_authorizationObject

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
  @git_bearer_authorization
end

#git_full_nameObject

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_urlObject

User provided values



11
12
13
# File 'match/lib/match/storage/git_storage.rb', line 11

def git_url
  @git_url
end

#git_user_emailObject

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

#platformObject

Returns the value of attribute platform.



19
20
21
# File 'match/lib/match/storage/git_storage.rb', line 19

def platform
  @platform
end

#shallow_cloneObject

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_docsObject

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

#typeObject

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



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'match/lib/match/storage/git_storage.rb', line 23

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]
  )
end

Instance Method Details

#delete_files(files_to_delete: [], custom_message: nil) ⇒ Object



123
124
125
126
127
# File 'match/lib/match/storage/git_storage.rb', line 123

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: custom_message)
end

#downloadObject



68
69
70
71
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
# File 'match/lib/match/storage/git_storage.rb', line 68

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.git_basic_authorization}'" unless self.git_basic_authorization.nil?
  command << " -c http.extraheader='Authorization: Bearer #{self.git_bearer_authorization}'" unless self.git_bearer_authorization.nil?

  if self.shallow_clone
    command << " --depth 1 --no-single-branch"
  elsif self.clone_branch_directly
    command += " -b #{self.branch.shellescape} --single-branch"
  end

  UI.message("Cloning remote git repo...")
  if self.branch && !self.clone_branch_directly
    UI.message("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 unless self.branch == "master"
end

#generate_commit_messageObject

Generate the commit message based on the user’s parameters



138
139
140
141
142
143
144
145
146
# File 'match/lib/match/storage/git_storage.rb', line 138

def generate_commit_message
  [
    "[fastlane]",
    "Updated",
    self.type,
    "and platform",
    self.platform
  ].join(" ")
end

#generate_matchfile_contentObject



148
149
150
151
152
153
# File 'match/lib/match/storage/git_storage.rb', line 148

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_descriptionObject



119
120
121
# File 'match/lib/match/storage/git_storage.rb', line 119

def human_readable_description
  "Git Repo [#{self.git_url}]"
end

#prefixed_working_directoryObject



64
65
66
# File 'match/lib/match/storage/git_storage.rb', line 64

def prefixed_working_directory
  return working_directory
end

#upload_files(files_to_upload: [], custom_message: nil) ⇒ Object



129
130
131
132
133
134
135
# File 'match/lib/match/storage/git_storage.rb', line 129

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: custom_message)
end