Commit 6f9665f2 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Use MD5 of branch name as id for Jira Connect

Jira doesn't accept IDs with slashes and other
special characters so we use a hash here to
ensure that it is alphanumeric.

This also keeps its uniqueness per branch name
which is needed for Jira to determine whether to
insert or add this dev info into the Jira issue.
parent 63a21c00
......@@ -4,7 +4,9 @@ module Atlassian
module JiraConnect
module Serializers
class BranchEntity < BaseEntity
expose :name, as: :id
expose :id do |branch|
Digest::SHA256.hexdigest(branch.name)
end
expose :issueKeys do |branch|
JiraIssueKeyExtractor.new(branch.name).issue_keys
end
......
# frozen_string_literal: true
require 'spec_helper'
describe Atlassian::JiraConnect::Serializers::BranchEntity do
let(:project) { create(:project, :repository) }
let(:branch) { project.repository.find_branch('improve/awesome') }
subject { described_class.represent(branch, project: project).as_json }
it 'sets the hash of the branch name as the id' do
expect(subject[:id]).to eq('bbfba9b197ace5da93d03382a7ce50081ae89d99faac1f2326566941288871ce')
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