2022-07-11 15:52:38 +08:00
|
|
|
class CommitLogsController < ApplicationController
|
|
|
|
|
|
|
|
def create
|
|
|
|
tip_exception "未认证" unless params[:token].to_s == "7917908927b6f1b792f2027a08a8b24a2de42c1692c2fd45da0dee5cf90a5af5"
|
|
|
|
ref = params[:ref]
|
2022-07-18 10:43:57 +08:00
|
|
|
user_name = params[:pusher][:login]
|
|
|
|
user_mail = params[:pusher][:email]
|
2022-07-11 15:52:38 +08:00
|
|
|
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]
|
2022-07-14 15:21:42 +08:00
|
|
|
owner_name = repository_full_name.split("/")[0]
|
|
|
|
owner = User.find_by(login: owner_name)
|
|
|
|
project = Project.where(identifier: repository_name).where(user_id: owner&.id)&.first
|
2022-07-11 15:52:38 +08:00
|
|
|
project = Project.where(identifier: repository_name).where(gpid: repository_id)&.first if project.blank?
|
2022-08-16 15:33:15 +08:00
|
|
|
project.update_column(:updated_on, Time.now) if project.present?
|
2022-07-22 10:11:21 +08:00
|
|
|
params[:commits].each do |commit|
|
|
|
|
commit_id = commit[:id]
|
|
|
|
message = commit[:message]
|
2024-04-24 11:16:59 +08:00
|
|
|
commit_date = Time.parse(commit[:timestamp]) || Time.now
|
2023-04-17 10:13:23 +08:00
|
|
|
commit_log = CommitLog.create(user: user, project: project, repository_id: repository_id,
|
2022-07-22 10:11:21 +08:00
|
|
|
name: repository_name, full_name: repository_full_name,
|
2024-04-24 11:16:59 +08:00
|
|
|
ref: ref, commit_id: commit_id, message: message, created_at: commit_date, updated_at: commit_date)
|
2023-04-18 14:08:31 +08:00
|
|
|
commit_log.project_trends.create(user_id: user.id, project_id: project&.id, action_type: "create") if user.id !=2
|
2022-09-15 09:57:28 +08:00
|
|
|
# 统计数据新增
|
|
|
|
CacheAsyncSetJob.perform_later("project_common_service", {commits: 1}, project.id)
|
2022-07-22 10:11:21 +08:00
|
|
|
end
|
2022-07-11 15:52:38 +08:00
|
|
|
|
|
|
|
end
|
|
|
|
end
|