Commit 339bc4d8 authored by Michael Kozono's avatar Michael Kozono

Merge branch '36544-backend-add-ability-to-embed-stack-trace-in-gitlab-issue-2' into 'master'

Accept sentry_issue_identifier on issue creation

See merge request gitlab-org/gitlab!21081
parents 2b2462d6 a12adf96
......@@ -118,13 +118,17 @@ export default {
<div v-if="loading" class="py-3">
<gl-loading-icon :size="3" />
</div>
<div v-else-if="showDetails" class="error-details">
<div class="top-area align-items-center justify-content-between py-3">
<span v-if="!loadingStacktrace && stacktrace" v-html="reported"></span>
<form ref="sentryIssueForm" :action="projectIssuesPath" method="POST">
<gl-form-input class="hidden" name="issue[title]" :value="issueTitle" />
<input name="issue[description]" :value="issueDescription" type="hidden" />
<gl-form-input
:value="error.id"
class="hidden"
name="issue[sentry_issue_attributes][sentry_issue_identifier]"
/>
<gl-form-input :value="csrfToken" class="hidden" name="authenticity_token" />
<loading-button
v-if="!error.gitlab_issue"
......
......@@ -237,7 +237,10 @@ class Projects::IssuesController < Projects::ApplicationController
end
def issue_params
params.require(:issue).permit(*issue_params_attributes)
params.require(:issue).permit(
*issue_params_attributes,
sentry_issue_attributes: [:sentry_issue_identifier]
)
end
def issue_params_attributes
......
......@@ -45,6 +45,8 @@ class Issue < ApplicationRecord
has_many :user_mentions, class_name: "IssueUserMention"
has_one :sentry_issue
accepts_nested_attributes_for :sentry_issue
validates :project, presence: true
alias_attribute :parent_ids, :project_id
......
......@@ -4,5 +4,7 @@ class SentryIssue < ApplicationRecord
belongs_to :issue
validates :issue, uniqueness: true, presence: true
validates :sentry_issue_identifier, presence: true
validates :sentry_issue_identifier,
uniqueness: true,
presence: true
end
......@@ -1073,6 +1073,24 @@ describe Projects::IssuesController do
expect(issue.time_estimate).to eq(7200)
end
end
context 'when created from sentry error' do
subject { post_new_issue(sentry_issue_attributes: { sentry_issue_identifier: 1234567 }) }
it 'creates an issue' do
expect { subject }.to change(Issue, :count)
end
it 'creates a sentry issue' do
expect { subject }.to change(SentryIssue, :count)
end
it 'with existing issue it will not create an issue' do
post_new_issue(sentry_issue_attributes: { sentry_issue_identifier: 1234567 })
expect { subject }.not_to change(Issue, :count)
end
end
end
describe 'POST #mark_as_spam' do
......
......@@ -110,7 +110,7 @@ describe('ErrorDetails', () => {
beforeEach(() => {
store.state.details.loading = false;
store.state.details.error = {
id: 1,
id: 129381,
title: 'Issue title',
external_url: 'http://sentry.gitlab.net/gitlab',
first_seen: '2017-05-26T13:32:48Z',
......@@ -121,6 +121,13 @@ describe('ErrorDetails', () => {
mountComponent();
});
it('should send sentry_issue_identifier', () => {
const sentryErrorIdInput = wrapper.find(
'glforminput-stub[name="issue[sentry_issue_attributes][sentry_issue_identifier]"',
);
expect(sentryErrorIdInput.attributes('value')).toBe('129381');
});
it('should set the form values with title and description', () => {
const csrfTokenInput = wrapper.find('glforminput-stub[name="authenticity_token"]');
const issueTitleInput = wrapper.find('glforminput-stub[name="issue[title]"]');
......
......@@ -13,5 +13,6 @@ describe SentryIssue do
it { is_expected.to validate_presence_of(:issue) }
it { is_expected.to validate_uniqueness_of(:issue) }
it { is_expected.to validate_presence_of(:sentry_issue_identifier) }
it { is_expected.to validate_uniqueness_of(:sentry_issue_identifier).with_message("has already been taken") }
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment