Class: RubocopChallenger::PullRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop_challenger/pull_request.rb

Overview

Creates a pull request

Instance Method Summary collapse

Constructor Details

#initialize(user_name:, user_email:, **options) ⇒ PullRequest

Returns a new instance of PullRequest.

Parameters:

  • user_name (String)

    The author name which use at the git commit

  • user_email (String)

    The email address which use at the git commit

  • options (Hash)

    Optional parameters

  • base_branch (Hash)

    a customizable set of options

  • labels (Hash)

    a customizable set of options

  • dry_run (Hash)

    a customizable set of options

  • project_column_name (Hash)

    a customizable set of options

  • project_id (Hash)

    a customizable set of options

  • verbose (Hash)

    a customizable set of options



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rubocop_challenger/pull_request.rb', line 26

def initialize(user_name:, user_email:, **options) # rubocop:disable Metrics/MethodLength
  @pr_comet = PrComet.new(
    base: options[:base_branch],
    branch: "rubocop-challenge/#{timestamp}",
    user_name: user_name,
    user_email: user_email,
    verbose: options[:verbose]
  )
  @labels = options[:labels]
  @dry_run = options[:dry_run]
  @project_column_name = options[:project_column_name]
  @project_id = options[:project_id]
end

Instance Method Details

#commit!(message) { ... } ⇒ Object

Add and commit local files to the pull request

Parameters:

  • message (String)

    The commit message

Yields:

  • Some commands where modify local files

Returns:

  • (Object)

    Return result of yield if you use &block



45
46
47
# File 'lib/rubocop_challenger/pull_request.rb', line 45

def commit!(message, &block)
  pr_comet.commit message, &block
end

#create_regenerate_todo_pr!(before_version, after_version) ⇒ Boolean

Creates a pull request which re-generate “.rubocop_todo.yml” with new version RuboCop.

Parameters:

  • before_version (String)

    The version of RuboCop which created “.rubocop_todo.yml” before re-generate.

  • after_version (String)

    The version of RuboCop which created “.rubocop_todo.yml” after re-generate

Returns:

  • (Boolean)

    Return true if its successed



75
76
77
78
79
80
# File 'lib/rubocop_challenger/pull_request.rb', line 75

def create_regenerate_todo_pr!(before_version, after_version)
  create_pull_request!(
    title: "Re-generate .rubocop_todo.yml with RuboCop v#{after_version}",
    body: generate_pull_request_body(before_version, after_version)
  )
end

#create_rubocop_challenge_pr!(rule, template_file_path = nil) ⇒ Boolean

Creates a pull request for the Rubocop Challenge

Parameters:

  • rule (Rubocop::Rule)

    The corrected rule

  • template_file_path (String, nil) (defaults to: nil)

    The template file name which use to generate the pull request body

Returns:

  • (Boolean)

    Return true if its successed



57
58
59
60
61
62
# File 'lib/rubocop_challenger/pull_request.rb', line 57

def create_rubocop_challenge_pr!(rule, template_file_path = nil)
  create_pull_request!(
    title: "#{rule.title}-#{timestamp}",
    body: Github::PrTemplate.new(rule, template_file_path).generate
  )
end