class CiHelper::BitBucketProcedure

Constants

BIT_BUCKET_LOGIN_URL

Attributes

account[R]
branch_name[R]
client[R]
destination[R]
password[R]
pull_request_page[R]
repository_page[R]
result[R]
reviewers[R]
title[R]
user_description[R]

Public Class Methods

new(account, password) click to toggle source
# File lib/ci_helper/bitbucket_procedure.rb, line 11
def initialize(account, password)
  @account  = account
  @password = password
  @client   = Mechanize.new
end

Public Instance Methods

add_destination(destination) click to toggle source
# File lib/ci_helper/bitbucket_procedure.rb, line 49
def add_destination(destination)
  @destination = destination
end
add_user_description(description) click to toggle source
# File lib/ci_helper/bitbucket_procedure.rb, line 53
def add_user_description(description)
  @user_description = description
end
branch_name=(name) click to toggle source
# File lib/ci_helper/bitbucket_procedure.rb, line 70
def branch_name=(name)
  @branch_name = name
end
create_pull_request() click to toggle source
# File lib/ci_helper/bitbucket_procedure.rb, line 17
def create_pull_request
  login
  go_to_repo_page
  go_to_pull_request_page

  create_pull_request_page = pull_request_page.link_with(href: '/vansys/vansys/pull-request/new').click
  set_form(create_pull_request_page.form_with(action: '/vansys/vansys/pull-request/new'))

  form_set do |config|
    config.title       = "#{issue_numbers.join(' ')} - #{title}"
    config.destination = destination.to_s
    config.source      = branch_name
    config.reviewers   = reviewers

    issue_numbers.each do |number|
      config.description_point = "#{CiHelper::REDMINE_DOMAIN}#{number}"
    end

    if result
      config.description_syntax('ruby') do |content|
        result.failures.each do |failure|
          content.append_description = failure.to_s
        end
      end
    end

    config.append_description = user_description
  end

  submit
end
go_to_pull_request_page() click to toggle source
# File lib/ci_helper/bitbucket_procedure.rb, line 96
def go_to_pull_request_page
  @pull_request_page = repository_page.link_with(href: '/vansys/vansys/pull-requests').click
end
go_to_repo_page() click to toggle source
# File lib/ci_helper/bitbucket_procedure.rb, line 91
def go_to_repo_page
  fail Exceptions::SettingError, "Please make sure you enter the correct account and password \n and run ci_helper -i again" if login_failed?
  @repository_page = @response_page.link_with(href: '/vansys/vansys').click
end
issue_numbers() click to toggle source

transform the user input branch name t3001 t3001_reopen or t3001_t3002_t3003 to [3001], [3001] or [3001,3002,3003]

# File lib/ci_helper/bitbucket_procedure.rb, line 66
def issue_numbers
  branch_name.split('_').each { |name| name.delete!('t') }.delete_if { |name| name.to_i.zero?}
end
login() click to toggle source
# File lib/ci_helper/bitbucket_procedure.rb, line 82
def login
  login_page = client.get(BIT_BUCKET_LOGIN_URL)

  @response_page = login_page.form_with(action: '/account/signin/') do |f|
    f.field_with(name: 'username').value = account
    f.field_with(name: 'password').value = password
  end.click_button
end
multiple_issues?() click to toggle source
# File lib/ci_helper/bitbucket_procedure.rb, line 61
def multiple_issues?
  issue_numbers.size > 1
end
pf_title=(title) click to toggle source
# File lib/ci_helper/bitbucket_procedure.rb, line 57
def pf_title=(title)
  @title = title
end
result=(result) click to toggle source
# File lib/ci_helper/bitbucket_procedure.rb, line 78
def result=(result)
  @result = result
end
reviewers=(reviewers) click to toggle source
# File lib/ci_helper/bitbucket_procedure.rb, line 74
def reviewers=(reviewers)
  @reviewers = reviewers
end

Private Instance Methods

login_failed?() click to toggle source
# File lib/ci_helper/bitbucket_procedure.rb, line 102
def login_failed?
  @response_page.uri.request_uri.match('signin')
end