Class: PdkSync::GitlabClient
- Inherits:
-
Object
- Object
- PdkSync::GitlabClient
- Defined in:
- lib/pdksync/gitlabclient.rb
Instance Method Summary collapse
-
#create_pull_request(project, target_branch, source_branch, title, message) ⇒ Object
A Gitlab merge request object for the newly created merge request.
-
#delete_branch(project, branch_name) ⇒ Boolean
True on success, false on failure.
-
#initialize(access_token, gitlab_api_endpoint) ⇒ GitlabClient
constructor
A new instance of GitlabClient.
-
#labels(project) ⇒ Array
List of available labels in the project.
-
#repository?(project) ⇒ Boolean
True if the project exists, false otherwise.
-
#update_issue(project, id, options) ⇒ Object
A Gitlab merge request object of the updated merge request.
Constructor Details
#initialize(access_token, gitlab_api_endpoint) ⇒ GitlabClient
Returns a new instance of 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
Returns A Gitlab merge request object for the newly created merge request.
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, ) = { source_branch: source_branch, target_branch: target_branch, description: } @client.create_merge_request(project, title, ) end |
#delete_branch(project, branch_name) ⇒ Boolean
Returns true on success, false on failure.
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
Returns List of available labels in the project.
61 62 63 |
# File 'lib/pdksync/gitlabclient.rb', line 61 def labels(project) @client.labels(project) end |
#repository?(project) ⇒ Boolean
Returns true if the project exists, false otherwise.
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, ) # Gitlab requires labels to be supplied as a comma-separated string labels = [:labels].join(',') @client.update_merge_request(project, id, labels: labels) end |