Module: Fastlane::Helper

Defined in:
lib/fastlane/plugin/snapshot_test/helper/helper.rb

Class Method Summary collapse

Class Method Details

.authenticate(gcloud_key_file) ⇒ Object



7
8
9
10
# File 'lib/fastlane/plugin/snapshot_test/helper/helper.rb', line 7

def self.authenticate(gcloud_key_file)
  UI.message "Authenticate with GCP"
  Action.sh("gcloud auth activate-service-account --key-file #{gcloud_key_file}")
end

.calc_aspect_ratio(imagePath) ⇒ Object



37
38
39
40
41
# File 'lib/fastlane/plugin/snapshot_test/helper/helper.rb', line 37

def self.calc_aspect_ratio(imagePath)
  width, height = FastImage.size(imagePath)
  UI.message "Image(#{imagePath}) size #{width} * #{height}"
  height / width.to_f
end

.find_base_commit_hash(bucket_name, base_branch, current_branch) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fastlane/plugin/snapshot_test/helper/helper.rb', line 20

def self.find_base_commit_hash(bucket_name, base_branch, current_branch)
  base_commit_hash = Action.sh("git merge-base origin/#{base_branch} #{current_branch}").chomp!
  dirs = `gsutil ls gs://#{bucket_name}/ | grep -e "/$"`.split("\n")
             .map { |s| s[/(?<=gs:\/\/#{bucket_name}\/)(.*)(?=\/)/] }
  hashes = Action.sh("git log origin/#{base_branch} --pretty=%H").split("\n")
  hashes[hashes.index(base_commit_hash)..-1].each { |hash|
    if dirs.include?(hash)
      return hash
    end
  }
  nil
end

.firebase_object_url(bucket, path) ⇒ Object



33
34
35
# File 'lib/fastlane/plugin/snapshot_test/helper/helper.rb', line 33

def self.firebase_object_url(bucket, path)
  "https://firebasestorage.googleapis.com/v0/b/#{bucket}/o/#{CGI.escape(path)}?alt=media"
end

.get_current_branchObject



16
17
18
# File 'lib/fastlane/plugin/snapshot_test/helper/helper.rb', line 16

def self.get_current_branch
  Action.sh("git symbolic-ref --short HEAD").chomp!
end

.get_current_commit_hashObject



12
13
14
# File 'lib/fastlane/plugin/snapshot_test/helper/helper.rb', line 12

def self.get_current_commit_hash
  Action.sh("git rev-parse HEAD").chomp!
end