class Gitlab::Cli::Project
Attributes
id[RW]
name[RW]
Public Class Methods
new(api, options)
click to toggle source
# File lib/gitlab/cli/project.rb, line 8 def initialize(api, options) @id = options[:id] @name = options[:name] @api = api end
Public Instance Methods
update_variables(variables)
click to toggle source
# File lib/gitlab/cli/project.rb, line 14 def update_variables(variables) if @id == 534 delete_existing_vars create_given_vars(variables) end end
Private Instance Methods
create_given_vars(variables)
click to toggle source
# File lib/gitlab/cli/project.rb, line 23 def create_given_vars(variables) variables.each do |variable| res = create_variable variable p res end end
create_variable(variable)
click to toggle source
# File lib/gitlab/cli/project.rb, line 35 def create_variable(variable) p "Creating variable #{variable}" response = @api.http_post("projects/#{@id}/variables", variable.to_json) response_body = JSON.parse(response.body) p "JSON Response: #{response_body}" if response.code == 201 p "Created variable #{variable}" response_body elsif response_body['message'] && response_body['message'] == '401 Unauthorized' raise response_body.inspect elsif response_body['message'] && response_body['message']['key'].include?('has already been taken') raise "#{variable['key']} is already used" else response end end
delete_existing_vars()
click to toggle source
# File lib/gitlab/cli/project.rb, line 30 def delete_existing_vars response = @api.http_get("projects/#{@id}/variables") response.each {|var| delete_variable(var['key'])} end
delete_variable(key)
click to toggle source
# File lib/gitlab/cli/project.rb, line 55 def delete_variable(key) p "deleting #{key}" response = @api.http_delete("/projects/#{@id}/variables/#{key}") if response.body json_response = JSON.parse(response.body) p "DELETE JSON Response : #{json_response}" json_response end end