Class: Match::GitHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/match/git_helper.rb

Class Method Summary collapse

Class Method Details

.clear_changesObject



74
75
76
77
78
79
80
# File 'lib/match/git_helper.rb', line 74

def self.clear_changes
  return unless @dir

  FileUtils.rm_rf(@dir)
  UI.success "🔒  Successfully encrypted certificates repo" # so the user is happy
  @dir = nil
end

.clone(git_url, shallow_clone, manual_password: nil, skip_docs: false) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/match/git_helper.rb', line 3

def self.clone(git_url, shallow_clone, manual_password: nil, skip_docs: false)
  return @dir if @dir

  @dir = Dir.mktmpdir
  command = "git clone '#{git_url}' '#{@dir}'"
  command << " --depth 1" if shallow_clone

  UI.message "Cloning remote git repo..."
  FastlaneCore::CommandExecutor.execute(command: command,
                                      print_all: $verbose,
                                  print_command: $verbose)

  UI.user_error!("Error cloning repo, make sure you have access to it '#{git_url}'") unless File.directory?(@dir)

  if !Helper.test? and GitHelper.match_version(@dir).nil? and manual_password.nil? and File.exist?(File.join(@dir, "README.md"))
    UI.important "Migrating to new match..."
    ChangePassword.update(params: { git_url: git_url,
                             shallow_clone: shallow_clone },
                                      from: "",
                                        to: Encrypt.new.password(git_url))
    return self.clone(git_url, shallow_clone)
  end

  copy_readme(@dir) unless skip_docs
  Encrypt.new.decrypt_repo(path: @dir, git_url: git_url, manual_password: manual_password)

  return @dir
end

.commit_changes(path, message, git_url) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/match/git_helper.rb', line 50

def self.commit_changes(path, message, git_url)
  Dir.chdir(path) do
    return if `git status`.include?("nothing to commit")

    Encrypt.new.encrypt_repo(path: path, git_url: git_url)
    File.write("match_version.txt", Match::VERSION) # unencrypted

    commands = []
    commands << "git add -A"
    commands << "git commit -m '#{message}'"
    commands << "git push origin master"

    UI.message "Pushing changes to remote git repo..."

    commands.each do |command|
      FastlaneCore::CommandExecutor.execute(command: command,
                                          print_all: $verbose,
                                      print_command: $verbose)
    end
  end
  FileUtils.rm_rf(path)
  @dir = nil
end

.copy_readme(directory) ⇒ Object

Copies the README.md into the git repo



83
84
85
86
# File 'lib/match/git_helper.rb', line 83

def self.copy_readme(directory)
  template = File.read("#{Helper.gem_path('match')}/lib/assets/READMETemplate.md")
  File.write(File.join(directory, "README.md"), template)
end

.generate_commit_message(params) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/match/git_helper.rb', line 32

def self.generate_commit_message(params)
  # 'Automatic commit via fastlane'
  [
    "[fastlane]",
    "Updated",
    params[:app_identifier],
    "for",
    params[:type].to_s
  ].join(" ")
end

.match_version(workspace) ⇒ Object



43
44
45
46
47
48
# File 'lib/match/git_helper.rb', line 43

def self.match_version(workspace)
  path = File.join(workspace, "match_version.txt")
  if File.exist?(path)
    Gem::Version.new(File.read(path))
  end
end