Class: GitLab::MergeRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/GitLab/merge_request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ MergeRequest

Returns a new instance of MergeRequest.



5
6
7
8
9
10
11
12
13
14
# File 'lib/GitLab/merge_request.rb', line 5

def initialize(params = {})
  @source_branch = params[:source_branch]
  @target_branch = params[:target_branch]
  @title      = params[:title]
  @labels     = params[:labels]
  @issue_iid  = params[:issue_iid]
  @type       = params[:type]
  @description = params[:description]
  @options    = params[:options]
end

Instance Attribute Details

#assignee_idObject

Returns the value of attribute assignee_id.



3
4
5
# File 'lib/GitLab/merge_request.rb', line 3

def assignee_id
  @assignee_id
end

#descriptionObject

Returns the value of attribute description.



3
4
5
# File 'lib/GitLab/merge_request.rb', line 3

def description
  @description
end

#issue_iidObject

Returns the value of attribute issue_iid.



3
4
5
# File 'lib/GitLab/merge_request.rb', line 3

def issue_iid
  @issue_iid
end

#labelsObject

Returns the value of attribute labels.



3
4
5
# File 'lib/GitLab/merge_request.rb', line 3

def labels
  @labels
end

#obj_gitlabObject

Returns the value of attribute obj_gitlab.



3
4
5
# File 'lib/GitLab/merge_request.rb', line 3

def obj_gitlab
  @obj_gitlab
end

#optionsObject

Returns the value of attribute options.



3
4
5
# File 'lib/GitLab/merge_request.rb', line 3

def options
  @options
end

#source_branchObject

Returns the value of attribute source_branch.



3
4
5
# File 'lib/GitLab/merge_request.rb', line 3

def source_branch
  @source_branch
end

#target_branchObject

Returns the value of attribute target_branch.



3
4
5
# File 'lib/GitLab/merge_request.rb', line 3

def target_branch
  @target_branch
end

#titleObject

Returns the value of attribute title.



3
4
5
# File 'lib/GitLab/merge_request.rb', line 3

def title
  @title
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/GitLab/merge_request.rb', line 3

def type
  @type
end

Instance Method Details

#createObject



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
49
# File 'lib/GitLab/merge_request.rb', line 16

def create
  print "Create Merge Request: ".yellow
  print "#{@source_branch} into #{@target_branch}\n\n".green
  assignee_id = GitLab::User.me["id"]
  if type != 'hotfix'
    users = GitLab::User.all
    print "Users list:\n\n".yellow
    print "----------------------------\n".blue
    print "#{"0".ljust(10)} - Empty\n".blue
    users.each do |user|
      print "#{user['id'].to_s.ljust(10)} - #{user['name']}\n".blue
    end
    print "----------------------------\n".blue
    print "Choice user ID for assignee:\n".yellow
    assignee_id = STDIN.gets.chomp
    print "\n#{assignee_id}, "
    print "ok!\n".green
  end
  
  url = "projects/#{$GITLAB_PROJECT_ID}/merge_requests" 
  
  labels = ['merge_request']
  labels << type if type
  @obj_gitlab = GitLab.request_post(url, {
    source_branch: @source_branch,
    target_branch: @target_branch,
    title: @title,
    labels: labels.join(','),
    description: @description,
    assignee_id: assignee_id.to_i
  })
  
  print "Merge request created with success!\n\n".green
end

#create_code_reviewObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/GitLab/merge_request.rb', line 52

def create_code_review
  print "Create merge request for code review: ".yellow
  print "#{@source_branch} into #{@target_branch}\n\n".green
  users = GitLab::User.all
  print "Users list:\n\n".yellow
  print "----------------------------\n".blue
  print "#{"0".ljust(10)} - Empty\n".blue
  users.each do |user|
    print "#{user['id'].to_s.ljust(10)} - #{user['name']}\n".blue
  end
  print "----------------------------\n".blue
  print "Choice user ID for assignee code review:\n".yellow
  assignee_id = STDIN.gets.chomp
  print "\n#{assignee_id}, "
  print "ok!\n".green
  
  url = "projects/#{$GITLAB_PROJECT_ID}/merge_requests" 
  title = "WIP: ##{@issue_iid} - Code review #{@source_branch}"
  @obj_gitlab = GitLab.request_post(url, {
    source_branch: @source_branch,
    target_branch: @target_branch,
    title: title,
    labels: @labels,
    assignee_id: assignee_id.to_i
  })
  
  print "Merge request for Code Review created with success!\n\n".green
end