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

Returns a new instance of GitStorage.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'match/lib/match/storage/git_storage.rb', line 35

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)
  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.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_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



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'match/lib/match/storage/git_storage.rb', line 21

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

Instance Method Details

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



99
100
101
102
103
# File 'match/lib/match/storage/git_storage.rb', line 99

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



56
57
58
59
60
61
62
63
64
65
66
67
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
# File 'match/lib/match/storage/git_storage.rb', line 56

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}' '#{self.working_directory}'"
  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
    FastlaneCore::CommandExecutor.execute(command: "GIT_TERMINAL_PROMPT=0 #{command}",
                                        print_all: FastlaneCore::Globals.verbose?,
                                    print_command: FastlaneCore::Globals.verbose?)
  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



114
115
116
117
118
119
120
121
122
# File 'match/lib/match/storage/git_storage.rb', line 114

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

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



105
106
107
108
109
110
111
# File 'match/lib/match/storage/git_storage.rb', line 105

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