Class: DevFlow::Commands::PR

Inherits:
DevFlow::Command show all
Defined in:
lib/devflow/commands/pr.rb

Constant Summary collapse

STORY_URL_BASE =
"#{DevFlow::TargetProcess::BASE_URI}/entity"
STORY_URL_PATTERN =
/#{STORY_URL_BASE}\/(\d+)/
STORY_REGEX =
/^(\d+)-(.*)/
FV_REGEX =
/^fv-(.*)/
PR_TEMPLATES_PATHS =
%w[
  .github/PULL_REQUEST_TEMPLATE.md
]

Instance Method Summary collapse

Methods inherited from DevFlow::Command

#initialize

Constructor Details

This class inherits a constructor from DevFlow::Command

Instance Method Details

#callObject



12
13
14
15
16
17
18
19
20
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
46
47
# File 'lib/devflow/commands/pr.rb', line 12

def call
  branch = `git rev-parse --abbrev-ref HEAD`

  def titleize(str)
    str.tr("-", " ").capitalize
  end

  case branch
  when story_regex
    story_id = $1
    story_url = STORY_URL_BASE + "/" + story_id
    title = "[#{story_id}] #{titleize($2)}"
  when fv_regex
    story_url = ""
    title = "[FV] #{titleize($1)}"
  else
    story_url = ""
    title = titleize(branch)
  end

  message = if (file = PR_TEMPLATES_PATHS.find { |p| File.exist?(p) })
              "                \#{title}\n\n                \#{File.read(file).gsub(STORY_URL_PATTERN, story_url)}\n              MESS\n            else\n              <<~MESS\n                \#{title}\n\n                \#{story_url}\n              MESS\n            end\n\n  puts message\nend\n"

#titleize(str) ⇒ Object



15
16
17
# File 'lib/devflow/commands/pr.rb', line 15

def titleize(str)
  str.tr("-", " ").capitalize
end