Skip to content
Snippets Groups Projects
Commit 9cbb009f authored by Luke Duncalfe's avatar Luke Duncalfe :red_circle:
Browse files

Use Gitlab::HTTP for outbound filtering rules

`Gitlab::HTTP` configures requests to observe the instance's outbound
filtering rules
https://gitlab.com/gitlab-org/gitlab/-/blob/1fe3a9de6de4527597e6be4b9b00c331dfce4fd1/lib/gitlab/http.rb#L58

https://gitlab.com/gitlab-org/gitlab/-/issues/501251

Changelog: fixed
parent cc2cd426
No related branches found
No related tags found
1 merge request!171881Use Gitlab::HTTP integration requests
......@@ -75,11 +75,11 @@ def check_commit(message, push_msg)
begin
story_on_task_url = format(STORY_URL_TEMPLATE, task_gid: task_id)
Gitlab::HTTP_V2.post(story_on_task_url, headers: { "Authorization" => "Bearer #{api_key}" }, body: { text: "#{push_msg} #{message}" })
Gitlab::HTTP.post(story_on_task_url, headers: { "Authorization" => "Bearer #{api_key}" }, body: { text: "#{push_msg} #{message}" })
if prepended_text.match?(proceded_keyword_finder)
task_url = format(TASK_URL_TEMPLATE, task_gid: task_id)
Gitlab::HTTP_V2.put(task_url, headers: { "Authorization" => "Bearer #{api_key}" }, body: { completed: true })
Gitlab::HTTP.put(task_url, headers: { "Authorization" => "Bearer #{api_key}" }, body: { completed: true })
end
rescue StandardError => e
log_error(e.message)
......@@ -89,7 +89,7 @@ def check_commit(message, push_msg)
end
def test(_)
result = Gitlab::HTTP_V2.get(PERSONAL_ACCESS_TOKEN_TEST_URL, headers: { "Authorization" => "Bearer #{api_key}" })
result = Gitlab::HTTP.get(PERSONAL_ACCESS_TOKEN_TEST_URL, headers: { "Authorization" => "Bearer #{api_key}" })
if result.success?
{ success: true }
......
......@@ -19,7 +19,7 @@ def needs_refresh?
end
def refresh!
response = Gitlab::HTTP_V2.post(REFRESH_TOKEN_URL, body: payload.to_json, headers: headers)
response = Gitlab::HTTP.post(REFRESH_TOKEN_URL, body: payload.to_json, headers: headers)
raise AtlassianTokenRefreshError, response["error"] unless response.success?
identity.update!(
......
......@@ -69,9 +69,9 @@
let(:ref) { 'main' }
it 'calls the Asana integration' do
expect(Gitlab::HTTP_V2).to receive(:post)
expect(Gitlab::HTTP).to receive(:post)
.with("https://app.asana.com/api/1.0/tasks/456789/stories", anything).once.and_return(asana_task)
expect(Gitlab::HTTP_V2).to receive(:put)
expect(Gitlab::HTTP).to receive(:put)
.with("https://app.asana.com/api/1.0/tasks/456789", completed_message).once.and_return(asana_task)
execute_integration
......@@ -82,8 +82,8 @@
let(:ref) { 'mai' }
it 'does not call the Asana integration' do
expect(Gitlab::HTTP_V2).not_to receive(:post)
expect(Gitlab::HTTP_V2).not_to receive(:put)
expect(Gitlab::HTTP).not_to receive(:post)
expect(Gitlab::HTTP).not_to receive(:put)
execute_integration
end
......@@ -102,7 +102,7 @@
end
it 'calls Asana integration to create a story' do
expect(Gitlab::HTTP_V2).to receive(:post)
expect(Gitlab::HTTP).to receive(:post)
.with("https://app.asana.com/api/1.0/tasks/#{gid}/stories", expected_message).once.and_return(asana_task)
execute_integration
......@@ -113,9 +113,9 @@
let(:message) { 'fix #456789' }
it 'calls Asana integration to create a story and close a task' do
expect(Gitlab::HTTP_V2).to receive(:post)
expect(Gitlab::HTTP).to receive(:post)
.with("https://app.asana.com/api/1.0/tasks/456789/stories", anything).once.and_return(asana_task)
expect(Gitlab::HTTP_V2).to receive(:put)
expect(Gitlab::HTTP).to receive(:put)
.with("https://app.asana.com/api/1.0/tasks/456789", completed_message).once.and_return(asana_task)
execute_integration
......@@ -126,9 +126,9 @@
let(:message) { 'closes https://app.asana.com/19292/956299/42' }
it 'calls Asana integration to close via url' do
expect(Gitlab::HTTP_V2).to receive(:post)
expect(Gitlab::HTTP).to receive(:post)
.with("https://app.asana.com/api/1.0/tasks/42/stories", anything).once.and_return(asana_task)
expect(Gitlab::HTTP_V2).to receive(:put)
expect(Gitlab::HTTP).to receive(:put)
.with("https://app.asana.com/api/1.0/tasks/42", completed_message).once.and_return(asana_task)
execute_integration
......@@ -146,41 +146,41 @@
end
it 'allows multiple matches per line' do
expect(Gitlab::HTTP_V2).to receive(:post)
expect(Gitlab::HTTP).to receive(:post)
.with("https://app.asana.com/api/1.0/tasks/123/stories", anything).once.and_return(asana_task)
expect(Gitlab::HTTP_V2).to receive(:put)
expect(Gitlab::HTTP).to receive(:put)
.with("https://app.asana.com/api/1.0/tasks/123", completed_message).once.and_return(asana_task)
asana_task_2 = double(double(data: { gid: 456 }))
expect(Gitlab::HTTP_V2).to receive(:post)
expect(Gitlab::HTTP).to receive(:post)
.with("https://app.asana.com/api/1.0/tasks/456/stories", anything).once.and_return(asana_task_2)
expect(Gitlab::HTTP_V2).to receive(:put)
expect(Gitlab::HTTP).to receive(:put)
.with("https://app.asana.com/api/1.0/tasks/456", completed_message).once.and_return(asana_task_2)
asana_task_3 = double(double(data: { gid: 789 }))
expect(Gitlab::HTTP_V2).to receive(:post)
expect(Gitlab::HTTP).to receive(:post)
.with("https://app.asana.com/api/1.0/tasks/789/stories", anything).once.and_return(asana_task_3)
asana_task_4 = double(double(data: { gid: 42 }))
expect(Gitlab::HTTP_V2).to receive(:post)
expect(Gitlab::HTTP).to receive(:post)
.with("https://app.asana.com/api/1.0/tasks/42/stories", anything).once.and_return(asana_task_4)
asana_task_5 = double(double(data: { gid: 12 }))
expect(Gitlab::HTTP_V2).to receive(:post)
expect(Gitlab::HTTP).to receive(:post)
.with("https://app.asana.com/api/1.0/tasks/12/stories", anything).once.and_return(asana_task_5)
expect(Gitlab::HTTP_V2).to receive(:put)
expect(Gitlab::HTTP).to receive(:put)
.with("https://app.asana.com/api/1.0/tasks/12", completed_message).once.and_return(asana_task_5)
asana_task_5 = double(double(data: { gid: 11 }))
expect(Gitlab::HTTP_V2).to receive(:post)
expect(Gitlab::HTTP).to receive(:post)
.with("https://app.asana.com/api/1.0/tasks/11/stories", anything).once.and_return(asana_task_5)
expect(Gitlab::HTTP_V2).not_to receive(:put)
expect(Gitlab::HTTP).not_to receive(:put)
.with("https://app.asana.com/api/1.0/tasks/11", completed_message)
asana_task_6 = double(double(data: { gid: 222 }))
expect(Gitlab::HTTP_V2).to receive(:post)
expect(Gitlab::HTTP).to receive(:post)
.with("https://app.asana.com/api/1.0/tasks/222/stories", anything).once.and_return(asana_task_6)
expect(Gitlab::HTTP_V2).not_to receive(:put)
expect(Gitlab::HTTP).not_to receive(:put)
.with("https://app.asana.com/api/1.0/tasks/222", completed_message)
execute_integration
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment