Class: Gitlab::Devops::Config
- Inherits:
-
Object
- Object
- Gitlab::Devops::Config
- Defined in:
- lib/gitlab/devops.rb
Class Method Summary collapse
- .apply(options) ⇒ Object
- .apply_group_settings(group, group_config) ⇒ Object
- .apply_project_settings(project, project_config) ⇒ Object
- .update_project_variables(project, variables) ⇒ Object
Class Method Details
.apply(options) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/gitlab/devops.rb', line 8 def self.apply() Gitlab.configure do |config| config.endpoint = "#{options['api_endpoint']}/#{options['api_version']}" config.private_token = ['private_token'] end group_configs = ['groups'] group_configs.each do |group_config| raise Error::Parsing, 'Group name must be provided' unless group_config['name'] groups = Gitlab.group_search(group_config['name']) raise Error::Error, "group not found for #{group_config['name']}" if groups.empty? groups.each do |group| apply_group_settings group, group_config end end end |
.apply_group_settings(group, group_config) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/gitlab/devops.rb', line 26 def self.apply_group_settings(group, group_config) projects = Gitlab.group_projects(group.id) projects.each do |project| apply_project_settings(project, group_config['settings']) end end |
.apply_project_settings(project, project_config) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/gitlab/devops.rb', line 33 def self.apply_project_settings(project, project_config) p "applying settings to project #{project.name}" project_config.each do |setting, value| case setting when 'variables' update_project_variables(project, value) if project.name == 'global-project-settings' else raise "Unsupported setting in config file: #{setting}. Please make sure all setting names mentioned in gitlab.config.yml file are in the defined list" end end end |
.update_project_variables(project, variables) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/gitlab/devops.rb', line 45 def self.update_project_variables(project, variables) existing_variables = Gitlab.variables(project.id) existing_variables.each do |variable| Gitlab.remove_variable(project.id, variable.key) end variables.each do |variable| p "updating var #{variable} for project #{project.name}" Gitlab.create_variable(project.id, variable['key'], variable['value']) end end |