Merge branch 'standalone_develop' into pre_trustie_server
This commit is contained in:
commit
19b6737260
2
Gemfile
2
Gemfile
|
@ -139,4 +139,4 @@ gem 'doorkeeper'
|
|||
|
||||
gem 'doorkeeper-jwt'
|
||||
|
||||
gem 'gitea-client', '~> 0.10.5'
|
||||
gem 'gitea-client', '~> 0.10.6'
|
|
@ -0,0 +1,8 @@
|
|||
class Api::V1::Projects::CodeStatsController < Api::V1::BaseController
|
||||
before_action :require_public_and_member_above, only: [:index]
|
||||
|
||||
def index
|
||||
@result_object = Api::V1::Projects::CodeStats::ListService.call(@project, {ref: params[:ref]}, current_user&.gitea_token)
|
||||
puts @result_object
|
||||
end
|
||||
end
|
|
@ -76,12 +76,13 @@ class SettingsController < ApplicationController
|
|||
url: EducoderOauth.oauth_url,
|
||||
method: 'get'
|
||||
}
|
||||
platform_url = Rails.application.config_for(:configuration)['platform_url']
|
||||
config = Rails.application.config_for(:configuration)
|
||||
(config.dig("oauth").keys - ["educoder"]).each do |provider|
|
||||
@third_party_new << {
|
||||
name: provider,
|
||||
url: "/auth/#{provider}",
|
||||
method: 'post'
|
||||
url: "#{platform_url}/auth/#{provider}",
|
||||
method: 'get'
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
# index_open_users_on_user_id (user_id)
|
||||
#
|
||||
|
||||
class OpenUsers::QQ < OpenUser
|
||||
class OpenUsers::Qq < OpenUser
|
||||
def nickname
|
||||
extra&.[]('nickname')
|
||||
end
|
||||
|
|
|
@ -120,7 +120,7 @@ class User < Owner
|
|||
has_one :user_extension, dependent: :destroy
|
||||
has_many :open_users, dependent: :destroy
|
||||
has_one :wechat_open_user, class_name: 'OpenUsers::Wechat'
|
||||
has_one :qq_open_user, class_name: 'OpenUsers::QQ'
|
||||
has_one :qq_open_user, class_name: 'OpenUsers::Qq'
|
||||
accepts_nested_attributes_for :user_extension, update_only: true
|
||||
has_many :fork_users, dependent: :destroy
|
||||
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
class Api::V1::Projects::CodeStats::ListService < ApplicationService
|
||||
|
||||
attr_reader :project, :ref, :owner, :repo, :token
|
||||
attr_accessor :gitea_data
|
||||
|
||||
def initialize(project, params, token=nil)
|
||||
@project = project
|
||||
@ref = params[:ref]
|
||||
@owner = project&.owner.login
|
||||
@repo = project&.identifier
|
||||
@token = token
|
||||
end
|
||||
|
||||
def call
|
||||
load_gitea_data
|
||||
|
||||
gitea_data
|
||||
end
|
||||
|
||||
private
|
||||
def request_params
|
||||
param = {
|
||||
access_token: token
|
||||
}
|
||||
param.merge!(ref: ref) if ref.present?
|
||||
|
||||
param
|
||||
end
|
||||
|
||||
def load_gitea_data
|
||||
@gitea_data = $gitea_client.get_repos_code_stats_by_owner_repo(owner, repo, {query: request_params}) rescue nil
|
||||
raise Error, '获取贡献者贡献度失败!' unless @gitea_data.is_a?(Hash)
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@ class Oauth::CreateOrFindQqAccountService < ApplicationService
|
|||
def call
|
||||
new_user = false
|
||||
# 存在该用户
|
||||
open_user = OpenUsers::QQ.find_by(uid: params['uid'])
|
||||
open_user = OpenUsers::Qq.find_by(uid: params['uid'])
|
||||
return [open_user.user, new_user] if open_user.present?
|
||||
|
||||
if user.blank? || !user.logged?
|
||||
|
@ -32,7 +32,7 @@ class Oauth::CreateOrFindQqAccountService < ApplicationService
|
|||
Util.download_file(params.dig('info', 'image'), avatar_path)
|
||||
end
|
||||
|
||||
new_open_user = OpenUsers::QQ.create!(user: user, uid: params['uid'])
|
||||
new_open_user = OpenUsers::Qq.create!(user: user, uid: params['uid'])
|
||||
|
||||
Rails.cache.write(new_open_user.can_bind_cache_key, 1, expires_in: 1.hours) if new_user # 方便后面进行账号绑定
|
||||
end
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
json.author_count @result_object["author_count"]
|
||||
json.commit_count @result_object["commit_count"]
|
||||
json.change_files @result_object["change_files"]
|
||||
json.additions @result_object["additions"]
|
||||
json.deletions @result_object["deletions"]
|
||||
json.commit_count_in_all_branches @result_object["commit_count_in_all_branches"]
|
||||
json.authors @result_object["authors"].each do |author|
|
||||
json.author do
|
||||
json.partial! 'api/v1/users/commit_user', locals: { user: render_cache_commit_author(author), name: author['name'] }
|
||||
end
|
||||
json.commits author["commits"]
|
||||
json.additions author["additions"]
|
||||
json.deletions author["deletions"]
|
||||
end
|
|
@ -1,10 +1,11 @@
|
|||
config = Rails.application.config_for(:configuration)
|
||||
|
||||
OmniAuth.config.add_camelization 'qq', 'QQ' if config.dig("oauth", "qq")
|
||||
OmniAuth.config.add_camelization 'github', 'GitHub' if config.dig("oauth", "github")
|
||||
OmniAuth.config.add_camelization 'gitee', 'Gitee' if config.dig("oauth", "gitee")
|
||||
OmniAuth.config.add_camelization 'wechat', 'Wechat' if config.dig("oauth", "wechat")
|
||||
# OmniAuth.config.add_camelization 'github', 'GitHub' if config.dig("oauth", "github")
|
||||
# OmniAuth.config.add_camelization 'gitee', 'Gitee' if config.dig("oauth", "gitee")
|
||||
# OmniAuth.config.add_camelization 'wechat', 'Wechat' if config.dig("oauth", "wechat")
|
||||
OmniAuth.config.logger = Rails.logger
|
||||
OmniAuth.config.allowed_request_methods = %i[get post]
|
||||
OmniAuth.config.before_request_phase = nil
|
||||
OmniAuth.config.before_callback_phase = nil
|
||||
OmniAuth.config.on_failure = Proc.new { |env|
|
||||
|
@ -22,6 +23,6 @@ Rails.application.config.middleware.use OmniAuth::Builder do
|
|||
provider :gitee, config.dig("oauth", "gitee", "appid"), config.dig("oauth", "gitee", "secret"), { provider_ignores_state: true, scope: "user_info emails" }
|
||||
end
|
||||
if config.dig("oauth", "wechat").present?
|
||||
provider :gitee, config.dig("oauth", "wechat", "appid"), config.dig("oauth", "wechat", "secret"), { provider_ignores_state: true, scope: "snsapi_login" }
|
||||
provider :wechat, config.dig("oauth", "wechat", "appid"), config.dig("oauth", "wechat", "secret"), { provider_ignores_state: true, scope: "snsapi_login" }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,7 +20,7 @@ Rails.application.routes.draw do
|
|||
get 'attachments/download/:id', to: 'attachments#show'
|
||||
get 'attachments/download/:id/:filename', to: 'attachments#show'
|
||||
|
||||
get 'auth/qq/callback', to: 'oauth/qq#create'
|
||||
# get 'auth/qq/callback', to: 'oauth/qq#create'
|
||||
get 'auth/failure', to: 'oauth/base#auth_failure'
|
||||
get 'auth/cas/callback', to: 'oauth/cas#create'
|
||||
get 'auth/:provider/callback', to: 'oauth/callbacks#create'
|
||||
|
|
|
@ -54,6 +54,7 @@ defaults format: :json do
|
|||
end
|
||||
end
|
||||
resources :commits, only: [:index]
|
||||
resources :code_stats, only: [:index]
|
||||
get '/commits/:sha/diff', to: 'commits#diff'
|
||||
get '/git/blobs/:sha', to: 'git#blobs'
|
||||
get '/git/trees/:sha', to: 'git#trees'
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class UpdateUserSuper < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
execute("ALTER TABLE `user_extensions` MODIFY `super_description` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue