Class: Fastlane::Helper::CsvTranslationHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/csv_translation/helper/csv_translation_helper.rb

Class Method Summary collapse

Class Method Details

.append_missing_eof(file_path) ⇒ Object

add missing newline if not present, at the end of the file



48
49
50
51
52
53
54
55
56
57
# File 'lib/fastlane/plugin/csv_translation/helper/csv_translation_helper.rb', line 48

def self.append_missing_eof(file_path)
  File.open(file_path, "r+") do |file|
    file.seek(-1, 2)

    if file.read(1) != "\n"
      file.write("\n")
      file.seek(0)
    end
  end
end

.create_feature_branch(params) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fastlane/plugin/csv_translation/helper/csv_translation_helper.rb', line 34

def self.create_feature_branch(params)
  git_clone_folder = self.fetch_csv_file(params)

  # creating and checkout new branch
  branch_name = params[:feature_branch_name]
  Fastlane::Actions::sh("cd #{git_clone_folder.shellescape} && git checkout -b #{branch_name}")

  # pushing newly created branch
  Fastlane::Actions::sh("cd #{git_clone_folder.shellescape} && git push -u origin #{branch_name}")

  return git_clone_folder
end

.csv_file_directory_nameObject



9
10
11
# File 'lib/fastlane/plugin/csv_translation/helper/csv_translation_helper.rb', line 9

def self.csv_file_directory_name
  return ".fl_clone_csv_file"
end

.csv_file_directory_pathObject



13
14
15
# File 'lib/fastlane/plugin/csv_translation/helper/csv_translation_helper.rb', line 13

def self.csv_file_directory_path
  return File.join(Dir.pwd, self.csv_file_directory_name)
end

.fetch_csv_file(params) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fastlane/plugin/csv_translation/helper/csv_translation_helper.rb', line 17

def self.fetch_csv_file(params)
  repository_name = params[:repository_name]
  branch_name = params[:branch_name]

  # Setup csv_file folder for fresh git clone.
  git_clone_folder = self.csv_file_directory_path
  FileUtils.rm_rf(git_clone_folder) if File.directory?(git_clone_folder)
  Dir.mkdir(self.csv_file_directory_name)

  UI.success("Fetching csv file from git repo... ⏳")
  git_url = "[email protected]:#{repository_name}"
  Fastlane::Actions::sh("git clone #{git_url.shellescape} #{git_clone_folder.shellescape}")
  Fastlane::Actions::sh("cd #{git_clone_folder.shellescape} && git checkout #{branch_name}")

  return git_clone_folder
end