CiHelper 1.1 → 2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c4adaaacbe78f767b551940eff716bd30a09497
4
- data.tar.gz: fa41339fec784306dfb560c56058bcf1754dc260
3
+ metadata.gz: 962fdd3ea07e2d9a2530b2f40d9f43adadfb34d6
4
+ data.tar.gz: 626d889374f8ea6da9583dc95c5eab5856da5dc8
5
5
  SHA512:
6
- metadata.gz: 5d7573713bea893d6894c5e145e15e43aad09b900412fcce91e1890e6cfb83b21c4feddbf3faac78096f078fb129f638928013c9b45e6927e5ef4f4d972b3593
7
- data.tar.gz: 0516f85d3c6c3f4e0c5ee6a16979d89538aad138bd75df9254e9e577d9ae60c499e3a363277e7cba5aac113d439d5a6581e3b0785c4e7081af54fff9b38a5b58
6
+ metadata.gz: 5aeebe913fe7012d7c34e10986e9e349d86ce6331f844e0dbec7715fe269758f3976a2bdebf3a7e7c555accf6cbf57bae304bc6a06f688cac47fa10b03eb1a2e
7
+ data.tar.gz: e9c3edf5026ba8f1e3ef84ba522eb2c5e08fa6b0c1e272984f20b44db41dcf214dbbb0b5feb21e948b2058c2dca5e56d9a81a8f18fb559cf6bc68c4e1f4b9217
data/lib/ci_helper.rb CHANGED
@@ -1,6 +1,8 @@
1
+ require 'ci_helper/redmine'
1
2
  require 'ci_helper/rspec_result_parser'
2
3
  require 'ci_helper/main_process'
3
4
  require 'ci_helper/ci_procedure'
5
+ require 'ci_helper/bitbucket'
4
6
  require 'ci_helper/bitbucket_procedure'
5
7
  require 'ci_helper/user_command_line_interface'
6
8
  require 'ci_helper/issue_monitor'
@@ -9,4 +11,5 @@ require 'ci_helper/installer'
9
11
  require 'ci_helper/constants'
10
12
  require 'ci_helper/exceptions'
11
13
  require 'ci_helper/redmine_procedure'
12
- require 'ci_helper/redmine/issue_updater'
14
+ require 'ci_helper/functions'
15
+
@@ -0,0 +1,22 @@
1
+ require 'ci_helper/bitbucket/pull_request_page'
2
+
3
+ module CiHelper
4
+ module Bitbucket
5
+
6
+ def form_set(&block)
7
+ block.call(pull_request_form)
8
+ end
9
+
10
+ def submit
11
+ pull_request_form.submit
12
+ end
13
+
14
+ def set_form(form)
15
+ pull_request_form.form = form
16
+ end
17
+
18
+ def pull_request_form
19
+ @form ||= CiHelper::Bitbucket::PullRequestPage.new
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,69 @@
1
+ require 'ci_helper/version'
2
+ module CiHelper
3
+ module Bitbucket
4
+
5
+ class PullRequestPage
6
+
7
+ # This class is responsible for the update the pull request form in the bitbucket
8
+ # example :
9
+ # object.form_set do |config|
10
+ # config.title = 'your title'
11
+ # config.destination = 'the branch name you want to merge'
12
+ # config.reviewer = 'the reviewer you want to add'
13
+ # config.append_description = 'text '
14
+ # config.description_syntax('ruby') do |content|
15
+ # content.value += 'your code'
16
+ # end
17
+ # end
18
+
19
+ attr_accessor :form, :point_counter
20
+
21
+ def initialize
22
+ @point_counter = 1
23
+ end
24
+
25
+ def title=(text)
26
+ form.field_with(name: 'title').value = text
27
+ end
28
+
29
+ def destination=(dest)
30
+ form.field_with(name: 'dest').options.select { |option| option.text == dest.to_s}.first.select
31
+ end
32
+
33
+ def source=(branch_name)
34
+ form.field_with(name: 'source').options.select { |option| option.text == branch_name}.first.select
35
+ end
36
+
37
+ def reviewers=(reviewers)
38
+ form.field_with(name: 'reviewers').value = reviewers
39
+ end
40
+
41
+ def description_point=(text)
42
+ description.value += "#{point_counter}. #{text}\n"
43
+ self.point_counter += 1
44
+ end
45
+
46
+ def append_description=(append_text)
47
+ description.value += "\n#{append_text}\n"
48
+ end
49
+
50
+ def description_syntax(language, &failure_block)
51
+ description.value += "```\n"
52
+ description.value += "#!#{language} \n"
53
+ failure_block.call(description) if block_given?
54
+ description.value += "```\n"
55
+ end
56
+
57
+ def submit
58
+ description.value += "\n CiHelper Version #{::CiHelper::VERSION}"
59
+ form.click_button
60
+ end
61
+
62
+ private
63
+
64
+ def description
65
+ form.field_with(name: 'description')
66
+ end
67
+ end
68
+ end
69
+ end
@@ -3,9 +3,10 @@ require 'mechanize'
3
3
  module CiHelper
4
4
  class BitBucketProcedure
5
5
  BIT_BUCKET_LOGIN_URL = 'https://bitbucket.org/account/signin/'
6
+ include CiHelper::Bitbucket
6
7
 
7
8
  attr_reader :account, :password, :client, :destination, :user_description, :title, :reviewers
8
- attr_reader :pull_request_page, :repository_page
9
+ attr_reader :pull_request_page, :repository_page, :branch_name, :result
9
10
 
10
11
  def initialize(account, password)
11
12
  @account = account
@@ -13,33 +14,37 @@ module CiHelper
13
14
  @client = Mechanize.new
14
15
  end
15
16
 
16
- def create_pull_request(result)
17
+ def create_pull_request
17
18
  login
18
19
  go_to_repo_page
19
20
  go_to_pull_request_page
20
21
 
21
22
  create_pull_request_page = pull_request_page.link_with(href: '/vansys/vansys/pull-request/new').click
22
- redirect_page = create_pull_request_page.form_with(action: '/vansys/vansys/pull-request/new') do |request_form|
23
-
24
- request_form.field_with(name: 'title').value = "##{result.issue_number} - #{title}"
25
- request_form.field_with(name: 'dest').options.select { |option| option.text == destination.to_s }.first.select
26
- request_form.field_with(name: 'source').options.select { |option| option.text == result.branch_name }.first.select
27
- request_form.field_with(name: 'reviewers').value = reviewers
28
- description = request_form.field_with(name: 'description')
29
- description.value = "1. #{CiHelper::REDMINE_DOMAIN}#{result.issue_number.delete('t')}\n"
30
- description.value += "2. #{result.console_link} \n"
31
- description.value += "```\n"
32
- description.value += "#!ruby \n"
33
-
34
- result.failures.each do |failure|
35
- description.value += "#{failure.to_s}\n"
23
+ set_form(create_pull_request_page.form_with(action: '/vansys/vansys/pull-request/new'))
24
+
25
+ form_set do |config|
26
+ config.title = "#{issue_numbers.join(' ')} - #{title}"
27
+ config.destination = destination.to_s
28
+ config.source = branch_name
29
+ config.reviewers = reviewers
30
+
31
+ issue_numbers.each do |number|
32
+ config.description_point = "#{CiHelper::REDMINE_DOMAIN}#{number}"
36
33
  end
37
34
 
38
- description.value += "```\n"
35
+ if result
36
+ config.description_syntax('ruby') do |content|
37
+ result.failures.each do |failure|
38
+ content.append_description = failure.to_s
39
+ end
40
+ end
41
+ end
39
42
 
40
- description.value += user_description
41
- end.click_button
42
- redirect_page
43
+
44
+ config.append_description = user_description
45
+ end
46
+
47
+ submit
43
48
  end
44
49
 
45
50
  def add_destination(destination)
@@ -50,14 +55,30 @@ module CiHelper
50
55
  @user_description = description
51
56
  end
52
57
 
53
- def add_pf_title(title)
58
+ def pf_title=(title)
54
59
  @title = title
55
60
  end
56
61
 
62
+ def multiple_issues?
63
+ issue_numbers.size > 1
64
+ end
65
+
66
+ def issue_numbers
67
+ branch_name.split('_').each { |name| name.delete!('t') }
68
+ end
69
+
70
+ def branch_name=(name)
71
+ @branch_name = name
72
+ end
73
+
57
74
  def reviewers=(reviewers)
58
75
  @reviewers = reviewers
59
76
  end
60
77
 
78
+ def result=(result)
79
+ @result = result
80
+ end
81
+
61
82
  def login
62
83
  login_page = client.get(BIT_BUCKET_LOGIN_URL)
63
84
 
data/lib/ci_helper/cli.rb CHANGED
@@ -61,15 +61,15 @@ module CiHelper
61
61
  end
62
62
 
63
63
  def get_initialize_data
64
- puts 'Please input your ci server a/c '
64
+ puts 'Please input your ci server account '
65
65
  ci_account = gets.chop
66
66
  puts 'Please input your ci server password'
67
67
  ci_password = gets.chop
68
- puts 'Please input your bitbucket a/c'
68
+ puts 'Please input your bitbucket account'
69
69
  bitbucket_account = gets.chop
70
- puts 'Please input your bitbucket passwrod'
70
+ puts 'Please input your bitbucket password'
71
71
  bitbucket_password = gets.chop
72
- puts 'Please input your redmine a/c'
72
+ puts 'Please input your redmine account'
73
73
  redmine_ac = gets.chop
74
74
  puts 'Please input your remind password'
75
75
  redmine_pass = gets.chop
@@ -10,6 +10,7 @@ unfortunately you need to pass the ci and you can get a UT passed >.^ '\n"
10
10
  CI_URL = 'http://ci.raamsys.co.uk/job/RAAM/'
11
11
  REDMINE_DOMAIN = 'http://redmine.raamsys.co.uk/issues/'
12
12
  BITBUCKET_DOMAIN = 'https://bitbucket.org'
13
+
13
14
  PRIORITY = { '1' => 'immediately',
14
15
  '2' => 'urgent',
15
16
  '3' => 'High',
@@ -0,0 +1,4 @@
1
+ require 'ci_helper/functions/base'
2
+ require 'ci_helper/functions/jenkin'
3
+ require 'ci_helper/functions/pull_request'
4
+ require 'ci_helper/functions/redmine'
@@ -0,0 +1,25 @@
1
+ module CiHelper
2
+ module Functions
3
+ class Base
4
+ attr_reader :user_cli, :config,
5
+ :issue_monitor, :bit_bucket_client,
6
+ :redmine_client
7
+
8
+
9
+ def initialize(config)
10
+ @user_cli = CiHelper::UserCommandLineInterface.new
11
+
12
+
13
+
14
+ # @config = YAML.load_file("#{target}/#{CiHelper::CONFIG_FILE_NAME}")
15
+ @issue_monitor = IssueMonitor.new(config.ci_ac, config.ci_pass)
16
+ @bit_bucket_client = BitBucketProcedure.new(config.bit_ac, config.bit_pass)
17
+ @redmine_client = RedmineProcedure.new(config.redmine_ac, config.redmine_pass)
18
+ end
19
+
20
+ def run
21
+ fail NotImplementedError, 'Please implement your function first'
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,71 @@
1
+ module CiHelper
2
+ module Functions
3
+ class Jenkin < Base
4
+ def run
5
+ user_cli.wellcome
6
+ while true
7
+ issue_monitor.matching_strategy = user_cli.get_user_issue_pattern
8
+
9
+ next if issue_monitor.matching_strategy.empty?
10
+
11
+ unless issue_monitor.goto_monitor_page
12
+ next if user_cli.user_want_skip?
13
+ end
14
+
15
+ while !issue_monitor.finish_test?
16
+ user_cli.wait_issue_finish
17
+ end
18
+
19
+ if issue_monitor.success?
20
+ print_console_link
21
+ get_redmine_info
22
+ ask_user_pull_request_information
23
+ # TODO: need to implement the updater_issue class, and then try auto update the issue status
24
+ # update_issue
25
+ else
26
+ print_fails
27
+ print_console_link
28
+ if user_cli.force_create_pull_request?
29
+ redmine_client.issue_no = result.issue_number
30
+ get_redmine_info
31
+ ask_user_pull_request_information
32
+ # update_issue
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def print_fails
41
+ puts 'issue failed here is failures '
42
+ issue_monitor.failures_each do |fail|
43
+ puts fail
44
+ end
45
+ end
46
+
47
+ def ask_user_pull_request_information
48
+ bit_bucket_client.pf_title = redmine_client.issue.description
49
+ user_cli.print_target(redmine_client.target)
50
+ bit_bucket_client.add_destination(user_cli.get_destination)
51
+ bit_bucket_client.add_user_description(user_cli.get_more_info)
52
+ bit_bucket_client.reviewers = user_cli.get_reviewers
53
+ bit_bucket_client.result = result
54
+ user_cli.waiting_for_creation
55
+ bit_bucket_client.create_pull_request(result)
56
+ sleep(0.5)
57
+ bit_bucket_client.go_to_pull_request_page
58
+ sleep(0.5)
59
+ puts "this is your pull request page : #{CiHelper::BITBUCKET_DOMAIN}#{bit_bucket_client.pull_request_page.link_with(class: 'execute').href}"
60
+ end
61
+
62
+ def print_console_link
63
+ puts "Console link: #{result.console_link}"
64
+ end
65
+
66
+ def result
67
+ @result ||= issue_monitor.content
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,37 @@
1
+ module CiHelper
2
+ module Functions
3
+ class PullRequest < Base
4
+
5
+ def run
6
+ bit_bucket_client.branch_name = user_cli.get_branch_name
7
+
8
+ if bit_bucket_client.multiple_issues?
9
+ bit_bucket_client.pf_title = user_cli.customize_title
10
+ else
11
+ get_redmine_info
12
+ bit_bucket_client.pf_title = redmine_client.issue.description
13
+ end
14
+
15
+ bit_bucket_client.add_destination(user_cli.get_destination)
16
+ bit_bucket_client.add_user_description(user_cli.get_more_info)
17
+ bit_bucket_client.reviewers = user_cli.get_reviewers
18
+ user_cli.waiting_for_creation
19
+
20
+ bit_bucket_client.create_pull_request
21
+ sleep(0.5)
22
+ bit_bucket_client.go_to_pull_request_page
23
+ sleep(0.5)
24
+
25
+ puts "this is your pull request page : #{CiHelper::BITBUCKET_DOMAIN}#{bit_bucket_client.pull_request_page.link_with(class: 'execute').href}"
26
+ end
27
+
28
+ private
29
+
30
+ def get_redmine_info
31
+ redmine_client.issue_no = bit_bucket_client.issue_numbers.first
32
+ redmine_client.login
33
+ redmine_client.set_issue_form
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,33 @@
1
+ module CiHelper
2
+ module Functions
3
+ class Redmine < Base
4
+ def run
5
+ @issue_numbers = user_cli.get_issue_numbers
6
+
7
+ if multiple_issues?
8
+ # TODO: handle multiple issue situation
9
+ # This feature need to wait the issue to handle the status which is not exists
10
+ # automaticly change the status for user
11
+ #
12
+ puts 'sorry now we can not handle this situation '
13
+ else
14
+ redmine_client.issue_no = @issue_numbers
15
+ redmine_client.issue_setting do |config|
16
+
17
+ redmine_client.issue.print_all_status
18
+ config.status = user_cli.get_status
19
+ config.text_box = user_cli.get_more_info
20
+ end
21
+
22
+ redmine_client.issue.submit
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def multiple_issues?
29
+ @issue_numbers.split(' ').size > 1
30
+ end
31
+ end
32
+ end
33
+ end
@@ -2,7 +2,9 @@ require 'yaml'
2
2
  require 'byebug'
3
3
  module CiHelper
4
4
  class MainProcess
5
- # This class is responsible the all flow of the testing watching testing result -> create pull request
5
+
6
+ # This class is responsible for asking the function user want to use
7
+ # TODO: maybe this class in the future we can extract to command line use Thor to implement it
6
8
 
7
9
  USER_CONFIG = Struct.new(:ci_ac, :ci_pass,
8
10
  :bit_ac, :bit_pass,
@@ -17,47 +19,24 @@ module CiHelper
17
19
  fail CiHelper::ConfigError, 'Please install to set your account first ' unless config
18
20
 
19
21
  structlize_config
20
-
21
- @issue_monitor = IssueMonitor.new(config.ci_ac, config.ci_pass)
22
- @bit_bucket_client = BitBucketProcedure.new(config.bit_ac, config.bit_pass)
23
- @redmine_client = RedmineProcedure.new(config.redmine_ac, config.redmine_pass)
24
22
  end
25
23
 
26
24
  def run
27
- user_cli.wellcome
28
25
  while true
29
- issue_monitor.matching_strategy = user_cli.get_user_issue_pattern
30
-
31
- next if issue_monitor.matching_strategy.empty?
32
-
33
- unless issue_monitor.goto_monitor_page
34
- next if user_cli.user_want_skip?
35
- end
36
-
37
- while !issue_monitor.finish_test?
38
- user_cli.wait_issue_finish
39
- end
40
-
41
- if issue_monitor.success?
42
- print_console_link
43
- get_redmine_info
44
- create_pull_request
45
- # TODO: need to implement the updater_issue class, and then try auto update the issue status
46
- # update_issue
26
+ @option = user_cli.get_user_choose
27
+
28
+ if ci_monitor?
29
+ CiHelper::Functions::Jenkin.new(config).run
30
+ elsif update_issue?
31
+ CiHelper::Functions::Redmine.new(config).run
32
+ elsif create_pull_request?
33
+ CiHelper::Functions::PullRequest.new(config).run
47
34
  else
48
- print_fails
49
- print_console_link
50
- if user_cli.force_create_pull_request?
51
- get_redmine_info
52
- create_pull_request
53
- # update_issue
54
- end
35
+ puts 'Please dont act like a monkey'
55
36
  end
56
37
  end
57
38
  end
58
39
 
59
- private
60
-
61
40
  def structlize_config
62
41
  self.config = USER_CONFIG.new(config[:ci][:account],
63
42
  config[:ci][:password],
@@ -67,46 +46,16 @@ module CiHelper
67
46
  config[:redmine][:password])
68
47
  end
69
48
 
70
-
71
- def print_fails
72
- puts 'issue failed here is failures '
73
- issue_monitor.failures_each do |fail|
74
- puts fail
75
- end
49
+ def ci_monitor?
50
+ @option == '1'
76
51
  end
77
52
 
78
- def print_console_link
79
- puts "Console link: #{result.console_link}"
80
- end
81
-
82
- def create_pull_request
83
- bit_bucket_client.add_pf_title(redmine_client.description)
84
- bit_bucket_client.add_destination(user_cli.get_destination)
85
- bit_bucket_client.add_user_description(user_cli.get_more_info)
86
- bit_bucket_client.reviewers = user_cli.get_reviewers
87
- user_cli.waiting_for_creation
88
- bit_bucket_client.create_pull_request(result)
89
- sleep(0.5)
90
- bit_bucket_client.go_to_pull_request_page
91
- sleep(0.5)
92
- puts "this is your pull request page : #{CiHelper::BITBUCKET_DOMAIN}#{bit_bucket_client.pull_request_page.link_with(class: 'execute').href}"
93
- end
94
-
95
- def get_redmine_info
96
- redmine_client.issue_no = result.issue_number
97
- redmine_client.login
98
- end
99
-
100
- def update_issue
101
- redmie_client.set do |issue|
102
- issue.status = 'ut_passed'
103
- issue.text_box = result.commit_hash
104
- end
105
- redmine_client.submit
53
+ def update_issue?
54
+ @option == '3'
106
55
  end
107
56
 
108
- def result
109
- @result ||= issue_monitor.content
57
+ def create_pull_request?
58
+ @option == '2'
110
59
  end
111
60
  end
112
61
  end
@@ -1,14 +1,24 @@
1
1
  require 'ci_helper/redmine/issue_updater'
2
2
 
3
+ # when include this module you can set your issue updator and set the update form
4
+ # object.update_issue_page
3
5
  module CiHelper
4
6
  module Redmine
5
7
 
6
- def update_issue_papge=(page)
7
- issue.update_page = page
8
+ def issue_setting(&block)
9
+ block.call(issue)
10
+ end
11
+
12
+ def issue_form=(form)
13
+ issue.form = form
14
+ end
15
+
16
+ def submit
17
+ issue.submit
8
18
  end
9
19
 
10
20
  def issue
11
- @issue ||= Redmine::IssueUpdator.new
21
+ @issue ||= CiHelper::Redmine::IssueUpdater.new
12
22
  end
13
23
  end
14
24
  end
@@ -1,23 +1,88 @@
1
1
  module CiHelper
2
2
  module Redmine
3
+
4
+ # when include Redmine and you will have issue instance that you can use
5
+ # before use it to set your form
6
+ #
7
+ # object.issue_setting do |config|
8
+ # config.status = 'Your status in text or in value'
9
+ # config.text_box = 'your description in string'
10
+ # end
11
+ #
12
+ # object.issue.submit
13
+
3
14
  class IssueUpdater
4
15
 
5
- attr_accessor :update_page
16
+ attr_accessor :update_page, :form
17
+
18
+ STATUS = { 1 => 'New', 2 => 'Progress', 3 => 'Resolved', 5 => 'Closed', 8 => 'UT passed', 10 => 'Reopen' ,12 => 'Information Waiting'}
19
+ STATUS_WORKING_FLOW = [1,2,3,8]
20
+
21
+ def description
22
+ form.field_with(name: 'issue[subject]').value
23
+ end
24
+
25
+ def priority
26
+ # TODO: supply an api for user to pasted the priority of this issue
27
+ fail NotImplementedError, 'not check this method '
28
+ transform_to_word(issue_form.field_with(name: 'issue[prioirty_id]').text.to_i)
29
+ end
6
30
 
7
- def status=(params)
31
+ def status=(user_input)
32
+ # make sure let user select value or text
33
+ status_select_list.value = status_options.select { |option| option.value == user_input}
8
34
  end
9
35
 
10
36
  def text_box=(text)
37
+ text_field.value = text
38
+ end
39
+
40
+ def print_all_status
41
+ status_options_in_text.each_index { |index| puts "status: #{status_options_in_text[index]}, value: #{status_options_in_value[index]}"}
42
+ end
43
+
44
+ def status_options_in_value
45
+ status_select_list.options.map(&:value)
46
+ end
47
+
48
+ def status_options_in_text
49
+ status_select_list.options.map(&:text)
50
+ end
51
+
52
+ def target_version
53
+ target_version_select_list.options.select{ |option| option.value == target_version_select_list.value }
11
54
  end
12
55
 
13
56
  def submit
57
+ # need to handle the submit success or not
58
+ fail Exceptions::SettingError, 'Please set your form before use it' unless form
59
+
14
60
  form.click_button
15
61
  end
16
62
 
17
63
  private
18
64
 
19
- def form
65
+ def status_options
66
+ status_select_list.options
67
+ end
68
+
69
+ def status_select_list
70
+ form.field_with(name: 'issue[status_id]')
71
+ end
72
+
73
+ def text_field
74
+ form.field_with(name: 'issue[notes]')
75
+ end
76
+
77
+ def target_version_select_list
78
+ form.field_with(name: 'issue[fixed_version_id]')
79
+ end
80
+
81
+ private
20
82
 
83
+ # TODO: not implement yet
84
+ def transform_to_word(id)
85
+ CiHelper::PRIORITY[id]
21
86
  end
22
87
  end
23
88
  end
@@ -1,46 +1,41 @@
1
-
2
1
  module CiHelper
3
-
2
+ # This class responsible for traversing the page in the redmine
3
+ # and find the issue form, re-get the page
4
4
 
5
5
  class RedmineProcedure
6
6
  # TODO: use this when implement the auto update
7
- # include Redmine
7
+ include CiHelper::Redmine
8
8
  attr_reader :issue_page, :issue_no, :client, :account, :password
9
9
 
10
10
 
11
11
  def initialize(account, password)
12
12
  @account = account
13
13
  @password = password
14
- @client = Mechanize.new
14
+ @client = Mechanize.new
15
15
  end
16
16
 
17
17
  def issue_no=(no)
18
- @issue_no = no
19
- end
20
-
21
- def description
22
- issue_form.field_with(name: 'issue[subject]').value
18
+ if issue_no
19
+ @issue_no = no
20
+ refresh_issue_page
21
+ set_issue_form
22
+ else
23
+ @issue_no = no
24
+ login
25
+ set_issue_form
26
+ end
23
27
  end
24
28
 
25
- def priority
26
- transform_to_word(issue_form.field_with(name: 'issue[prioirty_id]').text.to_i)
29
+ def set_issue_form
30
+ self.issue_form = form
27
31
  end
28
32
 
29
-
30
- def issue_form
33
+ def form
31
34
  issue_page.form_with(action: "/issues/#{issue_no}")
32
35
  end
33
36
 
34
- def set(&block)
35
- block.call(issue)
36
- end
37
-
38
- def submit
39
- issue.submit
40
- end
41
-
42
37
  def login
43
- login_page = client.get("#{CiHelper::REDMINE_DOMAIN}#{issue_no}")
38
+ login_page = get_issue_page
44
39
 
45
40
  @issue_page = login_page.form_with(action: '/login') do |f|
46
41
  f.field_with(name: 'username').value = account
@@ -48,10 +43,18 @@ module CiHelper
48
43
  end.click_button
49
44
  end
50
45
 
46
+ def refresh_issue_page
47
+ @issue_page = get_issue_page
48
+ end
49
+
50
+ def get_issue_page
51
+ client.get("#{CiHelper::REDMINE_DOMAIN}#{issue_no}")
52
+ end
53
+
51
54
  private
52
55
 
53
56
  def transform_to_word(id)
54
57
  CiHelper::PRIORITY[id]
55
58
  end
56
59
  end
57
- end
60
+ end
@@ -62,17 +62,52 @@ module CiHelper
62
62
  end
63
63
  end
64
64
 
65
+ def get_branch_name
66
+ get_user_input do
67
+ puts branch_name_question
68
+ end
69
+ end
70
+
71
+ def customize_title
72
+ get_user_input do
73
+ puts cusotmize_title_question
74
+ end
75
+ end
76
+
77
+ def get_user_choose
78
+ get_user_input do
79
+ puts options
80
+ end
81
+ end
82
+
65
83
  def get_reviewers
66
84
  option = get_user_input do
67
85
  puts reviewer_question
68
86
  end
87
+ # FIXME: the responsibility to transfer the option to bitbucket acceptable params should be the bit_bucket_procedure
69
88
  option_to_string(option)
70
89
  end
71
90
 
91
+ def get_issue_numbers
92
+ get_user_input do
93
+ puts issue_number_question
94
+ end
95
+ end
96
+
97
+ def get_status
98
+ get_user_input do
99
+ puts 'please input status in value'
100
+ end
101
+ end
102
+
72
103
  def waiting_for_creation
73
104
  puts 'Please move your finger away from the enter, and dont keep pushing the fuckkkkkkking enter, I am creating the pf >.^ '
74
105
  end
75
106
 
107
+ def print_target(target)
108
+ puts "This is your target version #{target}\n"
109
+ end
110
+
76
111
  private
77
112
 
78
113
  def get_user_input(&question_block)
@@ -87,13 +122,26 @@ module CiHelper
87
122
  choosen_key = option.split(' ')
88
123
  reviewer = []
89
124
  choosen_key.each do |value|
90
- fail Exceptions::SettingError, 'Please dont choose Ciao Bao its dangerous !!!!!!!' if value.to_i == CiHelper::DANGEROUS
125
+ if value.to_i == CiHelper::DANGEROUS
126
+ print_ngyan_cat
127
+ fail Exceptions::SettingError, 'Please dont choose Ciao Bao its dangerous !!!!!!!'
128
+ end
129
+
91
130
  reviewer << REVIEWERS[value.to_i]
92
131
  end
93
132
 
94
133
  reviewer.join(',')
95
134
  end
96
135
 
136
+ # TODO: extract to a ngyan cat print lib
137
+ def print_ngyan_cat
138
+ puts ' O----O,'
139
+ puts ' : | 38|\/\ ^^^^'
140
+ puts ' M ~\___(+.+)'
141
+ puts ' U U'
142
+
143
+ end
144
+
97
145
  def issue_not_found_question
98
146
  'Your issue is queue or enter wrong issue number, do you want to wait the queue?'
99
147
  end
@@ -125,5 +173,24 @@ module CiHelper
125
173
  def reviewer_question
126
174
  "Please provide the reviewer 0. Anna 1. Cheryl 2. Millie 3.\\\\ Handsome Alan /////4. GGD 5. Ivan 6. CiaoBao order in gender and alphabetically \n EX: 0 1 2 with one space will be Anna, Cherylyu and Millie"
127
175
  end
176
+
177
+ def branch_name_question
178
+ 'Please Provide branch name you want to merge'
179
+ end
180
+
181
+ def cusotmize_title_question
182
+ 'You branch seems have a lot of issue, please provide your title of pull request'
183
+ end
184
+
185
+ def options
186
+ " 1. Monitor issue in CI and create pull request \n
187
+ 2. input branch name to create pull request \n
188
+ 3. update issue status \n
189
+ please input 1, 2 or 3"
190
+ end
191
+
192
+ def issue_number_question
193
+ 'please input your ticket number you want to update'
194
+ end
128
195
  end
129
196
  end
@@ -1,3 +1,3 @@
1
1
  module CiHelper
2
- VERSION = '1.1'
2
+ VERSION = '2.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: CiHelper
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.1'
4
+ version: '2.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alan Yu
@@ -61,12 +61,18 @@ extra_rdoc_files: []
61
61
  files:
62
62
  - bin/ci_helper
63
63
  - lib/ci_helper.rb
64
+ - lib/ci_helper/bitbucket.rb
64
65
  - lib/ci_helper/bitbucket/pull_request_page.rb
65
66
  - lib/ci_helper/bitbucket_procedure.rb
66
67
  - lib/ci_helper/ci_procedure.rb
67
68
  - lib/ci_helper/cli.rb
68
69
  - lib/ci_helper/constants.rb
69
70
  - lib/ci_helper/exceptions.rb
71
+ - lib/ci_helper/functions.rb
72
+ - lib/ci_helper/functions/base.rb
73
+ - lib/ci_helper/functions/jenkin.rb
74
+ - lib/ci_helper/functions/pull_request.rb
75
+ - lib/ci_helper/functions/redmine.rb
70
76
  - lib/ci_helper/installer.rb
71
77
  - lib/ci_helper/issue_monitor.rb
72
78
  - lib/ci_helper/main_process.rb