forked from Gitlink/forgeplus
新增: 合并请求审核model
This commit is contained in:
parent
e76503ae26
commit
76cc185a1d
|
@ -0,0 +1,19 @@
|
||||||
|
class ReviewsController < ApplicationController
|
||||||
|
before_action :require_login
|
||||||
|
before_action :load_project
|
||||||
|
before_action :load_pull_request
|
||||||
|
|
||||||
|
def create
|
||||||
|
@journal, @review = Api::V1::Projects::PullRequests::Reviews::CreateService.call(@project, @pull_request, review_params, current_user)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def review_params
|
||||||
|
params.require(:review).permit(:content, :commit_id, :status)
|
||||||
|
end
|
||||||
|
|
||||||
|
def load_pull_request
|
||||||
|
@pull_request = @project.pull_requests.where(gitea_number: params[:id]).where.not(id: params[:id]).take || PullRequest.find_by_id(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -68,6 +68,7 @@ class Issue < ApplicationRecord
|
||||||
has_many :issue_tags, through: :issue_tags_relates
|
has_many :issue_tags, through: :issue_tags_relates
|
||||||
has_many :issue_times, dependent: :destroy
|
has_many :issue_times, dependent: :destroy
|
||||||
has_many :issue_depends, dependent: :destroy
|
has_many :issue_depends, dependent: :destroy
|
||||||
|
has_many :reviews, dependent: :destroy
|
||||||
scope :issue_includes, ->{includes(:user)}
|
scope :issue_includes, ->{includes(:user)}
|
||||||
scope :issue_many_includes, ->{includes(journals: :user)}
|
scope :issue_many_includes, ->{includes(journals: :user)}
|
||||||
scope :issue_issue, ->{where(issue_classify: [nil,"issue"])}
|
scope :issue_issue, ->{where(issue_classify: [nil,"issue"])}
|
||||||
|
|
|
@ -12,11 +12,13 @@
|
||||||
# parent_id :integer
|
# parent_id :integer
|
||||||
# comments_count :integer default("0")
|
# comments_count :integer default("0")
|
||||||
# reply_id :integer
|
# reply_id :integer
|
||||||
|
# review_id :integer
|
||||||
#
|
#
|
||||||
# Indexes
|
# Indexes
|
||||||
#
|
#
|
||||||
# index_journals_on_created_on (created_on)
|
# index_journals_on_created_on (created_on)
|
||||||
# index_journals_on_journalized_id (journalized_id)
|
# index_journals_on_journalized_id (journalized_id)
|
||||||
|
# index_journals_on_review_id (review_id)
|
||||||
# index_journals_on_user_id (user_id)
|
# index_journals_on_user_id (user_id)
|
||||||
# journals_journalized_id (journalized_id,journalized_type)
|
# journals_journalized_id (journalized_id,journalized_type)
|
||||||
#
|
#
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
# == Schema Information
|
||||||
|
#
|
||||||
|
# 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
|
||||||
|
#
|
||||||
|
# Indexes
|
||||||
|
#
|
||||||
|
# index_reviews_on_issue_id (issue_id)
|
||||||
|
# index_reviews_on_reviewer_id (reviewer_id)
|
||||||
|
#
|
||||||
|
|
||||||
|
class Review < ApplicationRecord
|
||||||
|
|
||||||
|
belongs_to :issue
|
||||||
|
belongs_to :reviewer, class_name: 'User', foreign_key: :reviewer_id
|
||||||
|
has_one :journal, dependent: :destroy
|
||||||
|
|
||||||
|
enum status: {common: 0, approved: 1, rejected: 2}
|
||||||
|
end
|
|
@ -0,0 +1,40 @@
|
||||||
|
class Api::V1::Projects::PullRequests::Reviews::CreateService < ApplicationService
|
||||||
|
include ActiveModel::Model
|
||||||
|
|
||||||
|
attr_reader :project, :pull_request, :issue, :status, :commit_id, :content, :current_user
|
||||||
|
attr_accessor :review, :journal
|
||||||
|
|
||||||
|
validates :status, inclusion: { in: %w(common approved rejected), message: '请输入正确的Type'}
|
||||||
|
|
||||||
|
def initialize(project, pull_request, params, current_user)
|
||||||
|
@project = project
|
||||||
|
@pull_request = pull_request
|
||||||
|
@issue = pull_request&.issue
|
||||||
|
@status = params[:status]
|
||||||
|
@commit_id = params[:commit_id]
|
||||||
|
@content = params[:content]
|
||||||
|
@current_user = current_user
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
raise Error, errors.full_messages.join(", ") unless valid?
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
create_review
|
||||||
|
create_journal
|
||||||
|
end
|
||||||
|
|
||||||
|
return @journal, @review
|
||||||
|
rescue
|
||||||
|
raise Error, '服务器错误,请联系系统管理员!'
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def create_review
|
||||||
|
@review = issue.reviews.create!(status: status, content: content, commit_id: commit_id, reviewer_id: @current_user.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_journal
|
||||||
|
@journal = issue.journals.create!(notes: content, user_id: @current_user.id, review_id: @review.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,10 @@
|
||||||
|
json.issue do
|
||||||
|
json.partial! 'pull_requests/detail', issue: @pull_request.issue
|
||||||
|
end
|
||||||
|
json.journal_id @journal.id
|
||||||
|
json.journal_notes @journal.notes
|
||||||
|
json.review_id @review.id
|
||||||
|
json.commit_id @review.commit_id
|
||||||
|
json.content @review.content
|
||||||
|
json.status @review.status
|
||||||
|
json.created_at format_time(@review.created_at)
|
|
@ -528,6 +528,7 @@ Rails.application.routes.draw do
|
||||||
post :refuse_merge
|
post :refuse_merge
|
||||||
get :files
|
get :files
|
||||||
get :commits
|
get :commits
|
||||||
|
resources :reviews, only: [:create]
|
||||||
end
|
end
|
||||||
collection do
|
collection do
|
||||||
post :check_can_merge
|
post :check_can_merge
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
class CreateReviews < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
create_table :reviews do |t|
|
||||||
|
t.references :issue
|
||||||
|
t.references :reviewer
|
||||||
|
t.text :content
|
||||||
|
t.string :commit_id
|
||||||
|
t.integer :status, default: 0
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
|
||||||
|
add_reference :journals, :review
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,5 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Review, type: :model do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
Loading…
Reference in New Issue