Class: ReleaseMe::BumpTag
- Inherits:
-
Object
- Object
- ReleaseMe::BumpTag
- Includes:
- VcsProvider
- Defined in:
- lib/release_me/bump_tag.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#version_instance ⇒ Object
readonly
Returns the value of attribute version_instance.
Instance Method Summary collapse
-
#bump_version_file ⇒ Hash
Output from bump version.
- #commits_url ⇒ Object
- #file_update_body_request(file_contents, message) ⇒ Object
-
#initialize(options) ⇒ BumpTag
constructor
A new instance of BumpTag.
- #private_token ⇒ Object
- #project_url ⇒ Object
- #run ⇒ Object
-
#send_data(uri, body, method = nil) ⇒ String
Message body for url call in JSON format.
-
#tag(version, commit_id) ⇒ String
-
json encoded result from http call.
-
- #tag_body_request(tag_name, commit_id) ⇒ Object
- #tags_url ⇒ Object
-
#update_version(version_object) ⇒ String
Commit id of submitted body.
- #vcs_config ⇒ Object
Methods included from VcsProvider
Constructor Details
#initialize(options) ⇒ BumpTag
Returns a new instance of BumpTag.
11 12 13 14 15 16 17 18 |
# File 'lib/release_me/bump_tag.rb', line 11 def initialize() @options = opts = { json: true, version: [:version_type] } @version_instance = ReleaseMe::BumpVersion.new(opts) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/release_me/bump_tag.rb', line 8 def @options end |
#version_instance ⇒ Object (readonly)
Returns the value of attribute version_instance.
8 9 10 |
# File 'lib/release_me/bump_tag.rb', line 8 def version_instance @version_instance end |
Instance Method Details
#bump_version_file ⇒ Hash
Returns output from bump version.
41 42 43 |
# File 'lib/release_me/bump_tag.rb', line 41 def bump_version_file JSON.parse(version_instance.run) end |
#commits_url ⇒ Object
24 25 26 |
# File 'lib/release_me/bump_tag.rb', line 24 def commits_url @commit_url ||= URI("#{project_url}/#{vcs_config.commits_path}") end |
#file_update_body_request(file_contents, message) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/release_me/bump_tag.rb', line 45 def file_update_body_request(file_contents, ) { id: vcs_config.project_id, branch_name: vcs_config.branch_name, author_email: vcs_config., author_name: vcs_config., commit_message: , actions: [ { action: :update, file_path: version_instance.app_version_file.gsub(Dir.pwd + '/', ''), content: file_contents } ] }.to_json end |
#private_token ⇒ Object
20 21 22 |
# File 'lib/release_me/bump_tag.rb', line 20 def private_token vcs_config.private_token end |
#project_url ⇒ Object
28 29 30 |
# File 'lib/release_me/bump_tag.rb', line 28 def project_url @project_url ||= "#{vcs_config.base_url}/#{vcs_config.project_id}" end |
#run ⇒ Object
126 127 128 129 130 131 132 133 |
# File 'lib/release_me/bump_tag.rb', line 126 def run version_output = bump_version_file unless [:dry_run] commit_id = update_version(version_output) tag(version_output['new_version'], commit_id) unless @options[:no_tagging] end "Tagged: #{version_output['new_version']}" end |
#send_data(uri, body, method = nil) ⇒ String
Returns message body for url call in JSON format.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/release_me/bump_tag.rb', line 95 def send_data(uri, body, method = nil) use_ssl = uri.scheme == 'https' conn = Net::HTTP.new(uri.host, uri.port) # conn.set_debug_output conn.use_ssl = use_ssl # Don't verify conn.verify_mode = ::OpenSSL::SSL::VERIFY_NONE if vcs_config.no_verify request = case method when :put Net::HTTP::Put.new(uri.path) else Net::HTTP::Post.new(uri.path) end request.body = body # private token is specific to gitlab and must be set request['PRIVATE-TOKEN'] = vcs_config.private_token request.content_type = 'application/json' if [:dry_run] puts body else response = conn.request(request) if response.is_a? Net::HTTPSuccess response.body else puts response.code puts response.body exit 1 end end end |
#tag(version, commit_id) ⇒ String
Returns - json encoded result from http call.
86 87 88 89 |
# File 'lib/release_me/bump_tag.rb', line 86 def tag(version, commit_id) body = tag_body_request(version, commit_id) send_data(, body, :post) end |
#tag_body_request(tag_name, commit_id) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/release_me/bump_tag.rb', line 62 def tag_body_request(tag_name, commit_id) { id: vcs_config.project_id, tag_name: tag_name, ref: commit_id, # or git rev-parse HEAD # messasge: # release_description: }.to_json end |
#tags_url ⇒ Object
32 33 34 |
# File 'lib/release_me/bump_tag.rb', line 32 def @tags_url ||= URI("#{project_url}/#{vcs_config.}") end |
#update_version(version_object) ⇒ String
Returns commit id of submitted body.
73 74 75 76 77 78 79 80 81 |
# File 'lib/release_me/bump_tag.rb', line 73 def update_version(version_object) new_version = version_object['new_version'] file_content = version_object['file_content'] = "Auto tagged to #{new_version}" body = file_update_body_request(file_content, ) response = send_data(commits_url, body) # the id may be specific to gitlab api JSON.parse(response)['id'] end |
#vcs_config ⇒ Object
36 37 38 |
# File 'lib/release_me/bump_tag.rb', line 36 def vcs_config @vcs_config ||= provider_config([:project_path]) end |