Commit 9db551e8 authored by Andy Soiron's avatar Andy Soiron

Scan MR description when syncing builds with Jira

This scans the MR description for Jira issue keys when syncing
builds with Jira. Issue keys can be included in:

* MR title
* MR description
* Branch name
* Commit message

Commit messages will not be scanned here because they need to be loaded
from Gitaly and this can cause N+1 problems.

Changelog: fixed
parent 33a87eea
...@@ -26,7 +26,7 @@ module Atlassian ...@@ -26,7 +26,7 @@ module Atlassian
# merge request title. # merge request title.
@issue_keys ||= begin @issue_keys ||= begin
pipeline.all_merge_requests.flat_map do |mr| pipeline.all_merge_requests.flat_map do |mr|
src = "#{mr.source_branch} #{mr.title}" src = "#{mr.source_branch} #{mr.title} #{mr.description}"
JiraIssueKeyExtractor.new(src).issue_keys JiraIssueKeyExtractor.new(src).issue_keys
end.uniq end.uniq
end end
......
...@@ -33,6 +33,10 @@ FactoryBot.define do ...@@ -33,6 +33,10 @@ FactoryBot.define do
title { generate(:jira_title) } title { generate(:jira_title) }
end end
trait :jira_description do
description { generate(:jira_description) }
end
trait :jira_branch do trait :jira_branch do
source_branch { generate(:jira_branch) } source_branch { generate(:jira_branch) }
end end
......
...@@ -18,6 +18,7 @@ FactoryBot.define do ...@@ -18,6 +18,7 @@ FactoryBot.define do
sequence(:draft_title) { |n| "Draft: #{n}" } sequence(:draft_title) { |n| "Draft: #{n}" }
sequence(:wip_title) { |n| "WIP: #{n}" } sequence(:wip_title) { |n| "WIP: #{n}" }
sequence(:jira_title) { |n| "[PROJ-#{n}]: fix bug" } sequence(:jira_title) { |n| "[PROJ-#{n}]: fix bug" }
sequence(:jira_description) { |n| "This is a description\n here is the description\n Related to: PROJ-#{n}" }
sequence(:jira_branch) { |n| "feature/PROJ-#{n}" } sequence(:jira_branch) { |n| "feature/PROJ-#{n}" }
sequence(:job_name) { |n| "job #{n}" } sequence(:job_name) { |n| "job #{n}" }
sequence(:work_item_type_name) { |n| "bug#{n}" } sequence(:work_item_type_name) { |n| "bug#{n}" }
......
...@@ -31,7 +31,7 @@ RSpec.describe Atlassian::JiraConnect::Serializers::BuildEntity do ...@@ -31,7 +31,7 @@ RSpec.describe Atlassian::JiraConnect::Serializers::BuildEntity do
context 'when the pipeline does belong to a Jira issue' do context 'when the pipeline does belong to a Jira issue' do
let(:pipeline) { create(:ci_pipeline, merge_request: merge_request) } let(:pipeline) { create(:ci_pipeline, merge_request: merge_request) }
%i[jira_branch jira_title].each do |trait| %i[jira_branch jira_title jira_description].each do |trait|
context "because it belongs to an MR with a #{trait}" do context "because it belongs to an MR with a #{trait}" do
let(:merge_request) { create(:merge_request, trait) } let(:merge_request) { create(:merge_request, trait) }
......
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