Commit a12adf96 authored by Allison Browne's avatar Allison Browne Committed by Michael Kozono

Add table to story sentry issues

Add table to store the sentry event and issue ids
that are related to a gitlab issue
parent 2b2462d6
...@@ -118,13 +118,17 @@ export default { ...@@ -118,13 +118,17 @@ export default {
<div v-if="loading" class="py-3"> <div v-if="loading" class="py-3">
<gl-loading-icon :size="3" /> <gl-loading-icon :size="3" />
</div> </div>
<div v-else-if="showDetails" class="error-details"> <div v-else-if="showDetails" class="error-details">
<div class="top-area align-items-center justify-content-between py-3"> <div class="top-area align-items-center justify-content-between py-3">
<span v-if="!loadingStacktrace && stacktrace" v-html="reported"></span> <span v-if="!loadingStacktrace && stacktrace" v-html="reported"></span>
<form ref="sentryIssueForm" :action="projectIssuesPath" method="POST"> <form ref="sentryIssueForm" :action="projectIssuesPath" method="POST">
<gl-form-input class="hidden" name="issue[title]" :value="issueTitle" /> <gl-form-input class="hidden" name="issue[title]" :value="issueTitle" />
<input name="issue[description]" :value="issueDescription" type="hidden" /> <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" /> <gl-form-input :value="csrfToken" class="hidden" name="authenticity_token" />
<loading-button <loading-button
v-if="!error.gitlab_issue" v-if="!error.gitlab_issue"
......
...@@ -237,7 +237,10 @@ class Projects::IssuesController < Projects::ApplicationController ...@@ -237,7 +237,10 @@ class Projects::IssuesController < Projects::ApplicationController
end end
def issue_params def issue_params
params.require(:issue).permit(*issue_params_attributes) params.require(:issue).permit(
*issue_params_attributes,
sentry_issue_attributes: [:sentry_issue_identifier]
)
end end
def issue_params_attributes def issue_params_attributes
......
...@@ -45,6 +45,8 @@ class Issue < ApplicationRecord ...@@ -45,6 +45,8 @@ class Issue < ApplicationRecord
has_many :user_mentions, class_name: "IssueUserMention" has_many :user_mentions, class_name: "IssueUserMention"
has_one :sentry_issue has_one :sentry_issue
accepts_nested_attributes_for :sentry_issue
validates :project, presence: true validates :project, presence: true
alias_attribute :parent_ids, :project_id alias_attribute :parent_ids, :project_id
......
...@@ -4,5 +4,7 @@ class SentryIssue < ApplicationRecord ...@@ -4,5 +4,7 @@ class SentryIssue < ApplicationRecord
belongs_to :issue belongs_to :issue
validates :issue, uniqueness: true, presence: true validates :issue, uniqueness: true, presence: true
validates :sentry_issue_identifier, presence: true validates :sentry_issue_identifier,
uniqueness: true,
presence: true
end end
...@@ -1073,6 +1073,24 @@ describe Projects::IssuesController do ...@@ -1073,6 +1073,24 @@ describe Projects::IssuesController do
expect(issue.time_estimate).to eq(7200) expect(issue.time_estimate).to eq(7200)
end end
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 end
describe 'POST #mark_as_spam' do describe 'POST #mark_as_spam' do
......
...@@ -110,7 +110,7 @@ describe('ErrorDetails', () => { ...@@ -110,7 +110,7 @@ describe('ErrorDetails', () => {
beforeEach(() => { beforeEach(() => {
store.state.details.loading = false; store.state.details.loading = false;
store.state.details.error = { store.state.details.error = {
id: 1, id: 129381,
title: 'Issue title', title: 'Issue title',
external_url: 'http://sentry.gitlab.net/gitlab', external_url: 'http://sentry.gitlab.net/gitlab',
first_seen: '2017-05-26T13:32:48Z', first_seen: '2017-05-26T13:32:48Z',
...@@ -121,6 +121,13 @@ describe('ErrorDetails', () => { ...@@ -121,6 +121,13 @@ describe('ErrorDetails', () => {
mountComponent(); 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', () => { it('should set the form values with title and description', () => {
const csrfTokenInput = wrapper.find('glforminput-stub[name="authenticity_token"]'); const csrfTokenInput = wrapper.find('glforminput-stub[name="authenticity_token"]');
const issueTitleInput = wrapper.find('glforminput-stub[name="issue[title]"]'); const issueTitleInput = wrapper.find('glforminput-stub[name="issue[title]"]');
......
...@@ -13,5 +13,6 @@ describe SentryIssue do ...@@ -13,5 +13,6 @@ describe SentryIssue do
it { is_expected.to validate_presence_of(:issue) } it { is_expected.to validate_presence_of(:issue) }
it { is_expected.to validate_uniqueness_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_presence_of(:sentry_issue_identifier) }
it { is_expected.to validate_uniqueness_of(:sentry_issue_identifier).with_message("has already been taken") }
end end
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