diff --git a/app/models/issue.rb b/app/models/issue.rb index fa8c43ea9..2a3b95958 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -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"])} diff --git a/app/models/journal.rb b/app/models/journal.rb index 297c7a148..19fdce1c9 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -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 diff --git a/app/models/pull_request.rb b/app/models/pull_request.rb index e36af832b..b3ab1e03b 100644 --- a/app/models/pull_request.rb +++ b/app/models/pull_request.rb @@ -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)} diff --git a/app/models/pull_requests_reviewer.rb b/app/models/pull_requests_reviewer.rb new file mode 100644 index 000000000..31502b2a9 --- /dev/null +++ b/app/models/pull_requests_reviewer.rb @@ -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 diff --git a/app/models/review.rb b/app/models/review.rb index f2d3e678d..715e11683 100644 --- a/app/models/review.rb +++ b/app/models/review.rb @@ -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 diff --git a/db/migrate/20220725020217_create_pull_requests_reviewers.rb b/db/migrate/20220725020217_create_pull_requests_reviewers.rb new file mode 100644 index 000000000..be5c561cf --- /dev/null +++ b/db/migrate/20220725020217_create_pull_requests_reviewers.rb @@ -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 diff --git a/db/migrate/20220725020443_change_reviews_reference_to_pull_requests.rb b/db/migrate/20220725020443_change_reviews_reference_to_pull_requests.rb new file mode 100644 index 000000000..e03943915 --- /dev/null +++ b/db/migrate/20220725020443_change_reviews_reference_to_pull_requests.rb @@ -0,0 +1,6 @@ +class ChangeReviewsReferenceToPullRequests < ActiveRecord::Migration[5.2] + def change + remove_reference :reviews, :issue + add_reference :reviews, :pull_request + end +end diff --git a/spec/models/pull_requests_reviewer_spec.rb b/spec/models/pull_requests_reviewer_spec.rb new file mode 100644 index 000000000..f3dfd9b95 --- /dev/null +++ b/spec/models/pull_requests_reviewer_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe PullRequestsReviewer, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end