avm-tools 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 47963424dd2adf9abec36f3469cb2ec324d6610b13b8f1080e1ed24827ed29c3
4
+ data.tar.gz: 327281544236ae524f23e79b07047eb532c7ed0d4e46024a88e7fe0937860a23
5
+ SHA512:
6
+ metadata.gz: 4317de96095e224feb963c6ea2763c78541d70d47f222f67828741eff4ee7ab83b817c236c8a051a115a01e95a0b51d1f32b6ee16097d7c4d081b9755ee588fe
7
+ data.tar.gz: 4dc0c24e635ac76d856da4bace11d42bf8bc021e7fbe6197450e0877c08f8a0f11db1234f667bcc4022ed7810eaa7235cd54a6e8c75f895d31d6ab3aac711976
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
data/exe/avm ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH.unshift("#{__dir__}/../lib")
5
+
6
+ require 'avm/tools'
7
+ require 'eac_ruby_utils'
8
+
9
+ class AvmRunner < ::EacRubyUtils::Console::DocoptRunner
10
+ include ::EacRubyUtils::Console::Speaker
11
+
12
+ DOC = <<~DOCOPT
13
+ Tools for AVM.
14
+
15
+ Usage:
16
+ __PROGRAM__ [options] git complete-issue
17
+ __PROGRAM__ -h | --help
18
+
19
+ Options:
20
+ -h --help Show this screen.
21
+ DOCOPT
22
+
23
+ private
24
+
25
+ def run
26
+ raise "Unknown command: #{options}" unless git_complete_issue?
27
+
28
+ ::Avm::Tools::Git::CompleteIssue.new(git_complete_issue_options)
29
+ end
30
+
31
+ def git_complete_issue_options
32
+ { dir: '.' }
33
+ end
34
+
35
+ def git_complete_issue?
36
+ options.fetch('git') && options.fetch('complete-issue')
37
+ end
38
+ end
39
+
40
+ AvmRunner.new
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_launcher'
4
+
5
+ module Avm
6
+ module Tools
7
+ require 'avm/tools/version'
8
+ require 'avm/tools/git'
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module Tools
5
+ module Git
6
+ require 'avm/tools/git/complete_issue'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,138 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module Tools
5
+ module Git
6
+ class CompleteIssue
7
+ include ::Eac::SimpleCache
8
+ include ::EacRubyUtils::Console::Speaker
9
+
10
+ def initialize(options)
11
+ @git = ::EacLauncher::Git::Base.new(options.fetch(:dir))
12
+ run
13
+ end
14
+
15
+ def run
16
+ check_issue_branch
17
+ assert_tag
18
+ push
19
+ remove_local_branch
20
+ end
21
+
22
+ def branch
23
+ @git.current_branch
24
+ end
25
+
26
+ def branch_hash
27
+ @git.rev_parse("refs/heads/#{branch}")
28
+ end
29
+
30
+ def branch_name
31
+ branch.split('/')[-1]
32
+ end
33
+
34
+ def issue_id
35
+ m = branch_name.match(/\A#{Regexp.quote('issue_')}(\d+)\z/)
36
+ m ? m[1].to_i : nil
37
+ end
38
+
39
+ def remote_master_hash
40
+ remote_hashs['refs/heads/master']
41
+ end
42
+
43
+ def remote_branch_hash
44
+ remote_hashs["refs/heads/#{branch}"]
45
+ end
46
+
47
+ def remote_tag_hash
48
+ remote_hashs[tag]
49
+ end
50
+
51
+ private
52
+
53
+ attr_reader :options
54
+
55
+ def remote_name
56
+ 'origin'
57
+ end
58
+
59
+ def check_issue_branch
60
+ raise "Branch is not a issue branch (\"#{branch}\"|\"#{branch_name}\")" unless
61
+ branch_valid?
62
+ raise "Hash not found for \"#{branch}\"" unless branch_hash
63
+ end
64
+
65
+ def branch_valid?
66
+ issue_id || options[:no_avm_branch_name]
67
+ end
68
+
69
+ def assert_tag
70
+ if tag_hash
71
+ return if tag_hash == branch_hash
72
+
73
+ delete_tag
74
+ end
75
+ create_tag
76
+ end
77
+
78
+ def delete_tag
79
+ info 'Removendo tag...'
80
+ git(['tag', '-d', branch_name])
81
+ end
82
+
83
+ def push
84
+ if pushs.empty?
85
+ info 'PUSH: Nada a enviar'
86
+ else
87
+ info "PUSH: enviando \"#{pushs}\"..."
88
+ git(%w[push origin] + pushs)
89
+ end
90
+ end
91
+
92
+ def pushs_uncached
93
+ [master_push, remove_branch_push, tag_push].reject(&:nil?)
94
+ end
95
+
96
+ def master_push
97
+ remote_master_hash != branch_hash ? "#{branch_hash}:refs/heads/master" : nil
98
+ end
99
+
100
+ def remove_branch_push
101
+ remote_branch_hash ? ":refs/heads/#{branch}" : nil
102
+ end
103
+
104
+ def tag_push
105
+ !remote_tag_hash || remote_tag_hash != branch_hash ? tag : nil
106
+ end
107
+
108
+ def remove_local_branch
109
+ info 'Removendo branch local...'
110
+ bn = branch_name
111
+ git(['checkout', branch_hash])
112
+ git(['branch', '-D', bn])
113
+ end
114
+
115
+ def tag
116
+ "refs/tags/#{branch_name}"
117
+ end
118
+
119
+ def tag_hash
120
+ @git.rev_parse(tag)
121
+ end
122
+
123
+ def create_tag
124
+ git(['tag', branch_name, branch_hash])
125
+ end
126
+
127
+ def remote_hashs_uncached
128
+ @git.remote_hashs(remote_name)
129
+ end
130
+
131
+ def git(args, exit_outputs = {})
132
+ r = @git.execute!(args, exit_outputs: exit_outputs)
133
+ r.is_a?(String) ? r.strip : r
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module Tools
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: avm-tools
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Esquilo Azul Company
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-06-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: eac_launcher
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.5'
27
+ description:
28
+ email:
29
+ executables:
30
+ - avm
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - Gemfile
35
+ - exe/avm
36
+ - lib/avm/tools.rb
37
+ - lib/avm/tools/git.rb
38
+ - lib/avm/tools/git/complete_issue.rb
39
+ - lib/avm/tools/version.rb
40
+ homepage:
41
+ licenses: []
42
+ metadata: {}
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 2.7.7
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Tools for AVM.
63
+ test_files: []