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



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
# File 'lib/devflow/commands/pr.rb', line 14

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

  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}" \
        "" \
        "#{File.read(file).gsub(STORY_URL_PATTERN, story_url)}"
    else
      "#{title}" \
        "" \
        "#{story_url}"
    end

  puts message
end

#titleize(str) ⇒ Object



44
45
46
# File 'lib/devflow/commands/pr.rb', line 44

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