Module: GitlabApi::ApiClient::Mergerequest

Included in:
GitlabKernel
Defined in:
lib/git/gitlab/api/mergerequest.rb

Constant Summary collapse

PER_PAGE =
100
PAGE =
1

Instance Method Summary collapse

Instance Method Details

#_mergerequests(list, pid, page, per_page) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/git/gitlab/api/mergerequest.rb', line 71

def _mergerequests(list, pid, page, per_page)
  m = @client.merge_requests(pid, :page => page, :per_page => per_page)
  if m.count < per_page
    list + m
  else
    _mergerequests(list + m, pid, page +  1, per_page)
  end
end

#all_mergerequests(pid, page, per_page) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/git/gitlab/api/mergerequest.rb', line 70

def all_mergerequests(pid, page, per_page)
  def _mergerequests(list, pid, page, per_page)
    m = @client.merge_requests(pid, :page => page, :per_page => per_page)
    if m.count < per_page
      list + m
    else
      _mergerequests(list + m, pid, page +  1, per_page)
    end
  end

  m = @client.merge_requests(pid, :page => page, :per_page => per_page)
  if m.count < per_page
    m
  else
    _mergerequests(m, pid, page + 1, per_page)
  end
end

#create_merge_request(title, assign, source, target = "master") ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/git/gitlab/api/mergerequest.rb', line 11

def create_merge_request(title, assign, source, target = "master")
  pid = project_id

  mr_title = if title == nil
    @repository.head.name
  else
    title
  end

  mr_source = if source == nil
    @repository.head.name
  else
    source
  end

  assignee_id = if assign == nil
    0
  else
    @client.users.select { |user|
      user.username == assign
    }[0].id
  end

  begin
    mergerequest = if assignee_id > 0
      @client.create_merge_request(pid, mr_title, :source_branch => mr_source, :target_branch => target, :assignee_id => assignee_id)
    else
      @client.create_merge_request(pid, mr_title, :source_branch => mr_source, :target_branch => target)
    end
  rescue Gitlab::Error::NotFound => e
    raise GitlabApi::Error::MergeRequestError, "Failed Create Merge Request"
  end

  project_url = @client.project(pid).web_url
  mergerequest_url = project_url + "/merge_requests/" + mergerequest.iid.to_s

  mergerequest_url
end

#mergerequest(id) ⇒ Object



58
59
60
61
62
63
64
65
66
67
# File 'lib/git/gitlab/api/mergerequest.rb', line 58

def mergerequest(id)
  pid = project_id

  begin
    mr = @client.merge_request(pid, id)
  rescue Gitlab::Error::NotFound => e
    raise GitlabApi::Error::MergeRequestError, "Can not find #{id} mergerequest"
  end
  mr
end

#mergerequestsObject



50
51
52
53
54
55
56
# File 'lib/git/gitlab/api/mergerequest.rb', line 50

def mergerequests
  pid = project_id

  all_mergerequests(pid, PAGE, PER_PAGE).select { |m|
    m.state == "opened"
  }
end