增加从webhook接收仓库日志记录
This commit is contained in:
parent
0dd062ce1c
commit
ed0655452c
|
@ -0,0 +1,23 @@
|
||||||
|
class CommitLogsController < ApplicationController
|
||||||
|
|
||||||
|
def create
|
||||||
|
tip_exception "未认证" unless params[:token].to_s == "7917908927b6f1b792f2027a08a8b24a2de42c1692c2fd45da0dee5cf90a5af5"
|
||||||
|
ref = params[:ref]
|
||||||
|
commit_id = params[:commits][0][:id]
|
||||||
|
message = params[:commits][0][:message]
|
||||||
|
user_name = params[:message][0][:committer][:username]
|
||||||
|
user_mail = params[:message][0][:committer][:email]
|
||||||
|
user = User.find_by(mail: user_mail)
|
||||||
|
user = User.find_by(login: user_name) if user.blank?
|
||||||
|
|
||||||
|
repository_id = params[:repository][:id]
|
||||||
|
repository_name = params[:repository][:name]
|
||||||
|
repository_full_name = params[:repository][:full_name]
|
||||||
|
project = Project.where(identifier: repository_name).where(user_id: user.id)&.first
|
||||||
|
project = Project.where(identifier: repository_name).where(gpid: repository_id)&.first if project.blank?
|
||||||
|
CommitLog.create(user: user, project: project, repository_id: repository_id,
|
||||||
|
name: repository_name, full_name: repository_full_name,
|
||||||
|
ref: ref, commit_id: commit_id, message: message)
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,6 @@
|
||||||
|
class CommitLog < ApplicationRecord
|
||||||
|
belongs_to :user
|
||||||
|
belongs_to :project
|
||||||
|
belongs_to :repository
|
||||||
|
|
||||||
|
end
|
|
@ -973,6 +973,8 @@ Rails.application.routes.draw do
|
||||||
get 'oauth/get_code', to: 'oauth#get_code'
|
get 'oauth/get_code', to: 'oauth#get_code'
|
||||||
get 'oauth/get_token_callback', to: 'oauth#get_token_callback'
|
get 'oauth/get_token_callback', to: 'oauth#get_token_callback'
|
||||||
|
|
||||||
|
resources :commit_logs, :only => [:create]
|
||||||
|
|
||||||
root 'main#index'
|
root 'main#index'
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
class CreateCommitLogs < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
create_table :commit_logs do |t|
|
||||||
|
t.references :user
|
||||||
|
t.references :project
|
||||||
|
t.integer :repository_id
|
||||||
|
t.string :name
|
||||||
|
t.string :full_name
|
||||||
|
t.string :commit_id
|
||||||
|
t.string :ref
|
||||||
|
t.string :message
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index :commit_logs, :commit_id
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue