Browse Source

CloudIDEA文件标记已读未读

pull/313/head
“xxq250” 3 years ago
parent
commit
4ccf8ea5ff
6 changed files with 64 additions and 1 deletions
  1. +29
    -0
      app/controllers/mark_files_controller.rb
  2. +5
    -0
      app/models/mark_file.rb
  3. +1
    -0
      app/models/pull_request.rb
  4. +12
    -0
      app/views/mark_files/index.json.jbuilder
  5. +2
    -1
      config/routes.rb
  6. +15
    -0
      db/migrate/20220728022339_create_mark_files.rb

+ 29
- 0
app/controllers/mark_files_controller.rb View File

@@ -0,0 +1,29 @@
class MarkFilesController < ApplicationController
before_action :require_login
before_action :load_project
before_action :load_pull_request

def index
@files_result = Gitea::PullRequest::FilesService.call(@owner.login, @project.identifier, @pull_request.gitea_number, current_user&.gitea_token)

MarkFile.bulk_insert(*%i[pull_request_id, file_path_sha file_path created_at updated_at]) do |worker|
@files_result['Files'].echo do |file|
worker.add(pull_request_id: @pull_request.id, file_path_sha: SecureRandom.uuid.gsub("-", ""), file_path: file['Name'])
end
end
@mark_files = MarkFile.where(pull_request_id: @pull_request.id)
end

def create
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

+ 5
- 0
app/models/mark_file.rb View File

@@ -0,0 +1,5 @@
class MarkFile < ApplicationRecord
belongs_to :pull_request


end

+ 1
- 0
app/models/pull_request.rb View File

@@ -43,6 +43,7 @@ class PullRequest < ApplicationRecord
has_many :reviews, dependent: :destroy
has_many :pull_requests_reviewers, dependent: :destroy
has_many :reviewers, through: :pull_requests_reviewers
has_many :mark_files, dependent: :destroy

scope :merged_and_closed, ->{where.not(status: 0)}
scope :opening, -> {where(status: 0)}


+ 12
- 0
app/views/mark_files/index.json.jbuilder View File

@@ -0,0 +1,12 @@
json.status 0
json.message 'success'
json.count @mark_files.count
json.files do
json.array! @mark_files do |file|
json.sha file.file_path_sha
json.name file.file_path
json.mark_as_read file.mark_as_read
json.updated_after_read file.updated_after_read
end

end

+ 2
- 1
config/routes.rb View File

@@ -528,7 +528,8 @@ Rails.application.routes.draw do
post :refuse_merge
get :files
get :commits
resources :reviews, only: [:create]
resources :reviews, only: [:create]
resources :mark_files, only: [:index, :create]
end
collection do
post :check_can_merge


+ 15
- 0
db/migrate/20220728022339_create_mark_files.rb View File

@@ -0,0 +1,15 @@
class CreateMarkFiles < ActiveRecord::Migration[5.2]
def change
create_table :mark_files do |t|
t.references :pull_request
t.integer :user_id
t.string :file_path_sha
t.string :file_path
t.boolean :mark_as_read, default: false
t.boolean :updated_after_read, default: false
t.timestamps
end

add_index :mark_files, :file_path_sha
end
end

Loading…
Cancel
Save