Skip to content
Merged
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
2 changes: 1 addition & 1 deletion lib/ruboty/handlers/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Ruboty
module Handlers
class Github < Base
ISSUE_PATTERN = %r{(?:https?://[^/]+/)?(?<repo>.+)(?:#|/pull/|/issues/)(?<number>\d+) ?}.freeze
ISSUE_PATTERN = %r{<?(?:https?://[^/]+/|[^/]+\.[^/]+/)?(?<repo>[^/]+/[^/]+)(?:#|/pull/|/issues/)(?<number>\d+)>? ?}.freeze
Comment thread
atm-snag2 marked this conversation as resolved.

env :GITHUB_BASE_URL, 'Pass GitHub URL if needed (e.g. https://github.example.com)', optional: true

Expand Down
82 changes: 82 additions & 0 deletions spec/ruboty/handlers/github_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,55 @@
end
end

describe 'ISSUE_PATTERN' do
subject(:match) { described_class::ISSUE_PATTERN.match(input) }

context 'with owner/repo#number format' do
let(:input) { 'alice/test#123' }

it 'extracts repo and number' do
expect(match[:repo]).to eq('alice/test')
expect(match[:number]).to eq('123')
end
end

context 'with full URL using /issues/' do
let(:input) { 'https://github.com/alice/test/issues/123' }

it 'extracts repo and number' do
expect(match[:repo]).to eq('alice/test')
expect(match[:number]).to eq('123')
end
end

context 'with full URL using /pull/' do
let(:input) { 'https://github.com/alice/test/pull/123' }

it 'extracts repo and number' do
expect(match[:repo]).to eq('alice/test')
expect(match[:number]).to eq('123')
end
end

context 'with protocol-stripped URL (Slack display text)' do
let(:input) { 'github.com/alice/test/pull/123' }

it 'extracts repo and number' do
expect(match[:repo]).to eq('alice/test')
expect(match[:number]).to eq('123')
end
end
Comment thread
atm-snag2 marked this conversation as resolved.

context 'with angle-bracketed URL' do
let(:input) { '<https://github.com/alice/test/pull/123>' }

it 'extracts repo and number' do
expect(match[:repo]).to eq('alice/test')
expect(match[:number]).to eq('123')
end
end
end

describe '#close_issue' do
before do
stub_request(:get, "https://api.github.com/repos/#{user}/#{repository}/issues/#{issue_number}")
Expand Down Expand Up @@ -183,6 +232,39 @@
call
end
end

context 'with full URL format' do
let(:body) do
"@ruboty close https://github.com/#{user}/#{repository}/issues/#{issue_number}"
end

it 'closes specified issue' do
expect(robot).to receive(:say).with(hash_including(body: "Closed #{html_url}"))
call
end
end

context 'with protocol-stripped URL format (Slack display text)' do
let(:body) do
"@ruboty close github.com/#{user}/#{repository}/issues/#{issue_number}"
end

it 'closes specified issue' do
expect(robot).to receive(:say).with(hash_including(body: "Closed #{html_url}"))
call
end
end
Comment thread
atm-snag2 marked this conversation as resolved.

context 'with angle-bracketed URL format' do
let(:body) do
"@ruboty close <https://github.com/#{user}/#{repository}/issues/#{issue_number}>"
end

it 'closes specified issue' do
expect(robot).to receive(:say).with(hash_including(body: "Closed #{html_url}"))
call
end
end
end

describe '#remember' do
Expand Down
Loading