fastlane-plugin-csv_translation 0.3.0 β†’ 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bad9b02f320e313b6aadeccc265b8d96e6753b2d3750ddf04601cbcd2ef8611f
4
- data.tar.gz: 94690626575fd7853302aad9cad12d813619429550d484c23c09e09e558a1834
3
+ metadata.gz: d0f16b7ee0ca379dd5ea0519771ff45f609c567715fc10e6245175a9dde17571
4
+ data.tar.gz: 4735dd08f4a574bf92d820937a51131a7ea73525801e507ae67bf20f37e01b48
5
5
  SHA512:
6
- metadata.gz: 0af2a8d700c7ed36c93e8faadeb0071c69d7bf715d182cf721d1108d6709c6e9e2c53e59169e917166fd0e54c739feffd70ef1a1e4a7e086cdb35bf7fd6d1d80
7
- data.tar.gz: a51ff28ce777a9a8e881e4309be443723d850e560e432f345c2f0a33c06d753c390af0e360296cef2b0f1d52a8ea0a9c2b2cd8291f3b9a3fd02b9de0c10e6aa4
6
+ metadata.gz: 82be092d741b44d89dbbc1bf0b476575f4a0decb18c3f12583c87904c0de618f18a3d61af94a033099e516fee67ef55d9e06945446c1ed62adfba86acf122e65
7
+ data.tar.gz: 423d5e8a753a5aeb1ccd4a80ecab0e71ed98f2a9b45696c69ab43bf530ff619ffc973bcfe06e24df0a58151efb0e7652f715970a1a15bc812591ffad3ce20f79
data/README.md CHANGED
@@ -28,7 +28,7 @@ This plugin opens up an opportunity to automate reading from/writing of any `CSV
28
28
  <img width="1476" alt="Example CSV" src="https://user-images.githubusercontent.com/5364500/81500222-fe912780-92d0-11ea-87a7-952a78b5cdf7.png">
29
29
 
30
30
  ## Actions
31
- `fastlane-plugin-csv_translation` consists of 3 actions enabling you to manipulate `CSV` file from [`fastlane`](https://fastlane.tools).
31
+ `fastlane-plugin-csv_translation` consists of 4 actions enabling you to manipulate `CSV` file from [`fastlane`](https://fastlane.tools).
32
32
 
33
33
  ### πŸ“‘ get_csv_translation_requests
34
34
  Get all the translation info as hash from the CSV file, **print** the `translation_status` if translation_requests found.
@@ -64,6 +64,19 @@ create_csv_translation_request(
64
64
  )
65
65
  ```
66
66
 
67
+ ### πŸ”rebase_csv_translation_request
68
+ Rebase a translation request entry inside the CSV file. It will append a new row top of target branch in CSV file and then git commit the CSV file changes.
69
+
70
+ ``` ruby
71
+ rebase_csv_translation_request(
72
+ repository_name: "crazymanish/example-csv-repo", # Specify the CSV git file repo
73
+ branch_name: "master", #Specify the target branch (default: master)
74
+ feature_branch_name: "some_feature_branch", #Specify the feature branch name
75
+ file_path: "example.csv", # Specify the CSV file path under the git repo
76
+ identifier: "PRJ-3030" # Specify the CSV row identifier
77
+ )
78
+ ```
79
+
67
80
  ### βœ‚οΈ delete_csv_translation_request
68
81
  Delete a new translation request entry from the CSV file based on CSV row Identifier. It will delete the matched row from the CSV file and then git commit the CSV file changes.
69
82
 
@@ -19,14 +19,25 @@ module Fastlane
19
19
  csv_file_path = "#{csv_file_folder}/#{params[:file_path]}"
20
20
  csv_payload = params[:payload]
21
21
 
22
+ # add missing newline if not present, at the end of the file
23
+ File.open(csv_file_path, "r+") do |csv|
24
+ csv.seek(-1, 2)
25
+
26
+ if csv.read(1) != "\n"
27
+ csv.write("\n")
28
+ csv.seek(0)
29
+ end
30
+ end
31
+
22
32
  # adding new entry into csv file
23
33
  require 'csv'
24
- CSV.open(csv_file_path, 'a+', headers: csv_payload.keys) do |csv|
25
- csv << csv_payload.values
34
+ headers = CSV.open(csv_file_path, &:readline)
35
+ CSV.open(csv_file_path, 'a', headers: headers, force_quotes: true) do |csv|
36
+ csv << csv_payload
26
37
  end
27
38
 
28
39
  # creating csv translation request
29
- git_message = "New translation request: #{csv_payload}"
40
+ git_message = "New translation request:\n#{csv_payload}"
30
41
  git_commit_info = ""
31
42
  Dir.chdir(csv_file_folder) do
32
43
  GitCommitAction.run(path: ".", message: git_message)
@@ -92,12 +103,12 @@ module Fastlane
92
103
  'create_csv_translation_request(
93
104
  repository_name: "fastlane/fastlane",
94
105
  file_path: "translation/some_csv_name.csv",
95
- payload: {header_name: "some_value"})',
106
+ payload: {"header_name" => "some_value"})',
96
107
  'create_csv_translation_request(
97
108
  repository_name: "fastlane/fastlane",
98
109
  branch_name: "master",
99
110
  file_path: "translation/some_csv_name.csv",
100
- payload: {header_name: "some_value"})'
111
+ payload: {"header_name" => "some_value"})'
101
112
  ]
102
113
  end
103
114
 
@@ -26,7 +26,7 @@ module Fastlane
26
26
  translation_requests = CSV.table(csv_file_path, headers: true)
27
27
  translation_requests.delete_if { |row| row.map { |value| value.to_s }.join("").include?(csv_row_identifier) }
28
28
 
29
- CSV.open(csv_file_path, "w", write_headers: true, headers: headers) do |csv|
29
+ CSV.open(csv_file_path, "w", write_headers: true, headers: headers, force_quotes: true) do |csv|
30
30
  translation_requests.each { |translation_request| csv << translation_request }
31
31
  end
32
32
 
@@ -40,14 +40,14 @@ module Fastlane
40
40
  # log message if translation request not found.
41
41
  if is_git_status_clean
42
42
  UI.important("Please check \"#{csv_row_identifier}\", not found the translation request. ⁉️")
43
- end
44
-
45
- git_message = "Deleted translation request: identifier: #{csv_row_identifier}"
46
- GitCommitAction.run(path: ".", message: git_message)
47
- PushToGitRemoteAction.run(remote: "origin")
48
- git_commit_info = Actions.last_git_commit_dict
43
+ else
44
+ git_message = "Deleted translation request: identifier: #{csv_row_identifier}"
45
+ GitCommitAction.run(path: ".", message: git_message)
46
+ PushToGitRemoteAction.run(remote: "origin")
47
+ git_commit_info = Actions.last_git_commit_dict
49
48
 
50
- UI.success("Successfully #{git_message} πŸš€")
49
+ UI.success("Successfully #{git_message} πŸš€")
50
+ end
51
51
  end
52
52
 
53
53
  # building deleted translation request info
@@ -0,0 +1,134 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/csv_translation_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ module SharedValues
7
+ REBASE_CSV_TRANSLATION_REQUEST_INFO = :REBASE_CSV_TRANSLATION_REQUEST_INFO
8
+ end
9
+
10
+ class RebaseCsvTranslationRequestAction < Action
11
+ def self.run(params)
12
+ # fetching csv file
13
+ csv_file_folder = Helper::CsvTranslationHelper.fetch_csv_file(
14
+ repository_name: params[:repository_name],
15
+ branch_name: params[:feature_branch_name]
16
+ )
17
+
18
+ csv_file_path = "#{csv_file_folder}/#{params[:file_path]}"
19
+ csv_row_identifier = params[:identifier]
20
+
21
+ require 'csv'
22
+
23
+ # picking translation request-identifier entry from the feature_branch csv file
24
+ feature_branch_translation_requests = CSV.table(csv_file_path, headers: true)
25
+ feature_branch_translation_requests = feature_branch_translation_requests.select { |row| row.map { |value| value.to_s }.join("").include?(csv_row_identifier) }
26
+
27
+ # rebasing CSV file
28
+ git_commit_info = {}
29
+ Dir.chdir(csv_file_folder) do
30
+ # Step1: Checkout the target branch csv file
31
+ sh("git fetch --all")
32
+ sh("git checkout #{params[:branch_name]} -- #{params[:file_path]}")
33
+
34
+ # Step2: Commit csv file so rebase can be performed
35
+ git_message = "Rebase translation request: identifier:\n#{csv_row_identifier}"
36
+ GitCommitAction.run(path: ".", message: git_message)
37
+
38
+ # Step3: Perfoms rebasing, take all changes from target branch
39
+ sh("git rebase -X theirs " + params[:branch_name])
40
+
41
+ # Step4: Add missing newline if not present, at the end of the file
42
+ Helper::CsvTranslationHelper.append_missing_eof(csv_file_path)
43
+
44
+ # Step5: Append back feature branch translation_requests
45
+ all_translation_requests = CSV.table(csv_file_path, headers: true)
46
+ all_translation_requests.delete_if { |row| row.map { |value| value.to_s }.join("").include?(csv_row_identifier) }
47
+
48
+ headers = CSV.open(csv_file_path, &:readline)
49
+ CSV.open(csv_file_path, "w", write_headers: true, headers: headers, force_quotes: true) do |csv|
50
+ all_translation_requests.each { |translation_request| csv << translation_request }
51
+ feature_branch_translation_requests.each { |translation_request| csv << translation_request }
52
+ end
53
+
54
+ # Step6: Commit and push to remote
55
+ GitCommitAction.run(path: ".", message: git_message)
56
+ PushToGitRemoteAction.run(remote: "origin", force: true)
57
+
58
+ git_commit_info = Actions.last_git_commit_dict
59
+ UI.success("Successfully #{git_message} πŸš€")
60
+ end
61
+
62
+ # building deleted translation request info
63
+ rebase_translation_request_info = {
64
+ identifier: csv_row_identifier,
65
+ git_commit_info: git_commit_info}
66
+
67
+ Actions.lane_context[SharedValues::REBASE_CSV_TRANSLATION_REQUEST_INFO] = rebase_translation_request_info
68
+ return rebase_translation_request_info
69
+ end
70
+
71
+ def self.description
72
+ "Rebase a translation request based on identifier value."
73
+ end
74
+
75
+ def self.output
76
+ [
77
+ ['REBASE_CSV_TRANSLATION_REQUEST_INFO', 'Rebased translation request info i.e identifier, git_commit info']
78
+ ]
79
+ end
80
+
81
+ def self.available_options
82
+ [
83
+ FastlaneCore::ConfigItem.new(key: :repository_name,
84
+ env_name: "FL_REBASE_CSV_TRANSLATION_REQUEST_REPOSITORY_NAME",
85
+ description: "The name to your repository, e.g. 'fastlane/fastlane'",
86
+ verify_block: proc do |value|
87
+ UI.user_error!("No repository_name given in input param") unless (value and not value.empty?)
88
+ end),
89
+ FastlaneCore::ConfigItem.new(key: :branch_name,
90
+ env_name: "FL_REBASE_CSV_TRANSLATION_REQUEST_BRANCH_NAME",
91
+ description: "The branch name to your repository, (default master)",
92
+ is_string: true,
93
+ default_value: "master"),
94
+ FastlaneCore::ConfigItem.new(key: :feature_branch_name,
95
+ env_name: "FL_REBASE_CSV_TRANSLATION_REQUEST_FEATURE_BRANCH_NAME",
96
+ description: "The feature branch name for new translation request (Useful if no direct commit allowed in master)",
97
+ is_string: true),
98
+ FastlaneCore::ConfigItem.new(key: :file_path,
99
+ env_name: "FL_REBASE_CSV_TRANSLATION_REQUEST_FILE_PATH",
100
+ description: "The file path to your csv file",
101
+ is_string: true),
102
+ FastlaneCore::ConfigItem.new(key: :identifier,
103
+ env_name: "FL_REBASE_CSV_TRANSLATION_REQUEST_IDENTIFIER",
104
+ description: "An identifier value of the CSV file row",
105
+ is_string: true)
106
+ ]
107
+ end
108
+
109
+ def self.authors
110
+ ["crazymanish"]
111
+ end
112
+
113
+ def self.example_code
114
+ [
115
+ 'rebase_csv_translation_request(
116
+ repository_name: "fastlane/fastlane",
117
+ feature_branch_name: "some_feature_branch",
118
+ file_path: "translation/some_csv_name.csv",
119
+ identifier: "some_identifier_value")',
120
+ 'rebase_csv_translation_request(
121
+ repository_name: "fastlane/fastlane",
122
+ branch_name: "master",
123
+ feature_branch_name: "some_feature_branch",
124
+ file_path: "translation/some_csv_name.csv",
125
+ identifier: "some_identifier_value")'
126
+ ]
127
+ end
128
+
129
+ def self.is_supported?(platform)
130
+ true
131
+ end
132
+ end
133
+ end
134
+ end
@@ -6,12 +6,12 @@ module Fastlane
6
6
  module Helper
7
7
  class CsvTranslationHelper
8
8
 
9
- def self.csv_file_folder_name
9
+ def self.csv_file_directory_name
10
10
  return ".fl_clone_csv_file"
11
11
  end
12
12
 
13
- def self.csv_file_folder_path
14
- return File.join(Dir.pwd, self.csv_file_folder_name)
13
+ def self.csv_file_directory_path
14
+ return File.join(Dir.pwd, self.csv_file_directory_name)
15
15
  end
16
16
 
17
17
  def self.fetch_csv_file(params)
@@ -19,22 +19,20 @@ module Fastlane
19
19
  branch_name = params[:branch_name]
20
20
 
21
21
  # Setup csv_file folder for fresh git clone.
22
- git_clone_folder = self.csv_file_folder_path
22
+ git_clone_folder = self.csv_file_directory_path
23
23
  FileUtils.rm_rf(git_clone_folder) if File.directory?(git_clone_folder)
24
- Dir.mkdir(self.csv_file_folder_name)
24
+ Dir.mkdir(self.csv_file_directory_name)
25
25
 
26
26
  UI.success("Fetching csv file from git repo... ⏳")
27
- branch_option = "--branch #{branch_name}" if branch_name != 'HEAD'
28
27
  git_url = "git@github.com:#{repository_name}"
29
- Fastlane::Actions::sh("git clone #{git_url.shellescape} #{git_clone_folder.shellescape} --depth 1 -n #{branch_option}")
28
+ Fastlane::Actions::sh("git clone #{git_url.shellescape} #{git_clone_folder.shellescape}")
30
29
  Fastlane::Actions::sh("cd #{git_clone_folder.shellescape} && git checkout #{branch_name}")
31
30
 
32
31
  return git_clone_folder
33
32
  end
34
33
 
35
34
  def self.create_feature_branch(params)
36
- self.fetch_csv_file(params)
37
- git_clone_folder = self.csv_file_folder_path
35
+ git_clone_folder = self.fetch_csv_file(params)
38
36
 
39
37
  # creating and checkout new branch
40
38
  branch_name = params[:feature_branch_name]
@@ -46,6 +44,18 @@ module Fastlane
46
44
  return git_clone_folder
47
45
  end
48
46
 
47
+ # add missing newline if not present, at the end of the file
48
+ def self.append_missing_eof(file_path)
49
+ File.open(file_path, "r+") do |file|
50
+ file.seek(-1, 2)
51
+
52
+ if file.read(1) != "\n"
53
+ file.write("\n")
54
+ file.seek(0)
55
+ end
56
+ end
57
+ end
58
+
49
59
  end
50
60
  end
51
61
  end
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module CsvTranslation
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-csv_translation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manish Rathi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-19 00:00:00.000000000 Z
11
+ date: 2020-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -148,6 +148,7 @@ files:
148
148
  - lib/fastlane/plugin/csv_translation/actions/create_csv_translation_request.rb
149
149
  - lib/fastlane/plugin/csv_translation/actions/delete_csv_translation_request.rb
150
150
  - lib/fastlane/plugin/csv_translation/actions/get_csv_translation_requests.rb
151
+ - lib/fastlane/plugin/csv_translation/actions/rebase_csv_translation_request.rb
151
152
  - lib/fastlane/plugin/csv_translation/helper/csv_translation_helper.rb
152
153
  - lib/fastlane/plugin/csv_translation/version.rb
153
154
  homepage: https://github.com/crazymanish/fastlane-plugin-csv_translation