summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG10
-rw-r--r--CONTRIBUTING.md2
-rw-r--r--Gemfile1
-rw-r--r--Gemfile.lock5
-rw-r--r--app/controllers/admin/identities_controller.rb17
-rw-r--r--app/controllers/application_controller.rb15
-rw-r--r--app/controllers/omniauth_callbacks_controller.rb16
-rw-r--r--app/controllers/projects/services_controller.rb5
-rw-r--r--app/models/ci/build.rb13
-rw-r--r--app/models/ci/commit.rb10
-rw-r--r--app/models/concerns/participable.rb2
-rw-r--r--app/models/issue.rb2
-rw-r--r--app/models/jira_issue.rb2
-rw-r--r--app/models/merge_request.rb2
-rw-r--r--app/models/project.rb8
-rw-r--r--app/models/project_services/jira_service.rb241
-rw-r--r--app/models/user.rb1
-rw-r--r--app/services/create_commit_builds_service.rb18
-rw-r--r--app/services/issues/close_service.rb5
-rw-r--r--app/services/system_note_service.rb9
-rw-r--r--app/views/admin/dashboard/index.html.haml4
-rw-r--r--app/views/admin/identities/index.html.haml1
-rw-r--r--app/views/admin/identities/new.html.haml4
-rw-r--r--app/views/devise/mailer/unlock_instructions.html.erb7
-rw-r--r--app/views/devise/mailer/unlock_instructions.html.haml10
-rw-r--r--app/views/devise/unlocks/new.html.erb12
-rw-r--r--app/views/devise/unlocks/new.html.haml14
-rw-r--r--app/views/projects/builds/show.html.haml4
-rw-r--r--app/views/projects/commit/_commit_box.html.haml2
-rw-r--r--app/views/projects/commits/_commit.html.haml2
-rw-r--r--app/views/projects/issues/_merge_requests.html.haml7
-rw-r--r--config/gitlab.yml.example13
-rw-r--r--config/initializers/1_settings.rb6
-rw-r--r--config/initializers/devise.rb14
-rw-r--r--config/routes.rb2
-rw-r--r--db/migrate/20151012173029_set_jira_service_api_url.rb50
-rw-r--r--db/migrate/20151210030143_add_unlock_token_to_user.rb5
-rw-r--r--db/schema.rb1
-rw-r--r--doc/ci/variables/README.md2
-rw-r--r--doc/ci/yaml/README.md3
-rw-r--r--doc/integration/README.md2
-rw-r--r--doc/integration/cas.md62
-rw-r--r--doc/integration/jira.md113
-rw-r--r--doc/integration/jira_issue_reference.pngbin0 -> 39942 bytes
-rw-r--r--doc/integration/jira_project_name.pngbin0 -> 60598 bytes
-rw-r--r--doc/integration/jira_service.pngbin0 -> 59082 bytes
-rw-r--r--doc/integration/jira_service_close_issue.pngbin0 -> 88433 bytes
-rw-r--r--doc/integration/jira_service_page.pngbin0 -> 162449 bytes
-rw-r--r--doc/integration/jira_workflow_screenshot.pngbin0 -> 121534 bytes
-rw-r--r--features/project/service.feature6
-rw-r--r--features/steps/project/services.rb18
-rw-r--r--lib/banzai/filter/external_issue_reference_filter.rb20
-rw-r--r--lib/gitlab/git.rb4
-rw-r--r--lib/gitlab/o_auth/session.rb17
-rw-r--r--lib/gitlab/reference_extractor.rb12
-rw-r--r--spec/features/commits_spec.rb29
-rw-r--r--spec/helpers/merge_requests_helper_spec.rb21
-rw-r--r--spec/lib/gitlab/reference_extractor_spec.rb10
-rw-r--r--spec/models/build_spec.rb70
-rw-r--r--spec/models/concerns/mentionable_spec.rb13
-rw-r--r--spec/models/jira_issue_spec.rb30
-rw-r--r--spec/models/merge_request_spec.rb11
-rw-r--r--spec/models/project_services/jira_service_spec.rb118
-rw-r--r--spec/models/user_spec.rb1
-rw-r--r--spec/services/create_commit_builds_service_spec.rb17
-rw-r--r--spec/services/git_push_service_spec.rb69
-rw-r--r--spec/services/system_note_service_spec.rb61
-rw-r--r--spec/support/jira_service_helper.rb67
68 files changed, 1220 insertions, 98 deletions
diff --git a/CHANGELOG b/CHANGELOG
index acad4644f5f..bd566fd9f49 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,8 +1,12 @@
Please view this file on the master branch, on stable branches it's out of date.
-v 8.3.0 (unreleased)
+v 8.4.0 (unreleased)
+
+v 8.3.0
+ - Add CAS support (tduehr)
- Bump rack-attack to 4.3.1 for security fix (Stan Hu)
- API support for starred projects for authorized user (Zeger-Jan van de Weg)
+ - Add link to merge request on build detail page.
- Add open_issues_count to project API (Stan Hu)
- Expand character set of usernames created by Omniauth (Corey Hinshaw)
- Add button to automatically merge a merge request when the build succeeds (Zeger-Jan van de Weg)
@@ -19,13 +23,16 @@ v 8.3.0 (unreleased)
- Fix 500 error when update group member permission
- Trim leading and trailing whitespace of milestone and issueable titles (Jose Corcuera)
- Recognize issue/MR/snippet/commit links as references
+ - Backport JIRA features from EE to CE
- Add ignore whitespace change option to commit view
- Fire update hook from GitLab
+ - Allow account unlock via email
- Style warning about mentioning many people in a comment
- Fix: sort milestones by due date once again (Greg Smethells)
- Migrate all CI::Services and CI::WebHooks to Services and WebHooks
- Don't show project fork event as "imported"
- Add API endpoint to fetch merge request commits list
+ - Don't create CI status for refs that doesn't have .gitlab-ci.yml, even if the builds are enabled
- Expose events API with comment information and author info
- Fix: Ensure "Remove Source Branch" button is not shown when branch is being deleted. #3583
- Run custom Git hooks when branch is created or deleted.
@@ -57,6 +64,7 @@ v 8.3.0 (unreleased)
- Do not show build status unless builds are enabled and `.gitlab-ci.yml` is present
- Persist runners registration token in database
- Fix online editor should not remove newlines at the end of the file
+ - Expose Git's version in the admin area
v 8.2.3
- Fix application settings cache not expiring after changes (Stan Hu)
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 7ced7c57889..950824e35ab 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -358,7 +358,7 @@ available at [http://contributor-covenant.org/version/1/1/0/](http://contributor
[core team]: https://about.gitlab.com/core-team/
[getting help page]: https://about.gitlab.com/getting-help/
[Codetriage]: http://www.codetriage.com/gitlabhq/gitlabhq
-[up-for-grabs]: https://gitlab.com/gitlab-org/gitlab-ce/issues?label_name=up+for+grabs
+[up-for-grabs]: https://gitlab.com/gitlab-org/gitlab-ce/issues?label_name=up-for-grabs
[medium-up-for-grabs]: https://medium.com/@kentcdodds/first-timers-only-78281ea47455
[ce-tracker]: https://gitlab.com/gitlab-org/gitlab-ce/issues
[ee-tracker]: https://gitlab.com/gitlab-org/gitlab-ee/issues
diff --git a/Gemfile b/Gemfile
index 26cd52e54d2..321e7b2bc92 100644
--- a/Gemfile
+++ b/Gemfile
@@ -23,6 +23,7 @@ gem 'devise-async', '~> 0.9.0'
gem 'doorkeeper', '~> 2.2.0'
gem 'omniauth', '~> 1.2.2'
gem 'omniauth-bitbucket', '~> 0.0.2'
+gem 'omniauth-cas3', '~> 1.1.2'
gem 'omniauth-facebook', '~> 3.0.0'
gem 'omniauth-github', '~> 1.1.1'
gem 'omniauth-gitlab', '~> 1.0.0'
diff --git a/Gemfile.lock b/Gemfile.lock
index c1c01835e4b..b8517d932a4 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -439,6 +439,10 @@ GEM
multi_json (~> 1.7)
omniauth (~> 1.1)
omniauth-oauth (~> 1.0)
+ omniauth-cas3 (1.1.3)
+ addressable (~> 2.3)
+ nokogiri (~> 1.6.6)
+ omniauth (~> 1.2)
omniauth-facebook (3.0.0)
omniauth-oauth2 (~> 1.2)
omniauth-github (1.1.2)
@@ -894,6 +898,7 @@ DEPENDENCIES
octokit (~> 3.7.0)
omniauth (~> 1.2.2)
omniauth-bitbucket (~> 0.0.2)
+ omniauth-cas3 (~> 1.1.2)
omniauth-facebook (~> 3.0.0)
omniauth-github (~> 1.1.1)
omniauth-gitlab (~> 1.0.0)
diff --git a/app/controllers/admin/identities_controller.rb b/app/controllers/admin/identities_controller.rb
index d28614731f9..e383fe38ea6 100644
--- a/app/controllers/admin/identities_controller.rb
+++ b/app/controllers/admin/identities_controller.rb
@@ -1,6 +1,21 @@
class Admin::IdentitiesController < Admin::ApplicationController
before_action :user
- before_action :identity, except: :index
+ before_action :identity, except: [:index, :new, :create]
+
+ def new
+ @identity = Identity.new
+ end
+
+ def create
+ @identity = Identity.new(identity_params)
+ @identity.user_id = user.id
+
+ if @identity.save
+ redirect_to admin_user_identities_path(@user), notice: 'User identity was successfully created.'
+ else
+ render :new
+ end
+ end
def index
@identities = @user.identities
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 0d182e8eb04..01e2e7b2f98 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -10,6 +10,7 @@ class ApplicationController < ActionController::Base
before_action :authenticate_user_from_token!
before_action :authenticate_user!
+ before_action :validate_user_service_ticket!
before_action :reject_blocked!
before_action :check_password_expiration
before_action :ldap_security_check
@@ -202,6 +203,20 @@ class ApplicationController < ActionController::Base
end
end
+ def validate_user_service_ticket!
+ return unless signed_in? && session[:service_tickets]
+
+ valid = session[:service_tickets].all? do |provider, ticket|
+ Gitlab::OAuth::Session.valid?(provider, ticket)
+ end
+
+ unless valid
+ session[:service_tickets] = nil
+ sign_out current_user
+ redirect_to new_user_session_path
+ end
+ end
+
def check_password_expiration
if current_user && current_user.password_expires_at && current_user.password_expires_at < Time.now && !current_user.ldap_user?
redirect_to new_profile_password_path and return
diff --git a/app/controllers/omniauth_callbacks_controller.rb b/app/controllers/omniauth_callbacks_controller.rb
index f809fa7500a..4cad98b8e98 100644
--- a/app/controllers/omniauth_callbacks_controller.rb
+++ b/app/controllers/omniauth_callbacks_controller.rb
@@ -1,6 +1,6 @@
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
- protect_from_forgery except: [:kerberos, :saml]
+ protect_from_forgery except: [:kerberos, :saml, :cas3]
Gitlab.config.omniauth.providers.each do |provider|
define_method provider['name'] do
@@ -42,6 +42,14 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
render 'errors/omniauth_error', layout: "errors", status: 422
end
+ def cas3
+ ticket = params['ticket']
+ if ticket
+ handle_service_ticket oauth['provider'], ticket
+ end
+ handle_omniauth
+ end
+
private
def handle_omniauth
@@ -84,6 +92,12 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
redirect_to new_user_session_path
end
+ def handle_service_ticket provider, ticket
+ Gitlab::OAuth::Session.create provider, ticket
+ session[:service_tickets] ||= {}
+ session[:service_tickets][provider] = ticket
+ end
+
def oauth
@oauth ||= request.env['omniauth.auth']
end
diff --git a/app/controllers/projects/services_controller.rb b/app/controllers/projects/services_controller.rb
index 6e7590260ff..8b2577aebe1 100644
--- a/app/controllers/projects/services_controller.rb
+++ b/app/controllers/projects/services_controller.rb
@@ -1,5 +1,5 @@
class Projects::ServicesController < Projects::ApplicationController
- ALLOWED_PARAMS = [:title, :token, :type, :active, :api_key, :api_version, :subdomain,
+ ALLOWED_PARAMS = [:title, :token, :type, :active, :api_key, :api_url, :api_version, :subdomain,
:room, :recipients, :project_url, :webhook,
:user_key, :device, :priority, :sound, :bamboo_url, :username, :password,
:build_key, :server, :teamcity_url, :drone_url, :build_type,
@@ -10,7 +10,8 @@ class Projects::ServicesController < Projects::ApplicationController
:notify_only_broken_builds, :add_pusher,
:send_from_committer_email, :disable_diffs, :external_wiki_url,
:notify, :color,
- :server_host, :server_port, :default_irc_uri, :enable_ssl_verification]
+ :server_host, :server_port, :default_irc_uri, :enable_ssl_verification,
+ :jira_issue_transition_id]
# Parameters to ignore if no value is specified
FILTER_BLANK_PARAMS = [:password]
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 6d9cdb95295..7b89fe069ea 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -135,6 +135,16 @@ module Ci
predefined_variables + yaml_variables + project_variables + trigger_variables
end
+ def merge_request
+ merge_requests = MergeRequest.includes(:merge_request_diff)
+ .where(source_branch: ref, source_project_id: commit.gl_project_id)
+ .reorder(iid: :asc)
+
+ merge_requests.find do |merge_request|
+ merge_request.commits.any? { |ci| ci.id == commit.sha }
+ end
+ end
+
def project
commit.project
end
@@ -170,7 +180,8 @@ module Ci
def extract_coverage(text, regex)
begin
- matches = text.gsub(Regexp.new(regex)).to_a.last
+ matches = text.scan(Regexp.new(regex)).last
+ matches = matches.last if matches.kind_of?(Array)
coverage = matches.gsub(/\d+(\.\d+)?/).first
if coverage.present?
diff --git a/app/models/ci/commit.rb b/app/models/ci/commit.rb
index 6bf596e5d3e..d2a29236942 100644
--- a/app/models/ci/commit.rb
+++ b/app/models/ci/commit.rb
@@ -218,16 +218,6 @@ module Ci
update!(committed_at: DateTime.now)
end
- ##
- # This method checks if build status should be displayed.
- #
- # Build status should be available only if builds are enabled
- # on project level and `.gitlab-ci.yml` file is present.
- #
- def show_build_status?
- project.builds_enabled? && ci_yaml_file
- end
-
private
def save_yaml_error(error)
diff --git a/app/models/concerns/participable.rb b/app/models/concerns/participable.rb
index 808d80b0530..fc6f83b918b 100644
--- a/app/models/concerns/participable.rb
+++ b/app/models/concerns/participable.rb
@@ -37,7 +37,7 @@ module Participable
# Be aware that this method makes a lot of sql queries.
# Save result into variable if you are going to reuse it inside same request
- def participants(current_user = self.author, load_lazy_references: true)
+ def participants(current_user = self.author)
participants =
Gitlab::ReferenceExtractor.lazily do
self.class.participant_attrs.flat_map do |attr|
diff --git a/app/models/issue.rb b/app/models/issue.rb
index 4571d7f0ee1..80ecd15077f 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -86,7 +86,7 @@ class Issue < ActiveRecord::Base
def referenced_merge_requests
Gitlab::ReferenceExtractor.lazily do
[self, *notes].flat_map do |note|
- note.all_references(load_lazy_references: false).merge_requests
+ note.all_references.merge_requests
end
end.sort_by(&:iid)
end
diff --git a/app/models/jira_issue.rb b/app/models/jira_issue.rb
new file mode 100644
index 00000000000..5b21aac5e43
--- /dev/null
+++ b/app/models/jira_issue.rb
@@ -0,0 +1,2 @@
+class JiraIssue < ExternalIssue
+end
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index d7430d36c41..ac25d38eb63 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -335,7 +335,7 @@ class MergeRequest < ActiveRecord::Base
issues = commits.flat_map { |c| c.closes_issues(current_user) }
issues.push(*Gitlab::ClosingIssueExtractor.new(project, current_user).
closed_by_message(description))
- issues.uniq
+ issues.uniq(&:id)
else
[]
end
diff --git a/app/models/project.rb b/app/models/project.rb
index 13fd383237c..b28a7ca429c 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -499,6 +499,10 @@ class Project < ActiveRecord::Base
@ci_service ||= ci_services.find(&:activated?)
end
+ def jira_tracker?
+ issues_tracker.to_param == 'jira'
+ end
+
def avatar_type
unless self.avatar.image?
self.errors.add :avatar, 'only images allowed'
@@ -799,6 +803,10 @@ class Project < ActiveRecord::Base
false
end
+ def jira_tracker_active?
+ jira_tracker? && jira_service.active
+ end
+
def ci_commit(sha)
ci_commits.find_by(sha: sha)
end
diff --git a/app/models/project_services/jira_service.rb b/app/models/project_services/jira_service.rb
index 35e30b1cb0b..e216f406e1c 100644
--- a/app/models/project_services/jira_service.rb
+++ b/app/models/project_services/jira_service.rb
@@ -19,9 +19,24 @@
#
class JiraService < IssueTrackerService
+ include HTTParty
include Gitlab::Application.routes.url_helpers
- prop_accessor :title, :description, :project_url, :issues_url, :new_issue_url
+ DEFAULT_API_VERSION = 2
+
+ prop_accessor :username, :password, :api_url, :jira_issue_transition_id,
+ :title, :description, :project_url, :issues_url, :new_issue_url
+
+ before_validation :set_api_url, :set_jira_issue_transition_id
+
+ before_update :reset_password
+
+ def reset_password
+ # don't reset the password if a new one is provided
+ if api_url_changed? && !password_touched?
+ self.password = nil
+ end
+ end
def help
line1 = 'Setting `project_url`, `issues_url` and `new_issue_url` will '\
@@ -54,4 +69,228 @@ class JiraService < IssueTrackerService
def to_param
'jira'
end
+
+ def fields
+ super.push(
+ { type: 'text', name: 'api_url', placeholder: 'https://jira.example.com/rest/api/2' },
+ { type: 'text', name: 'username', placeholder: '' },
+ { type: 'password', name: 'password', placeholder: '' },
+ { type: 'text', name: 'jira_issue_transition_id', placeholder: '2' }
+ )
+ end
+
+ def execute(push, issue = nil)
+ if issue.nil?
+ # No specific issue, that means
+ # we just want to test settings
+ test_settings
+ else
+ close_issue(push, issue)
+ end
+ end
+
+ def create_cross_reference_note(mentioned, noteable, author)
+ issue_name = mentioned.id
+ project = self.project
+ noteable_name = noteable.class.name.underscore.downcase
+ noteable_id = if noteable.is_a?(Commit)
+ noteable.id
+ else
+ noteable.iid
+ end
+
+ entity_url = build_entity_url(noteable_name.to_sym, noteable_id)
+
+ data = {
+ user: {
+ name: author.name,
+ url: resource_url(user_path(author)),
+ },
+ project: {
+ name: project.path_with_namespace,
+ url: resource_url(namespace_project_path(project.namespace, project))
+ },
+ entity: {
+ name: noteable_name.humanize.downcase,
+ url: entity_url
+ }
+ }
+
+ add_comment(data, issue_name)
+ end
+
+ def test_settings
+ result = JiraService.get(
+ jira_api_test_url,
+ headers: {
+ 'Content-Type' => 'application/json',
+ 'Authorization' => "Basic #{auth}"
+ }
+ )
+
+ case result.code
+ when 201, 200
+ Rails.logger.info("#{self.class.name} SUCCESS #{result.code}: Successfully connected to #{api_url}.")
+ true
+ else
+ Rails.logger.info("#{self.class.name} ERROR #{result.code}: #{result.parsed_response}")
+ false
+ end
+ rescue Errno::ECONNREFUSED => e
+ Rails.logger.info "#{self.class.name} ERROR: #{e.message}. API URL: #{api_url}."
+ false
+ end
+
+ private
+
+ def build_api_url_from_project_url
+ server = URI(project_url)
+ default_ports = [["http",80],["https",443]].include?([server.scheme,server.port])
+ server_url = "#{server.scheme}://#{server.host}"
+ server_url.concat(":#{server.port}") unless default_ports
+ "#{server_url}/rest/api/#{DEFAULT_API_VERSION}"
+ rescue
+ "" # looks like project URL was not valid
+ end
+
+ def set_api_url
+ self.api_url = build_api_url_from_project_url if self.api_url.blank?
+ end
+
+ def set_jira_issue_transition_id
+ self.jira_issue_transition_id ||= "2"
+ end
+
+ def close_issue(entity, issue)
+ commit_id = if entity.is_a?(Commit)
+ entity.id
+ elsif entity.is_a?(MergeRequest)
+ entity.last_commit.id
+ end
+ commit_url = build_entity_url(:commit, commit_id)
+
+ # Depending on the JIRA project's workflow, a comment during transition
+ # may or may not be allowed. Split the operation in to two calls so the
+ # comment always works.
+ transition_issue(issue)
+ add_issue_solved_comment(issue, commit_id, commit_url)
+ end
+
+ def transition_issue(issue)
+ message = {
+ transition: {
+ id: jira_issue_transition_id
+ }
+ }
+ send_message(close_issue_url(issue.iid), message.to_json)
+ end
+
+ def add_issue_solved_comment(issue, commit_id, commit_url)
+ comment = {
+ body: "Issue solved with [#{commit_id}|#{commit_url}]."
+ }
+
+ send_message(comment_url(issue.iid), comment.to_json)
+ end
+
+ def add_comment(data, issue_name)
+ url = comment_url(issue_name)
+ user_name = data[:user][:name]
+ user_url = data[:user][:url]
+ entity_name = data[:entity][:name]
+ entity_url = data[:entity][:url]
+ project_name = data[:project][:name]
+
+ message = {
+ body: "[#{user_name}|#{user_url}] mentioned this issue in [a #{entity_name} of #{project_name}|#{entity_url}]."
+ }
+
+ unless existing_comment?(issue_name, message[:body])
+ send_message(url, message.to_json)
+ end
+ end
+
+
+ def auth
+ require 'base64'
+ Base64.urlsafe_encode64("#{self.username}:#{self.password}")
+ end
+
+ def send_message(url, message)
+ result = JiraService.post(
+ url,
+ body: message,
+ headers: {
+ 'Content-Type' => 'application/json',
+ 'Authorization' => "Basic #{auth}"
+ }
+ )
+
+ message = case result.code
+ when 201, 200, 204
+ "#{self.class.name} SUCCESS #{result.code}: Successfully posted to #{url}."
+ when 401
+ "#{self.class.name} ERROR 401: Unauthorized. Check the #{self.username} credentials and JIRA access permissions and try again."
+ else
+ "#{self.class.name} ERROR #{result.code}: #{result.parsed_response}"
+ end
+
+ Rails.logger.info(message)
+ message
+ rescue URI::InvalidURIError, Errno::ECONNREFUSED => e
+ Rails.logger.info "#{self.class.name} ERROR: #{e.message}. Hostname: #{url}."
+ end
+
+ def existing_comment?(issue_name, new_comment)
+ result = JiraService.get(
+ comment_url(issue_name),
+ headers: {
+ 'Content-Type' => 'application/json',
+ 'Authorization' => "Basic #{auth}"
+ }
+ )
+
+ case result.code
+ when 201, 200
+ existing_comments = JSON.parse(result.body)['comments']
+
+ if existing_comments.present?
+ return existing_comments.map { |comment| comment['body'].include?(new_comment) }.any?
+ end
+ end
+
+ false
+ rescue JSON::ParserError
+ false
+ end
+
+ def resource_url(resource)
+ "#{Settings.gitlab['url'].chomp("/")}#{resource}"
+ end
+
+ def build_entity_url(entity_name, entity_id)
+ resource_url(
+ polymorphic_url(
+ [
+ self.project.namespace.becomes(Namespace),
+ self.project,
+ entity_name
+ ],
+ id: entity_id,
+ routing_type: :path
+ )
+ )
+ end
+
+ def close_issue_url(issue_name)
+ "#{self.api_url}/issue/#{issue_name}/transitions"
+ end
+
+ def comment_url(issue_name)
+ "#{self.api_url}/issue/#{issue_name}/comment"
+ end
+
+ def jira_api_test_url
+ "#{self.api_url}/myself"
+ end
end
diff --git a/app/models/user.rb b/app/models/user.rb
index e0ce091c54e..df87f3b79bd 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -26,6 +26,7 @@
# bio :string(255)
# failed_attempts :integer default(0)
# locked_at :datetime
+# unlock_token :string(255)
# username :string(255)
# can_create_group :boolean default(TRUE), not null
# can_create_team :boolean default(TRUE), not null
diff --git a/app/services/create_commit_builds_service.rb b/app/services/create_commit_builds_service.rb
index 759c334ebe9..31b407efeb1 100644
--- a/app/services/create_commit_builds_service.rb
+++ b/app/services/create_commit_builds_service.rb
@@ -16,9 +16,23 @@ class CreateCommitBuildsService
return false
end
- tag = Gitlab::Git.tag_ref?(origin_ref)
- commit = project.ensure_ci_commit(sha)
+ commit = project.ci_commit(sha)
+ unless commit
+ commit = project.ci_commits.new(sha: sha)
+
+ # Skip creating ci_commit when no gitlab-ci.yml is found
+ unless commit.ci_yaml_file
+ return false
+ end
+
+ # Create a new ci_commit
+ commit.save!
+ end
+
+ # Skip creating builds for commits that have [ci skip]
unless commit.skip_ci?
+ # Create builds for commit
+ tag = Gitlab::Git.tag_ref?(origin_ref)
commit.update_committed!
commit.create_builds(ref, tag, user)
end
diff --git a/app/services/issues/close_service.rb b/app/services/issues/close_service.rb
index 3d85f97b7e5..a1a20e47681 100644
--- a/app/services/issues/close_service.rb
+++ b/app/services/issues/close_service.rb
@@ -1,6 +1,11 @@
module Issues
class CloseService < Issues::BaseService
def execute(issue, commit = nil)
+ if project.jira_tracker? && project.jira_service.active
+ project.jira_service.execute(commit, issue)
+ return issue
+ end
+
if project.default_issues_tracker? && issue.close
event_service.close_issue(issue, current_user)
create_note(issue, commit)
diff --git a/app/services/system_note_service.rb b/app/services/system_note_service.rb
index 6975b2ee55b..98a71cbf1ad 100644
--- a/app/services/system_note_service.rb
+++ b/app/services/system_note_service.rb
@@ -241,9 +241,14 @@ class SystemNoteService
note_options.merge!(noteable: noteable)
end
- create_note(note_options)
+ if noteable.is_a?(ExternalIssue)
+ noteable.project.issues_tracker.create_cross_reference_note(noteable, mentioner, author)
+ else
+ create_note(note_options)
+ end
end
+
def self.cross_reference?(note_text)
note_text.start_with?(cross_reference_note_prefix)
end
@@ -259,7 +264,7 @@ class SystemNoteService
#
# Returns Boolean
def self.cross_reference_disallowed?(noteable, mentioner)
- return true if noteable.is_a?(ExternalIssue)
+ return true if noteable.is_a?(ExternalIssue) && !noteable.project.jira_tracker_active?
return false unless mentioner.is_a?(MergeRequest)
return false unless noteable.is_a?(Commit)
diff --git a/app/views/admin/dashboard/index.html.haml b/app/views/admin/dashboard/index.html.haml
index 8657d2c71fe..531247e9148 100644
--- a/app/views/admin/dashboard/index.html.haml
+++ b/app/views/admin/dashboard/index.html.haml
@@ -80,6 +80,10 @@
%span.pull-right
= API::API::version
%p
+ Git
+ %span.pull-right
+ = Gitlab::Git.version
+ %p
Ruby
%span.pull-right
#{RUBY_VERSION}p#{RUBY_PATCHLEVEL}
diff --git a/app/views/admin/identities/index.html.haml b/app/views/admin/identities/index.html.haml
index 8358a14445b..741d111fb7d 100644
--- a/app/views/admin/identities/index.html.haml
+++ b/app/views/admin/identities/index.html.haml
@@ -1,6 +1,7 @@
- page_title "Identities", @user.name, "Users"
= render 'admin/users/head'
+= link_to 'New Identity', new_admin_user_identity_path, class: 'pull-right btn btn-new'
- if @identities.present?
.table-holder
%table.table
diff --git a/app/views/admin/identities/new.html.haml b/app/views/admin/identities/new.html.haml
new file mode 100644
index 00000000000..e30bf0ef0ee
--- /dev/null
+++ b/app/views/admin/identities/new.html.haml
@@ -0,0 +1,4 @@
+- page_title "New Identity"
+%h3.page-title New identity
+%hr
+= render 'form'
diff --git a/app/views/devise/mailer/unlock_instructions.html.erb b/app/views/devise/mailer/unlock_instructions.html.erb
deleted file mode 100644
index 79d6c761d8f..00000000000
--- a/app/views/devise/mailer/unlock_instructions.html.erb
+++ /dev/null
@@ -1,7 +0,0 @@
-<p>Hello <%= @resource.email %>!</p>
-
-<p>Your account has been locked due to an excessive amount of unsuccessful sign in attempts.</p>
-
-<p>Click the link below to unlock your account:</p>
-
-<p><%= link_to 'Unlock your account', unlock_url(@resource, unlock_token: @token) %></p>
diff --git a/app/views/devise/mailer/unlock_instructions.html.haml b/app/views/devise/mailer/unlock_instructions.html.haml
new file mode 100644
index 00000000000..52b327e20c5
--- /dev/null
+++ b/app/views/devise/mailer/unlock_instructions.html.haml
@@ -0,0 +1,10 @@
+%p
+Hello #{@resource.name}!
+
+%p
+ Your GitLab account has been locked due to an excessive amount of unsuccessful
+ sign in attempts. Your account will automatically unlock in
+ = time_ago_in_words(Devise.unlock_in.from_now)
+ or you may click the link below to unlock now.
+
+%p= link_to 'Unlock your account', unlock_url(@resource, unlock_token: @token)
diff --git a/app/views/devise/unlocks/new.html.erb b/app/views/devise/unlocks/new.html.erb
deleted file mode 100644
index f9277d1673f..00000000000
--- a/app/views/devise/unlocks/new.html.erb
+++ /dev/null
@@ -1,12 +0,0 @@
-<h2>Resend unlock instructions</h2>
-
-<%= form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %>
- <%= devise_error_messages! %>
-
- <div><%= f.label :email %><br />
- <%= f.email_field :email %></div>
-
- <div><%= f.submit "Resend unlock instructions" %></div>
-<% end %>
-
-<%= render partial: "devise/shared/links" %>
diff --git a/app/views/devise/unlocks/new.html.haml b/app/views/devise/unlocks/new.html.haml
new file mode 100644
index 00000000000..49c087c0646
--- /dev/null
+++ b/app/views/devise/unlocks/new.html.haml
@@ -0,0 +1,14 @@
+.login-box
+ .login-heading
+ %h3 Resend unlock email
+ .login-body
+ = form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f|
+ .devise-errors
+ = devise_error_messages!
+ .clearfix.append-bottom-20
+ = f.email_field :email, class: 'form-control', placeholder: 'Email', autofocus: 'autofocus', autocapitalize: 'off', autocorrect: 'off'
+ .clearfix
+ = f.submit 'Resend unlock instructions', class: 'btn btn-success'
+
+.clearfix.prepend-top-20
+ = render 'devise/shared/sign_in_link'
diff --git a/app/views/projects/builds/show.html.haml b/app/views/projects/builds/show.html.haml
index 20a5b6a66e7..5b7ecce86ab 100644
--- a/app/views/projects/builds/show.html.haml
+++ b/app/views/projects/builds/show.html.haml
@@ -7,6 +7,10 @@
%strong.monospace= link_to @build.commit.short_sha, ci_status_path(@build.commit)
from
= link_to @build.ref, namespace_project_commits_path(@project.namespace, @project, @build.ref)
+ - merge_request = @build.merge_request
+ - if merge_request
+ via
+ = link_to "merge request ##{merge_request.iid}", merge_request_path(merge_request)
#up-build-trace
- if @commit.matrix_for_ref?(@build.ref)
diff --git a/app/views/projects/commit/_commit_box.html.haml b/app/views/projects/commit/_commit_box.html.haml
index cd40bfafcc2..ddb77fd796b 100644
--- a/app/views/projects/commit/_commit_box.html.haml
+++ b/app/views/projects/commit/_commit_box.html.haml
@@ -40,7 +40,7 @@
- @commit.parents.each do |parent|
= link_to parent.short_id, namespace_project_commit_path(@project.namespace, @project, parent), class: "monospace"
-- if @ci_commit && @ci_commit.show_build_status?
+- if @ci_commit
.pull-right
= link_to ci_status_path(@ci_commit), class: "ci-status ci-#{@ci_commit.status}" do
= ci_status_icon(@ci_commit)
diff --git a/app/views/projects/commits/_commit.html.haml b/app/views/projects/commits/_commit.html.haml
index 1303b27c4f3..28b82dd31f3 100644
--- a/app/views/projects/commits/_commit.html.haml
+++ b/app/views/projects/commits/_commit.html.haml
@@ -17,7 +17,7 @@
%a.text-expander.js-toggle-button ...
.pull-right
- - if ci_commit && ci_commit.show_build_status?
+ - if ci_commit
= render_ci_status(ci_commit)
&nbsp;
= clipboard_button(clipboard_text: commit.id)
diff --git a/app/views/projects/issues/_merge_requests.html.haml b/app/views/projects/issues/_merge_requests.html.haml
index fe856ac991e..254968e4f67 100644
--- a/app/views/projects/issues/_merge_requests.html.haml
+++ b/app/views/projects/issues/_merge_requests.html.haml
@@ -15,9 +15,10 @@
%span.merge-request-info
%strong
= link_to_gfm merge_request.title, merge_request_path(merge_request), class: "row_title"
- in
- - project = merge_request.target_project
- = link_to project.name_with_namespace, namespace_project_path(project.namespace, project)
+ - unless @issue.project.id == merge_request.target_project.id
+ in
+ - project = merge_request.target_project
+ = link_to project.name_with_namespace, namespace_project_path(project.namespace, project)
%span.merge-request-status.prepend-left-10
- if merge_request.merged?
MERGED
diff --git a/config/gitlab.yml.example b/config/gitlab.yml.example
index db378118f85..fcf034d7911 100644
--- a/config/gitlab.yml.example
+++ b/config/gitlab.yml.example
@@ -287,6 +287,15 @@ production: &base
# arguments, followed by optional 'args' which can be either a hash or an array.
# Documentation for this is available at http://doc.gitlab.com/ce/integration/omniauth.html
providers:
+ # See omniauth-cas3 for more configuration details
+ # - { name: 'cas3',
+ # label: 'cas3',
+ # args: {
+ # url: 'https://sso.example.com',
+ # disable_ssl_verification: false,
+ # login_url: '/cas/login',
+ # service_validate_url: '/cas/p3/serviceValidate',
+ # logout_url: '/cas/logout'} }
# - { name: 'github',
# app_id: 'YOUR_APP_ID',
# app_secret: 'YOUR_APP_SECRET',
@@ -324,6 +333,10 @@ production: &base
# application_name: 'YOUR_APP_NAME',
# application_password: 'YOUR_APP_PASSWORD' } }
+ # SSO maximum session duration in seconds. Defaults to CAS default of 8 hours.
+ # cas3:
+ # session_duration: 28800
+
# Shared file storage settings
shared:
# path: /mnt/gitlab # Default: shared
diff --git a/config/initializers/1_settings.rb b/config/initializers/1_settings.rb
index 63d8ae17436..1043fc01ab1 100644
--- a/config/initializers/1_settings.rb
+++ b/config/initializers/1_settings.rb
@@ -126,6 +126,10 @@ Settings.omniauth['block_auto_created_users'] = true if Settings.omniauth['block
Settings.omniauth['auto_link_ldap_user'] = false if Settings.omniauth['auto_link_ldap_user'].nil?
Settings.omniauth['providers'] ||= []
+Settings.omniauth['cas3'] ||= Settingslogic.new({})
+Settings.omniauth.cas3['session_duration'] ||= 8.hours
+Settings.omniauth['session_tickets'] ||= Settingslogic.new({})
+Settings.omniauth.session_tickets['cas3'] = 'ticket'
Settings['shared'] ||= Settingslogic.new({})
Settings.shared['path'] = File.expand_path(Settings.shared['path'] || "shared", Rails.root)
@@ -164,7 +168,7 @@ Settings.gitlab['signin_enabled'] ||= true if Settings.gitlab['signin_enabled'].
Settings.gitlab['twitter_sharing_enabled'] ||= true if Settings.gitlab['twitter_sharing_enabled'].nil?
Settings.gitlab['restricted_visibility_levels'] = Settings.send(:verify_constant_array, Gitlab::VisibilityLevel, Settings.gitlab['restricted_visibility_levels'], [])
Settings.gitlab['username_changing_enabled'] = true if Settings.gitlab['username_changing_enabled'].nil?
-Settings.gitlab['issue_closing_pattern'] = '((?:[Cc]los(?:e[sd]?|ing)|[Ff]ix(?:e[sd]|ing)?|[Rr]esolv(?:e[sd]?|ing)) +(?:(?:issues? +)?%{issue_ref}(?:(?:, *| +and +)?))+)' if Settings.gitlab['issue_closing_pattern'].nil?
+Settings.gitlab['issue_closing_pattern'] = '((?:[Cc]los(?:e[sd]?|ing)|[Ff]ix(?:e[sd]|ing)?|[Rr]esolv(?:e[sd]?|ing)) +(?:(?:issues? +)?%{issue_ref}(?:(?:, *| +and +)?)|([A-Z]*-\d*))+)' if Settings.gitlab['issue_closing_pattern'].nil?
Settings.gitlab['default_projects_features'] ||= {}
Settings.gitlab['webhook_timeout'] ||= 10
Settings.gitlab['max_attachment_size'] ||= 10
diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb
index 5fb43a86e13..d82cfb3ec0c 100644
--- a/config/initializers/devise.rb
+++ b/config/initializers/devise.rb
@@ -121,14 +121,14 @@ Devise.setup do |config|
config.lock_strategy = :failed_attempts
# Defines which key will be used when locking and unlocking an account
- # config.unlock_keys = [ :email ]
+ config.unlock_keys = [ :email ]
# Defines which strategy will be used to unlock an account.
# :email = Sends an unlock link to the user email
# :time = Re-enables login after a certain amount of time (see :unlock_in below)
# :both = Enables both strategies
# :none = No unlock strategy. You should handle unlocking by yourself.
- config.unlock_strategy = :time
+ config.unlock_strategy = :both
# Number of authentication tries before locking an account if lock_strategy
# is failed attempts.
@@ -241,6 +241,16 @@ Devise.setup do |config|
# An Array from the configuration will be expanded.
provider_arguments.concat provider['args']
when Hash
+ # Add procs for handling SLO
+ if provider['name'] == 'cas3'
+ provider['args'][:on_single_sign_out] = lambda do |request|
+ ticket = request.params[:session_index]
+ raise "Service Ticket not found." unless Gitlab::OAuth::Session.valid?(:cas3, ticket)
+ Gitlab::OAuth::Session.destroy(:cas3, ticket)
+ true
+ end
+ end
+
# A Hash from the configuration will be passed as is.
provider_arguments << provider['args'].symbolize_keys
end
diff --git a/config/routes.rb b/config/routes.rb
index 57be57e3251..b9242327de1 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -188,7 +188,7 @@ Rails.application.routes.draw do
namespace :admin do
resources :users, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ } do
resources :keys, only: [:show, :destroy]
- resources :identities, only: [:index, :edit, :update, :destroy]
+ resources :identities, except: [:show]
delete 'stop_impersonation' => 'impersonation#destroy', on: :collection
diff --git a/db/migrate/20151012173029_set_jira_service_api_url.rb b/db/migrate/20151012173029_set_jira_service_api_url.rb
new file mode 100644
index 00000000000..2af99e0db0b
--- /dev/null
+++ b/db/migrate/20151012173029_set_jira_service_api_url.rb
@@ -0,0 +1,50 @@
+class SetJiraServiceApiUrl < ActiveRecord::Migration
+ # This migration can be performed online without errors, but some Jira API calls may be missed
+ # when doing so because api_url is not yet available.
+
+ def build_api_url_from_project_url(project_url, api_version)
+ # this is the exact logic previously used to build the Jira API URL from project_url
+ server = URI(project_url)
+ default_ports = [80, 443].include?(server.port)
+ server_url = "#{server.scheme}://#{server.host}"
+ server_url.concat(":#{server.port}") unless default_ports
+ "#{server_url}/rest/api/#{api_version}"
+ end
+
+ def get_api_version_from_api_url(api_url)
+ match = /\/rest\/api\/(?<api_version>\w+)$/.match(api_url)
+ match && match['api_version']
+ end
+
+ def change
+ reversible do |dir|
+ select_all("SELECT id, properties FROM services WHERE services.type IN ('JiraService')").each do |jira_service|
+ id = jira_service["id"]
+ properties = JSON.parse(jira_service["properties"])
+ properties_was = properties.clone
+
+ dir.up do
+ # remove api_version and set api_url
+ if properties['api_version'].present? && properties['project_url'].present?
+ begin
+ properties['api_url'] ||= build_api_url_from_project_url(properties['project_url'], properties['api_version'])
+ rescue
+ # looks like project_url was not a valid URL. Do nothing.
+ end
+ end
+ properties.delete('api_version') if properties.include?('api_version')
+ end
+
+ dir.down do
+ # remove api_url and set api_version (default to '2')
+ properties['api_version'] ||= get_api_version_from_api_url(properties['api_url']) || '2'
+ properties.delete('api_url') if properties.include?('api_url')
+ end
+
+ if properties != properties_was
+ execute("UPDATE services SET properties = '#{quote_string(properties.to_json)}' WHERE id = #{id}")
+ end
+ end
+ end
+ end
+end
diff --git a/db/migrate/20151210030143_add_unlock_token_to_user.rb b/db/migrate/20151210030143_add_unlock_token_to_user.rb
new file mode 100644
index 00000000000..0ea66ba65df
--- /dev/null
+++ b/db/migrate/20151210030143_add_unlock_token_to_user.rb
@@ -0,0 +1,5 @@
+class AddUnlockTokenToUser < ActiveRecord::Migration
+ def change
+ add_column :users, :unlock_token, :string
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 0167e30ff8b..60b42f7a473 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -837,6 +837,7 @@ ActiveRecord::Schema.define(version: 20151210125932) do
t.integer "consumed_timestep"
t.integer "layout", default: 0
t.boolean "hide_project_limit", default: false
+ t.string "unlock_token"
end
add_index "users", ["admin"], name: "index_users_on_admin", using: :btree
diff --git a/doc/ci/variables/README.md b/doc/ci/variables/README.md
index 022afb70042..b99ea25a3fe 100644
--- a/doc/ci/variables/README.md
+++ b/doc/ci/variables/README.md
@@ -27,7 +27,6 @@ The API_TOKEN will take the Secure Variable value: `SECURE`.
| **CI_BUILD_TAG** | 0.5 | The commit tag name. Present only when building tags. |
| **CI_BUILD_NAME** | 0.5 | The name of the build as defined in `.gitlab-ci.yml` |
| **CI_BUILD_STAGE** | 0.5 | The name of the stage as defined in `.gitlab-ci.yml` |
-| **CI_BUILD_BEFORE_SHA** | all | The first commit that were included in push request |
| **CI_BUILD_REF_NAME** | all | The branch or tag name for which project is built |
| **CI_BUILD_ID** | all | The unique id of the current build that GitLab CI uses internally |
| **CI_BUILD_REPO** | all | The URL to clone the Git repository |
@@ -40,7 +39,6 @@ The API_TOKEN will take the Secure Variable value: `SECURE`.
Example values:
```bash
-export CI_BUILD_BEFORE_SHA="9df57456fa9de2a6d335ca5edf9750ed812b9df0"
export CI_BUILD_ID="50"
export CI_BUILD_REF="1ecfd275763eff1d6b4844ea3168962458c9f27a"
export CI_BUILD_REF_NAME="master"
diff --git a/doc/ci/yaml/README.md b/doc/ci/yaml/README.md
index c5bdce2f778..fd0d49de4e4 100644
--- a/doc/ci/yaml/README.md
+++ b/doc/ci/yaml/README.md
@@ -336,7 +336,8 @@ The above script will:
### artifacts
-_**Note:** Introduced in GitLab Runner v0.7.0._
+_**Note:** Introduced in GitLab Runner v0.7.0. Also, the Windows shell executor
+ does not currently support artifact uploads._
`artifacts` is used to specify list of files and directories which should be
attached to build after success. Below are some examples.
diff --git a/doc/integration/README.md b/doc/integration/README.md
index eff39a626ae..6263353851f 100644
--- a/doc/integration/README.md
+++ b/doc/integration/README.md
@@ -4,10 +4,12 @@ GitLab integrates with multiple third-party services to allow external issue tra
See the documentation below for details on how to configure these services.
+- [Jira](jira.md) Integrate with the JIRA issue tracker
- [External issue tracker](external-issue-tracker.md) Redmine, JIRA, etc.
- [LDAP](ldap.md) Set up sign in via LDAP
- [OmniAuth](omniauth.md) Sign in via Twitter, GitHub, GitLab, and Google via OAuth.
- [SAML](saml.md) Configure GitLab as a SAML 2.0 Service Provider
+- [CAS](cas.md) Configure GitLab to sign in using CAS
- [Slack](slack.md) Integrate with the Slack chat service
- [OAuth2 provider](oauth_provider.md) OAuth2 application creation
- [Gmail actions buttons](gmail_action_buttons_for_gitlab.md) Adds GitLab actions to messages
diff --git a/doc/integration/cas.md b/doc/integration/cas.md
new file mode 100644
index 00000000000..e6b2071f193
--- /dev/null
+++ b/doc/integration/cas.md
@@ -0,0 +1,62 @@
+# CAS OmniAuth Provider
+
+To enable the CAS OmniAuth provider you must register your application with your CAS instance. This requires the service URL GitLab will supply to CAS. It should be something like: `https://gitlab.example.com:443/users/auth/cas3/callback?url`. By default handling for SLO is enabled, you only need to configure CAS for backchannel logout.
+
+1. On your GitLab server, open the configuration file.
+
+ For omnibus package:
+
+ ```sh
+ sudo editor /etc/gitlab/gitlab.rb
+ ```
+
+ For installations from source:
+
+ ```sh
+ cd /home/git/gitlab
+
+ sudo -u git -H editor config/gitlab.yml
+ ```
+
+1. See [Initial OmniAuth Configuration](omniauth.md#initial-omniauth-configuration) for initial settings.
+
+1. Add the provider configuration:
+
+ For omnibus package:
+
+ ```ruby
+ gitlab_rails['omniauth_providers'] = [
+ {
+ name: "cas3",
+ label: "cas",
+ args: {
+ url: 'CAS_SERVER',
+ login_url: '/CAS_PATH/login',
+ service_validate_url: '/CAS_PATH/p3/serviceValidate',
+ logout_url: '/CAS_PATH/logout'} }
+ }
+ }
+ ]
+ ```
+
+ For installations from source:
+
+ ```
+ - { name: 'cas3',
+ label: 'cas',
+ args: {
+ url: 'CAS_SERVER',
+ login_url: '/CAS_PATH/login',
+ service_validate_url: '/CAS_PATH/p3/serviceValidate',
+ logout_url: '/CAS_PATH/logout'} }
+ ```
+
+1. Change 'CAS_PATH' to the root of your CAS instance (ie. `cas`).
+
+1. If your CAS instance does not use default TGC lifetimes, update the `cas3.session_duration` to at least the current TGC maximum lifetime. To explicitly disable SLO, regardless of CAS settings, set this to 0.
+
+1. Save the configuration file.
+
+1. Restart GitLab for the changes to take effect.
+
+On the sign in page there should now be a CAS tab in the sign in form.
diff --git a/doc/integration/jira.md b/doc/integration/jira.md
new file mode 100644
index 00000000000..624601d0fac
--- /dev/null
+++ b/doc/integration/jira.md
@@ -0,0 +1,113 @@
+# GitLab Jira integration
+
+GitLab can be configured to interact with Jira.
+Configuration happens via username and password.
+Connecting to a Jira server via CAS is not possible.
+
+Each project can be configured to connect to a different Jira instance, configuration is explained [here](#configuration).
+If you have one Jira instance you can pre-fill the settings page with a default template. To configure the template [see external issue tracker document](external-issue-tracker.md#service-template)).
+
+Once the project is connected to Jira, you can reference and close the issues in Jira directly from GitLab.
+
+
+## Table of Contents
+
+* [Referencing Jira Issues from GitLab](#referencing-jira-issues)
+* [Closing Jira Issues from GitLab](#closing-jira-issues)
+* [Configuration](#configuration)
+
+### Referencing Jira Issues
+
+When GitLab project has Jira issue tracker configured and enabled, mentioning Jira issue in GitLab will automatically add a comment in Jira issue with the link back to GitLab. This means that in comments in merge requests and commits referencing an issue, eg. `PROJECT-7`, will add a comment in Jira issue in the format:
+
+
+```
+ USER mentioned this issue in LINK_TO_THE_MENTION
+```
+
+* `USER` A user that mentioned the issue. This is the link to the user profile in GitLab.
+* `LINK_TO_THE_MENTION` Link to the origin of mention with a name of the entity where Jira issue was mentioned.
+Can be commit or merge request.
+
+
+![example of mentioning or closing the Jira issue](jira_issue_reference.png)
+
+
+### Closing Jira Issues
+
+Jira issues can be closed directly from GitLab by using trigger words, eg. `Resolves PROJECT-1`, `Closes PROJECT-1` or `Fixes PROJECT-1`, in commits and merge requests.
+When a commit which contains the trigger word in the commit message is pushed, GitLab will add a comment in the mentioned Jira issue.
+
+For example, for project named PROJECT in Jira, we implemented a new feature and created a merge request in GitLab.
+
+This feature was requested in Jira issue PROJECT-7. Merge request in GitLab contains the improvement and in merge request description we say that this merge request `Closes PROJECT-7` issue.
+
+Once this merge request is merged, Jira issue will be automatically closed with a link to the commit that resolved the issue.
+
+![A Git commit that causes the Jira issue to be closed](merge_request_close_jira.png)
+
+
+![The GitLab integration user leaves a comment on Jira](jira_service_close_issue.png)
+
+
+## Configuration
+
+### Configuring JIRA
+
+We need to create a user in JIRA which will have access to all projects that need to integrate with GitLab.
+Login to your JIRA instance as admin and under Administration go to User Management and create a new user.
+As an example, we'll create a user named `gitlab` and add it to `jira-developers` group.
+
+**It is important that the user `gitlab` has write-access to projects in JIRA**
+
+### Configuring GitLab
+
+### GitLab 7.8 EE and up with JIRA v6.x
+
+To enable JIRA integration in a project, navigate to the project Settings page and go to Services. Here you will find JIRA.
+
+Fill in the required details on the page:
+
+![Jira service page](jira_service_page.png)
+
+* `description` A name for the issue tracker (to differentiate between instances, for instance).
+* `project url` The URL to the JIRA project which is being linked to this GitLab project.
+* `issues url` The URL to the JIRA project issues overview for the project that is linked to this GitLab project.
+* `new issue url` This is the URL to create a new issue in JIRA for the project linked to this GitLab project.
+* `api url` The base URL of the JIRA API. It may be omitted, in which case GitLab will automatically use API version `2` based on the `project url`, i.e. `https://jira.example.com/rest/api/2`.
+* `username` The username of the user created in [configuring JIRA step](#configuring-jira).
+* `password` The password of the user created in [configuring JIRA step](#configuring-jira).
+* `Jira issue transition` This is the id of a transition that moves issues to a closed state. You can find this number under [JIRA workflow administration, see screenshot](jira_workflow_screenshot.png). By default, this id is `2`. (In the example image, this is `2` as well)
+
+After saving the configuration, your GitLab project will be able to interact with the linked JIRA project.
+
+
+### GitLab 6.x-7.7 with JIRA v6.x
+
+**Note: GitLab 7.8 and up contain various integration improvements. We strongly recommend upgrading.**
+
+
+In `gitlab.yml` enable [JIRA issue tracker section by uncommenting the lines](https://gitlab.com/subscribers/gitlab-ee/blob/6-8-stable-ee/config/gitlab.yml.example#L111-115).
+This will make sure that all issues within GitLab are pointing to the JIRA issue tracker.
+
+We can also enable JIRA service that will allow us to interact with JIRA issues.
+
+For example, we can close issues in JIRA by a commit in GitLab.
+
+Go to project settings page and fill in the project name for the JIRA project:
+
+![Set the JIRA project name in GitLab to 'NEW'](jira_project_name.png)
+
+Next, go to the services page and find JIRA.
+
+![Jira services page](jira_service.png)
+
+1. Tick the active check box to enable the service.
+1. Supply the url to JIRA server, for example http://jira.sample
+1. Supply the username of a user we created under `Configuring JIRA` section, for example `gitlab`
+1. Supply the password of the user
+1. Optional: supply the JIRA api version, default is version
+1. Optional: supply the JIRA issue transition ID (issue transition to closed). This is dependant on JIRA settings, default is 2
+1. Save
+
+Now we should be able to interact with JIRA issues.
diff --git a/doc/integration/jira_issue_reference.png b/doc/integration/jira_issue_reference.png
new file mode 100644
index 00000000000..15739a22dc7
--- /dev/null
+++ b/doc/integration/jira_issue_reference.png
Binary files differ
diff --git a/doc/integration/jira_project_name.png b/doc/integration/jira_project_name.png
new file mode 100644
index 00000000000..5986fdb63fb
--- /dev/null
+++ b/doc/integration/jira_project_name.png
Binary files differ
diff --git a/doc/integration/jira_service.png b/doc/integration/jira_service.png
new file mode 100644
index 00000000000..1f6628c4371
--- /dev/null
+++ b/doc/integration/jira_service.png
Binary files differ
diff --git a/doc/integration/jira_service_close_issue.png b/doc/integration/jira_service_close_issue.png
new file mode 100644
index 00000000000..67dfc6144c4
--- /dev/null
+++ b/doc/integration/jira_service_close_issue.png
Binary files differ
diff --git a/doc/integration/jira_service_page.png b/doc/integration/jira_service_page.png
new file mode 100644
index 00000000000..69ec44e826f
--- /dev/null
+++ b/doc/integration/jira_service_page.png
Binary files differ
diff --git a/doc/integration/jira_workflow_screenshot.png b/doc/integration/jira_workflow_screenshot.png
new file mode 100644
index 00000000000..8635a32eb68
--- /dev/null
+++ b/doc/integration/jira_workflow_screenshot.png
Binary files differ
diff --git a/features/project/service.feature b/features/project/service.feature
index ff3e7a0b38e..3a7b8308524 100644
--- a/features/project/service.feature
+++ b/features/project/service.feature
@@ -55,6 +55,12 @@ Feature: Project Services
And I fill email on push settings
Then I should see email on push service settings saved
+ Scenario: Activate JIRA service
+ When I visit project "Shop" services page
+ And I click jira service link
+ And I fill jira settings
+ Then I should see jira service settings saved
+
Scenario: Activate Irker (IRC Gateway) service
When I visit project "Shop" services page
And I click Irker service link
diff --git a/features/steps/project/services.rb b/features/steps/project/services.rb
index ed3957ca873..536199ddb4f 100644
--- a/features/steps/project/services.rb
+++ b/features/steps/project/services.rb
@@ -173,6 +173,24 @@ class Spinach::Features::ProjectServices < Spinach::FeatureSteps
expect(find_field('Sound').find('option[selected]').value).to eq 'bike'
end
+ step 'I click jira service link' do
+ click_link 'JIRA'
+ end
+
+ step 'I fill jira settings' do
+ fill_in 'Project url', with: 'http://jira.example'
+ fill_in 'Username', with: 'gitlab'
+ fill_in 'Password', with: 'gitlab'
+ fill_in 'Api url', with: 'http://jira.example/rest/api/2'
+ click_button 'Save'
+ end
+
+ step 'I should see jira service settings saved' do
+ expect(find_field('Project url').value).to eq 'http://jira.example'
+ expect(find_field('Username').value).to eq 'gitlab'
+ expect(find_field('Api url').value).to eq 'http://jira.example/rest/api/2'
+ end
+
step 'I click Atlassian Bamboo CI service link' do
click_link 'Atlassian Bamboo CI'
end
diff --git a/lib/banzai/filter/external_issue_reference_filter.rb b/lib/banzai/filter/external_issue_reference_filter.rb
index f5737a7ac19..f5942740cd6 100644
--- a/lib/banzai/filter/external_issue_reference_filter.rb
+++ b/lib/banzai/filter/external_issue_reference_filter.rb
@@ -23,6 +23,18 @@ module Banzai
end
end
+ def self.referenced_by(node)
+ project = Project.find(node.attr("data-project")) rescue nil
+ return unless project
+
+ id = node.attr("data-external-issue")
+ external_issue = ExternalIssue.new(id, project)
+
+ return unless external_issue
+
+ { external_issue: external_issue }
+ end
+
def call
# Early return if the project isn't using an external tracker
return doc if project.nil? || project.default_issues_tracker?
@@ -46,12 +58,14 @@ module Banzai
def issue_link_filter(text, link_text: nil)
project = context[:project]
- self.class.references_in(text) do |match, issue|
- url = url_for_issue(issue, project, only_path: context[:only_path])
+ self.class.references_in(text) do |match, id|
+ ExternalIssue.new(id, project)
+
+ url = url_for_issue(id, project, only_path: context[:only_path])
title = escape_once("Issue in #{project.external_issue_tracker.title}")
klass = reference_class(:issue)
- data = data_attribute(project: project.id)
+ data = data_attribute(project: project.id, external_issue: id)
text = link_text || match
diff --git a/lib/gitlab/git.rb b/lib/gitlab/git.rb
index 0c350d7c675..f065cc5e9e9 100644
--- a/lib/gitlab/git.rb
+++ b/lib/gitlab/git.rb
@@ -20,6 +20,10 @@ module Gitlab
def blank_ref?(ref)
ref == BLANK_SHA
end
+
+ def version
+ Gitlab::VersionInfo.parse(Gitlab::Popen.popen(%W(#{Gitlab.config.git.bin_path} --version)).first)
+ end
end
end
end
diff --git a/lib/gitlab/o_auth/session.rb b/lib/gitlab/o_auth/session.rb
new file mode 100644
index 00000000000..f33bfd0bd0e
--- /dev/null
+++ b/lib/gitlab/o_auth/session.rb
@@ -0,0 +1,17 @@
+module Gitlab
+ module OAuth
+ module Session
+ def self.create(provider, ticket)
+ Rails.cache.write("gitlab:#{provider}:#{ticket}", ticket, expires_in: Gitlab.config.omniauth.cas3.session_duration)
+ end
+
+ def self.destroy(provider, ticket)
+ Rails.cache.delete("gitlab:#{provider}:#{ticket}")
+ end
+
+ def self.valid?(provider, ticket)
+ Rails.cache.read("gitlab:#{provider}:#{ticket}").present?
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/reference_extractor.rb b/lib/gitlab/reference_extractor.rb
index 42f7c26f3c4..0a70d21b1ce 100644
--- a/lib/gitlab/reference_extractor.rb
+++ b/lib/gitlab/reference_extractor.rb
@@ -18,10 +18,20 @@ module Gitlab
super(text, context.merge(project: project))
end
- %i(user label issue merge_request snippet commit commit_range).each do |type|
+ %i(user label merge_request snippet commit commit_range).each do |type|
define_method("#{type}s") do
@references[type] ||= references(type, project: project, current_user: current_user)
end
end
+
+ def issues
+ options = { project: project, current_user: current_user }
+
+ if project && project.jira_tracker?
+ @references[:external_issue] ||= references(:external_issue, options)
+ else
+ @references[:issue] ||= references(:issue, options)
+ end
+ end
end
end
diff --git a/spec/features/commits_spec.rb b/spec/features/commits_spec.rb
index ecc85376ffc..fe7f07f5b75 100644
--- a/spec/features/commits_spec.rb
+++ b/spec/features/commits_spec.rb
@@ -19,30 +19,13 @@ describe 'Commits' do
let!(:build) { FactoryGirl.create :ci_build, commit: commit }
describe 'Project commits' do
- context 'builds enabled' do
- context '.gitlab-ci.yml found' do
- before do
- visit namespace_project_commits_path(project.namespace, project, :master)
- end
-
- it 'should show build status' do
- page.within("//li[@id='commit-#{commit.short_sha}']") do
- expect(page).to have_css(".ci-status-link")
- end
- end
- end
+ before do
+ visit namespace_project_commits_path(project.namespace, project, :master)
+ end
- context 'no .gitlab-ci.yml found' do
- before do
- stub_ci_commit_yaml_file(nil)
- visit namespace_project_commits_path(project.namespace, project, :master)
- end
-
- it 'should not show build status' do
- page.within("//li[@id='commit-#{commit.short_sha}']") do
- expect(page).to have_no_css(".ci-status-link")
- end
- end
+ it 'should show build status' do
+ page.within("//li[@id='commit-#{commit.short_sha}']") do
+ expect(page).to have_css(".ci-status-link")
end
end
end
diff --git a/spec/helpers/merge_requests_helper_spec.rb b/spec/helpers/merge_requests_helper_spec.rb
index 0ef1efb8bce..28fb3216f60 100644
--- a/spec/helpers/merge_requests_helper_spec.rb
+++ b/spec/helpers/merge_requests_helper_spec.rb
@@ -1,24 +1,37 @@
require 'spec_helper'
describe MergeRequestsHelper do
- describe "#issues_sentence" do
+ describe '#issues_sentence' do
subject { issues_sentence(issues) }
let(:issues) do
[build(:issue, iid: 1), build(:issue, iid: 2), build(:issue, iid: 3)]
end
it { is_expected.to eq('#1, #2, and #3') }
+
+ context 'for JIRA issues' do
+ let(:project) { create(:project) }
+ let(:issues) do
+ [
+ JiraIssue.new('JIRA-123', project),
+ JiraIssue.new('JIRA-456', project),
+ JiraIssue.new('FOOBAR-7890', project)
+ ]
+ end
+
+ it { is_expected.to eq('FOOBAR-7890, JIRA-123, and JIRA-456') }
+ end
end
- describe "#format_mr_branch_names" do
- describe "within the same project" do
+ describe '#format_mr_branch_names' do
+ describe 'within the same project' do
let(:merge_request) { create(:merge_request) }
subject { format_mr_branch_names(merge_request) }
it { is_expected.to eq([merge_request.source_branch, merge_request.target_branch]) }
end
- describe "within different projects" do
+ describe 'within different projects' do
let(:project) { create(:project) }
let(:fork_project) { create(:project, forked_from_project: project) }
let(:merge_request) { create(:merge_request, source_project: fork_project, target_project: project) }
diff --git a/spec/lib/gitlab/reference_extractor_spec.rb b/spec/lib/gitlab/reference_extractor_spec.rb
index 66dc5d4911d..7d963795e17 100644
--- a/spec/lib/gitlab/reference_extractor_spec.rb
+++ b/spec/lib/gitlab/reference_extractor_spec.rb
@@ -97,6 +97,16 @@ describe Gitlab::ReferenceExtractor, lib: true do
expect(extracted.first.commit_to).to eq commit
end
+ context 'with an external issue tracker' do
+ let(:project) { create(:jira_project) }
+ subject { described_class.new(project, project.creator) }
+
+ it 'returns JIRA issues for a JIRA-integrated project' do
+ subject.analyze('JIRA-123 and FOOBAR-4567')
+ expect(subject.issues).to eq [JiraIssue.new('JIRA-123', project), JiraIssue.new('FOOBAR-4567', project)]
+ end
+ end
+
context 'with a project with an underscore' do
let(:other_project) { create(:project, path: 'test_project') }
let(:issue) { create(:issue, project: other_project) }
diff --git a/spec/models/build_spec.rb b/spec/models/build_spec.rb
index 96b6f1dbca6..1c22e3cb7c4 100644
--- a/spec/models/build_spec.rb
+++ b/spec/models/build_spec.rb
@@ -189,6 +189,12 @@ describe Ci::Build, models: true do
it { is_expected.to eq(98.29) }
end
+
+ context 'using a regex capture' do
+ subject { build.extract_coverage('TOTAL 9926 3489 65%', 'TOTAL\s+\d+\s+\d+\s+(\d{1,3}\%)') }
+
+ it { is_expected.to eq(65) }
+ end
end
describe :variables do
@@ -390,4 +396,68 @@ describe Ci::Build, models: true do
it { is_expected.to include('gitlab-ci-token') }
it { is_expected.to include(project.web_url[7..-1]) }
end
+
+ def create_mr(build, commit, factory: :merge_request, created_at: Time.now)
+ FactoryGirl.create(factory,
+ source_project_id: commit.gl_project_id,
+ target_project_id: commit.gl_project_id,
+ source_branch: build.ref,
+ created_at: created_at)
+ end
+
+ describe :merge_request do
+ context 'when a MR has a reference to the commit' do
+ before do
+ @merge_request = create_mr(build, commit, factory: :merge_request)
+
+ commits = [double(id: commit.sha)]
+ allow(@merge_request).to receive(:commits).and_return(commits)
+ allow(MergeRequest).to receive_message_chain(:includes, :where, :reorder).and_return([@merge_request])
+ end
+
+ it 'returns the single associated MR' do
+ expect(build.merge_request.id).to eq(@merge_request.id)
+ end
+ end
+
+ context 'when there is not a MR referencing the commit' do
+ it 'returns nil' do
+ expect(build.merge_request).to be_nil
+ end
+ end
+
+ context 'when more than one MR have a reference to the commit' do
+ before do
+ @merge_request = create_mr(build, commit, factory: :merge_request)
+ @merge_request.close!
+ @merge_request2 = create_mr(build, commit, factory: :merge_request)
+
+ commits = [double(id: commit.sha)]
+ allow(@merge_request).to receive(:commits).and_return(commits)
+ allow(@merge_request2).to receive(:commits).and_return(commits)
+ allow(MergeRequest).to receive_message_chain(:includes, :where, :reorder).and_return([@merge_request, @merge_request2])
+ end
+
+ it 'returns the first MR' do
+ expect(build.merge_request.id).to eq(@merge_request.id)
+ end
+ end
+
+ context 'when a Build is created after the MR' do
+ before do
+ @merge_request = create_mr(build, commit, factory: :merge_request_with_diffs)
+ commit2 = FactoryGirl.create :ci_commit, project: project
+ @build2 = FactoryGirl.create :ci_build, commit: commit2
+
+ commits = [double(id: commit.sha), double(id: commit2.sha)]
+ allow(@merge_request).to receive(:commits).and_return(commits)
+ allow(MergeRequest).to receive_message_chain(:includes, :where, :reorder).and_return([@merge_request])
+ end
+
+ it 'returns the current MR' do
+ expect(@build2.merge_request.id).to eq(@merge_request.id)
+ end
+ end
+
+ end
end
diff --git a/spec/models/concerns/mentionable_spec.rb b/spec/models/concerns/mentionable_spec.rb
index 6179882e935..6653621a83e 100644
--- a/spec/models/concerns/mentionable_spec.rb
+++ b/spec/models/concerns/mentionable_spec.rb
@@ -1,5 +1,18 @@
require 'spec_helper'
+describe Mentionable do
+ include Mentionable
+
+ describe :references do
+ let(:project) { create(:project) }
+
+ it 'excludes JIRA references' do
+ allow(project).to receive_messages(jira_tracker?: true)
+ expect(referenced_mentionables(project, 'JIRA-123')).to be_empty
+ end
+ end
+end
+
describe Issue, "Mentionable" do
describe '#mentioned_users' do
let!(:user) { create(:user, username: 'stranger') }
diff --git a/spec/models/jira_issue_spec.rb b/spec/models/jira_issue_spec.rb
new file mode 100644
index 00000000000..1634265b439
--- /dev/null
+++ b/spec/models/jira_issue_spec.rb
@@ -0,0 +1,30 @@
+require 'spec_helper'
+
+describe JiraIssue do
+ let(:project) { create(:project) }
+ subject { JiraIssue.new('JIRA-123', project) }
+
+ describe 'id' do
+ subject { super().id }
+ it { is_expected.to eq('JIRA-123') }
+ end
+
+ describe 'iid' do
+ subject { super().iid }
+ it { is_expected.to eq('JIRA-123') }
+ end
+
+ describe 'to_s' do
+ subject { super().to_s }
+ it { is_expected.to eq('JIRA-123') }
+ end
+
+ describe :== do
+ specify { expect(subject).to eq(JiraIssue.new('JIRA-123', project)) }
+ specify { expect(subject).not_to eq(JiraIssue.new('JIRA-124', project)) }
+
+ it 'only compares with JiraIssues' do
+ expect(subject).not_to eq('JIRA-123')
+ end
+ end
+end
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb
index 1aeba9b2b3b..e0653a8327d 100644
--- a/spec/models/merge_request_spec.rb
+++ b/spec/models/merge_request_spec.rb
@@ -164,6 +164,17 @@ describe MergeRequest, models: true do
expect(subject.closes_issues).to include(issue2)
end
+
+ context 'for a project with JIRA integration' do
+ let(:issue0) { JiraIssue.new('JIRA-123', subject.project) }
+ let(:issue1) { JiraIssue.new('FOOBAR-4567', subject.project) }
+
+ it 'returns sorted JiraIssues' do
+ allow(subject.project).to receive_messages(default_branch: subject.target_branch)
+
+ expect(subject.closes_issues).to eq([issue0, issue1])
+ end
+ end
end
describe "#work_in_progress?" do
diff --git a/spec/models/project_services/jira_service_spec.rb b/spec/models/project_services/jira_service_spec.rb
index 7d91ebe9ce6..2f8193170ae 100644
--- a/spec/models/project_services/jira_service_spec.rb
+++ b/spec/models/project_services/jira_service_spec.rb
@@ -26,6 +26,113 @@ describe JiraService, models: true do
it { is_expected.to have_one :service_hook }
end
+ describe "Execute" do
+ let(:user) { create(:user) }
+ let(:project) { create(:project) }
+ let(:merge_request) { create(:merge_request) }
+
+ before do
+ @jira_service = JiraService.new
+ allow(@jira_service).to receive_messages(
+ project_id: project.id,
+ project: project,
+ service_hook: true,
+ project_url: 'http://jira.example.com',
+ username: 'gitlab_jira_username',
+ password: 'gitlab_jira_password'
+ )
+ @jira_service.save # will build API URL, as api_url was not specified above
+ @sample_data = Gitlab::PushDataBuilder.build_sample(project, user)
+ # https://github.com/bblimke/webmock#request-with-basic-authentication
+ @api_url = 'http://gitlab_jira_username:gitlab_jira_password@jira.example.com/rest/api/2/issue/JIRA-123/transitions'
+ @comment_url = 'http://gitlab_jira_username:gitlab_jira_password@jira.example.com/rest/api/2/issue/JIRA-123/comment'
+
+ WebMock.stub_request(:post, @api_url)
+ WebMock.stub_request(:post, @comment_url)
+ end
+
+ it "should call JIRA API" do
+ @jira_service.execute(merge_request, JiraIssue.new("JIRA-123", project))
+ expect(WebMock).to have_requested(:post, @comment_url).with(
+ body: /Issue solved with/
+ ).once
+ end
+
+ it "calls the api with jira_issue_transition_id" do
+ @jira_service.jira_issue_transition_id = 'this-is-a-custom-id'
+ @jira_service.execute(merge_request, JiraIssue.new("JIRA-123", project))
+ expect(WebMock).to have_requested(:post, @api_url).with(
+ body: /this-is-a-custom-id/
+ ).once
+ end
+ end
+
+ describe "Stored password invalidation" do
+ let(:project) { create(:project) }
+
+ context "when a password was previously set" do
+ before do
+ @jira_service = JiraService.create(
+ project: create(:project),
+ properties: {
+ api_url: 'http://jira.example.com/rest/api/2',
+ username: 'mic',
+ password: "password"
+ }
+ )
+ end
+
+ it "reset password if url changed" do
+ @jira_service.api_url = 'http://jira_edited.example.com/rest/api/2'
+ @jira_service.save
+ expect(@jira_service.password).to be_nil
+ end
+
+ it "does not reset password if username changed" do
+ @jira_service.username = "some_name"
+ @jira_service.save
+ expect(@jira_service.password).to eq("password")
+ end
+
+ it "does not reset password if new url is set together with password, even if it's the same password" do
+ @jira_service.api_url = 'http://jira_edited.example.com/rest/api/2'
+ @jira_service.password = 'password'
+ @jira_service.save
+ expect(@jira_service.password).to eq("password")
+ expect(@jira_service.api_url).to eq("http://jira_edited.example.com/rest/api/2")
+ end
+
+ it "should reset password if url changed, even if setter called multiple times" do
+ @jira_service.api_url = 'http://jira1.example.com/rest/api/2'
+ @jira_service.api_url = 'http://jira1.example.com/rest/api/2'
+ @jira_service.save
+ expect(@jira_service.password).to be_nil
+ end
+ end
+
+ context "when no password was previously set" do
+ before do
+ @jira_service = JiraService.create(
+ project: create(:project),
+ properties: {
+ api_url: 'http://jira.example.com/rest/api/2',
+ username: 'mic'
+ }
+ )
+ end
+
+ it "saves password if new url is set together with password" do
+ @jira_service.api_url = 'http://jira_edited.example.com/rest/api/2'
+ @jira_service.password = 'password'
+ @jira_service.save
+ expect(@jira_service.password).to eq("password")
+ expect(@jira_service.api_url).to eq("http://jira_edited.example.com/rest/api/2")
+ end
+
+ end
+ end
+
+
describe "Validations" do
context "active" do
before do
@@ -78,11 +185,12 @@ describe JiraService, models: true do
context 'when gitlab.yml was initialized' do
before do
- settings = { "jira" => {
- "title" => "Jira",
- "project_url" => "http://jira.sample/projects/project_a",
- "issues_url" => "http://jira.sample/issues/:id",
- "new_issue_url" => "http://jira.sample/projects/project_a/issues/new"
+ settings = {
+ "jira" => {
+ "title" => "Jira",
+ "project_url" => "http://jira.sample/projects/project_a",
+ "issues_url" => "http://jira.sample/issues/:id",
+ "new_issue_url" => "http://jira.sample/projects/project_a/issues/new"
}
}
allow(Gitlab.config).to receive(:issues_tracker).and_return(settings)
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 376266c0955..2f184bbaf92 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -26,6 +26,7 @@
# bio :string(255)
# failed_attempts :integer default(0)
# locked_at :datetime
+# unlock_token :string(255)
# username :string(255)
# can_create_group :boolean default(TRUE), not null
# can_create_team :boolean default(TRUE), not null
diff --git a/spec/services/create_commit_builds_service_spec.rb b/spec/services/create_commit_builds_service_spec.rb
index 40ba6549e1f..ea5dcfa068a 100644
--- a/spec/services/create_commit_builds_service_spec.rb
+++ b/spec/services/create_commit_builds_service_spec.rb
@@ -52,7 +52,7 @@ describe CreateCommitBuildsService, services: true do
end
end
- it 'skips commits without .gitlab-ci.yml' do
+ it 'skips creating ci_commit for refs without .gitlab-ci.yml' do
stub_ci_commit_yaml_file(nil)
result = service.execute(project, user,
ref: 'refs/heads/0_1',
@@ -60,13 +60,11 @@ describe CreateCommitBuildsService, services: true do
after: '31das312',
commits: [{ message: 'Message' }]
)
- expect(result).to be_persisted
- expect(result.builds.any?).to be_falsey
- expect(result.status).to eq('skipped')
- expect(result.yaml_errors).to be_nil
+ expect(result).to be_falsey
+ expect(Ci::Commit.count).to eq(0)
end
- it 'skips commits if yaml is invalid' do
+ it 'fails commits if yaml is invalid' do
message = 'message'
allow_any_instance_of(Ci::Commit).to receive(:git_commit_message) { message }
stub_ci_commit_yaml_file('invalid: file: file')
@@ -77,6 +75,7 @@ describe CreateCommitBuildsService, services: true do
after: '31das312',
commits: commits
)
+ expect(commit).to be_persisted
expect(commit.builds.any?).to be false
expect(commit.status).to eq('failed')
expect(commit.yaml_errors).to_not be_nil
@@ -97,6 +96,7 @@ describe CreateCommitBuildsService, services: true do
after: '31das312',
commits: commits
)
+ expect(commit).to be_persisted
expect(commit.builds.any?).to be false
expect(commit.status).to eq("skipped")
end
@@ -112,6 +112,7 @@ describe CreateCommitBuildsService, services: true do
commits: commits
)
+ expect(commit).to be_persisted
expect(commit.builds.first.name).to eq("staging")
end
@@ -124,6 +125,7 @@ describe CreateCommitBuildsService, services: true do
after: '31das312',
commits: commits
)
+ expect(commit).to be_persisted
expect(commit.builds.any?).to be false
expect(commit.status).to eq("skipped")
expect(commit.yaml_errors).to be_nil
@@ -140,6 +142,7 @@ describe CreateCommitBuildsService, services: true do
after: '31das312',
commits: commits
)
+ expect(commit).to be_persisted
expect(commit.builds.count(:all)).to eq(2)
commit = service.execute(project, user,
@@ -148,6 +151,7 @@ describe CreateCommitBuildsService, services: true do
after: '31das312',
commits: commits
)
+ expect(commit).to be_persisted
expect(commit.builds.count(:all)).to eq(2)
end
@@ -163,6 +167,7 @@ describe CreateCommitBuildsService, services: true do
commits: commits
)
+ expect(commit).to be_persisted
expect(commit.status).to eq("failed")
expect(commit.builds.any?).to be false
end
diff --git a/spec/services/git_push_service_spec.rb b/spec/services/git_push_service_spec.rb
index a04c242cf0e..c1080ef190a 100644
--- a/spec/services/git_push_service_spec.rb
+++ b/spec/services/git_push_service_spec.rb
@@ -265,6 +265,75 @@ describe GitPushService, services: true do
expect(Issue.find(issue.id)).to be_opened
end
end
+
+ # EE-only tests
+ context "for jira issue tracker" do
+ include JiraServiceHelper
+
+ let(:jira_tracker) { project.create_jira_service if project.jira_service.nil? }
+
+ before do
+ jira_service_settings
+
+ WebMock.stub_request(:post, jira_api_transition_url)
+ WebMock.stub_request(:post, jira_api_comment_url)
+ WebMock.stub_request(:get, jira_api_comment_url).to_return(body: jira_issue_comments)
+ WebMock.stub_request(:get, jira_api_test_url)
+
+ allow(closing_commit).to receive_messages({
+ issue_closing_regex: Regexp.new(Gitlab.config.gitlab.issue_closing_pattern),
+ safe_message: message,
+ author_name: commit_author.name,
+ author_email: commit_author.email
+ })
+
+ allow(project.repository).to receive_messages(commits_between: [closing_commit])
+ end
+
+ after do
+ jira_tracker.destroy!
+ end
+
+ context "mentioning an issue" do
+ let(:message) { "this is some work.\n\nrelated to JIRA-1" }
+
+ it "should initiate one api call to jira server to mention the issue" do
+ service.execute(project, user, @oldrev, @newrev, @ref)
+
+ expect(WebMock).to have_requested(:post, jira_api_comment_url).with(
+ body: /mentioned this issue in/
+ ).once
+ end
+ end
+
+ context "closing an issue" do
+ let(:message) { "this is some work.\n\ncloses JIRA-1" }
+
+ it "should initiate one api call to jira server to close the issue" do
+ transition_body = {
+ transition: {
+ id: '2'
+ }
+ }.to_json
+
+ service.execute(project, user, @oldrev, @newrev, @ref)
+ expect(WebMock).to have_requested(:post, jira_api_transition_url).with(
+ body: transition_body
+ ).once
+ end
+
+ it "should initiate one api call to jira server to comment on the issue" do
+ comment_body = {
+ body: "Issue solved with [#{closing_commit.id}|http://localhost/#{project.path_with_namespace}/commit/#{closing_commit.id}]."
+ }.to_json
+
+ service.execute(project, user, @oldrev, @newrev, @ref)
+ expect(WebMock).to have_requested(:post, jira_api_comment_url).with(
+ body: comment_body
+ ).once
+ end
+ end
+ end
end
describe "empty project" do
diff --git a/spec/services/system_note_service_spec.rb b/spec/services/system_note_service_spec.rb
index 0a4f9b230e8..c9f828ae2f7 100644
--- a/spec/services/system_note_service_spec.rb
+++ b/spec/services/system_note_service_spec.rb
@@ -425,4 +425,65 @@ describe SystemNoteService, services: true do
end
end
end
+
+ include JiraServiceHelper
+
+ describe 'JIRA integration' do
+ let(:project) { create(:project) }
+ let(:author) { create(:user) }
+ let(:issue) { create(:issue, project: project) }
+ let(:mergereq) { create(:merge_request, :simple, target_project: project, source_project: project) }
+ let(:jira_issue) { JiraIssue.new("JIRA-1", project)}
+ let(:jira_tracker) { project.create_jira_service if project.jira_service.nil? }
+ let(:commit) { project.commit }
+
+ context 'in JIRA issue tracker' do
+ before do
+ jira_service_settings
+ WebMock.stub_request(:post, jira_api_comment_url)
+ end
+
+ after do
+ jira_tracker.destroy!
+ end
+
+ describe "new reference" do
+ before do
+ WebMock.stub_request(:get, jira_api_comment_url).to_return(body: jira_issue_comments)
+ end
+
+ subject { described_class.cross_reference(jira_issue, commit, author) }
+
+ it { is_expected.to eq(jira_status_message) }
+ end
+
+ describe "existing reference" do
+ before do
+ message = "[#{author.name}|http://localhost/u/#{author.username}] mentioned this issue in [a commit of #{project.path_with_namespace}|http://localhost/#{project.path_with_namespace}/commit/#{commit.id}]."
+ WebMock.stub_request(:get, jira_api_comment_url).to_return(body: "{\"comments\":[{\"body\":\"#{message}\"}]}")
+ end
+
+ subject { described_class.cross_reference(jira_issue, commit, author) }
+ it { is_expected.not_to eq(jira_status_message) }
+ end
+ end
+
+ context 'issue from an issue' do
+ context 'in JIRA issue tracker' do
+ before do
+ jira_service_settings
+ WebMock.stub_request(:post, jira_api_comment_url)
+ WebMock.stub_request(:get, jira_api_comment_url).to_return(body: jira_issue_comments)
+ end
+
+ after do
+ jira_tracker.destroy!
+ end
+
+ subject { described_class.cross_reference(jira_issue, issue, author) }
+
+ it { is_expected.to eq(jira_status_message) }
+ end
+ end
+ end
end
diff --git a/spec/support/jira_service_helper.rb b/spec/support/jira_service_helper.rb
new file mode 100644
index 00000000000..a3f496359b1
--- /dev/null
+++ b/spec/support/jira_service_helper.rb
@@ -0,0 +1,67 @@
+module JiraServiceHelper
+
+ def jira_service_settings
+ properties = {
+ "title"=>"JIRA tracker",
+ "project_url"=>"http://jira.example/issues/?jql=project=A",
+ "issues_url"=>"http://jira.example/browse/JIRA-1",
+ "new_issue_url"=>"http://jira.example/secure/CreateIssue.jspa",
+ "api_url"=>"http://jira.example/rest/api/2"
+ }
+
+ jira_tracker.update_attributes(properties: properties, active: true)
+ end
+
+ def jira_status_message
+ "JiraService SUCCESS 200: Successfully posted to #{jira_api_comment_url}."
+ end
+
+ def jira_issue_comments
+ "{\"startAt\":0,\"maxResults\":11,\"total\":11,
+ \"comments\":[{\"self\":\"http://0.0.0.0:4567/rest/api/2/issue/10002/comment/10609\",
+ \"id\":\"10609\",\"author\":{\"self\":\"http://0.0.0.0:4567/rest/api/2/user?username=gitlab\",
+ \"name\":\"gitlab\",\"emailAddress\":\"gitlab@example.com\",
+ \"avatarUrls\":{\"16x16\":\"http://0.0.0.0:4567/secure/useravatar?size=xsmall&avatarId=10122\",
+ \"24x24\":\"http://0.0.0.0:4567/secure/useravatar?size=small&avatarId=10122\",
+ \"32x32\":\"http://0.0.0.0:4567/secure/useravatar?size=medium&avatarId=10122\",
+ \"48x48\":\"http://0.0.0.0:4567/secure/useravatar?avatarId=10122\"},
+ \"displayName\":\"GitLab\",\"active\":true},
+ \"body\":\"[Administrator|http://localhost:3000/u/root] mentioned JIRA-1 in Merge request of [gitlab-org/gitlab-test|http://localhost:3000/gitlab-org/gitlab-test/merge_requests/2].\",
+ \"updateAuthor\":{\"self\":\"http://0.0.0.0:4567/rest/api/2/user?username=gitlab\",\"name\":\"gitlab\",\"emailAddress\":\"gitlab@example.com\",
+ \"avatarUrls\":{\"16x16\":\"http://0.0.0.0:4567/secure/useravatar?size=xsmall&avatarId=10122\",
+ \"24x24\":\"http://0.0.0.0:4567/secure/useravatar?size=small&avatarId=10122\",
+ \"32x32\":\"http://0.0.0.0:4567/secure/useravatar?size=medium&avatarId=10122\",
+ \"48x48\":\"http://0.0.0.0:4567/secure/useravatar?avatarId=10122\"},\"displayName\":\"GitLab\",\"active\":true},
+ \"created\":\"2015-02-12T22:47:07.826+0100\",
+ \"updated\":\"2015-02-12T22:47:07.826+0100\"},
+ {\"self\":\"http://0.0.0.0:4567/rest/api/2/issue/10002/comment/10700\",
+ \"id\":\"10700\",\"author\":{\"self\":\"http://0.0.0.0:4567/rest/api/2/user?username=gitlab\",
+ \"name\":\"gitlab\",\"emailAddress\":\"gitlab@example.com\",
+ \"avatarUrls\":{\"16x16\":\"http://0.0.0.0:4567/secure/useravatar?size=xsmall&avatarId=10122\",
+ \"24x24\":\"http://0.0.0.0:4567/secure/useravatar?size=small&avatarId=10122\",
+ \"32x32\":\"http://0.0.0.0:4567/secure/useravatar?size=medium&avatarId=10122\",
+ \"48x48\":\"http://0.0.0.0:4567/secure/useravatar?avatarId=10122\"},\"displayName\":\"GitLab\",\"active\":true},
+ \"body\":\"[Administrator|http://localhost:3000/u/root] mentioned this issue in [a commit of h5bp/html5-boilerplate|http://localhost:3000/h5bp/html5-boilerplate/commit/2439f77897122fbeee3bfd9bb692d3608848433e].\",
+ \"updateAuthor\":{\"self\":\"http://0.0.0.0:4567/rest/api/2/user?username=gitlab\",\"name\":\"gitlab\",\"emailAddress\":\"gitlab@example.com\",
+ \"avatarUrls\":{\"16x16\":\"http://0.0.0.0:4567/secure/useravatar?size=xsmall&avatarId=10122\",
+ \"24x24\":\"http://0.0.0.0:4567/secure/useravatar?size=small&avatarId=10122\",
+ \"32x32\":\"http://0.0.0.0:4567/secure/useravatar?size=medium&avatarId=10122\",
+ \"48x48\":\"http://0.0.0.0:4567/secure/useravatar?avatarId=10122\"},\"displayName\":\"GitLab\",\"active\":true},
+ \"created\":\"2015-04-01T03:45:55.667+0200\",
+ \"updated\":\"2015-04-01T03:45:55.667+0200\"
+ }
+ ]}"
+ end
+
+ def jira_api_comment_url
+ 'http://jira.example/rest/api/2/issue/JIRA-1/comment'
+ end
+
+ def jira_api_transition_url
+ 'http://jira.example/rest/api/2/issue/JIRA-1/transitions'
+ end
+
+ def jira_api_test_url
+ 'http://jira.example/rest/api/2/myself'
+ end
+end