CiHelper 1.0.6 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d8c52d40497ebba3b19db7b4d1e05bbca768252d
4
- data.tar.gz: 9c9e4b2c132f498a391e36f7978594fa68751ef4
3
+ metadata.gz: 5c4adaaacbe78f767b551940eff716bd30a09497
4
+ data.tar.gz: fa41339fec784306dfb560c56058bcf1754dc260
5
5
  SHA512:
6
- metadata.gz: 0fcd2ed0ec9f311dc005ae693d89de73342a84e0401bbbef7a83022e72933db7dd5df83fa326740745234454fdc584ad178a69967c7287a2421951ad58458d60
7
- data.tar.gz: 3308a94ee7f5a0d81aeaa854e5aed9a32de692ed61412d3496bfc6df57dbc6f0a6082baf30658b79cbe5d03dd7dbc28817a8836de4ee8faec1b5876ad2c4621f
6
+ metadata.gz: 5d7573713bea893d6894c5e145e15e43aad09b900412fcce91e1890e6cfb83b21c4feddbf3faac78096f078fb129f638928013c9b45e6927e5ef4f4d972b3593
7
+ data.tar.gz: 0516f85d3c6c3f4e0c5ee6a16979d89538aad138bd75df9254e9e577d9ae60c499e3a363277e7cba5aac113d439d5a6581e3b0785c4e7081af54fff9b38a5b58
File without changes
@@ -1,70 +1,85 @@
1
- class BitBucketProcedure
2
- BIT_BUCKET_LOGIN_URL = 'https://bitbucket.org/account/signin/'
3
-
4
- attr_reader :account, :password, :client, :destination, :user_description, :title
5
- attr_reader :pull_request_page, :repository_page
6
-
7
- def initialize(account, password)
8
- @account = account
9
- @password = password
10
- @client = Mechanize.new
11
- end
12
-
13
- def create_pull_request(result)
14
- login
15
- go_to_repo_page
16
- go_to_pull_request_page
17
-
18
- create_pull_request_page = pull_request_page.link_with(href: '/vansys/vansys/pull-request/new').click
19
- redirect_page = create_pull_request_page.form_with(action: '/vansys/vansys/pull-request/new') do |request_form|
20
-
21
- request_form.field_with(name: 'title').value = "issue number #{result.issue_number.to_s} auto create pull request "
22
- request_form.field_with(name: 'dest').options.select { |option| option.text == destination.to_s }.first.select
23
- request_form.field_with(name: 'source').options.select { |option| option.text == result.branch_name }.first.select
24
- description = request_form.field_with(name: 'description')
25
- description.value = "1. #{CiHelper::REDMINE_DOMAIN}#{result.issue_number.delete('t')}\n"
26
- description.value += "2. #{result.console_link} \n"
27
- description.value += "```\n"
28
- description.value += "#!ruby \n"
29
-
30
- result.failures.each do |failure|
31
- description.value += "#{failure.to_s}\n"
32
- end
33
-
34
- description.value += "```\n"
35
-
36
- description.value += user_description
37
- end.click_button
38
- redirect_page
39
- end
40
-
41
- def add_destination(destination)
42
- @destination = destination
43
- end
44
-
45
- def add_user_description(description)
46
- @user_description = description
47
- end
48
-
49
- def add_pf_title(title)
50
- @title = title
51
- end
52
-
53
- def login
54
- login_page = client.get(BIT_BUCKET_LOGIN_URL)
55
-
56
- @response_page = login_page.form_with(action: '/account/signin/') do |f|
57
- f.field_with(name: 'username').value = account
58
- f.field_with(name: 'password').value = password
59
- end.click_button
60
- end
61
-
62
- def go_to_repo_page
63
- @repository_page = @response_page.link_with(href: '/vansys/vansys').click
64
- end
65
-
66
- def go_to_pull_request_page
67
- @pull_request_page = repository_page.link_with(href: '/vansys/vansys/pull-requests').click
1
+ require 'mechanize'
2
+
3
+ module CiHelper
4
+ class BitBucketProcedure
5
+ BIT_BUCKET_LOGIN_URL = 'https://bitbucket.org/account/signin/'
6
+
7
+ attr_reader :account, :password, :client, :destination, :user_description, :title, :reviewers
8
+ attr_reader :pull_request_page, :repository_page
9
+
10
+ def initialize(account, password)
11
+ @account = account
12
+ @password = password
13
+ @client = Mechanize.new
14
+ end
15
+
16
+ def create_pull_request(result)
17
+ login
18
+ go_to_repo_page
19
+ go_to_pull_request_page
20
+
21
+ 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"
36
+ end
37
+
38
+ description.value += "```\n"
39
+
40
+ description.value += user_description
41
+ end.click_button
42
+ redirect_page
43
+ end
44
+
45
+ def add_destination(destination)
46
+ @destination = destination
47
+ end
48
+
49
+ def add_user_description(description)
50
+ @user_description = description
51
+ end
52
+
53
+ def add_pf_title(title)
54
+ @title = title
55
+ end
56
+
57
+ def reviewers=(reviewers)
58
+ @reviewers = reviewers
59
+ end
60
+
61
+ def login
62
+ login_page = client.get(BIT_BUCKET_LOGIN_URL)
63
+
64
+ @response_page = login_page.form_with(action: '/account/signin/') do |f|
65
+ f.field_with(name: 'username').value = account
66
+ f.field_with(name: 'password').value = password
67
+ end.click_button
68
+ end
69
+
70
+ def go_to_repo_page
71
+ fail Exceptions::SettingError, "Please make sure you enter the correct account and password \n and run ci_helper -i again" if login_failed?
72
+ @repository_page = @response_page.link_with(href: '/vansys/vansys').click
73
+ end
74
+
75
+ def go_to_pull_request_page
76
+ @pull_request_page = repository_page.link_with(href: '/vansys/vansys/pull-requests').click
77
+ end
78
+
79
+ private
80
+
81
+ def login_failed?
82
+ @response_page.uri.request_uri.match('signin')
83
+ end
68
84
  end
69
85
  end
70
-
@@ -1,89 +1,88 @@
1
1
  require 'mechanize'
2
2
 
3
- class CiProcedure
3
+ module CiHelper
4
+ class CiProcedure
4
5
  # this class hardcoding the procedure to the result page
5
6
 
6
- CI_LOGIN_URL = 'http://ci.raamsys.co.uk/login?from=%2F'
7
- CI_DOMAIN = 'http://ci.raamsys.co.uk/'
8
- attr_accessor :result, :issue_page, :console_page, :raam_page
9
- attr_reader :account, :password, :mechanize,
10
- :raam_page, :main_page,
11
- :matching_strategy
7
+ CI_LOGIN_URL = 'http://ci.raamsys.co.uk/login?from=%2F'
8
+ CI_DOMAIN = 'http://ci.raamsys.co.uk/'
12
9
 
10
+ attr_accessor :result, :issue_page, :console_page, :matching_strategy, :raam_page
11
+ attr_reader :account, :password, :mechanize, :main_page
13
12
 
14
- Result = Struct.new(:status, :failures)
15
13
 
16
- def initialize(account, password, matching_strategy)
17
- @account = account
18
- @password = password
19
- @matching_strategy = matching_strategy
20
- @mechanize = Mechanize.new
21
- end
14
+ Result = Struct.new(:status, :failures)
22
15
 
23
- def run
24
- @main_page = login
25
- @raam_page = go_to_pull_request_page
26
- @issue_page = go_to_issue
27
- @console_page = go_to_console_output
28
- end
16
+ def initialize(account, password)
17
+ @account = account
18
+ @password = password
19
+ @mechanize = Mechanize.new
20
+ end
29
21
 
30
- def re_get_console_output
31
- self.raam_page = go_to_pull_request_page
32
- self.issue_page = go_to_issue
33
- self.console_page = go_to_console_output
34
- get_console_output
35
- end
22
+ def run
23
+ @main_page = login
24
+ @raam_page = go_to_pull_request_page
25
+ @issue_page = go_to_issue
26
+ @console_page = go_to_console_output
27
+ end
36
28
 
37
- def get_console_output
38
- console_page.search("pre.console-output").text.split("\n")
39
- end
29
+ def re_get_console_output
30
+ self.raam_page = go_to_pull_request_page
31
+ self.issue_page = go_to_issue
32
+ self.console_page = go_to_console_output
33
+ get_console_output
34
+ end
40
35
 
41
- def issue_number
42
- branch_name[1..4]
43
- end
36
+ def get_console_output
37
+ console_page.search("pre.console-output").text
38
+ end
44
39
 
45
- def branch_name
46
- issue_link.text.split(' ')[1]
47
- end
40
+ def issue_number
41
+ branch_name[1..4]
42
+ end
48
43
 
49
- def commit_hash
50
- issue_link.text.split(' ')[2]
51
- end
44
+ def branch_name
45
+ issue_link.text.split(' ')[1]
46
+ end
52
47
 
53
- private
48
+ def commit_hash
49
+ issue_link.text.split(' ')[2]
50
+ end
54
51
 
55
- def login
56
- login_page = mechanize.get(CI_LOGIN_URL)
52
+ private
57
53
 
58
- response_page = login_page.form_with(action: 'j_acegi_security_check') do |form|
59
- form.fields_with(name: 'j_username').first.value = account
60
- form.fields_with(name: 'j_password').first.value = password
61
- end.click_button
54
+ def login
55
+ login_page = mechanize.get(CI_LOGIN_URL)
62
56
 
63
- puts 'login success'
64
- response_page
65
- end
57
+ response_page = login_page.form_with(action: 'j_acegi_security_check') do |form|
58
+ form.fields_with(name: 'j_username').first.value = account
59
+ form.fields_with(name: 'j_password').first.value = password
60
+ end.click_button
66
61
 
67
- def go_to_pull_request_page
68
- main_page.link_with(text: 'Vansys - pull request').click
69
- end
62
+ puts 'login success'
63
+ response_page
64
+ end
70
65
 
71
- def go_to_develop_page
72
- main_page.link_with(text: 'Vansys - develop').click
73
- end
66
+ def go_to_pull_request_page
67
+ main_page.link_with(text: 'Vansys - pull request').click
68
+ end
74
69
 
75
- def go_to_issue
76
- fail CiHelper::Exceptions::IssueNotFound, 'you may be enter wrong ticket number ' unless issue_link
77
- issue_link.click
78
- end
70
+ def go_to_develop_page
71
+ main_page.link_with(text: 'Vansys - develop').click
72
+ end
79
73
 
80
- def go_to_console_output
81
- issue_page ? issue_page.link_with(text: 'Console Output').click : false
82
- end
74
+ def go_to_issue
75
+ fail CiHelper::Exceptions::IssueNotFound, 'you may be enter wrong ticket number ' unless issue_link
76
+ issue_link.click
77
+ end
78
+
79
+ def go_to_console_output
80
+ issue_page ? issue_page.link_with(text: 'Console Output').click : false
81
+ end
83
82
 
84
- def issue_link
85
- links = raam_page.links
86
- links.select { |link| link.text.match(matching_strategy) }.first
83
+ def issue_link
84
+ links = raam_page.links
85
+ links.select { |link| link.text.match(matching_strategy) }.first
86
+ end
87
87
  end
88
88
  end
89
-
data/lib/ci_helper/cli.rb CHANGED
@@ -69,10 +69,14 @@ module CiHelper
69
69
  bitbucket_account = gets.chop
70
70
  puts 'Please input your bitbucket passwrod'
71
71
  bitbucket_password = gets.chop
72
-
72
+ puts 'Please input your redmine a/c'
73
+ redmine_ac = gets.chop
74
+ puts 'Please input your remind password'
75
+ redmine_pass = gets.chop
73
76
 
74
77
  { ci: { account: ci_account, password: ci_password },
75
- bitbucket: { account: bitbucket_account, password: bitbucket_password } }
78
+ bitbucket: { account: bitbucket_account, password: bitbucket_password },
79
+ redmine: { account: redmine_ac, password: redmine_pass}}
76
80
  end
77
81
  end
78
82
  end
@@ -10,4 +10,10 @@ 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
+ PRIORITY = { '1' => 'immediately',
14
+ '2' => 'urgent',
15
+ '3' => 'High',
16
+ '4' => 'normal',
17
+ '5' => 'low'}
18
+ DANGEROUS = 6
13
19
  end
@@ -2,4 +2,6 @@ module CiHelper::Exceptions
2
2
  class IssueNotFound < StandardError; end
3
3
  class InvalidGitRepo < StandardError; end
4
4
  class ConfigError < StandardError; end
5
+ class NoQuestionError < StandardError; end
6
+ class SettingError < StandardError; end
5
7
  end
@@ -13,7 +13,7 @@ module CiHelper
13
13
  ci_config_file = File.join(target, CiHelper::CONFIG_FILE_NAME)
14
14
 
15
15
  result = File.open(ci_config_file, 'w') { |f| f.write(user_setting.to_yaml)}
16
- puts 'intialize success You can run the montior now ' if result
16
+ puts 'initialize success You can run the monitor now ' if result
17
17
  end
18
18
  end
19
19
  end
@@ -1,79 +1,62 @@
1
- class IssueMonitor
1
+ module CiHelper
2
+ class IssueMonitor
3
+ include CiHelper::RspecResultParser
2
4
 
3
- attr_accessor :issue_status
4
- attr_reader :fail_examples, :ci_procedure, :result, :status
5
+ attr_accessor :issue_status
6
+ attr_reader :ci_procedure
5
7
 
6
- Result = Struct.new(:status, :failures,
7
- :console_link, :issue_number,
8
- :branch_name, :commit_hash)
8
+ Result = Struct.new(:status, :failures,
9
+ :console_link, :issue_number,
10
+ :branch_name, :commit_hash)
9
11
 
10
- def initialize(account, password, match_strategy)
11
- @ci_procedure = CiProcedure.new(account, password, match_strategy)
12
- end
13
-
14
- def goto_monitor_page
15
- begin
16
- ci_procedure.run
17
- if finish_test?
18
- parse_output(ci_procedure.get_console_output)
19
- end
20
- true
21
- rescue CiHelper::Exceptions::IssueNotFound => e
22
- puts "#{e.message} #{ci_procedure.matching_strategy}"
23
- false
12
+ def initialize(account, password)
13
+ @ci_procedure = CiProcedure.new(account, password)
24
14
  end
25
- end
26
15
 
27
- def success?
28
- parse_output(ci_procedure.get_console_output)
29
- finish_test? ? status[0].match('success') : false
30
- end
31
-
32
- def finish_test?
33
- begin
34
- output = ci_procedure.re_get_console_output
35
- output.empty? ? false : true
36
- rescue CiHelper::Exceptions::IssueNotFound => e
37
- puts "#{e.message} #{ci_procedure.matching_strategy}"
38
- false
16
+ def matching_strategy=(pattern)
17
+ ci_procedure.matching_strategy = pattern
39
18
  end
40
- end
41
-
42
- def failures_each
43
- fail_examples.each { |failed_example| yield(failed_example) }
44
- end
45
19
 
46
- def content
47
- Result.new(success?, fail_examples,
48
- "#{ci_procedure.console_page.uri.host}/#{ci_procedure.console_page.uri.request_uri}",
49
- ci_procedure.issue_number,
50
- ci_procedure.branch_name,
51
- ci_procedure.commit_hash)
52
- end
20
+ def matching_strategy
21
+ ci_procedure.matching_strategy
22
+ end
53
23
 
54
- private
24
+ def goto_monitor_page
25
+ begin
26
+ ci_procedure.run
27
+ rescue CiHelper::Exceptions::IssueNotFound => e
28
+ puts "#{e.message} #{ci_procedure.matching_strategy}"
29
+ return false
30
+ end
55
31
 
56
- def parse_output(console_output)
57
- start_index = nil
58
- fail_example_start_index = nil
59
- fail_example_end_index = nil
60
- result_index = false
32
+ true
33
+ end
61
34
 
62
- console_output.each_index do |index|
35
+ def success?
36
+ parser.console_output = ci_procedure.get_console_output
37
+ parser.formalize_output
38
+ parser.success?
39
+ end
63
40
 
64
- if console_output[index].match('Finished in')
65
- start_index = index
66
- elsif console_output[index].match('Failed examples:')
67
- fail_example_start_index = index
68
- elsif console_output[index].match('Randomized')
69
- fail_example_end_index = index
70
- elsif console_output[index].match('Finished: ')
71
- result_index = index
41
+ def finish_test?
42
+ begin
43
+ ci_procedure.re_get_console_output.empty? ? false : true
44
+ rescue CiHelper::Exceptions::IssueNotFound => e
45
+ puts "#{e.message} #{ci_procedure.matching_strategy}"
46
+ false
72
47
  end
73
48
  end
74
49
 
75
- @status = console_output[start_index, start_index + 1]
76
- @fail_examples = console_output[fail_example_start_index..fail_example_end_index] if fail_example_start_index
77
- @result = result_index
50
+ def failures_each
51
+ parser.fail_examples.each { |failed_example| yield(failed_example) }
52
+ end
53
+
54
+ def content
55
+ Result.new(success?, parser.fail_examples,
56
+ "#{ci_procedure.console_page.uri.host}/#{ci_procedure.console_page.uri.request_uri}",
57
+ ci_procedure.issue_number,
58
+ ci_procedure.branch_name,
59
+ ci_procedure.commit_hash)
60
+ end
78
61
  end
79
- end
62
+ end
@@ -1,84 +1,113 @@
1
1
  require 'yaml'
2
2
  require 'byebug'
3
- # TODO: need to refactor this class
4
- class MainProcess
3
+ module CiHelper
4
+ class MainProcess
5
+ # This class is responsible the all flow of the testing watching testing result -> create pull request
5
6
 
6
- USER_CONFIG = Struct.new(:ci_ac, :ci_pass, :bit_ac, :bit_pass)
7
+ USER_CONFIG = Struct.new(:ci_ac, :ci_pass,
8
+ :bit_ac, :bit_pass,
9
+ :redmine_ac, :redmine_pass)
7
10
 
8
- attr_accessor :config
11
+ attr_accessor :config, :user_cli
12
+ attr_reader :issue_monitor, :bit_bucket_client, :redmine_client
9
13
 
10
- def initialize(target)
11
- @config = YAML.load_file("#{target}/#{CiHelper::CONFIG_FILE_NAME}")
12
- fail CiHelper::ConfigError, 'Please install to set your account first ' unless config
13
- structulize_config
14
- end
14
+ def initialize(target)
15
+ @config = YAML.load_file("#{target}/#{CiHelper::CONFIG_FILE_NAME}")
16
+ @user_cli = UserCommandLineInterface.new
17
+ fail CiHelper::ConfigError, 'Please install to set your account first ' unless config
15
18
 
16
- def run
17
- puts CiHelper::HELLO_MSG
18
- while true
19
- @issue_is_queued_in_ci = false
20
- puts 'Please Input your next ticked number or commit hash to specifiy the multi test result in the CI'
21
- match_strategy = gets.chop
22
- issue_monitor = IssueMonitor.new(config.ci_ac, config.ci_pass, match_strategy)
23
-
24
- unless issue_monitor.goto_monitor_page # no issue pull request found
25
- # ask user to wait this issue or not
26
- puts 'Your issue is queue or enter wrong issue number, do you want to wait the queue?'
27
- puts 'y\n'
28
- user_input = gets.chop
29
- next if user_input == 'n' || user_input == 'N'
30
- end
19
+ structlize_config
31
20
 
32
- while !issue_monitor.finish_test?
33
- puts 'Your Issue is running the test now, I will check for you every 60seconds'
34
- sleep(CiHelper::WAITING_TIME)
35
- end
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
+ end
36
25
 
37
- if issue_monitor.success?
38
- result = issue_monitor.content
39
- puts " Console link: #{result.console_link}"
40
- bit_bucket_client = BitBucketProcedure.new(config.bit_ac, config.bit_pass)
41
- bit_bucket_client.create_pull_request(issue_monitor.content)
42
- else
26
+ def run
27
+ user_cli.wellcome
28
+ 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
43
36
 
44
- puts 'issue failed here is failures '
45
- issue_monitor.failures_each do |fail|
46
- puts fail
37
+ while !issue_monitor.finish_test?
38
+ user_cli.wait_issue_finish
47
39
  end
48
40
 
49
- result = issue_monitor.content
50
- puts " Console link: #{result.console_link}"
51
-
52
- puts "Are You still wanna crete a pull request ? \n Please make sure all the values are all unstable or you will be killed by Gadii >W<"
53
- puts 'y/n'
54
- user_input = gets.chop
55
- if user_input == 'y' || user_input == 'Y'
56
- bit_bucket_client = BitBucketProcedure.new(config.bit_ac, config.bit_pass)
57
- puts 'Please Provide the destination'
58
- destination = gets.chop
59
- puts 'Please Provide the more description you want add in the text box'
60
- user_description =gets.chop
61
- bit_bucket_client.add_destination(destination)
62
- bit_bucket_client.add_user_description(user_description)
63
- bit_bucket_client.create_pull_request(issue_monitor.content)
64
- sleep(0.5)
65
- bit_bucket_client.go_to_pull_request_page
66
- sleep(0.5)
67
- puts "this is your pull request page : #{CiHelper::BITBUCKET_DOMAIN}#{bit_bucket_client.pull_request_page.link_with(class: 'execute').href}"
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
47
+ 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
68
55
  end
69
56
  end
70
57
  end
71
- end
72
58
 
73
- private
59
+ private
74
60
 
75
- def structulize_config
76
- self.config = USER_CONFIG.new(config[:ci][:account],
77
- config[:ci][:password],
78
- config[:bitbucket][:account],
79
- config[:bitbucket][:password])
80
- end
81
- end
61
+ def structlize_config
62
+ self.config = USER_CONFIG.new(config[:ci][:account],
63
+ config[:ci][:password],
64
+ config[:bitbucket][:account],
65
+ config[:bitbucket][:password],
66
+ config[:redmine][:account],
67
+ config[:redmine][:password])
68
+ end
69
+
70
+
71
+ def print_fails
72
+ puts 'issue failed here is failures '
73
+ issue_monitor.failures_each do |fail|
74
+ puts fail
75
+ end
76
+ end
77
+
78
+ def print_console_link
79
+ puts "Console link: #{result.console_link}"
80
+ end
82
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
83
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
106
+ end
107
+
108
+ def result
109
+ @result ||= issue_monitor.content
110
+ end
111
+ end
112
+ end
84
113
 
@@ -25,5 +25,4 @@ class Robot
25
25
  end
26
26
  end
27
27
 
28
-
29
28
  end
@@ -0,0 +1,24 @@
1
+ module CiHelper
2
+ module Redmine
3
+ class IssueUpdater
4
+
5
+ attr_accessor :update_page
6
+
7
+ def status=(params)
8
+ end
9
+
10
+ def text_box=(text)
11
+ end
12
+
13
+ def submit
14
+ form.click_button
15
+ end
16
+
17
+ private
18
+
19
+ def form
20
+
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ require 'ci_helper/redmine/issue_updater'
2
+
3
+ module CiHelper
4
+ module Redmine
5
+
6
+ def update_issue_papge=(page)
7
+ issue.update_page = page
8
+ end
9
+
10
+ def issue
11
+ @issue ||= Redmine::IssueUpdator.new
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,57 @@
1
+
2
+ module CiHelper
3
+
4
+
5
+ class RedmineProcedure
6
+ # TODO: use this when implement the auto update
7
+ # include Redmine
8
+ attr_reader :issue_page, :issue_no, :client, :account, :password
9
+
10
+
11
+ def initialize(account, password)
12
+ @account = account
13
+ @password = password
14
+ @client = Mechanize.new
15
+ end
16
+
17
+ def issue_no=(no)
18
+ @issue_no = no
19
+ end
20
+
21
+ def description
22
+ issue_form.field_with(name: 'issue[subject]').value
23
+ end
24
+
25
+ def priority
26
+ transform_to_word(issue_form.field_with(name: 'issue[prioirty_id]').text.to_i)
27
+ end
28
+
29
+
30
+ def issue_form
31
+ issue_page.form_with(action: "/issues/#{issue_no}")
32
+ end
33
+
34
+ def set(&block)
35
+ block.call(issue)
36
+ end
37
+
38
+ def submit
39
+ issue.submit
40
+ end
41
+
42
+ def login
43
+ login_page = client.get("#{CiHelper::REDMINE_DOMAIN}#{issue_no}")
44
+
45
+ @issue_page = login_page.form_with(action: '/login') do |f|
46
+ f.field_with(name: 'username').value = account
47
+ f.field_with(name: 'password').value = password
48
+ end.click_button
49
+ end
50
+
51
+ private
52
+
53
+ def transform_to_word(id)
54
+ CiHelper::PRIORITY[id]
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,45 @@
1
+ module CiHelper
2
+ module RspecResultParser
3
+ class Parser
4
+ # This class handle the the result page in the to see the result of test and failures
5
+
6
+ attr_reader :fail_examples, :result, :status, :console_output
7
+
8
+ def console_output=(output_string)
9
+ @console_output = output_string.split("\n")
10
+ formalize_output
11
+ end
12
+
13
+ def success?
14
+ status[0].match('success') ? true : false
15
+ end
16
+
17
+ def formalize_output
18
+ fail Exceptions::SettingError, 'Please set the console output first ' unless console_output
19
+
20
+ start_index = nil
21
+ fail_example_start_index = nil
22
+ fail_example_end_index = nil
23
+ result_index = false
24
+
25
+ console_output.each_index do |index|
26
+
27
+ if console_output[index].match('Finished in')
28
+ start_index = index
29
+ elsif console_output[index].match('Failed examples:')
30
+ fail_example_start_index = index
31
+ elsif console_output[index].match('Randomized')
32
+ fail_example_end_index = index
33
+ elsif console_output[index].match('Finished: ')
34
+ result_index = index
35
+ end
36
+ end
37
+
38
+ @status = console_output[start_index, start_index + 1]
39
+ @fail_examples = console_output[fail_example_start_index..fail_example_end_index] if fail_example_start_index
40
+ @result = result_index
41
+ end
42
+ end
43
+ end
44
+ end
45
+
@@ -0,0 +1,8 @@
1
+ require 'ci_helper/rspec_result_parser/parser'
2
+ module CiHelper
3
+ module RspecResultParser
4
+ def parser
5
+ @parser ||= RspecResultParser::Parser.new
6
+ end
7
+ end
8
+ end
@@ -1,32 +1,129 @@
1
- require_relative 'issue_monitor'
1
+ module CiHelper
2
+ class UserCommandLineInterface
2
3
 
3
- class UserCommandLineInterface
4
4
 
5
- attr_reader :issue_monitor
5
+ # TODO : need to move to bitbucket related setting to let user set
6
+ REVIEWERS = ['anna_ho_2014', 'cherylyu_jcm',
7
+ 'millieho', 'AlanYu', 'GGD', 'ivan_ho_jcm']
6
8
 
7
- def initialize
8
- @issue_monitor = IssueMonitor.new(CiConfig.ci_account, CiConfig.ci_password, ticket_no)
9
- end
9
+ # this class is responsible for get the user input and print the question message
10
+ attr_accessor :user_answer, :matching_strategy
11
+ attr_reader :issue_monitor
10
12
 
11
- def run
13
+ def wellcome
14
+ puts CiHelper::HELLO_MSG
15
+ end
12
16
 
13
- end
17
+ def get_user_issue_pattern
18
+ self.matching_strategy = get_user_input do
19
+ puts matching_strategy_question
20
+ end
14
21
 
15
- def user_answer?
16
- result = gets.chop
17
- result == 'y' || result == 'Y'
18
- end
22
+ matching_strategy
23
+ end
19
24
 
20
- def get_ticket_no
21
25
 
22
- end
26
+ def wait_issue_finish
27
+ puts waitting_reminder
28
+ sleep(CiHelper::WAITING_TIME)
29
+ end
23
30
 
24
- def ticket_question
25
- puts 'Please Input your next ticked number '
26
- end
31
+ def user_want_skip?
32
+ self.user_answer = get_user_input do
33
+ puts issue_not_found_question
34
+ puts 'y\n'
35
+ end
36
+
37
+ !user_answer?
38
+ end
39
+
40
+ def force_create_pull_request?
41
+ self.user_answer = get_user_input do
42
+ puts fail_test_pull_request_question
43
+ puts 'y\n'
44
+ end
45
+
46
+ user_answer?
47
+ end
48
+
49
+ def user_answer?
50
+ user_answer == 'y' || user_answer == 'Y'
51
+ end
52
+
53
+ def get_destination
54
+ get_user_input do
55
+ puts destination_question
56
+ end
57
+ end
58
+
59
+ def get_more_info
60
+ get_user_input do
61
+ puts more_info_question
62
+ end
63
+ end
64
+
65
+ def get_reviewers
66
+ option = get_user_input do
67
+ puts reviewer_question
68
+ end
69
+ option_to_string(option)
70
+ end
71
+
72
+ def waiting_for_creation
73
+ puts 'Please move your finger away from the enter, and dont keep pushing the fuckkkkkkking enter, I am creating the pf >.^ '
74
+ end
75
+
76
+ private
77
+
78
+ def get_user_input(&question_block)
79
+ fail CiHelper::Exceptions::NoQuestionError, 'Please assign a question to get user bollean answer' unless question_block
80
+
81
+ question_block.call
82
+
83
+ return gets.chop
84
+ end
85
+
86
+ def option_to_string(option)
87
+ choosen_key = option.split(' ')
88
+ reviewer = []
89
+ choosen_key.each do |value|
90
+ fail Exceptions::SettingError, 'Please dont choose Ciao Bao its dangerous !!!!!!!' if value.to_i == CiHelper::DANGEROUS
91
+ reviewer << REVIEWERS[value.to_i]
92
+ end
93
+
94
+ reviewer.join(',')
95
+ end
96
+
97
+ def issue_not_found_question
98
+ 'Your issue is queue or enter wrong issue number, do you want to wait the queue?'
99
+ end
100
+
101
+ def matching_strategy_question
102
+ 'Please Input your next ticket number or commit hash to specify the multi test result in the CI'
103
+ end
104
+
105
+ def queueing_question
106
+ 'Your issue is queue or enter wrong issue number, do you want to wait the queue?'
107
+ end
108
+
109
+ def waitting_reminder
110
+ 'Your Issue is running the test now, I will check for you every 60seconds'
111
+ end
112
+
113
+ def fail_test_pull_request_question
114
+ "Are You still wanna crete a pull request ? \n Please make sure all the values are all unstable or you will be killed by Gadii >W<"
115
+ end
116
+
117
+ def destination_question
118
+ 'Please Provide the destination'
119
+ end
120
+
121
+ def more_info_question
122
+ 'Please Provide the more description you want add in the text box'
123
+ end
27
124
 
28
- def queueing_question
29
- puts 'Your issue is queue or enter wrong issue number, do you want to wait the queue?'
30
- puts 'y\n'
125
+ def reviewer_question
126
+ "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
+ end
31
128
  end
32
129
  end
@@ -1,3 +1,3 @@
1
1
  module CiHelper
2
- VERSION = '1.0.6'
2
+ VERSION = '1.1'
3
3
  end
data/lib/ci_helper.rb CHANGED
@@ -1,8 +1,12 @@
1
+ require 'ci_helper/rspec_result_parser'
1
2
  require 'ci_helper/main_process'
2
3
  require 'ci_helper/ci_procedure'
3
4
  require 'ci_helper/bitbucket_procedure'
5
+ require 'ci_helper/user_command_line_interface'
4
6
  require 'ci_helper/issue_monitor'
5
7
  require 'ci_helper/utils'
6
8
  require 'ci_helper/installer'
7
9
  require 'ci_helper/constants'
8
- require 'ci_helper/exceptions'
10
+ require 'ci_helper/exceptions'
11
+ require 'ci_helper/redmine_procedure'
12
+ require 'ci_helper/redmine/issue_updater'
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.0.6
4
+ version: '1.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alan Yu
@@ -10,6 +10,34 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2015-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: mechanize
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -33,6 +61,7 @@ extra_rdoc_files: []
33
61
  files:
34
62
  - bin/ci_helper
35
63
  - lib/ci_helper.rb
64
+ - lib/ci_helper/bitbucket/pull_request_page.rb
36
65
  - lib/ci_helper/bitbucket_procedure.rb
37
66
  - lib/ci_helper/ci_procedure.rb
38
67
  - lib/ci_helper/cli.rb
@@ -42,8 +71,11 @@ files:
42
71
  - lib/ci_helper/issue_monitor.rb
43
72
  - lib/ci_helper/main_process.rb
44
73
  - lib/ci_helper/message.rb
74
+ - lib/ci_helper/redmine.rb
75
+ - lib/ci_helper/redmine/issue_updater.rb
45
76
  - lib/ci_helper/redmine_procedure.rb
46
- - lib/ci_helper/result_parser.rb
77
+ - lib/ci_helper/rspec_result_parser.rb
78
+ - lib/ci_helper/rspec_result_parser/parser.rb
47
79
  - lib/ci_helper/user_command_line_interface.rb
48
80
  - lib/ci_helper/utils.rb
49
81
  - lib/ci_helper/version.rb
@@ -1,5 +0,0 @@
1
- # This class handle the the result page in the to see the result of test and failures
2
-
3
- class ResultParser
4
-
5
- end