CiHelper 0.0.2 → 1.0.0

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: fc97f3aa3f06feae56dc974ec5b64839a3b6208a
4
- data.tar.gz: 1e9c71d13ec3bb145aec02c36f8b2d67ae19a268
3
+ metadata.gz: 552b3f86b048155b318564a7c0f8f1a0d7f29d99
4
+ data.tar.gz: 021e1fc98fd6f9cc251d3c7b952020c3f93cddac
5
5
  SHA512:
6
- metadata.gz: 9add8d1bc3ccce686d0099ce923caa4804669bc9c55c521393a2aa8c3a03f3633d82a0d29f41affb28a0ccf4c922ce7c15e948f00185e734eb2e1c85b5a2a0b5
7
- data.tar.gz: aaf22f4693d23a32f960453ffea9ce03d1359f5cf65ee73a8218b4db69e48801e283e3b75b54312c4be4d9ac2730fae081760277cd64a7d6f33c09dda7fe814f
6
+ metadata.gz: 80f619e46206226cef2be4f7c31ebc2c2cbd1f298a67b56ec553b0ced50de685a6a927c475724547c64592ed9c8d4c0b3626c07843e1cc01cd6559c237fd44c7
7
+ data.tar.gz: eaf0311b741bf17c71505d1e9dbf3d8efc15248b8a76279850c9fb54558cb4e83349facb1b08fadf804c8721b0a843f09617645f56b41148679ae96ea057f607
@@ -1,57 +1,70 @@
1
-
2
-
3
1
  class BitBucketProcedure
4
- BIT_BUCKET_LOGIN_URL = 'https://bitbucket.org/account/signin/'
5
- REDMINE_DOMAIN = 'http://redmine.raamsys.co.uk/issues/'
2
+ BIT_BUCKET_LOGIN_URL = 'https://bitbucket.org/account/signin/'
6
3
 
7
- attr_reader :account, :password, :client
4
+ attr_reader :account, :password, :client, :destination, :user_description, :title
5
+ attr_reader :pull_request_page, :repository_page
8
6
 
9
7
  def initialize(account, password)
10
8
  @account = account
11
9
  @password = password
12
- @client = Mechanize.new
10
+ @client = Mechanize.new
13
11
  end
14
12
 
15
13
  def create_pull_request(result)
16
- pull_request_page = login
17
- create_pull_request_page = pull_request_page.link_with(href:'/vansys/vansys/pull-request/new').click
18
- request_form = create_pull_request_page.form_with(action: '/vansys/vansys/pull-request/new')
14
+ login
15
+ go_to_repo_page
16
+ go_to_pull_request_page
19
17
 
20
- request_form.field_with(name: 'title').value = 'This is auto create pull request'
21
- # TODO: let user to choose the destination
22
- request_form.field_with(name: 'dest').options.select { |option| option.text == 'develop'}.first.select
23
- request_form.field_with(name: 'source').options.select { |option| option.text == result.issue_number }.first.select
18
+ create_pull_requcest_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|
24
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"
25
29
 
26
- description = request_form.field_with(name: 'description')
27
- description.value = "1. #{REDMINE_DOMAIN}#{result.issue_number.delete('t')}\n"
28
- description.value += "2. #{result.console_link} \n"
29
- description.value += "```\n"
30
- description.value += "#!ruby \n"
30
+ result.failures.each do |failure|
31
+ description.value += "#{failure.to_s}\n"
32
+ end
31
33
 
32
- result.failures.each do |failure|
33
- description.value += "#{failure.to_s}\n"
34
- end
34
+ description.value += "```\n"
35
35
 
36
- description.value += '```'
37
- request_form.click_button
36
+ description.value += user_description
37
+ end.click_button
38
+ redirect_page
39
+ end
38
40
 
41
+ def add_destination(destination)
42
+ @destination = destination
39
43
  end
40
44
 
41
- private
45
+ def add_user_description(description)
46
+ @user_description = description
47
+ end
48
+
49
+ def add_pf_title(title)
50
+ @title = title
51
+ end
42
52
 
43
53
  def login
44
54
  login_page = client.get(BIT_BUCKET_LOGIN_URL)
45
55
 
46
- response_page = login_page.form_with(action: '/account/signin/') do |f|
56
+ @response_page = login_page.form_with(action: '/account/signin/') do |f|
47
57
  f.field_with(name: 'username').value = account
48
58
  f.field_with(name: 'password').value = password
49
59
  end.click_button
60
+ end
50
61
 
51
- respository_page = response_page.link_with(href: '/vansys/vansys').click
52
- pull_request_page = respository_page.link_with(href: '/vansys/vansys/pull-requests').click
62
+ def go_to_repo_page
63
+ @repository_page = @response_page.link_with(href: '/vansys/vansys').click
64
+ end
53
65
 
54
- pull_request_page
66
+ def go_to_pull_request_page
67
+ @pull_request_page = repository_page.link_with(href: '/vansys/vansys/pull-requests').click
55
68
  end
56
69
  end
57
70
 
@@ -1,22 +1,23 @@
1
- # this class hardcoding the procedure to the result page
2
-
3
1
  require 'mechanize'
4
2
 
5
-
6
3
  class CiProcedure
4
+ # this class hardcoding the procedure to the result page
7
5
 
8
6
  CI_LOGIN_URL = 'http://ci.raamsys.co.uk/login?from=%2F'
9
7
  CI_DOMAIN = 'http://ci.raamsys.co.uk/'
10
8
  attr_accessor :result, :issue_page
11
- attr_reader :account, :password, :mechanize, :issue_number, :console_page, :raam_page, :main_page
9
+ attr_reader :account, :password, :mechanize,
10
+ :console_page, :raam_page, :main_page,
11
+ :matching_strategy
12
+
12
13
 
13
14
  Result = Struct.new(:status, :failures)
14
15
 
15
- def initialize(account, password, issue_number)
16
- @account = account
17
- @password = password
18
- @mechanize = Mechanize.new
19
- @issue_number = issue_number
16
+ def initialize(account, password, matching_strategy)
17
+ @account = account
18
+ @password = password
19
+ @matching_strategy = matching_strategy
20
+ @mechanize = Mechanize.new
20
21
  end
21
22
 
22
23
  def run
@@ -27,7 +28,8 @@ class CiProcedure
27
28
  end
28
29
 
29
30
  def re_get_console_output
30
- @issue_page = go_to_issue
31
+ @issue_page = go_to_issue
32
+ @console_page = go_to_console_output
31
33
  get_console_output
32
34
  end
33
35
 
@@ -35,6 +37,18 @@ class CiProcedure
35
37
  console_page.search("pre.console-output").text.split("\n")
36
38
  end
37
39
 
40
+ def issue_number
41
+ branch_name[1..4]
42
+ end
43
+
44
+ def branch_name
45
+ issue_link.text.split(' ')[1]
46
+ end
47
+
48
+ def commit_hash
49
+ issue_link.text.split(' ')[2]
50
+ end
51
+
38
52
  private
39
53
 
40
54
  def login
@@ -58,17 +72,17 @@ class CiProcedure
58
72
  end
59
73
 
60
74
  def go_to_issue
61
- link = match_link(raam_page.links)
62
- fail CiHelper::Exceptions::IssueNotFound, 'you may be enter wrong ticket number ' unless link
63
- link.click
75
+ fail CiHelper::Exceptions::IssueNotFound, 'you may be enter wrong ticket number ' unless issue_link
76
+ issue_link.click
64
77
  end
65
78
 
66
79
  def go_to_console_output
67
80
  issue_page ? issue_page.link_with(text: 'Console Output').click : false
68
81
  end
69
82
 
70
- def match_link(links)
71
- links.select { |link| link.text.match(issue_number) }.first
83
+ def issue_link
84
+ links = raam_page.links
85
+ @link ||= links.select { |link| link.text.match(matching_strategy) }.first
72
86
  end
73
87
  end
74
88
 
@@ -1,11 +1,13 @@
1
1
  module CiHelper
2
- HOME = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
2
+ HOME = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
3
3
  CONFIG_FILE_NAME = '.ci_helper_config.yml'
4
4
  # HOOK_DIRECTORY = File.join(HOME, 'lib', 'overcommit', 'hook')
5
- REPO_URL = 'https://github.com/alan2112000/ci_helper'
6
- BUG_REPORT_URL = "#{REPO_URL}/issues"
7
- WAITING_TIME = 60
8
- HELLO_MSG = "Hello Everybody, Congratulation You finished a issue,
5
+ REPO_URL = 'https://github.com/alan2112000/ci_helper'
6
+ BUG_REPORT_URL = "#{REPO_URL}/issues"
7
+ WAITING_TIME = 60
8
+ HELLO_MSG = "Hello Everybody, Congratulation You finished a issue,
9
9
  unfortunately you need to pass the ci and you can get a UT passed >.^ '\n"
10
- CI_URL = 'http://ci.raamsys.co.uk/job/RAAM/'
10
+ CI_URL = 'http://ci.raamsys.co.uk/job/RAAM/'
11
+ REDMINE_DOMAIN = 'http://redmine.raamsys.co.uk/issues/'
12
+ BITBUCKET_DOMAIN = 'https://bitbucket.org'
11
13
  end
@@ -1,13 +1,14 @@
1
1
  class IssueMonitor
2
2
 
3
- attr_accessor :issue_number, :issue_status
3
+ attr_accessor :issue_status
4
4
  attr_reader :fail_examples, :ci_procedure, :result, :status
5
5
 
6
- Result = Struct.new(:status, :failures, :console_link, :issue_number)
6
+ Result = Struct.new(:status, :failures,
7
+ :console_link, :issue_number,
8
+ :branch_name, :commit_hash)
7
9
 
8
- def initialize(account, password, ticked_number)
9
- @issue_number = "t#{ticked_number}"
10
- @ci_procedure = CiProcedure.new(account, password, ticked_number)
10
+ def initialize(account, password, match_strategy)
11
+ @ci_procedure = CiProcedure.new(account, password, match_strategy)
11
12
  end
12
13
 
13
14
  def goto_monitor_page
@@ -29,8 +30,8 @@ class IssueMonitor
29
30
 
30
31
  def finish_test?
31
32
  begin
32
- output = ci_procedure.re_get_console_output
33
- output.empty? ? false : true
33
+ output = ci_procedure.re_get_console_output
34
+ output.empty? ? false : true
34
35
  rescue CiHelper::Exception::IssueNotFound => e
35
36
  puts "#{e.message} #{issue_number}"
36
37
  false
@@ -42,7 +43,9 @@ class IssueMonitor
42
43
  end
43
44
 
44
45
  def content
45
- Result.new(success?, fail_examples, "#{ci_procedure.console_page.uri.host}/#{ci_procedure.console_page.uri.request_uri}", issue_number)
46
+ Result.new(success?, fail_examples,
47
+ "#{ci_procedure.console_page.uri.host}/#{ci_procedure.console_page.uri.request_uri}", ci_procedure.issue_number,
48
+ ci_procedure.branch_name, ci_procedure.commit_hash)
46
49
  end
47
50
 
48
51
  private
@@ -55,7 +58,7 @@ class IssueMonitor
55
58
 
56
59
  console_output.each_index do |index|
57
60
 
58
- if console_output[index].match('Finished in')
61
+ if console_output[index].match('Finished in')
59
62
  start_index = index
60
63
  elsif console_output[index].match('Failed examples:')
61
64
  fail_example_start_index = index
@@ -64,7 +67,6 @@ class IssueMonitor
64
67
  elsif console_output[index].match('Finished: ')
65
68
  result_index = index
66
69
  end
67
-
68
70
  end
69
71
 
70
72
  @status = console_output[start_index, start_index + 1]
@@ -1,7 +1,5 @@
1
1
  require 'yaml'
2
- require_relative 'issue_monitor'
3
- require_relative 'bitbucket_procedure'
4
-
2
+ require 'byebug'
5
3
  # TODO: need to refactor this class
6
4
  class MainProcess
7
5
 
@@ -19,10 +17,9 @@ class MainProcess
19
17
  puts CiHelper::HELLO_MSG
20
18
  while true
21
19
  @issue_is_queued_in_ci = false
22
- puts 'Please Input your next ticked number '
23
- ticket_no = gets.chop
24
- issue_monitor = IssueMonitor.new(config.ci_ac, config.ci_pass, ticket_no)
25
-
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)
26
23
 
27
24
  unless issue_monitor.goto_monitor_page # no issue pull request found
28
25
  # ask user to wait this issue or not
@@ -57,9 +54,17 @@ class MainProcess
57
54
  user_input = gets.chop
58
55
  if user_input == 'y' || user_input == 'Y'
59
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)
60
63
  bit_bucket_client.create_pull_request(issue_monitor.content)
61
- else
62
-
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}"
63
68
  end
64
69
  end
65
70
  end
File without changes
@@ -1,3 +1,3 @@
1
1
  module CiHelper
2
- VERSION = '0.0.2'
2
+ VERSION = '1.0.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: 0.0.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alan Yu
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.7.3
19
+ version: '2.7'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.7.3
26
+ version: '2.7'
27
27
  description: In house tool only for JCM team
28
28
  email: alan21120000@gmail.com
29
29
  executables:
@@ -45,6 +45,7 @@ files:
45
45
  - lib/ci_helper/redmine_procedure.rb
46
46
  - lib/ci_helper/result_parser.rb
47
47
  - lib/ci_helper/user_command_line_interface.rb
48
+ - lib/ci_helper/user_intercation_interface.rb
48
49
  - lib/ci_helper/utils.rb
49
50
  - lib/ci_helper/version.rb
50
51
  homepage: http://rubygems.org/gems/ci_helper