Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-09-19 04:45:44 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-09-19 04:45:44 +0300
commit85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch)
tree9160f299afd8c80c038f08e1545be119f5e3f1e1 /lib/gitlab/jira
parent15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff)
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'lib/gitlab/jira')
-rw-r--r--lib/gitlab/jira/dvcs.rb48
-rw-r--r--lib/gitlab/jira/middleware.rb23
2 files changed, 71 insertions, 0 deletions
diff --git a/lib/gitlab/jira/dvcs.rb b/lib/gitlab/jira/dvcs.rb
new file mode 100644
index 00000000000..4415f98fc7f
--- /dev/null
+++ b/lib/gitlab/jira/dvcs.rb
@@ -0,0 +1,48 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Jira
+ module Dvcs
+ ENCODED_SLASH = '@'.freeze
+ SLASH = '/'.freeze
+ ENCODED_ROUTE_REGEX = /[a-zA-Z0-9_\-\.#{ENCODED_SLASH}]+/.freeze
+
+ def self.encode_slash(path)
+ path.gsub(SLASH, ENCODED_SLASH)
+ end
+
+ def self.decode_slash(path)
+ path.gsub(ENCODED_SLASH, SLASH)
+ end
+
+ # To present two types of projects stored by Jira,
+ # Type 1 are projects imported prior to nested group support,
+ # those project names are not full_path, so they are presented differently
+ # to maintain backwards compatibility.
+ # Type 2 are projects imported after nested group support,
+ # those project names are encoded full path
+ #
+ # @param [Project] project
+ def self.encode_project_name(project)
+ if project.namespace.has_parent?
+ encode_slash(project.full_path)
+ else
+ project.path
+ end
+ end
+
+ # To interpret two types of project names stored by Jira (see `encode_project_name`)
+ #
+ # @param [String] project
+ # Either an encoded full path, or just project name
+ # @param [String] namespace
+ def self.restore_full_path(namespace:, project:)
+ if project.include?(ENCODED_SLASH)
+ project.gsub(ENCODED_SLASH, SLASH)
+ else
+ "#{namespace}/#{project}"
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/jira/middleware.rb b/lib/gitlab/jira/middleware.rb
new file mode 100644
index 00000000000..8a74729da49
--- /dev/null
+++ b/lib/gitlab/jira/middleware.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Jira
+ class Middleware
+ def self.jira_dvcs_connector?(env)
+ env['HTTP_USER_AGENT']&.downcase&.start_with?('jira dvcs connector')
+ end
+
+ def initialize(app)
+ @app = app
+ end
+
+ def call(env)
+ if self.class.jira_dvcs_connector?(env)
+ env['HTTP_AUTHORIZATION'] = env['HTTP_AUTHORIZATION']&.sub('token', 'Bearer')
+ end
+
+ @app.call(env)
+ end
+ end
+ end
+end