Browse Source

为项目新增sonar_url 且增加回调接口

pull/220/head
chenjing 4 years ago
parent
commit
91fa87ada5
6 changed files with 34 additions and 11 deletions
  1. +1
    -0
      Gemfile
  2. +7
    -0
      Gemfile.lock
  3. +15
    -7
      app/controllers/projects_controller.rb
  4. +1
    -0
      app/helpers/projects_helper.rb
  5. +5
    -4
      config/routes.rb
  6. +5
    -0
      db/migrate/20211022030244_add_sonar_url_to_projects.rb

+ 1
- 0
Gemfile View File

@@ -63,6 +63,7 @@ end
group :development do
gem 'prettier'
gem 'pry-rails', '~> 0.3.9'
gem 'rubocop', '~> 0.52.0'
gem 'solargraph', '~> 0.38.0'
gem 'awesome_print'


+ 7
- 0
Gemfile.lock View File

@@ -99,6 +99,7 @@ GEM
archive-zip (~> 0.10)
nokogiri (~> 1.8)
chunky_png (1.3.11)
coderay (1.1.3)
concurrent-ruby (1.1.6)
connection_pool (2.2.2)
crass (1.0.6)
@@ -217,6 +218,11 @@ GEM
popper_js (1.16.0)
powerpack (0.1.2)
prettier (0.18.2)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
pry-rails (0.3.9)
pry (>= 0.10.4)
public_suffix (4.0.3)
puma (3.12.2)
raabro (1.4.0)
@@ -469,6 +475,7 @@ DEPENDENCIES
parallel (~> 1.19, >= 1.19.1)
pdfkit
prettier
pry-rails (~> 0.3.9)
puma (~> 3.11)
rack-cors
rack-mini-profiler


+ 15
- 7
app/controllers/projects_controller.rb View File

@@ -4,7 +4,7 @@ class ProjectsController < ApplicationController
include ProjectsHelper
include Acceleratorable

before_action :require_login, except: %i[index branches branches_slice group_type_list simple show fork_users praise_users watch_users recommend about menu_list]
before_action :require_login, except: %i[index branches branches_slice group_type_list simple show fork_users praise_users watch_users recommend about menu_list sonar_url]
before_action :require_profile_completed, only: [:create, :migrate]
before_action :load_repository, except: %i[index group_type_list migrate create recommend]
before_action :authorizate_user_can_edit_project!, only: %i[update]
@@ -58,14 +58,14 @@ class ProjectsController < ApplicationController
def migrate
Projects::MigrateForm.new(mirror_params).validate!

@project =
@project =
if enable_accelerator?(mirror_params[:clone_addr])
source_clone_url = mirror_params[:clone_addr]
uid_logger("########## 已动加速器 ##########")
result = Gitea::Accelerator::MigrateService.call(mirror_params)
if result[:status] == :success
Rails.logger.info "########## 加速镜像成功 ########## "
Projects::MigrateService.call(current_user,
Projects::MigrateService.call(current_user,
mirror_params.merge(source_clone_url: source_clone_url,
clone_addr: accelerator_url(mirror_params[:repository_name])))
else
@@ -117,7 +117,7 @@ class ProjectsController < ApplicationController
ActiveRecord::Base.transaction do
# TODO:
# 临时特殊处理修改website、lesson_url操作方法
if project_params.has_key?("website")
if project_params.has_key?("website")
@project.update(project_params)
elsif project_params.has_key?("default_branch")
@project.update(project_params)
@@ -126,11 +126,11 @@ class ProjectsController < ApplicationController
}
Gitea::Repository::UpdateService.call(@owner, @project.identifier, gitea_params)
else
validate_params = project_params.slice(:name, :description,
validate_params = project_params.slice(:name, :description,
:project_category_id, :project_language_id, :private, :identifier)
Projects::UpdateForm.new(validate_params.merge(user_id: @project.user_id, project_identifier: @project.identifier)).validate!
private = @project.forked_from_project.present? ? !@project.forked_from_project.is_public : params[:private] || false

new_project_params = project_params.except(:private).merge(is_public: !private)
@@ -225,6 +225,14 @@ class ProjectsController < ApplicationController
end
end

def sonar_url
token = request.headers["HTTP_SONAR_TOKEN"]
playod = JWT.decode(token,EducoderOauth.client_id)[0]
data = HashWithIndifferentAccess.new playod
return normal_status(-1, "sonar_url不能为空") if data["sonar_url"].blank?
@project.update(sonar_url:data["sonar_url"])
render :json => { status: 0, message: "更新成功"}
end

private
def project_params


+ 1
- 0
app/helpers/projects_helper.rb View File

@@ -54,6 +54,7 @@ module ProjectsHelper
tmp_json = tmp_json.merge({
identifier: render_identifier(project),
name: project.name,
sonar_url: project.sonar_url,
platform: project.platform,
id: project.id,
repo_id: repo.id,


+ 5
- 4
config/routes.rb View File

@@ -305,7 +305,7 @@ Rails.application.routes.draw do
# resource :unread_message_info, only: [:show]
# 通知中心
resources :messages, only: [:index, :create] do
resources :messages, only: [:index, :create] do
collection do
post :read
@@ -422,6 +422,7 @@ Rails.application.routes.draw do
get :branches
get :branches_slice
get :simple
post :sonar_url
get :watchers, to: 'projects#watch_users'
get :stargazers, to: 'projects#praise_users'
get :members, to: 'projects#fork_users'
@@ -674,9 +675,9 @@ Rails.application.routes.draw do
resources :project_licenses
resources :project_ignores
resources :reversed_keywords
resources :system_notifications
resources :message_templates, only: [:index, :edit, :update] do
collection do
resources :system_notifications
resources :message_templates, only: [:index, :edit, :update] do
collection do
get :init_data
end
end


+ 5
- 0
db/migrate/20211022030244_add_sonar_url_to_projects.rb View File

@@ -0,0 +1,5 @@
class AddSonarUrlToProjects < ActiveRecord::Migration[5.2]
def change
add_column :projects, :sonar_url, :string
end
end

Loading…
Cancel
Save