class Ninny::Repository::Gitlab

Attributes

gitlab[R]
project_id[R]

Public Class Methods

new() click to toggle source
# File lib/ninny/repository/gitlab.rb, line 8
def initialize
  @gitlab = ::Gitlab.client(
    endpoint: Ninny.project_config.gitlab_endpoint,
    private_token: Ninny.user_config.gitlab_private_token
  )
  @project_id = Ninny.project_config.gitlab_project_id
end

Public Instance Methods

create_merge_request_note(id, body) click to toggle source
# File lib/ninny/repository/gitlab.rb, line 41
def create_merge_request_note(id, body)
  gitlab.create_merge_request_note(project_id, id, body)
end
current_pull_request() click to toggle source
# File lib/ninny/repository/gitlab.rb, line 16
def current_pull_request
  to_pr(
    gitlab.merge_requests(
      project_id,
      {
        source_branch: Ninny.git.current_branch.name,
        target_branch: Ninny.project_config.deploy_branch,
        state: 'opened'
      }
    ).last
  )
end
open_pull_requests() click to toggle source
# File lib/ninny/repository/gitlab.rb, line 33
def open_pull_requests
  gitlab.merge_requests(project_id, { state: 'opened' }).map { |mr| to_pr(mr) }
end
pull_request(id) click to toggle source
# File lib/ninny/repository/gitlab.rb, line 37
def pull_request(id)
  to_pr(gitlab.merge_request(project_id, id))
end
pull_request_label() click to toggle source
# File lib/ninny/repository/gitlab.rb, line 29
def pull_request_label
  'Merge Request'
end

Private Instance Methods

to_pr(request) click to toggle source
# File lib/ninny/repository/gitlab.rb, line 45
def to_pr(request)
  request && PullRequest.new(
    number: request.iid,
    title: request.title,
    branch: request.source_branch,
    description: request.description,
    comment_lambda: ->(body) { Ninny.repo.create_merge_request_note(request.iid, body) }
  )
end