Skip to content

Commit 3aab4d8

Browse files
authored
Support Pull Request Templates (#22)
* initial commit for Support Pull Request Templates, fixes #18 * take existing pr template into account when creating PR
1 parent ffcfec8 commit 3aab4d8

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

exe/pr

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ require "optionparser"
33
require "active_support"
44
require "active_support/all"
55

6-
@estimation = nil
76
@simulate = false
87
@issue_number = nil
98

@@ -44,9 +43,6 @@ end
4443

4544
OptionParser.new do |opts|
4645
opts.banner = "Usage: pr [options] [title]\nDefaults: pr" + File::SEPARATOR
47-
opts.on("-e", "--estimation ESTIMATION", Integer, "Estimated time in hours.") do |e|
48-
@estimation = e.presence
49-
end
5046
opts.on("-s", "--simulate", "Simulate the actions: prints out the write-commands instead of executing them, prefixed with ▶️ .") do
5147
@simulate = true
5248
end
@@ -63,11 +59,12 @@ branch += "#{@issue_number}_" if @issue_number
6359
branch += name.parameterize.underscore
6460

6561
title = name
66-
title += " [#{@estimation}]" if @estimation
6762

6863
body_lines = []
64+
path = ".github/pull_request_template.md"
65+
body_lines.push File.read(path) if File.exists?(path)
6966
body_lines.push "fixes ##{@issue_number}" if @issue_number
70-
body = body_lines.join("\n")
67+
body = body_lines.join("\n\n")
7168

7269
base_branch = current_branch
7370
exit 1 unless ["master", "main", "develop"].include?(base_branch) || confirm("Your base branch #{base_branch} doesn't seem to be a common base branch name. Do you want to continue?")
@@ -78,10 +75,13 @@ puts "Creating branch #{branch}"
7875
sh "git checkout -b #{branch}"
7976

8077
puts "Creating empty commit"
81-
sh "git commit -m 'initial commit for #{title}' --allow-empty"
78+
commit_message = "initial commit for #{title}"
79+
commit_message += ", fixes ##{@issue_number}" if @issue_number
80+
sh "git commit -m '#{commit_message}' --allow-empty"
8281

8382
puts "Pushing to origin"
8483
sh "git push -u origin #{branch}"
8584

8685
puts "Creating pull request"
87-
sh "gh pr create --draft --title '#{title}' --body '#{body}' --base #{base_branch}"
86+
ENV["PR_BODY"] = body_lines.join("\n")
87+
sh "gh pr create --draft --title '#{title}' --body \"$PR_BODY\" --base #{base_branch}"

0 commit comments

Comments
 (0)