Skip to content

Commit c75546e

Browse files
committed
fix(cli): validate URL before loading config
1 parent a3472e8 commit c75546e

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

lib/aireview/cli.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ def start
4242

4343
def run_review(argv)
4444
options, mr_url = review_options_and_url(argv)
45+
parser_result = MrParser.parse(mr_url)
4546
config = load_review_config(options)
46-
context = load_review_context(mr_url, config, options)
47+
context = load_review_context(parser_result, config, options)
4748

4849
execute_review(config, context, options)
4950
end
@@ -72,8 +73,7 @@ def load_review_config(options)
7273
config
7374
end
7475

75-
def load_review_context(mr_url, config, options)
76-
parser_result = MrParser.parse(mr_url)
76+
def load_review_context(parser_result, config, options)
7777
gitlab_client = build_gitlab_client(config, parser_result)
7878
merge_request, changes = fetch_merge_request_data(gitlab_client, parser_result)
7979

spec/cli_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# frozen_string_literal: true
2+
3+
require 'stringio'
4+
require 'aireview'
5+
6+
RSpec.describe Aireview::CLI do
7+
describe '.start' do
8+
it 'rejects an invalid URL before loading config' do
9+
error_output = StringIO.new
10+
11+
expect(Aireview::Config).not_to receive(:load)
12+
13+
status = described_class.start(
14+
['review', 'gitlab.company.com/team/project/-/merge_requests/123'],
15+
out: StringIO.new,
16+
err: error_output
17+
)
18+
19+
expect(status).to eq(1)
20+
expect(error_output.string).to include('Merge request URL must include http:// or https://')
21+
end
22+
end
23+
end

0 commit comments

Comments
 (0)