pd1_tools 0.43.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (222) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +12 -0
  3. data/exe/pd1 +8 -0
  4. data/lib/avmtrf1/active_directory/user.rb +28 -0
  5. data/lib/avmtrf1/active_directory.rb +8 -0
  6. data/lib/avmtrf1/ad_user.rb +11 -0
  7. data/lib/avmtrf1/check_point/session/login.rb +57 -0
  8. data/lib/avmtrf1/check_point/session.rb +60 -0
  9. data/lib/avmtrf1/check_point.rb +3 -0
  10. data/lib/avmtrf1/default_esosti.rb +20 -0
  11. data/lib/avmtrf1/default_jira.rb +18 -0
  12. data/lib/avmtrf1/default_redmine.rb +16 -0
  13. data/lib/avmtrf1/docker/image.rb +49 -0
  14. data/lib/avmtrf1/docker/image_runner.rb +83 -0
  15. data/lib/avmtrf1/docker.rb +9 -0
  16. data/lib/avmtrf1/esosti/entities/issue.rb +24 -0
  17. data/lib/avmtrf1/esosti/entities.rb +9 -0
  18. data/lib/avmtrf1/esosti/instance/changed.rb +33 -0
  19. data/lib/avmtrf1/esosti/instance.rb +22 -0
  20. data/lib/avmtrf1/esosti/raw_data_sanitizer.rb +47 -0
  21. data/lib/avmtrf1/esosti/session/action_base.rb +34 -0
  22. data/lib/avmtrf1/esosti/session/atividades.rb +35 -0
  23. data/lib/avmtrf1/esosti/session/login.rb +47 -0
  24. data/lib/avmtrf1/esosti/session/solicitacao/main.rb +49 -0
  25. data/lib/avmtrf1/esosti/session/solicitacao.rb +81 -0
  26. data/lib/avmtrf1/esosti/session.rb +36 -0
  27. data/lib/avmtrf1/esosti.rb +8 -0
  28. data/lib/avmtrf1/executables.rb +23 -0
  29. data/lib/avmtrf1/forponto/parsers/day_registers.rb +19 -0
  30. data/lib/avmtrf1/forponto/parsers/espelho/day_node.rb +50 -0
  31. data/lib/avmtrf1/forponto/parsers/espelho/methods_as_fields.rb +21 -0
  32. data/lib/avmtrf1/forponto/parsers/espelho/row_node.rb +34 -0
  33. data/lib/avmtrf1/forponto/parsers/espelho/rows_consumer.rb +71 -0
  34. data/lib/avmtrf1/forponto/parsers/espelho/sub_node.rb +20 -0
  35. data/lib/avmtrf1/forponto/parsers/espelho/summary_node.rb +55 -0
  36. data/lib/avmtrf1/forponto/parsers/espelho/utils.rb +32 -0
  37. data/lib/avmtrf1/forponto/parsers/espelho.rb +26 -0
  38. data/lib/avmtrf1/forponto/session/day_registers.rb +39 -0
  39. data/lib/avmtrf1/forponto/session/interval.rb +27 -0
  40. data/lib/avmtrf1/forponto/session/login.rb +45 -0
  41. data/lib/avmtrf1/forponto/session.rb +32 -0
  42. data/lib/avmtrf1/forponto/user/balance.rb +155 -0
  43. data/lib/avmtrf1/forponto/user/day_registers.rb +32 -0
  44. data/lib/avmtrf1/forponto/user/month.rb +141 -0
  45. data/lib/avmtrf1/forponto/user.rb +22 -0
  46. data/lib/avmtrf1/git/cached_repository.rb +27 -0
  47. data/lib/avmtrf1/git/gitlab.rb +11 -0
  48. data/lib/avmtrf1/git/issue_on_repository.rb +100 -0
  49. data/lib/avmtrf1/git/push_large/_utils.rb +16 -0
  50. data/lib/avmtrf1/git/push_large/lfs_commit/cache.rb +21 -0
  51. data/lib/avmtrf1/git/push_large/lfs_commit/checkout_previous_revision.rb +35 -0
  52. data/lib/avmtrf1/git/push_large/lfs_commit/commit_changes.rb +48 -0
  53. data/lib/avmtrf1/git/push_large/lfs_commit/helpers.rb +29 -0
  54. data/lib/avmtrf1/git/push_large/lfs_commit/pick_source_revision.rb +103 -0
  55. data/lib/avmtrf1/git/push_large/lfs_commit/push.rb +90 -0
  56. data/lib/avmtrf1/git/push_large/lfs_commit/track_large_files.rb +53 -0
  57. data/lib/avmtrf1/git/push_large/lfs_commit.rb +47 -0
  58. data/lib/avmtrf1/git/push_large/source_commit/push.rb +42 -0
  59. data/lib/avmtrf1/git/push_large/source_commit.rb +58 -0
  60. data/lib/avmtrf1/git/push_large.rb +69 -0
  61. data/lib/avmtrf1/git/reference.rb +34 -0
  62. data/lib/avmtrf1/git.rb +10 -0
  63. data/lib/avmtrf1/gitlab/commit.rb +37 -0
  64. data/lib/avmtrf1/gitlab/repository.rb +41 -0
  65. data/lib/avmtrf1/ini/profile.rb +42 -0
  66. data/lib/avmtrf1/ini.rb +55 -0
  67. data/lib/avmtrf1/inventario_sistemas/parser/body.rb +27 -0
  68. data/lib/avmtrf1/inventario_sistemas/parser/body_row.rb +12 -0
  69. data/lib/avmtrf1/inventario_sistemas/parser/header.rb +38 -0
  70. data/lib/avmtrf1/inventario_sistemas/parser/header_column.rb +27 -0
  71. data/lib/avmtrf1/inventario_sistemas/parser.rb +40 -0
  72. data/lib/avmtrf1/inventario_sistemas/site_build/html_page_base/elements.rb +54 -0
  73. data/lib/avmtrf1/inventario_sistemas/site_build/html_page_base/layout.rb +55 -0
  74. data/lib/avmtrf1/inventario_sistemas/site_build/html_page_base/stylesheet.css +57 -0
  75. data/lib/avmtrf1/inventario_sistemas/site_build/html_page_base.rb +41 -0
  76. data/lib/avmtrf1/inventario_sistemas/site_build/index.rb +20 -0
  77. data/lib/avmtrf1/inventario_sistemas/site_build/sistema.rb +62 -0
  78. data/lib/avmtrf1/inventario_sistemas/site_build/sistemas_index.rb +31 -0
  79. data/lib/avmtrf1/inventario_sistemas/site_build.rb +71 -0
  80. data/lib/avmtrf1/inventario_sistemas.rb +38 -0
  81. data/lib/avmtrf1/issues/factory.rb +22 -0
  82. data/lib/avmtrf1/issues.rb +7 -0
  83. data/lib/avmtrf1/jira/entities/issue.rb +30 -0
  84. data/lib/avmtrf1/jira/entities.rb +9 -0
  85. data/lib/avmtrf1/jira/instance.rb +28 -0
  86. data/lib/avmtrf1/jira.rb +8 -0
  87. data/lib/avmtrf1/node_js/docker_image.rb +14 -0
  88. data/lib/avmtrf1/node_js.rb +9 -0
  89. data/lib/avmtrf1/openvpn/config/builder.rb +59 -0
  90. data/lib/avmtrf1/openvpn/config/parser/builder.rb +62 -0
  91. data/lib/avmtrf1/openvpn/config/parser/line.rb +47 -0
  92. data/lib/avmtrf1/openvpn/config/parser/simple.rb +27 -0
  93. data/lib/avmtrf1/openvpn/config/parser/tag.rb +39 -0
  94. data/lib/avmtrf1/openvpn/config/parser.rb +20 -0
  95. data/lib/avmtrf1/oracle/connection/base.rb +66 -0
  96. data/lib/avmtrf1/oracle/connection/string_builder.rb +44 -0
  97. data/lib/avmtrf1/oracle/connection.rb +12 -0
  98. data/lib/avmtrf1/oracle/object/base.rb +39 -0
  99. data/lib/avmtrf1/oracle/object/table.rb +15 -0
  100. data/lib/avmtrf1/oracle/object/user.rb +15 -0
  101. data/lib/avmtrf1/oracle/object/view.rb +15 -0
  102. data/lib/avmtrf1/oracle/object.rb +25 -0
  103. data/lib/avmtrf1/oracle/objects/relation.rb +23 -0
  104. data/lib/avmtrf1/oracle/objects/sql_builder.rb +64 -0
  105. data/lib/avmtrf1/oracle/objects.rb +53 -0
  106. data/lib/avmtrf1/oracle/oci8.rb +29 -0
  107. data/lib/avmtrf1/oracle.rb +10 -0
  108. data/lib/avmtrf1/patches/avm/git/issue/complete.rb +50 -0
  109. data/lib/avmtrf1/patches/avm/git/issue.rb +4 -0
  110. data/lib/avmtrf1/patches/avm/git/launcher/base.rb +46 -0
  111. data/lib/avmtrf1/patches/avm/git/launcher.rb +4 -0
  112. data/lib/avmtrf1/patches/avm/git.rb +4 -0
  113. data/lib/avmtrf1/patches/avm.rb +4 -0
  114. data/lib/avmtrf1/patches/inifile.rb +13 -0
  115. data/lib/avmtrf1/patches.rb +4 -0
  116. data/lib/avmtrf1/php/docker_images/base.rb +49 -0
  117. data/lib/avmtrf1/php/docker_images/factory.rb +37 -0
  118. data/lib/avmtrf1/php/docker_images/v5.rb +47 -0
  119. data/lib/avmtrf1/php/docker_images/v7.rb +27 -0
  120. data/lib/avmtrf1/php/docker_images/v7_v4.rb +30 -0
  121. data/lib/avmtrf1/php/docker_images/v8.rb +19 -0
  122. data/lib/avmtrf1/php/docker_images.rb +11 -0
  123. data/lib/avmtrf1/php.rb +9 -0
  124. data/lib/avmtrf1/red/client/authorization.xml.erb +4 -0
  125. data/lib/avmtrf1/red/client.rb +38 -0
  126. data/lib/avmtrf1/red/helper.rb +35 -0
  127. data/lib/avmtrf1/red/profile/put_file.xml.erb +19 -0
  128. data/lib/avmtrf1/red/profile.rb +58 -0
  129. data/lib/avmtrf1/red/server.rb +33 -0
  130. data/lib/avmtrf1/red.rb +5 -0
  131. data/lib/avmtrf1/redmine/entities/issue.rb +29 -0
  132. data/lib/avmtrf1/redmine/entities/issue_status.rb +23 -0
  133. data/lib/avmtrf1/redmine/entities.rb +10 -0
  134. data/lib/avmtrf1/redmine/instance.rb +41 -0
  135. data/lib/avmtrf1/redmine.rb +7 -0
  136. data/lib/avmtrf1/rest_provider/entity.rb +18 -0
  137. data/lib/avmtrf1/rest_provider/instance/issues.rb +30 -0
  138. data/lib/avmtrf1/rest_provider/instance.rb +30 -0
  139. data/lib/avmtrf1/rest_provider/request.rb +44 -0
  140. data/lib/avmtrf1/rest_provider/response.rb +73 -0
  141. data/lib/avmtrf1/rest_provider.rb +7 -0
  142. data/lib/avmtrf1/result.rb +44 -0
  143. data/lib/avmtrf1/ruby.rb +9 -0
  144. data/lib/avmtrf1/tools/application.rb +13 -0
  145. data/lib/avmtrf1/tools/core_ext.rb +4 -0
  146. data/lib/avmtrf1/tools/msgraph/api/entity.rb +35 -0
  147. data/lib/avmtrf1/tools/msgraph/api/member.rb +31 -0
  148. data/lib/avmtrf1/tools/msgraph/api/root.rb +27 -0
  149. data/lib/avmtrf1/tools/msgraph/api/team/member_add.rb +36 -0
  150. data/lib/avmtrf1/tools/msgraph/api/team.rb +40 -0
  151. data/lib/avmtrf1/tools/msgraph/api.rb +55 -0
  152. data/lib/avmtrf1/tools/msgraph/error.rb +31 -0
  153. data/lib/avmtrf1/tools/msgraph/request_mixin.rb +18 -0
  154. data/lib/avmtrf1/tools/msgraph/response_mixin.rb +23 -0
  155. data/lib/avmtrf1/tools/msgraph/token_retrieve.rb +42 -0
  156. data/lib/avmtrf1/tools/msgraph.rb +11 -0
  157. data/lib/avmtrf1/tools/rubygems/dependency.rb +20 -0
  158. data/lib/avmtrf1/tools/rubygems/not_found_error.rb +17 -0
  159. data/lib/avmtrf1/tools/rubygems.rb +11 -0
  160. data/lib/avmtrf1/tools/runner/check_point/login.rb +33 -0
  161. data/lib/avmtrf1/tools/runner/check_point.rb +17 -0
  162. data/lib/avmtrf1/tools/runner/esosti/changed.rb +39 -0
  163. data/lib/avmtrf1/tools/runner/esosti/fetch.rb +39 -0
  164. data/lib/avmtrf1/tools/runner/esosti/request.rb +76 -0
  165. data/lib/avmtrf1/tools/runner/esosti.rb +27 -0
  166. data/lib/avmtrf1/tools/runner/forponto/espelho.rb +47 -0
  167. data/lib/avmtrf1/tools/runner/forponto/marcacoes.rb +32 -0
  168. data/lib/avmtrf1/tools/runner/forponto/resumos.rb +87 -0
  169. data/lib/avmtrf1/tools/runner/forponto/saldo.rb +91 -0
  170. data/lib/avmtrf1/tools/runner/forponto.rb +70 -0
  171. data/lib/avmtrf1/tools/runner/git/gitlab/commit_link.rb +81 -0
  172. data/lib/avmtrf1/tools/runner/git/gitlab.rb +20 -0
  173. data/lib/avmtrf1/tools/runner/git/issues_check.rb +59 -0
  174. data/lib/avmtrf1/tools/runner/git/push_large.rb +46 -0
  175. data/lib/avmtrf1/tools/runner/git.rb +14 -0
  176. data/lib/avmtrf1/tools/runner/inventario_sistemas.rb +71 -0
  177. data/lib/avmtrf1/tools/runner/msgraph/joined_teams.rb +39 -0
  178. data/lib/avmtrf1/tools/runner/msgraph/request.rb +45 -0
  179. data/lib/avmtrf1/tools/runner/msgraph/team/member/add.rb +48 -0
  180. data/lib/avmtrf1/tools/runner/msgraph/team/member.rb +25 -0
  181. data/lib/avmtrf1/tools/runner/msgraph/team/members.rb +38 -0
  182. data/lib/avmtrf1/tools/runner/msgraph/team.rb +27 -0
  183. data/lib/avmtrf1/tools/runner/msgraph/token.rb +31 -0
  184. data/lib/avmtrf1/tools/runner/msgraph.rb +43 -0
  185. data/lib/avmtrf1/tools/runner/node_js/docker.rb +15 -0
  186. data/lib/avmtrf1/tools/runner/node_js.rb +18 -0
  187. data/lib/avmtrf1/tools/runner/openvpn.rb +91 -0
  188. data/lib/avmtrf1/tools/runner/oracle/query.rb +71 -0
  189. data/lib/avmtrf1/tools/runner/oracle/source_get.rb +51 -0
  190. data/lib/avmtrf1/tools/runner/oracle/user_clear.rb +59 -0
  191. data/lib/avmtrf1/tools/runner/oracle.rb +37 -0
  192. data/lib/avmtrf1/tools/runner/php/docker.rb +20 -0
  193. data/lib/avmtrf1/tools/runner/php.rb +18 -0
  194. data/lib/avmtrf1/tools/runner/red.rb +83 -0
  195. data/lib/avmtrf1/tools/runner/source.rb +14 -0
  196. data/lib/avmtrf1/tools/runner.rb +43 -0
  197. data/lib/avmtrf1/tools.rb +4 -0
  198. data/lib/pd1_tools/version.rb +5 -0
  199. data/lib/pd1_tools.rb +7 -0
  200. data/template/avmtrf1/node_js/docker_image/Dockerfile.template +25 -0
  201. data/template/avmtrf1/node_js/docker_image/auxiliary/config_banner.sh +15 -0
  202. data/template/avmtrf1/node_js/docker_image/auxiliary/init.sh +18 -0
  203. data/template/avmtrf1/node_js/docker_image/auxiliary/lib.sh +30 -0
  204. data/template/avmtrf1/node_js/docker_image/auxiliary/ng_serve.sh +16 -0
  205. data/template/avmtrf1/node_js/docker_image/auxiliary/npm_install.sh +21 -0
  206. data/template/avmtrf1/node_js/docker_image/auxiliary/start.sh +17 -0
  207. data/template/avmtrf1/php/docker_images/base/Dockerfile.template +104 -0
  208. data/template/avmtrf1/php/docker_images/base/aux/apache_foreground.sh +16 -0
  209. data/template/avmtrf1/php/docker_images/base/aux/apache_user.sh +54 -0
  210. data/template/avmtrf1/php/docker_images/base/aux/app_user_run.sh +17 -0
  211. data/template/avmtrf1/php/docker_images/base/aux/config_banner.sh +20 -0
  212. data/template/avmtrf1/php/docker_images/base/aux/init.sh +39 -0
  213. data/template/avmtrf1/php/docker_images/base/aux/laravel.sh +58 -0
  214. data/template/avmtrf1/php/docker_images/base/aux/lib.sh +70 -0
  215. data/template/avmtrf1/php/docker_images/base/aux/pear.sh +35 -0
  216. data/template/avmtrf1/php/docker_images/base/aux/php_composer.sh +31 -0
  217. data/template/avmtrf1/php/docker_images/base/aux/php_values.sh +41 -0
  218. data/template/avmtrf1/php/docker_images/base/aux/setup_apache_site.sh +16 -0
  219. data/template/avmtrf1/php/docker_images/base/aux/start.sh +26 -0
  220. data/template/avmtrf1/php/docker_images/base/aux/templates/apache_site.conf +12 -0
  221. data/template/avmtrf1/tools/msgraph/token_retrieve/python_retriever.py +85 -0
  222. metadata +460 -0
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avmtrf1
4
+ module Git
5
+ class PushLarge
6
+ class LfsCommit
7
+ module PickSourceRevision
8
+ private
9
+
10
+ def add_cacheinfo_fail?(result)
11
+ !result.fetch(:exit_code).zero? && result.fetch(:stderr).include?('add_cacheinfo')
12
+ end
13
+
14
+ def cherry_pick_source_revision_uncached
15
+ checkout_base
16
+ return if previous_revision.blank?
17
+
18
+ infom message("Cherry pick #{source_commit.sha1}")
19
+ result = git.execute('cherry-pick', '--allow-empty', '--allow-empty-message',
20
+ '-Xtheirs', source_commit.sha1)
21
+ check_cherry_pick_result(result)
22
+ end
23
+
24
+ def check_cherry_pick_result(result)
25
+ return if result.fetch(:exit_code).zero?
26
+ return on_cherry_pick_conflict if cherry_pick_conflict?
27
+ return on_add_cacheinfo_fail if add_cacheinfo_fail?(result)
28
+
29
+ raise "Cherry pick failed: #{result}"
30
+ end
31
+
32
+ def cherry_pick_conflict?
33
+ ::File.exist?(::File.join(git, '.git', 'CHERRY_PICK_HEAD'))
34
+ end
35
+
36
+ def on_add_cacheinfo_fail
37
+ warn message('"add_cacheinfo" fail')
38
+ end
39
+
40
+ def on_cherry_pick_conflict
41
+ warn message('Cherry pick failed with conflict')
42
+ resolve_cherry_pick_conflicts
43
+
44
+ check_dirty_files
45
+ check_cherry_continue
46
+ end
47
+
48
+ def resolve_cherry_pick_conflicts
49
+ git.status_files.each do |scf|
50
+ if scf.dirty == 'D'
51
+ remove_file(scf.path)
52
+ elsif scf.dirty.present?
53
+ add_file(scf.path)
54
+ end
55
+ end
56
+ end
57
+
58
+ def remove_file(path)
59
+ infov message('Removing file'), path
60
+ git.execute!('rm', path)
61
+ end
62
+
63
+ def add_file(path)
64
+ infov message('Adding file'), path
65
+ git.execute!('add', path)
66
+ end
67
+
68
+ def check_dirty_files
69
+ infom message('Checking dirty files...')
70
+ df = dirty_files
71
+ infov message('Dirty files?'), df.any?
72
+ return unless df.any?
73
+
74
+ df.each do |f|
75
+ infov message(f.path, 1), "|#{f.stage}|#{f.dirty}|"
76
+ end
77
+ raise 'There are dirty files'
78
+ end
79
+
80
+ def dirty_files
81
+ git.status_files.select { |scf| scf.dirty.present? }
82
+ end
83
+
84
+ def check_cherry_continue
85
+ infom message('Continuing cherry pick')
86
+ git.execute!('-c', "core.editor=#{bash_editor}", 'cherry-pick', '--continue')
87
+ raise 'Still in cherry-pick conflict' if cherry_pick_conflict?
88
+
89
+ infom message('Cherry pick continue successful')
90
+ end
91
+
92
+ def bash_editor
93
+ if source_commit.subject.present?
94
+ 'true'
95
+ else
96
+ 'bash -c "printf \\"Mensagem original em branco.\\n\\" > $1"'
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avmtrf1
4
+ module Git
5
+ class PushLarge
6
+ class LfsCommit
7
+ module Push
8
+ private
9
+
10
+ PACK_ERROR_MESSAGE = 'pack exceeds maximum allowed size'
11
+ PACK_ERROR_TRUE = 'true'
12
+ PACK_ERROR_FALSE = 'false'
13
+
14
+ def push_ok_uncached
15
+ commit
16
+ fresh_push if push_pack_error_cache.read.blank?
17
+ after_push_banner
18
+ push_pack_error_cache.read != PACK_ERROR_TRUE
19
+ end
20
+
21
+ def after_push_banner
22
+ infov message('Commit SHA1'), commit.sha1
23
+ raise 'Cache of files size not found' if files_size_cache.read.blank?
24
+
25
+ infov message('Files size'), PushLarge.bytes_size(files_size_cache.read)
26
+ end
27
+
28
+ def fresh_push
29
+ fresh_push_banner
30
+ check_push_result(
31
+ git.execute(
32
+ 'push', push_large.remote_name, '--force',
33
+ "#{commit.sha1}:#{push_reference}"
34
+ )
35
+ )
36
+ end
37
+
38
+ def fresh_push_banner
39
+ infom message('Pushing...')
40
+ fresh_push_commit_banner
41
+ fresh_push_remote_banner
42
+ end
43
+
44
+ def fresh_push_commit_banner
45
+ infov message('SHA1', 1), commit.sha1
46
+ infov message('Files size', 1), PushLarge.bytes_size(commit.files_size)
47
+ end
48
+
49
+ def fresh_push_remote_banner
50
+ infov message('Remote', 1), push_large.remote_name
51
+ infov message('Reference', 1), push_reference
52
+ end
53
+
54
+ def push_reference
55
+ "refs/heads/#{push_large.target_ref}"
56
+ end
57
+
58
+ def check_push_result(result)
59
+ if result.fetch(:exit_code).zero?
60
+ on_push_result_ok
61
+ elsif result.fetch(:stderr).include?(PACK_ERROR_MESSAGE)
62
+ on_push_result_pack_error
63
+ else
64
+ on_push_result_arbitrary_error(result)
65
+ end
66
+ end
67
+
68
+ def on_push_result_ok
69
+ push_pack_error_cache.write(PACK_ERROR_FALSE)
70
+ success(push_message('successful'))
71
+ end
72
+
73
+ def on_push_result_pack_error
74
+ push_pack_error_cache.write(PACK_ERROR_TRUE)
75
+ warn(push_message("failed with message \"#{PACK_ERROR_MESSAGE}\""))
76
+ end
77
+
78
+ def on_push_result_arbitrary_error(result)
79
+ raise result.pretty_inspect.to_s
80
+ end
81
+
82
+ def push_message(suffix)
83
+ message("Push of #{commit.sha1} (Size: #{commit.files_size}, " \
84
+ "Files: #{commit.files.count}): #{suffix}.")
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avmtrf1
4
+ module Git
5
+ class PushLarge
6
+ class LfsCommit
7
+ module TrackLargeFiles
8
+ private
9
+
10
+ EXTENSIONS_REQUIRED_TO_TRACK = %w[
11
+ bak bkp bmp bpm cfm chm dat db doc fla flv gz jar log mp3 mp4 otf pdf ppt psd rar rtf
12
+ swf ttf wav wmf wmv wmz woff woff2 xmind z zip
13
+ ].freeze
14
+
15
+ def track_large_files_uncached
16
+ cherry_pick_source_revision
17
+ if lfs_file_min_size.present?
18
+
19
+ source_commit.files.each do |file|
20
+ next unless track_file_with_lfs?(file)
21
+
22
+ track_file(file)
23
+ end
24
+ raise 'None file was tracked' unless tracked_files.positive?
25
+ end
26
+ infov message('Tracked files'), @tracked_files
27
+ end
28
+
29
+ def track_file(file)
30
+ infov message('Tracking with LFS'), file
31
+ git.execute!('rm', '--cached', file.path)
32
+ git.execute!('lfs', 'track', file.path) unless tracked_file?(file)
33
+ @tracked_files += 1
34
+ end
35
+
36
+ def track_file_with_lfs?(file)
37
+ return false unless file.dst_size.positive?
38
+
39
+ required_extesion_to_track?(file) || (file.dst_size >= lfs_file_min_size)
40
+ end
41
+
42
+ def required_extesion_to_track?(file)
43
+ EXTENSIONS_REQUIRED_TO_TRACK.include?(::File.extname(file.path).gsub(/\A\./, ''))
44
+ end
45
+
46
+ def tracked_file?(file)
47
+ git.execute!('check-attr', '--all', '--', file.path).strip.present?
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avmtrf1/tools/core_ext'
4
+
5
+ module Avmtrf1
6
+ module Git
7
+ class PushLarge
8
+ class LfsCommit
9
+ require_sub __FILE__, include_modules: true
10
+ enable_simple_cache
11
+ enable_speaker
12
+
13
+ common_constructor :source_commit, :lfs_file_min_size do
14
+ @tracked_files = 0
15
+ @commit = nil
16
+ end
17
+
18
+ def push_ok?
19
+ push_ok
20
+ end
21
+
22
+ def start_banner
23
+ infov ' * LFS push', "revision: #{source_revision}" \
24
+ ", lfs_file_min_size: #{PushLarge.bytes_size(lfs_file_min_size)}"
25
+ end
26
+
27
+ private
28
+
29
+ def git
30
+ source_commit.git
31
+ end
32
+
33
+ def push_large
34
+ source_commit.push_large
35
+ end
36
+
37
+ def previous_revision
38
+ push_large.last_pushed_revision
39
+ end
40
+
41
+ def source_revision
42
+ source_commit.sha1
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'filesize'
4
+
5
+ module Avmtrf1
6
+ module Git
7
+ class PushLarge
8
+ class SourceCommit
9
+ module Push
10
+ private
11
+
12
+ LFS_FILE_MIN_SIZES = [nil, 1_048_576, 524_288, 131_072].freeze
13
+
14
+ def pushed_revision_uncached
15
+ fs_cache.child('pushed_revision')
16
+ end
17
+
18
+ def run_pushs
19
+ return if LFS_FILE_MIN_SIZES.any? do |lfs_file_min_size|
20
+ lfs_commit = ::Avmtrf1::Git::PushLarge::LfsCommit.new(self, lfs_file_min_size)
21
+ lfs_commit.start_banner
22
+ push_with_lfs(lfs_commit)
23
+ end
24
+
25
+ raise 'Push de todos os commits falharam'
26
+ end
27
+
28
+ def push_with_lfs(lfs_commit)
29
+ if lfs_commit.push_ok?
30
+ pushed_revision.write(lfs_commit.commit.sha1)
31
+ success " * Pushed: #{pushed_revision.read}"
32
+ true
33
+ else
34
+ warn ' * Push failed'
35
+ false
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/git/commit'
4
+ require 'avmtrf1/tools/core_ext'
5
+
6
+ module Avmtrf1
7
+ module Git
8
+ class PushLarge
9
+ class SourceCommit < ::Avm::Git::Commit
10
+ require_sub __FILE__, include_modules: true
11
+ enable_simple_cache
12
+ enable_speaker
13
+
14
+ attr_reader :push_large, :sha1, :no_lfs_max_size
15
+
16
+ def initialize(push_large, sha1)
17
+ super(push_large.git, sha1)
18
+ @push_large = push_large
19
+ end
20
+
21
+ def run
22
+ start_banner
23
+ if pushed_revision.read.present?
24
+ success ' * Target revision already pushed'
25
+ else
26
+ before_pushs_banner
27
+ run_pushs
28
+ after_pushs_banner
29
+ end
30
+ end
31
+
32
+ def fs_cache
33
+ @fs_cache ||= push_large.fs_cache.child(sha1)
34
+ end
35
+
36
+ private
37
+
38
+ def start_banner
39
+ infov ' * SHA1', sha1
40
+ infov ' * Subject', subject
41
+ infov ' * Author', author_all
42
+ infov ' * Commiter', commiter_all
43
+ infov ' * Files', files.count
44
+ end
45
+
46
+ def before_pushs_banner
47
+ infov ' * Files size', PushLarge.bytes_size(files_size)
48
+ infov ' * Pushed revision (BEFORE)', pushed_revision.read
49
+ end
50
+
51
+ def after_pushs_banner
52
+ infov ' * Pushed revision (AFTER)', pushed_revision.read
53
+ raise 'Target revision is blank' if pushed_revision.read.blank?
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ostruct'
4
+
5
+ require 'eac_ruby_utils/patches/module/speaker'
6
+ require 'eac_ruby_utils/require_sub'
7
+ require 'eac_ruby_utils/simple_cache'
8
+ require 'avmtrf1/patches/avm/git/launcher/base'
9
+
10
+ module Avmtrf1
11
+ module Git
12
+ class PushLarge
13
+ include ::EacRubyUtils::SimpleCache
14
+ enable_speaker
15
+
16
+ ::EacRubyUtils.require_sub(__FILE__)
17
+
18
+ attr_reader :git, :remote_name, :source_ref, :target_ref, :last_pushed_revision
19
+
20
+ def initialize(git_local_path, remote_name, source_ref, target_ref)
21
+ @git = ::Avm::Git::Launcher::Base.new(git_local_path)
22
+ @remote_name = remote_name
23
+ @source_ref = source_ref
24
+ @target_ref = target_ref
25
+ @last_pushed_revision = nil
26
+ end
27
+
28
+ def run
29
+ start_banner
30
+ push_revisions
31
+ end
32
+
33
+ def fs_cache_object_id
34
+ ::File.expand_path(git).parameterize
35
+ end
36
+
37
+ private
38
+
39
+ def start_banner
40
+ infov 'Git local', git
41
+ infov 'Remote name', remote_name
42
+ infov 'Source ref.', source_ref
43
+ infov 'Source rev.', source_rev
44
+ infov 'Target ref.', target_ref
45
+ infov 'Revisions to push', revisions.count
46
+ end
47
+
48
+ def push_revisions
49
+ count = 1
50
+ revisions.each do |rev|
51
+ infom "Pushing commit #{count}/#{revisions.count}..."
52
+ source_commit = ::Avmtrf1::Git::PushLarge::SourceCommit.new(self, rev)
53
+ source_commit.run
54
+ @last_pushed_revision = source_commit.pushed_revision.read
55
+ count += 1
56
+ end
57
+ end
58
+
59
+ def source_rev
60
+ git.rev_parse(source_ref)
61
+ end
62
+
63
+ def revisions_uncached
64
+ git.execute!('--no-pager', 'log', '--reverse', '--pretty=format:%H', source_rev)
65
+ .each_line.map(&:strip)
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ostruct'
4
+
5
+ module Avmtrf1
6
+ module Git
7
+ class Reference
8
+ include ::EacRubyUtils::SimpleCache
9
+
10
+ attr_reader :revision, :fullname
11
+
12
+ def initialize(git, fullname, revision)
13
+ @git = git
14
+ @fullname = fullname
15
+ @revision = revision
16
+ end
17
+
18
+ def type_uncached
19
+ parsed_fullname.type
20
+ end
21
+
22
+ delegate :name, to: :parsed_fullname
23
+
24
+ private
25
+
26
+ def parsed_fullname_uncached
27
+ m = %r{\Arefs/([^/]+)s/(.+)\z}.match(fullname)
28
+ return ::OpenStruct.new(name: m[2], type: m[1]) if m # rubocop:disable Style/OpenStructUse
29
+
30
+ raise "\"#{fullname}\" not match ref pattern"
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avmtrf1
4
+ module Git
5
+ require 'avmtrf1/git/cached_repository'
6
+ require 'avmtrf1/git/issue_on_repository'
7
+ require 'avmtrf1/git/push_large'
8
+ require 'avmtrf1/git/reference'
9
+ end
10
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avmtrf1
4
+ module Gitlab
5
+ class Commit
6
+ enable_speaker
7
+ enable_simple_cache
8
+ common_constructor :repository, :git, :source
9
+
10
+ delegate :id, to: :git_commit
11
+
12
+ def to_s
13
+ source
14
+ end
15
+
16
+ # @return [String]
17
+ def markdown_link(object_type = 'commit')
18
+ "[#{git_commit.abbreviated_commit_hash}|#{web_url(object_type)}]"
19
+ end
20
+
21
+ # @return [String]
22
+ def textile_link(object_type = 'commit')
23
+ "\"#{git_commit.abbreviated_commit_hash}\":#{web_url(object_type)}"
24
+ end
25
+
26
+ def web_url(object_type = 'commit')
27
+ "#{repository.web_url}/#{object_type}/#{git_commit.commit_hash}"
28
+ end
29
+
30
+ private
31
+
32
+ def git_commit_uncached
33
+ git.commit(git.rev_parse(source))
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avmtrf1/tools/core_ext'
4
+
5
+ module Avmtrf1
6
+ module Gitlab
7
+ class Repository
8
+ class << self
9
+ # @param uri [String]
10
+ # @return [Avmtrf1::Gitlab::Address, nil]
11
+ def by_uri(uri)
12
+ by_git_uri(uri) || by_https_uri(uri)
13
+ end
14
+
15
+ # @param uri [String]
16
+ # @return [Avmtrf1::Gitlab::Address, nil]
17
+ def by_git_uri(uri)
18
+ /\Agit@(.+):(.+)\z/i.if_match(uri, false) do |m|
19
+ new(:git, m[1], m[2])
20
+ end
21
+ end
22
+
23
+ # @param uri [String]
24
+ # @return [Avmtrf1::Gitlab::Address, nil]
25
+ def by_https_uri(uri)
26
+ %r{\Ahttps?://([^\/]+)/(.+)\z}i.if_match(uri, false) do |m|
27
+ new(:https, m[1], m[2])
28
+ end
29
+ end
30
+ end
31
+
32
+ common_constructor :protocol, :authority, :path do
33
+ self.path = '/' + path.to_s.gsub(/\.git\Z/, '').gsub(%r{\A/+}, '') # rubocop:disable Style/StringConcatenation
34
+ end
35
+
36
+ def web_url
37
+ "https://#{authority}#{path}"
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/simple_cache'
4
+
5
+ module Avmtrf1
6
+ class Ini
7
+ class Profile
8
+ include ::EacRubyUtils::SimpleCache
9
+
10
+ attr_reader :ini, :name, :parent_name, :self_data
11
+
12
+ # @param profiles [Avmtrf1::Ini::Profiles
13
+ def initialize(ini, name, parent_name, self_data)
14
+ @ini = ini
15
+ @name = name
16
+ @parent_name = parent_name
17
+ @self_data = self_data
18
+ end
19
+
20
+ delegate :[], to: :data
21
+
22
+ delegate :fetch, to: :data
23
+
24
+ def to_h(prefix = '')
25
+ data.select { |k, _v| k.start_with?(prefix) }
26
+ .map { |e| [e[0].gsub(/\A#{Regexp.quote(prefix)}/, ''), e[1]] }.to_h # rubocop:disable Style/MapToHash
27
+ end
28
+
29
+ private
30
+
31
+ def data_uncached
32
+ r = self_data
33
+ r = parent.data.merge(r) if parent
34
+ r
35
+ end
36
+
37
+ def parent
38
+ parent_name ? ini.profiles[parent_name] : nil
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/simple_cache'
4
+ require 'pp' # rubocop:disable Lint/RedundantRequireStatement
5
+ require 'avmtrf1/ini/profile'
6
+ require 'avmtrf1/patches/inifile'
7
+
8
+ module Avmtrf1
9
+ # Leitor de arquivos .ini com suporte a herança de seções/perfis.
10
+ class Ini
11
+ include ::EacRubyUtils::SimpleCache
12
+
13
+ class << self
14
+ SECTION_NAME_PATTERN = /\A([^\:]+)(?::([^\:]+))?\z/.freeze
15
+
16
+ # @return Um [Array] em que o primeiro elemento é o perfil e o segundo é seu super-perfil.
17
+ def parse_section_name(section_name)
18
+ m = SECTION_NAME_PATTERN.match(section_name)
19
+ return [m[1], m[2]] if m
20
+
21
+ raise "Section name pattern \"#{SECTION_NAME_PATTERN}\" not match \"#{section_name}\""
22
+ end
23
+
24
+ # @return [IniFile].
25
+ def inifile_from_file(path)
26
+ raise "\"#{path}\" does not exist or is not a file" unless ::File.file?(path)
27
+
28
+ r = ::IniFile.load(path)
29
+ return r if r.is_a?(::IniFile)
30
+
31
+ raise "\"#{path}\" not converted to Inifile"
32
+ end
33
+ end
34
+
35
+ attr_reader :inifile
36
+
37
+ # @param ini Um [IniFile] ou um caminho de arquivo .ini.
38
+ def initialize(inifile)
39
+ @inifile = inifile.is_a?(::IniFile) ? inifile : self.class.inifile_from_file(inifile.to_s)
40
+ end
41
+
42
+ private
43
+
44
+ def profiles_uncached
45
+ r = {}
46
+ inifile.each_section do |section|
47
+ profile_name, profile_parent_name = self.class.parse_section_name(section)
48
+ r[profile_name] = ::Avmtrf1::Ini::Profile.new(
49
+ self, profile_name, profile_parent_name, inifile[section]
50
+ )
51
+ end
52
+ r.sort.to_h.freeze
53
+ end
54
+ end
55
+ end