diff --git a/app/controllers/mark_files_controller.rb b/app/controllers/mark_files_controller.rb new file mode 100644 index 000000000..88856c35a --- /dev/null +++ b/app/controllers/mark_files_controller.rb @@ -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 \ No newline at end of file diff --git a/app/models/mark_file.rb b/app/models/mark_file.rb new file mode 100644 index 000000000..c6c834623 --- /dev/null +++ b/app/models/mark_file.rb @@ -0,0 +1,5 @@ +class MarkFile < ApplicationRecord + belongs_to :pull_request + + +end diff --git a/app/models/pull_request.rb b/app/models/pull_request.rb index 4ced61aa4..270e7dc76 100644 --- a/app/models/pull_request.rb +++ b/app/models/pull_request.rb @@ -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)} diff --git a/app/views/mark_files/index.json.jbuilder b/app/views/mark_files/index.json.jbuilder new file mode 100644 index 000000000..18bf90b5d --- /dev/null +++ b/app/views/mark_files/index.json.jbuilder @@ -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 diff --git a/config/routes.rb b/config/routes.rb index f32f1050f..5f8f9f74d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/db/migrate/20220728022339_create_mark_files.rb b/db/migrate/20220728022339_create_mark_files.rb new file mode 100644 index 000000000..45f4b1cb3 --- /dev/null +++ b/db/migrate/20220728022339_create_mark_files.rb @@ -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