Skip to content
代码片段 群组 项目
提交 350947ce 编辑于 作者: Jan Provaznik's avatar Jan Provaznik
浏览文件

Merge branch '391477_rename_project_param_to_container' into 'master'

Refactor initializer arguments for Issues::BuildService

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/111907



Merged-by: default avatarJan Provaznik <jprovaznik@gitlab.com>
Approved-by: default avatarMario Celi <mcelicalderon@gitlab.com>
Approved-by: default avatarJan Provaznik <jprovaznik@gitlab.com>
Reviewed-by: default avatarMichał Zając <mzajac@gitlab.com>
Co-authored-by: default avatarAlexandru Croitor <acroitor@gitlab.com>
No related branches found
No related tags found
无相关合并请求
...@@ -128,7 +128,7 @@ def new ...@@ -128,7 +128,7 @@ def new
discussion_to_resolve: params[:discussion_to_resolve], discussion_to_resolve: params[:discussion_to_resolve],
confidential: !!Gitlab::Utils.to_boolean(issue_params[:confidential]) confidential: !!Gitlab::Utils.to_boolean(issue_params[:confidential])
) )
service = ::Issues::BuildService.new(project: project, current_user: current_user, params: build_params) service = ::Issues::BuildService.new(container: project, current_user: current_user, params: build_params)
@issue = @noteable = service.execute @issue = @noteable = service.execute
......
...@@ -4,6 +4,11 @@ module Issues ...@@ -4,6 +4,11 @@ module Issues
class BuildService < Issues::BaseService class BuildService < Issues::BaseService
include ResolveDiscussions include ResolveDiscussions
# TODO: this is to be removed once we get to rename the IssuableBaseService project param to container
def initialize(container:, current_user: nil, params: {})
super(project: container, current_user: current_user, params: params)
end
def execute def execute
filter_resolve_discussion_params filter_resolve_discussion_params
......
...@@ -17,7 +17,7 @@ def initialize(project:, spam_params:, current_user: nil, params: {}, build_serv ...@@ -17,7 +17,7 @@ def initialize(project:, spam_params:, current_user: nil, params: {}, build_serv
@extra_params = params.delete(:extra_params) || {} @extra_params = params.delete(:extra_params) || {}
super(project: project, current_user: current_user, params: params) super(project: project, current_user: current_user, params: params)
@spam_params = spam_params @spam_params = spam_params
@build_service = build_service || BuildService.new(project: project, current_user: current_user, params: params) @build_service = build_service || BuildService.new(container: project, current_user: current_user, params: params)
end end
def execute(skip_system_notes: false) def execute(skip_system_notes: false)
......
...@@ -19,7 +19,7 @@ def execute ...@@ -19,7 +19,7 @@ def execute
update_service = Issues::UpdateService.new(project: project, current_user: current_user, params: { add_assignee_ids: params[:assignee_ids] }) update_service = Issues::UpdateService.new(project: project, current_user: current_user, params: { add_assignee_ids: params[:assignee_ids] })
update_service.execute(issue) update_service.execute(issue)
else else
build_service = Issues::BuildService.new(project: project, current_user: current_user, params: params) build_service = Issues::BuildService.new(container: project, current_user: current_user, params: params)
create(build_service.execute) create(build_service.execute)
end end
end end
......
...@@ -10,7 +10,7 @@ def initialize(project:, spam_params:, current_user: nil, params: {}, widget_par ...@@ -10,7 +10,7 @@ def initialize(project:, spam_params:, current_user: nil, params: {}, widget_par
current_user: current_user, current_user: current_user,
params: params, params: params,
spam_params: spam_params, spam_params: spam_params,
build_service: ::WorkItems::BuildService.new(project: project, current_user: current_user, params: params) build_service: ::WorkItems::BuildService.new(container: project, current_user: current_user, params: params)
) )
@widget_params = widget_params @widget_params = widget_params
end end
......
# frozen_string_literal: true
module Issues
class BuildFromVulnerabilityService < Issues::BuildService
def execute
vulnerability = params[:vulnerability]
params.merge!(
title: _("Investigate vulnerability: %{title}") % { title: vulnerability.title },
description: render_description(vulnerability),
confidential: true
)
super
end
private
def render_description(vulnerability)
ApplicationController.render(
template: 'vulnerabilities/issue_description',
formats: :md,
locals: { vulnerability: vulnerability.present }
)
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Issues::BuildFromVulnerabilityService do
describe '#execute' do
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, :public, :repository, namespace: group) }
let_it_be(:user) { create(:user) }
before_all do
group.add_developer(user)
end
before do
stub_licensed_features(security_dashboard: true)
end
it 'builds the issue with the given params' do
vulnerability = create(:vulnerability, :with_finding, project: project)
service = described_class.new(project: project, current_user: user, params: { vulnerability: vulnerability })
issue = service.execute
expect(issue).not_to be_persisted
expect(issue).to have_attributes(
project: project,
author: user,
title: "Investigate vulnerability: #{vulnerability.title}",
description:
<<~DESC
Issue created from vulnerability <a href="http://localhost/#{group.name}/#{project.name}/-/security/vulnerabilities/#{vulnerability.id}">#{vulnerability.id}</a>
### Description:
Description of #{vulnerability.title}
* Severity: #{vulnerability.severity}
* Confidence: #{vulnerability.confidence}
* Location: [maven/src/main/java/com/gitlab/security_products/tests/App.java:29](http://localhost/#{project.full_path}/-/blob/master/maven/src/main/java/com/gitlab/security_products/tests/App.java#L29)
#### Evidence
* Method: `GET`
* URL: http://goat:8080/WebGoat/logout
##### Request:
```
Accept : */*
```
##### Response:
```
Content-Length : 0
```
### Solution:
#{vulnerability.solution}
### Identifiers:
* [CVE-2018-1234](http://cve.mitre.org/cgi-bin/cvename.cgi?name=2018-1234)
### Links:
* [Cipher does not check for integrity first?](https://crypto.stackexchange.com/questions/31428/pbewithmd5anddes-cipher-does-not-check-for-integrity-first)
### Scanner:
* Name: Find Security Bugs
/confidential
DESC
)
end
context 'when a vulnerability has remediations' do
it 'displays Remediations section with attached diff' do
vulnerability = create(:vulnerability, :with_remediation, project: project)
service = described_class.new(project: project, current_user: user, params: { vulnerability: vulnerability })
issue = service.execute
expect(issue.description).to match(/Remediations/)
expect(issue.description).to match(/This is a diff/)
end
end
end
end
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
end end
def build_issue(issue_params = {}) def build_issue(issue_params = {})
described_class.new(project: project, current_user: user, params: issue_params).execute described_class.new(container: project, current_user: user, params: issue_params).execute
end end
context 'with an issue template' do context 'with an issue template' do
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
end end
def build_issue(issue_params = {}) def build_issue(issue_params = {})
described_class.new(project: project, current_user: user, params: issue_params).execute described_class.new(container: project, current_user: user, params: issue_params).execute
end end
context 'for a single discussion' do context 'for a single discussion' do
...@@ -45,7 +45,7 @@ def build_issue(issue_params = {}) ...@@ -45,7 +45,7 @@ def build_issue(issue_params = {})
describe '#items_for_discussions' do describe '#items_for_discussions' do
it 'has an item for each discussion' do it 'has an item for each discussion' do
create(:diff_note_on_merge_request, noteable: merge_request, project: merge_request.source_project, line_number: 13) create(:diff_note_on_merge_request, noteable: merge_request, project: merge_request.source_project, line_number: 13)
service = described_class.new(project: project, current_user: user, params: { merge_request_to_resolve_discussions_of: merge_request.iid }) service = described_class.new(container: project, current_user: user, params: { merge_request_to_resolve_discussions_of: merge_request.iid })
service.execute service.execute
...@@ -54,7 +54,7 @@ def build_issue(issue_params = {}) ...@@ -54,7 +54,7 @@ def build_issue(issue_params = {})
end end
describe '#item_for_discussion' do describe '#item_for_discussion' do
let(:service) { described_class.new(project: project, current_user: user, params: { merge_request_to_resolve_discussions_of: merge_request.iid }) } let(:service) { described_class.new(container: project, current_user: user, params: { merge_request_to_resolve_discussions_of: merge_request.iid }) }
it 'mentions the author of the note' do it 'mentions the author of the note' do
discussion = create(:diff_note_on_merge_request, author: create(:user, username: 'author')).to_discussion discussion = create(:diff_note_on_merge_request, author: create(:user, username: 'author')).to_discussion
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
expect(Issues::BuildService) expect(Issues::BuildService)
.to receive(:new) .to receive(:new)
.with(project: project, current_user: current_user, params: params) .with(container: project, current_user: current_user, params: params)
.and_call_original .and_call_original
expect { service.execute }.to change(Issue, :count).by(1) expect { service.execute }.to change(Issue, :count).by(1)
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
end end
describe '#execute' do describe '#execute' do
subject { described_class.new(project: project, current_user: user, params: {}).execute } subject { described_class.new(container: project, current_user: user, params: {}).execute }
it { is_expected.to be_a(::WorkItem) } it { is_expected.to be_a(::WorkItem) }
end end
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册