2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
2021-03-10 16:11:14 +00:00
|
|
|
|
|
|
|
class Integration::GitLabController < ApplicationController
|
|
|
|
prepend_before_action { authentication_check && authorize! }
|
|
|
|
|
|
|
|
def verify
|
|
|
|
gitlab = ::GitLab.new(params[:endpoint], params[:api_token])
|
2021-03-24 16:41:05 +00:00
|
|
|
|
|
|
|
gitlab.verify!
|
|
|
|
|
2021-03-10 16:11:14 +00:00
|
|
|
render json: {
|
2021-03-24 16:41:05 +00:00
|
|
|
result: 'ok',
|
2021-03-10 16:11:14 +00:00
|
|
|
}
|
|
|
|
rescue => e
|
|
|
|
logger.error e
|
|
|
|
|
|
|
|
render json: {
|
|
|
|
result: 'failed',
|
|
|
|
message: e.message,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def query
|
|
|
|
config = Setting.get('gitlab_config')
|
|
|
|
|
2021-03-24 16:41:05 +00:00
|
|
|
gitlab = ::GitLab.new(config['endpoint'], config['api_token'])
|
2021-03-10 16:11:14 +00:00
|
|
|
|
|
|
|
render json: {
|
|
|
|
result: 'ok',
|
|
|
|
response: gitlab.issues_by_urls(params[:links]),
|
|
|
|
}
|
|
|
|
rescue => e
|
|
|
|
logger.error e
|
|
|
|
|
|
|
|
render json: {
|
|
|
|
result: 'failed',
|
|
|
|
message: e.message,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
ticket = Ticket.find(params[:ticket_id])
|
|
|
|
ticket.with_lock do
|
|
|
|
authorize!(ticket, :show?)
|
|
|
|
ticket.preferences[:gitlab] ||= {}
|
|
|
|
ticket.preferences[:gitlab][:issue_links] = Array(params[:issue_links]).uniq
|
|
|
|
ticket.save!
|
|
|
|
end
|
|
|
|
|
|
|
|
render json: {
|
|
|
|
result: 'ok',
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|