Class: Abak::Flow::PullRequest

Inherits:
Object
  • Object
show all
Includes:
Ruler
Defined in:
lib/abak-flow/pull_request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, manager) ⇒ PullRequest

Returns a new instance of PullRequest.



10
11
12
13
14
15
16
17
18
# File 'lib/abak-flow/pull_request.rb', line 10

def initialize(params, manager)
  @manager = manager
  @errors = []

  @head = params.fetch(:head)
  @base = params.fetch(:base)
  @title = params.fetch(:title)
  @body = params.fetch(:body)
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



8
9
10
# File 'lib/abak-flow/pull_request.rb', line 8

def errors
  @errors
end

Returns the value of attribute link.



8
9
10
# File 'lib/abak-flow/pull_request.rb', line 8

def link
  @link
end

Instance Method Details

#display_nameObject



38
39
40
# File 'lib/abak-flow/pull_request.rb', line 38

def display_name
  I18n.t("pull_request.name")
end

#publishObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/abak-flow/pull_request.rb', line 42

def publish
  begin
    head_with_repo = [@manager.repository.origin.owner, @head] * ':'

    response = @manager.github.create_pull_request(
      @manager.repository.upstream.to_s, @base.to_s, head_with_repo, @title, @body)

    @link = response._links.html.href

    true
  rescue Exception => exception
    backtrace = exception.backtrace[0...10] * "\n"

    @errors = ["#{exception.message}\n\n#{backtrace}"]

    false
  end
end

#ready?Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/abak-flow/pull_request.rb', line 20

def ready?
  @errors = []

  multi_ruleset do
    fact(:head_is_incorrect)  { not @head.valid? }
    fact(:base_is_incorrect)  { not @base.valid? }
    fact(:title_is_incorrect) { @title.empty? }
    fact(:body_is_incorrect)  { @head.tracker_task? ? @body.empty? : false }

    rule([:head_is_incorrect])  { @errors << I18n.t("pull_request.errors.head_is_incorrect") }
    rule([:base_is_incorrect])  { @errors << I18n.t("pull_request.errors.base_is_incorrect") }
    rule([:title_is_incorrect]) { @errors << I18n.t("pull_request.errors.title_is_incorrect") }
    rule([:body_is_incorrect])  { @errors << I18n.t("pull_request.errors.body_is_incorrect") }
  end

  @errors.empty? ? true : false
end