修复:合并请求评审模型修改

This commit is contained in:
yystopf 2022-07-25 16:20:42 +08:00
parent 0df1e5fdd0
commit 1feb166fd5
8 changed files with 59 additions and 13 deletions

View File

@ -68,7 +68,6 @@ class Issue < ApplicationRecord
has_many :issue_tags, through: :issue_tags_relates
has_many :issue_times, dependent: :destroy
has_many :issue_depends, dependent: :destroy
has_many :reviews, dependent: :destroy
scope :issue_includes, ->{includes(:user)}
scope :issue_many_includes, ->{includes(journals: :user)}
scope :issue_issue, ->{where(issue_classify: [nil,"issue"])}

View File

@ -25,7 +25,8 @@
class Journal < ApplicationRecord
belongs_to :user
belongs_to :issue, foreign_key: :journalized_id, :touch => true
belongs_to :issue, foreign_key: :journalized_id, :touch => true, optional: true
belongs_to :journalized, polymorphic: true
has_many :journal_details, :dependent => :delete_all
has_many :attachments, as: :container, dependent: :destroy

View File

@ -32,12 +32,17 @@ class PullRequest < ApplicationRecord
belongs_to :issue
belongs_to :user
belongs_to :project, counter_cache: true, touch: true
# belongs_to :fork_project, foreign_key: :fork_project_id
belongs_to :fork_project, class_name: 'Project', foreign_key: :fork_project_id, optional: true
has_many :pull_request_assigns, foreign_key: :pull_request_id
has_many :pull_request_tags, foreign_key: :pull_request_id
has_many :project_trends, as: :trend, dependent: :destroy
has_many :attachments, as: :container, dependent: :destroy
has_one :gitea_pull, foreign_key: :id, primary_key: :gitea_number, class_name: 'Gitea::Pull'
has_many :journals, :as => :journalized, :dependent => :destroy
has_many :journal_details, through: :journals
has_many :reviews, dependent: :destroy
has_many :pull_requests_reviewers, dependent: :destroy
has_many :reviewers, through: :pull_requests_reviewers
scope :merged_and_closed, ->{where.not(status: 0)}
scope :opening, -> {where(status: 0)}

View File

@ -0,0 +1,21 @@
# == Schema Information
#
# Table name: pull_requests_reviewers
#
# id :integer not null, primary key
# pull_request_id :integer
# reviewer_id :integer
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_pull_requests_reviewers_on_pull_request_id (pull_request_id)
# index_pull_requests_reviewers_on_reviewer_id (reviewer_id)
#
class PullRequestsReviewer < ApplicationRecord
belongs_to :pull_request
belongs_to :reviewers, class_name: 'User', foreign_key: :reviewer_id
end

View File

@ -2,19 +2,19 @@
#
# Table name: reviews
#
# id :integer not null, primary key
# issue_id :integer
# reviewer_id :integer
# content :text(65535)
# commit_id :string(255)
# status :integer default("0")
# created_at :datetime not null
# updated_at :datetime not null
# id :integer not null, primary key
# reviewer_id :integer
# content :text(65535)
# commit_id :string(255)
# status :integer default("0")
# created_at :datetime not null
# updated_at :datetime not null
# pull_request_id :integer
#
# Indexes
#
# index_reviews_on_issue_id (issue_id)
# index_reviews_on_reviewer_id (reviewer_id)
# index_reviews_on_pull_request_id (pull_request_id)
# index_reviews_on_reviewer_id (reviewer_id)
#
class Review < ApplicationRecord

View File

@ -0,0 +1,9 @@
class CreatePullRequestsReviewers < ActiveRecord::Migration[5.2]
def change
create_table :pull_requests_reviewers do |t|
t.belongs_to :pull_request, index: true
t.belongs_to :reviewer, class_name: User, index:true
t.timestamps
end
end
end

View File

@ -0,0 +1,6 @@
class ChangeReviewsReferenceToPullRequests < ActiveRecord::Migration[5.2]
def change
remove_reference :reviews, :issue
add_reference :reviews, :pull_request
end
end

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe PullRequestsReviewer, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end