Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add create draft Pull Request option #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ You can specify this value by `GIT_PR_RELEASE_SSL_NO_VERIFY` to `1`.

If not specified, verify SSL certificate always.

### `pr-release.draft`

The pull request is draft no not.
Accepted values: `true` | `false`

You can specify this value by `GIT_PR_RELEASE_DRAFT` environment variable.

Default value: `false`.

## Errors and exit statuses

### No pull requests to be released
Expand Down
12 changes: 10 additions & 2 deletions lib/git/pr/release/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Pr
module Release
class CLI
include Git::Pr::Release::Util
attr_reader :repository, :production_branch, :staging_branch, :template_path, :labels
attr_reader :repository, :production_branch, :staging_branch, :template_path, :labels, :draft

def self.start
result = self.new.start
Expand Down Expand Up @@ -82,11 +82,18 @@ def configure
_labels = ENV.fetch('GIT_PR_RELEASE_LABELS') { git_config('labels') }
@labels = _labels && _labels.split(/\s*,\s*/) || []

_draft = ENV.fetch('GIT_PR_RELEASE_DRAFT') { git_config('draft') } || false
@draft = to_boolean(_draft)
if draft.nil?
raise "#{_draft} is not boolean. set true or false."
end

say "Repository: #{repository}", :debug
say "Production branch: #{production_branch}", :debug
say "Staging branch: #{staging_branch}", :debug
say "Template path: #{template_path}", :debug
say "Labels #{labels}", :debug
say "Draft #{draft}", :debug
end

def fetch_merged_prs
Expand Down Expand Up @@ -226,7 +233,8 @@ def detect_existing_release_pr

def prepare_release_pr
client.create_pull_request(
repository, production_branch, staging_branch, 'Preparing release pull request...', ''
repository, production_branch, staging_branch, 'Preparing release pull request...', '',
{ draft: draft }
)
end

Expand Down
18 changes: 18 additions & 0 deletions lib/git/pr/release/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,24 @@ def request_authorization(client, two_factor_code)

auth
end

def to_boolean(flag)
case flag
when TrueClass, FalseClass
flag
when String
flag = flag.downcase
if flag == 'true'
true
elsif flag == 'false'
false
else
nil
end
else
nil
end
end
end
end
end
Expand Down
54 changes: 54 additions & 0 deletions spec/git/pr/release/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
expect(@cli.staging_branch).to eq "staging"
expect(@cli.template_path).to eq nil
expect(@cli.labels).to eq []
expect(@cli.draft).to eq false
end
end

Expand Down Expand Up @@ -181,6 +182,58 @@
end
end
end

describe "draft" do
context "When draft is not set" do
it "draft is false" do
subject

expect(@cli.draft).to eq false
end
end

context "When draft is set by ENV" do
around do |example|
original = ENV.to_hash
begin
ENV["GIT_PR_RELEASE_DRAFT"] = 'true'
example.run
ensure
ENV.replace(original)
end
end

it "draft is configured" do
subject

expect(@cli.draft).to eq true
end
end

context "When draft is set by git_config" do
before {
allow(@cli).to receive(:git_config).with("draft") { true }
}

it "draft is configured" do
subject

expect(@cli.draft).to eq true
end
end

context "When draft is not set true | false" do
let(:draft) { 'not_true' }

before {
allow(@cli).to receive(:git_config).with("draft") { draft }
}

it "draft is configured" do
expect { subject }.to raise_error("#{draft} is not boolean. set true or false.")
end
end
end
end

describe "#fetch_merged_prs" do
Expand Down Expand Up @@ -368,6 +421,7 @@
"staging",
"Preparing release pull request...",
"", # empby body
{ draft: @cli.draft }
)
}
end
Expand Down