class PeopleGroup::Connectors::GitLab
Constants
- API_URL
Attributes
client[RW]
Public Class Methods
new(token: ENV['GITLAB_API_TOKEN'])
click to toggle source
# File lib/peoplegroup/connectors/gitlab.rb, line 12 def initialize(token: ENV['GITLAB_API_TOKEN']) @client = Gitlab.client(endpoint: API_URL, private_token: token) end
Public Instance Methods
add_group_member(group_id, user_id, access_level)
click to toggle source
# File lib/peoplegroup/connectors/gitlab.rb, line 50 def add_group_member(group_id, user_id, access_level) retry_on_error { @client.add_group_member(group_id, user_id, access_level) } end
commit_change_to_new_merge_request(project_id, branch_name, file_path, file_with_change, commit_message, description = nil, target_branch: 'master')
click to toggle source
# File lib/peoplegroup/connectors/gitlab.rb, line 141 def commit_change_to_new_merge_request(project_id, branch_name, file_path, file_with_change, commit_message, description = nil, target_branch: 'master') retry_on_error { @client.create_branch(project_id, branch_name, target_branch) } actions = [ { action: 'update', file_path: file_path, content: file_with_change } ] retry_on_error { @client.create_commit(project_id, branch_name, commit_message, actions) } options = { source_branch: branch_name, target_branch: target_branch, remove_source_branch: true } options[:description] = description if description retry_on_error { @client.create_merge_request(project_id, commit_message, options) } end
commit_change_to_new_merge_request_v2(project_id, branch_name, commit_message, description = nil, files_to_delete = [], files_to_update = [], target_branch: 'master')
click to toggle source
# File lib/peoplegroup/connectors/gitlab.rb, line 111 def commit_change_to_new_merge_request_v2(project_id, branch_name, commit_message, description = nil, files_to_delete = [], files_to_update = [], target_branch: 'master') actions = [] files_to_delete.each do |file| action = { action: 'delete', file_path: file } actions << action end files_to_update.each do |file| action = { action: 'update', file_path: file[:file_path], content: File.read(file[:tmp_file_path]) } actions << action end return unless actions.any? retry_on_error { @client.create_branch(project_id, branch_name, target_branch) } retry_on_error { @client.create_commit(project_id, branch_name, commit_message, actions) } options = { source_branch: branch_name, target_branch: target_branch, remove_source_branch: true } options[:description] = description if description retry_on_error { @client.create_merge_request(project_id, commit_message, options) } end
commit_new_files_to_new_merge_request(project_id, branch_name, new_files, commit_message, description = nil, target_branch: 'master')
click to toggle source
# File lib/peoplegroup/connectors/gitlab.rb, line 93 def commit_new_files_to_new_merge_request(project_id, branch_name, new_files, commit_message, description = nil, target_branch: 'master') retry_on_error { @client.create_branch(project_id, branch_name, target_branch) } actions = [] new_files.each do |file| actions << { action: 'create', file_path: file[:remote_path], content: File.read(file[:local_path]) } end retry_on_error { @client.create_commit(project_id, branch_name, commit_message, actions) } options = { source_branch: branch_name, target_branch: target_branch, remove_source_branch: true } options[:description] = description if description retry_on_error { @client.create_merge_request(project_id, commit_message, options) } end
create_epic_note(group_id, epic_id, text)
click to toggle source
# File lib/peoplegroup/connectors/gitlab.rb, line 157 def create_epic_note(group_id, epic_id, text) retry_on_error { @client.create_epic_note(group_id, epic_id, text) } end
create_group(name, path, options = {})
click to toggle source
# File lib/peoplegroup/connectors/gitlab.rb, line 38 def create_group(name, path, options = {}) retry_on_error { @client.create_group(name, path, options) } end
create_issue(project, title, options = {})
click to toggle source
# File lib/peoplegroup/connectors/gitlab.rb, line 58 def create_issue(project, title, options = {}) retry_on_error { @client.create_issue(project, title, options) } end
create_issue_note(project, id, text)
click to toggle source
# File lib/peoplegroup/connectors/gitlab.rb, line 62 def create_issue_note(project, id, text) retry_on_error { @client.create_issue_note(project, id, text) } end
edit_issue(project, id, options)
click to toggle source
# File lib/peoplegroup/connectors/gitlab.rb, line 70 def edit_issue(project, id, options) retry_on_error { @client.edit_issue(project, id, options) } end
find_gitlabber(field, query)
click to toggle source
# File lib/peoplegroup/connectors/gitlab.rb, line 16 def find_gitlabber(field, query) return if !query || query.empty? possible_members = get_group_members('gitlab-com', query: query) if field === :email possible_members.first else possible_members.find { |team_member| team_member.public_send(field) === query } end end
find_gitlabber_on(field, query, group)
click to toggle source
# File lib/peoplegroup/connectors/gitlab.rb, line 27 def find_gitlabber_on(field, query, group) return if !query || query.empty? possible_members = get_group_members(group, query: query) if field === :email possible_members.first else possible_members.find { |team_member| team_member.public_send(field) === query } end end
find_or_create_epic(group_id, title, options = {})
click to toggle source
# File lib/peoplegroup/connectors/gitlab.rb, line 86 def find_or_create_epic(group_id, title, options = {}) epic = find_epic(group_id, title) reopen_epic(epic) if epic && epic.state == 'closed' options[:confidential] = true epic || retry_on_error { @client.create_epic(group_id, title, options) } end
get_epics(group_id, options = {})
click to toggle source
# File lib/peoplegroup/connectors/gitlab.rb, line 161 def get_epics(group_id, options = {}) retry_on_error { @client.epics(group_id, options).auto_paginate } end
get_group_members(group_id, options = {})
click to toggle source
# File lib/peoplegroup/connectors/gitlab.rb, line 46 def get_group_members(group_id, options = {}) retry_on_error { @client.group_members(group_id, options).auto_paginate } end
get_issue(project, issue_id)
click to toggle source
# File lib/peoplegroup/connectors/gitlab.rb, line 82 def get_issue(project, issue_id) retry_on_error { @client.issue(project, issue_id) } end
get_issue_epics(group_id, epic_iid)
click to toggle source
# File lib/peoplegroup/connectors/gitlab.rb, line 165 def get_issue_epics(group_id, epic_iid) retry_on_error { @client.epic_issues(group_id, epic_iid) } end
get_issues(project, args)
click to toggle source
# File lib/peoplegroup/connectors/gitlab.rb, line 78 def get_issues(project, args) retry_on_error { @client.issues(project, args).auto_paginate } end
get_onboarding_issues(project, args)
click to toggle source
# File lib/peoplegroup/connectors/gitlab.rb, line 74 def get_onboarding_issues(project, args) retry_on_error { @client.issues(project, args).auto_paginate } end
get_subgroups(group_id, options = {})
click to toggle source
# File lib/peoplegroup/connectors/gitlab.rb, line 42 def get_subgroups(group_id, options = {}) retry_on_error { @client.group_subgroups(group_id, options).auto_paginate } end
issue_notes(project, id, options = {})
click to toggle source
# File lib/peoplegroup/connectors/gitlab.rb, line 66 def issue_notes(project, id, options = {}) retry_on_error { @client.issue_notes(project, id, options) } end
remove_group_member(group_id, user_id)
click to toggle source
# File lib/peoplegroup/connectors/gitlab.rb, line 54 def remove_group_member(group_id, user_id) retry_on_error { @client.remove_group_member(group_id, user_id) } end
Private Instance Methods
create_branch(project_id, branch_name, target_branch: 'master')
click to toggle source
# File lib/peoplegroup/connectors/gitlab.rb, line 183 def create_branch(project_id, branch_name, target_branch: 'master') retry_on_error { @client.create_branch(project_id, branch_name, target_branch) } end
create_commit(project_id, branch, commit_message, actions)
click to toggle source
# File lib/peoplegroup/connectors/gitlab.rb, line 191 def create_commit(project_id, branch, commit_message, actions) retry_on_error { @client.create_commit(project_id, branch, commit_message, actions, {}) } end
create_merge_request(project_id, title, options = {})
click to toggle source
# File lib/peoplegroup/connectors/gitlab.rb, line 187 def create_merge_request(project_id, title, options = {}) retry_on_error { @client.create_merge_request(project_id, title, options) } end
find_epic(group_id, title)
click to toggle source
# File lib/peoplegroup/connectors/gitlab.rb, line 175 def find_epic(group_id, title) args = { search: title } epics = retry_on_error { @client.epics(group_id, args).auto_paginate } epics.first end
reopen_epic(epic)
click to toggle source
# File lib/peoplegroup/connectors/gitlab.rb, line 195 def reopen_epic(epic) retry_on_error { @client.edit_epic(epic.group_id, epic.iid, { state_event: 'reopen' }) } end
retry_on_error(&block)
click to toggle source
# File lib/peoplegroup/connectors/gitlab.rb, line 171 def retry_on_error(&block) Utils.retry_on_error(errors: [Gitlab::Error::InternalServerError], delay: 3, &block) end