Class: Flux::CLI::Review

Inherits:
Thor
  • Object
show all
Includes:
Util
Defined in:
lib/flux/cli/review.rb

Defined Under Namespace

Modules: Github, ReviewBody

Constant Summary collapse

G =
Flux::Git
B =
G::Branch
PULL_REQUEST_HEADERS =
%w(>NUM >STORY AUTHOR DATE TITLE)

Instance Method Summary collapse

Methods included from Util

#puts_table

Instance Method Details

#diff(branch_name = B.current.name) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/flux/cli/review.rb', line 21

def diff(branch_name = B.current.name)
  reqs = Github::PullRequest.all(:branch_name => branch_name)

  if options[:from] && options[:to]
    to   = reqs.find { |r| r.number.to_i == options[:to].to_i }
    from = reqs.find { |r| r.number.to_i == options[:from].to_i }
  else
    to, from = reqs.first(2)
  end

  if from
    to_diff = Tempfile.new("to_diff")
    to_diff.write(to.diff)
    to_diff.flush

    from_diff = Tempfile.new("from_diff")
    from_diff.write(from.diff)
    from_diff.flush

    cmd =  "interdiff #{from_diff.path} #{to_diff.path}"
    cmd << "| colordiff" if options[:color]

    system cmd
  end
end

#history(branch_id = B.current.name) ⇒ Object



79
80
81
82
83
# File 'lib/flux/cli/review.rb', line 79

def history(branch_id = B.current.name)
  reqs = Github::PullRequest.all(:branch_name => branch_id)

  list_pull_requests reqs
end

#listObject



74
75
76
# File 'lib/flux/cli/review.rb', line 74

def list
  list_pull_requests Github::PullRequest.open
end

#request(branch = B.current) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/flux/cli/review.rb', line 48

def request(branch = B.current)
  branch = G::Branch(branch)

  invoke 'git:fetch'
  invoke 'branch:checks:synced', [branch]
  invoke 'branch:checks:rebased', [branch], :parent => 'origin/master'

  story  = Flux::PT::Project.
    current.stories.find(branch.config('story_id'))
  old    = Github::PullRequest.all(:branch_name => branch.name)
  last   = old.first

  last.close if last && last.open?

  body = {:branch_name => branch.name,
          :story_url   => story.url,
          :iterations  => old.map(&:html_url)}
  data = {:base  => 'master',
          :head  => branch.top.sha,
          :title => story.name,
          :body  => body}

  Github::PullRequest.create data
end