Class: PdkSync::GitlabClient

Inherits:
Object
  • Object
show all
Defined in:
lib/pdksync/gitlabclient.rb

Instance Method Summary collapse

Constructor Details

#initialize(access_token, gitlab_api_endpoint) ⇒ GitlabClient



15
16
17
# File 'lib/pdksync/gitlabclient.rb', line 15

def initialize(access_token, gitlab_api_endpoint)
  @client = Gitlab.client(endpoint: gitlab_api_endpoint, private_token: access_token)
end

Instance Method Details

#create_pull_request(project, target_branch, source_branch, title, message) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/pdksync/gitlabclient.rb', line 47

def create_pull_request(project, target_branch, source_branch, title, message)
  mr_options = {
    source_branch: source_branch,
    target_branch: target_branch,
    description: message
  }
  @client.create_merge_request(project, title, mr_options)
end

#delete_branch(project, branch_name) ⇒ Boolean



88
89
90
# File 'lib/pdksync/gitlabclient.rb', line 88

def delete_branch(project, branch_name)
  @client.delete_branch(project, branch_name)
end

#labels(project) ⇒ Array



61
62
63
# File 'lib/pdksync/gitlabclient.rb', line 61

def labels(project)
  @client.labels(project)
end

#repository?(project) ⇒ Boolean



23
24
25
26
27
28
29
# File 'lib/pdksync/gitlabclient.rb', line 23

def repository?(project)
  @client.project(project)

  true
rescue Gitlab::Error::NotFound
  false
end

#update_issue(project, id, options) ⇒ Object

Note:

This method is specifically used to set labels for a merge request

Returns A Gitlab merge request object of the updated merge request.



75
76
77
78
79
# File 'lib/pdksync/gitlabclient.rb', line 75

def update_issue(project, id, options)
  # Gitlab requires labels to be supplied as a comma-separated string
  labels = options[:labels].join(',')
  @client.update_merge_request(project, id, labels: labels)
end