新增:存储pull_request源仓库信息

This commit is contained in:
yystopf 2024-07-19 11:17:15 +08:00
parent f9e7dafefd
commit c9df8fa3fe
7 changed files with 50 additions and 28 deletions

View File

@ -217,6 +217,10 @@ class ProjectsController < ApplicationController
new_project_params = project_params.except(:private).merge(is_public: !private) new_project_params = project_params.except(:private).merge(is_public: !private)
@project.update_attributes!(new_project_params) @project.update_attributes!(new_project_params)
fork_pull_requests = PullRequest.where(fork_project_id: @project.id)
if fork_pull_requests.present?
fork_pull_requests.update_all(fork_project_identifier: @project.identifier)
end
@project.forked_projects.map{|p| p.update!(is_public: @project.is_public)} @project.forked_projects.map{|p| p.update!(is_public: @project.is_public)}
gitea_params = { gitea_params = {
private: private, private: private,

View File

@ -2,25 +2,27 @@
# #
# Table name: pull_requests # Table name: pull_requests
# #
# id :integer not null, primary key # id :integer not null, primary key
# gitea_id :integer # gitea_id :integer
# gitea_number :integer # gitea_number :integer
# user_id :integer # user_id :integer
# created_at :datetime not null # created_at :datetime not null
# updated_at :datetime not null # updated_at :datetime not null
# status :integer default("0") # status :integer default("0")
# project_id :integer # project_id :integer
# title :string(255) # title :string(255)
# milestone :integer # milestone :integer
# body :text(4294967295) # body :text(4294967295)
# head :string(255) # head :string(255)
# base :string(255) # base :string(255)
# issue_id :integer # issue_id :integer
# fork_project_id :integer # fork_project_id :integer
# is_original :boolean default("0") # is_original :boolean default("0")
# comments_count :integer default("0") # comments_count :integer default("0")
# commits_count :integer default("0") # commits_count :integer default("0")
# files_count :integer default("0") # files_count :integer default("0")
# fork_project_owner :string(255)
# fork_project_identifier :string(255)
# #
class PullRequest < ApplicationRecord class PullRequest < ApplicationRecord

View File

@ -15,6 +15,7 @@ class Projects::TransferService < ApplicationService
update_repo_url update_repo_url
update_visit_teams update_visit_teams
update_fork_info update_fork_info
update_fork_pull_request_info
end end
Rails.logger.info("##### Project transfer_service end ######") Rails.logger.info("##### Project transfer_service end ######")
@ -49,6 +50,11 @@ class Projects::TransferService < ApplicationService
fork_user.update(user_id: @new_owner.id) if fork_user.present? fork_user.update(user_id: @new_owner.id) if fork_user.present?
end end
def update_fork_pull_request_info
fork_pull_requests = PullRequest.where(fork_project_id: @project.id)
fork_pull_requests.update_all(fork_project_owner: @new_owner&.login) if fork_pull_requests.present?
end
def gitea_update_owner def gitea_update_owner
begin begin
@gitea_repo = $gitea_hat_client.post_repos_transfer_by_owner_repo(owner&.login, project.identifier, {body: {new_owner: new_owner&.login}.to_json}) @gitea_repo = $gitea_hat_client.post_repos_transfer_by_owner_repo(owner&.login, project.identifier, {body: {new_owner: new_owner&.login}.to_json})

View File

@ -1,6 +1,6 @@
class PullRequests::CreateService < ApplicationService class PullRequests::CreateService < ApplicationService
attr_reader :current_user, :owner, :project, :params attr_reader :current_user, :owner, :project, :params, :fork_project
attr_accessor :pull_issue, :pull_request attr_accessor :pull_issue, :pull_request
def initialize(current_user, owner, project, params) def initialize(current_user, owner, project, params)
@ -8,6 +8,7 @@ class PullRequests::CreateService < ApplicationService
@project = project @project = project
@params = params @params = params
@current_user = current_user @current_user = current_user
@fork_project = Project.find_by_id(params[:fork_project_id])
end end
def call def call
@ -102,7 +103,9 @@ class PullRequests::CreateService < ApplicationService
fork_project_id: @params[:fork_project_id], fork_project_id: @params[:fork_project_id],
is_original: is_original, is_original: is_original,
files_count: @params[:files_count] || 0, files_count: @params[:files_count] || 0,
commits_count: @params[:commits_count] || 0 commits_count: @params[:commits_count] || 0,
fork_project_owner: @fork_project&.owner&.login,
fork_project_identifier: @fork_project&.identifier
}) })
end end

View File

@ -23,10 +23,10 @@ json.issues do
json.pull_request_base pr.base json.pull_request_base pr.base
json.pull_request_staus pr.status == 1 ? "merged" : (pr.status == 2 ? "closed" : "open") json.pull_request_staus pr.status == 1 ? "merged" : (pr.status == 2 ? "closed" : "open")
json.is_original pr.is_original json.is_original pr.is_original
json.fork_project_id pr.fork_project_id.present? ? pr.fork_project_id : pr.project_id json.fork_project_id pr.fork_project_id
json.fork_project_identifier pr.fork_project_id.present? ? pr&.fork_project&.identifier : pr.project&.identifier json.fork_project_identifier pr.fork_project.present? ? pr&.fork_project&.identifier : pr.fork_project_identifier
json.fork_project_user pr.fork_project_id.present? ? pr&.fork_project&.owner.try(:login) : pr.project&.owner.try(:login) json.fork_project_user pr.fork_project.present? ? pr&.fork_project&.owner.try(:login) : pr.fork_project_owner
json.fork_project_user_name pr.fork_project_id.present? ? pr&.fork_project&.owner.try(:show_real_name) : pr.project&.owner.try(:show_real_name) json.fork_project_user_name pr.fork_project.present? ? pr&.fork_project&.owner.try(:show_real_name) : User.find_by(login: pr.fork_project_owner).try(:show_real_name)
json.reviewers pr.reviewers.pluck(:login) json.reviewers pr.reviewers.pluck(:login)
json.id issue.id json.id issue.id

View File

@ -25,9 +25,10 @@ end
json.pull_request do json.pull_request do
json.extract! @pull_request, :id,:base, :head, :status, :is_original json.extract! @pull_request, :id,:base, :head, :status, :is_original
json.pull_request_staus @pull_request.status == 1 ? "merged" : (@pull_request.status == 2 ? "closed" : "open") json.pull_request_staus @pull_request.status == 1 ? "merged" : (@pull_request.status == 2 ? "closed" : "open")
json.fork_project_id @pull_request.fork_project_id.present? ? @pull_request.fork_project_id : @pull_request.project_id json.fork_project_id @pull_request.fork_project_id
json.fork_project_user @pull_request.fork_project_id.present? ? @pull_request&.fork_project&.owner.try(:login) : @pull_request.project&.owner.try(:login) json.fork_project_identifier @pull_request.fork_project.present? ? @pull_request&.fork_project&.identifier : @pull_request.fork_project_identifier
json.fork_project_user_name @pull_request.fork_project_id.present? ? @pull_request&.fork_project&.owner.try(:show_real_name) : @pull_request.project&.owner.try(:show_real_name) json.fork_project_user @pull_request.fork_project.present? ? @pull_request&.fork_project&.owner.try(:login) : @pull_request.fork_project_owner
json.fork_project_user_name @pull_request.fork_project.present? ? @pull_request&.fork_project&.owner.try(:show_real_name) : User.find_by(login: @pull_request.fork_project_owner).try(:show_real_name)
json.create_user @pull_request&.user&.login json.create_user @pull_request&.user&.login
json.mergeable @gitea_pull["mergeable"] json.mergeable @gitea_pull["mergeable"]
json.state @gitea_pull["state"] json.state @gitea_pull["state"]

View File

@ -0,0 +1,6 @@
class AddForkProjectOwnerIdentifierToPullRequests < ActiveRecord::Migration[5.2]
def change
add_column :pull_requests, :fork_project_owner, :string
add_column :pull_requests, :fork_project_identifier, :string
end
end