CiHelper 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8b1d85508bd75f7abf51621a1145e6390455f81d
4
+ data.tar.gz: 952fb77c4734dc53e3adf83d7ecae852fd897c5f
5
+ SHA512:
6
+ metadata.gz: b2fdec71fde238e21fc09177b5855dfff990eda3bd220b8ec1f69a4ce345df3d1dbaf0d1764175e13d0abf7fe0ae1eba38c5a55e092bb9c3e6d27d71e18d3385
7
+ data.tar.gz: 523b9b78dbbdb7ceb3ea341fa61ea4941492df1d4cc418bd4c1db6231e5034b305a4561d24af4ada2dc33f1970db8b1d0b1f1624f70bbf5c4bba55015785db6d
data/bin/ci_helper ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # require_relative '../lib/ci_helper'
4
+ require 'ci_helper'
5
+ require 'ci_helper/cli'
6
+
7
+ CiHelper::CLI.new(ARGV, STDIN).run
@@ -0,0 +1,58 @@
1
+ require 'byebug'
2
+
3
+
4
+ class BitBucketProcedure
5
+ BIT_BUCKET_LOGIN_URL = 'https://bitbucket.org/account/signin/'
6
+ REDMINE_DOMAIN = 'http://redmine.raamsys.co.uk/issues/'
7
+
8
+ attr_reader :account, :password, :client
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
+ pull_request_page = login
18
+ create_pull_request_page = pull_request_page.link_with(href:'/vansys/vansys/pull-request/new').click
19
+ request_form = create_pull_request_page.form_with(action: '/vansys/vansys/pull-request/new')
20
+
21
+ request_form.field_with(name: 'title').value = 'This is auto create pull request'
22
+ # TODO: let user to choose the destination
23
+ request_form.field_with(name: 'dest').options.select { |option| option.text == 'develop'}.first.select
24
+ request_form.field_with(name: 'source').options.select { |option| option.text == result.issue_number }.first.select
25
+
26
+
27
+ description = request_form.field_with(name: 'description')
28
+ description.value = "1. #{REDMINE_DOMAIN}#{result.issue_number.delete('t')}\n"
29
+ description.value += "2. #{result.console_link} \n"
30
+ description.value += "```\n"
31
+ description.value += "#!ruby \n"
32
+
33
+ result.failures.each do |failure|
34
+ description.value += "#{failure.to_s}\n"
35
+ end
36
+
37
+ description.value += '```'
38
+ request_form.click_button
39
+
40
+ end
41
+
42
+ private
43
+
44
+ def login
45
+ login_page = client.get(BIT_BUCKET_LOGIN_URL)
46
+
47
+ response_page = login_page.form_with(action: '/account/signin/') do |f|
48
+ f.field_with(name: 'username').value = account
49
+ f.field_with(name: 'password').value = password
50
+ end.click_button
51
+
52
+ respository_page = response_page.link_with(href: '/vansys/vansys').click
53
+ pull_request_page = respository_page.link_with(href: '/vansys/vansys/pull-requests').click
54
+
55
+ pull_request_page
56
+ end
57
+ end
58
+
@@ -0,0 +1,74 @@
1
+ # this class hardcoding the procedure to the result page
2
+
3
+ require 'mechanize'
4
+
5
+
6
+ class CiProcedure
7
+
8
+ CI_LOGIN_URL = 'http://ci.raamsys.co.uk/login?from=%2F'
9
+ CI_DOMAIN = 'http://ci.raamsys.co.uk/'
10
+ attr_accessor :result, :issue_page
11
+ attr_reader :account, :password, :mechanize, :issue_number, :console_page, :raam_page, :main_page
12
+
13
+ Result = Struct.new(:status, :failures)
14
+
15
+ def initialize(account, password, issue_number)
16
+ @account = account
17
+ @password = password
18
+ @mechanize = Mechanize.new
19
+ @issue_number = issue_number
20
+ end
21
+
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
28
+
29
+ def re_get_console_output
30
+ @issue_page = go_to_issue
31
+ get_console_output
32
+ end
33
+
34
+ def get_console_output
35
+ console_page.search("pre.console-output").text.split("\n")
36
+ end
37
+
38
+ private
39
+
40
+ def login
41
+ login_page = mechanize.get(CI_LOGIN_URL)
42
+
43
+ response_page = login_page.form_with(action: 'j_acegi_security_check') do |form|
44
+ form.fields_with(name: 'j_username').first.value = account
45
+ form.fields_with(name: 'j_password').first.value = password
46
+ end.click_button
47
+
48
+ puts 'login success'
49
+ response_page
50
+ end
51
+
52
+ def go_to_pull_request_page
53
+ main_page.link_with(text: 'Vansys - pull request').click
54
+ end
55
+
56
+ def go_to_develop_page
57
+ main_page.link_with(text: 'Vansys - develop').click
58
+ end
59
+
60
+ 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
64
+ end
65
+
66
+ def go_to_console_output
67
+ issue_page ? issue_page.link_with(text: 'Console Output').click : false
68
+ end
69
+
70
+ def match_link(links)
71
+ links.select { |link| link.text.match(issue_number) }.first
72
+ end
73
+ end
74
+
@@ -0,0 +1,76 @@
1
+ require 'optparse'
2
+
3
+ module CiHelper
4
+ # Responsible for parsing command-line option and executing appropriate
5
+ # application logic based on those options
6
+ class CLI
7
+
8
+
9
+ attr_reader :arguments, :input, :options, :parser
10
+
11
+ def initialize(arguments, input)
12
+ @arguments = arguments
13
+ @input = input
14
+ @options = {}
15
+ options[:target] = CiHelper::Utils.repo_root
16
+ end
17
+
18
+ def run
19
+ @parser = create_option_parser
20
+ parser.parse!(arguments)
21
+ if initialize?
22
+ user_setting = get_initialize_data
23
+ Installer.new(options[:target], user_setting).install_ci_helper_config
24
+ elsif run?
25
+ MainProcess.new(options[:target]).run
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def create_option_parser
32
+ OptionParser.new do |opts|
33
+ opts.banner = "Usage: #{opts.program_name} [options]"
34
+
35
+ add_information_options(opts)
36
+ end
37
+ end
38
+
39
+ def add_information_options(opts)
40
+ opts.on('-h', '--help', 'Show this message') do
41
+ puts opts.help
42
+ end
43
+
44
+ opts.on('-i', '--install', 'Install a config setting by user input') do
45
+ @options[:action] = :install
46
+ end
47
+
48
+ opts.on('-r', '--run', 'run the ci helper') do
49
+ @options[:action] = :run
50
+ end
51
+ end
52
+
53
+ def initialize?
54
+ options[:action] == :install
55
+ end
56
+
57
+ def run?
58
+ options[:action] == :run
59
+ end
60
+
61
+ def get_initialize_data
62
+ puts 'Please input your ci server a/c '
63
+ ci_account = gets.chop
64
+ puts 'Please input your ci server password'
65
+ ci_password = gets.chop
66
+ puts 'Please input your bitbucket a/c'
67
+ bitbucket_account = gets.chop
68
+ puts 'Please input your bitbucket passwrod'
69
+ bitbucket_password = gets.chop
70
+
71
+
72
+ { ci: { account: ci_account, password: ci_password },
73
+ bitbucket: { account: bitbucket_account, password: bitbucket_password } }
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,11 @@
1
+ module CiHelper
2
+ HOME = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
3
+ CONFIG_FILE_NAME = '.ci_helper_config.yml'
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,
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/'
11
+ end
@@ -0,0 +1,5 @@
1
+ module CiHelper::Exceptions
2
+ class IssueNotFound < StandardError; end
3
+ class InvalidGitRepo < StandardError; end
4
+ class ConfigError < StandardError; end
5
+ end
@@ -0,0 +1,19 @@
1
+ require 'yaml'
2
+ module CiHelper
3
+ # Responsible for create the setting file in the git repo
4
+ class Installer
5
+ attr_reader :target, :user_setting
6
+
7
+ def initialize(target, user_setting)
8
+ @target = target
9
+ @user_setting = user_setting
10
+ end
11
+
12
+ def install_ci_helper_config
13
+ ci_config_file = File.join(target, CiHelper::CONFIG_FILE_NAME)
14
+
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
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,74 @@
1
+ class IssueMonitor
2
+
3
+ attr_accessor :issue_number, :issue_status
4
+ attr_reader :fail_examples, :ci_procedure, :result, :status
5
+
6
+ Result = Struct.new(:status, :failures, :console_link, :issue_number)
7
+
8
+ def initialize(account, password, ticked_number)
9
+ @issue_number = "t#{ticked_number}"
10
+ @ci_procedure = CiProcedure.new(account, password, ticked_number)
11
+ end
12
+
13
+ def goto_monitor_page
14
+ begin
15
+ ci_procedure.run
16
+ if finish_test?
17
+ parse_output(ci_procedure.get_console_output)
18
+ end
19
+ true
20
+ rescue CiHelper::Exceptions::IssueNotFound => e
21
+ puts "#{e.message} #{issue_number}"
22
+ false
23
+ end
24
+ end
25
+
26
+ def success?
27
+ finish_test? ? status[0].match('success') : false
28
+ end
29
+
30
+ def finish_test?
31
+ begin
32
+ output = ci_procedure.re_get_console_output
33
+ output.empty? ? false : true
34
+ rescue CiHelper::Exception::IssueNotFound => e
35
+ puts "#{e.message} #{issue_number}"
36
+ false
37
+ end
38
+ end
39
+
40
+ def failures_each
41
+ fail_examples.each { |failed_example| yield(failed_example) }
42
+ end
43
+
44
+ def content
45
+ Result.new(success?, fail_examples, "#{ci_procedure.console_page.uri.host}/#{ci_procedure.console_page.uri.request_uri}", issue_number)
46
+ end
47
+
48
+ private
49
+
50
+ def parse_output(console_output)
51
+ start_index = nil
52
+ fail_example_start_index = nil
53
+ fail_example_end_index = nil
54
+ result_index = false
55
+
56
+ console_output.each_index do |index|
57
+
58
+ if console_output[index].match('Finished in')
59
+ start_index = index
60
+ elsif console_output[index].match('Failed examples:')
61
+ fail_example_start_index = index
62
+ elsif console_output[index].match('Randomized')
63
+ fail_example_end_index = index
64
+ elsif console_output[index].match('Finished: ')
65
+ result_index = index
66
+ end
67
+
68
+ end
69
+
70
+ @status = console_output[start_index, start_index + 1]
71
+ @fail_examples = console_output[fail_example_start_index..fail_example_end_index] if fail_example_start_index
72
+ @result = result_index
73
+ end
74
+ end
@@ -0,0 +1,79 @@
1
+ require 'yaml'
2
+ require_relative 'issue_monitor'
3
+ require_relative 'bitbucket_procedure'
4
+
5
+ # TODO: need to refactor this class
6
+ class MainProcess
7
+
8
+ USER_CONFIG = Struct.new(:ci_ac,:ci_pass, :bit_ac, :bit_pass)
9
+
10
+ attr_accessor :config
11
+
12
+ def initialize(target)
13
+ @config = YAML.load_file("#{target}/#{CiHelper::CONFIG_FILE_NAME}")
14
+ fail CiHelper::ConfigError, 'Please install to set your account first ' unless config
15
+ structulize_config
16
+ end
17
+
18
+ def run
19
+ puts CiHelper::HELLO_MSG
20
+ while true
21
+ @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
+
26
+
27
+ unless issue_monitor.goto_monitor_page # no issue pull request found
28
+ # ask user to wait this issue or not
29
+ puts 'Your issue is queue or enter wrong issue number, do you want to wait the queue?'
30
+ puts 'y\n'
31
+ user_input = gets.chop
32
+ next if user_input == 'n' || user_input == 'N'
33
+ end
34
+
35
+ while !issue_monitor.finish_test?
36
+ puts 'Your Issue is running the test now, I will check for you every 60seconds'
37
+ sleep(CiHelper::WAITING_TIME)
38
+ end
39
+
40
+ if issue_monitor.success?
41
+ result = issue_monitor.content
42
+ puts " Console link: #{result.console_link}"
43
+ bit_bucket_client = BitBucketProcedure.new(config.bit_ac,config.bit_pass)
44
+ bit_bucket_client.create_pull_request(issue_monitor.content)
45
+ else
46
+
47
+ puts 'issue failed here is failures '
48
+ issue_monitor.failures_each do |fail|
49
+ puts fail
50
+ end
51
+
52
+ result = issue_monitor.content
53
+ puts " Console link: #{result.console_link}"
54
+
55
+ 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<"
56
+ puts 'y/n'
57
+ user_input = gets.chop
58
+ if user_input == 'y' || user_input == 'Y'
59
+ bit_bucket_client = BitBucketProcedure.new(config.bit_ac, config.bit_pass)
60
+ bit_bucket_client.create_pull_request(issue_monitor.content)
61
+ else
62
+
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ private
69
+
70
+ def structulize_config
71
+ self.config = USER_CONFIG.new(config[:ci][:account],
72
+ config[:ci][:password],
73
+ config[:bitbucket][:account],
74
+ config[:bitbucket][:password])
75
+ end
76
+ end
77
+
78
+
79
+
@@ -0,0 +1,29 @@
1
+ class Robot
2
+
3
+ class << self
4
+
5
+
6
+ def
7
+ def hello_msg
8
+
9
+ end
10
+ def ask_ticket_no
11
+ puts 'Please Input ur next ticked number '
12
+ end
13
+
14
+ def console_link(link)
15
+ puts " Console link: #{link}"
16
+ end
17
+
18
+ def teslant_failed
19
+
20
+ end
21
+
22
+ def confirm_with_user_with_failures
23
+ puts 'Are You still wanna crete a pull request ? Please make sure all the values are all unstable or you will be killed by Gadii >W<'
24
+
25
+ end
26
+ end
27
+
28
+
29
+ end
File without changes
@@ -0,0 +1,5 @@
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
@@ -0,0 +1,32 @@
1
+ require_relative 'issue_monitor'
2
+
3
+ class UserCommandLineInterface
4
+
5
+ attr_reader :issue_monitor
6
+
7
+ def initialize
8
+ @issue_monitor = IssueMonitor.new(CiConfig.ci_account, CiConfig.ci_password, ticket_no)
9
+ end
10
+
11
+ def run
12
+
13
+ end
14
+
15
+ def user_answer?
16
+ result = gets.chop
17
+ result == 'y' || result == 'Y'
18
+ end
19
+
20
+ def get_ticket_no
21
+
22
+ end
23
+
24
+ def ticket_question
25
+ puts 'Please Input your next ticked number '
26
+ end
27
+
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'
31
+ end
32
+ end
@@ -0,0 +1,18 @@
1
+ module CiHelper
2
+ class Utils
3
+ def self.repo_root
4
+ @repo_root ||=
5
+ begin
6
+ # TODO : understand the code here
7
+ git_dir = Pathname.new(File.expand_path('.')).enum_for(:ascend).find do |path|
8
+ File.exist?(File.join(path, '.git'))
9
+ end
10
+
11
+ unless git_dir
12
+ raise CiHelper::Exceptions::InvalidGitRepo, 'no .git directory found'
13
+ end
14
+ git_dir.to_s
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module CiHelper
2
+ VERSION = '0.0.1'
3
+ end
data/lib/ci_helper.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'ci_helper/main_process'
2
+ require 'ci_helper/ci_procedure'
3
+ require 'ci_helper/bitbucket_procedure'
4
+ require 'ci_helper/issue_monitor'
5
+ require 'byebug'
6
+ require 'ci_helper/utils'
7
+ require 'ci_helper/installer'
8
+ require 'ci_helper/constants'
9
+ require 'ci_helper/exceptions'
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: CiHelper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alan Yu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: let you create pull request and montior the failures easier in CI
14
+ email: alan21120000@gmail.com
15
+ executables:
16
+ - ci_helper
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/ci_helper
21
+ - lib/ci_helper.rb
22
+ - lib/ci_helper/bitbucket_procedure.rb
23
+ - lib/ci_helper/ci_procedure.rb
24
+ - lib/ci_helper/cli.rb
25
+ - lib/ci_helper/constants.rb
26
+ - lib/ci_helper/exceptions.rb
27
+ - lib/ci_helper/installer.rb
28
+ - lib/ci_helper/issue_monitor.rb
29
+ - lib/ci_helper/main_process.rb
30
+ - lib/ci_helper/message.rb
31
+ - lib/ci_helper/redmine_procedure.rb
32
+ - lib/ci_helper/result_parser.rb
33
+ - lib/ci_helper/user_command_line_interface.rb
34
+ - lib/ci_helper/utils.rb
35
+ - lib/ci_helper/version.rb
36
+ homepage: http://rubygems.org/gems/ci_helper
37
+ licenses:
38
+ - MIT
39
+ metadata: {}
40
+ post_install_message: Initialize a config file by running `ci_helper --install` in
41
+ your GIT repo
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 2.2.2
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: A tool for contious integration server
61
+ test_files: []