change pull-request
This commit is contained in:
parent
4dcdea33aa
commit
4212d46b3f
|
@ -2,15 +2,15 @@ class PullRequestsController < ApplicationController
|
|||
before_action :require_login, except: [:index, :show]
|
||||
before_action :find_project_with_id
|
||||
before_action :set_repository
|
||||
before_action :find_pull_request, except: [:index, :new, :create, :check_can_merge]
|
||||
before_action :get_relatived, only: [:new, :edit]
|
||||
before_action :find_pull_request, except: [:index, :new, :create, :check_can_merge,:get_branches,:create_merge_infos]
|
||||
# before_action :get_relatived, only: [:edit]
|
||||
include TagChosenHelper
|
||||
include ApplicationHelper
|
||||
|
||||
|
||||
def index
|
||||
# @issues = Gitea::PullRequest::ListService.new(@user,@repository.try(:identifier)).call #通过gitea获取
|
||||
issues = @project.issues.issue_pull_request.issue_index_includes.includes(:pull_request)
|
||||
issues = @project.issues.issue_pull_request.issue_index_includes.includes(pull_request: :user)
|
||||
issues = issues.where(is_private: false) unless current_user.present? && (current_user.admin? || @project.member?(current_user))
|
||||
@all_issues_size = issues.size
|
||||
@open_issues_size = issues.joins(:pull_request).where(pull_requests: {status: 0}).size
|
||||
|
@ -24,15 +24,28 @@ class PullRequestsController < ApplicationController
|
|||
end
|
||||
|
||||
def new
|
||||
@all_branches = []
|
||||
get_all_branches = Gitea::Repository::Branches::ListService.new(@user, @repository.try(:identifier)).call
|
||||
if get_all_branches && get_all_branches.size > 0
|
||||
get_all_branches.each do |b|
|
||||
@all_branches.push(b["name"])
|
||||
end
|
||||
@all_branches = PullRequests::BranchesService.new(@user, @project).call
|
||||
@is_fork = @project.forked_from_project_id.present?
|
||||
@projects_names = [{
|
||||
project_name: "#{@user.try(:show_real_name)}/#{@repository.try(:identifier)}",
|
||||
project_id: @project.id
|
||||
}]
|
||||
@merge_projects = @projects_names
|
||||
fork_project = @project.fork_project if @is_fork
|
||||
if fork_project.present?
|
||||
@merge_projects.push({
|
||||
project_name: "#{fork_project.owner.try(:show_real_name)}/#{fork_project.repository.try(:identifier)}",
|
||||
project_id: fork_project.id
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
def get_branches
|
||||
branch_result = PullRequests::BranchesService.new(@user, @project).call
|
||||
render json: branch_result
|
||||
# return json: branch_result
|
||||
end
|
||||
|
||||
def create
|
||||
if params[:title].nil?
|
||||
normal_status(-1, "名称不能为空")
|
||||
|
@ -81,6 +94,8 @@ class PullRequestsController < ApplicationController
|
|||
end
|
||||
|
||||
def edit
|
||||
@fork_project_user = @project&.fork_project&.owner.try(:show_real_name)
|
||||
@fork_project_identifier = @project&.fork_project&.repository.try(:identifier)
|
||||
|
||||
end
|
||||
|
||||
|
@ -102,7 +117,7 @@ class PullRequestsController < ApplicationController
|
|||
end
|
||||
|
||||
if @issue.update_attributes(@issue_params)
|
||||
if @pull_request.update_attributes(@local_params)
|
||||
if @pull_request.update_attributes(@local_params.compact)
|
||||
gitea_request = Gitea::PullRequest::UpdateService.new(current_user, @repository.try(:identifier), @requests_params, @pull_request.try(:gpid)).call
|
||||
if gitea_request
|
||||
if params[:issue_tag_ids].present?
|
||||
|
@ -143,6 +158,10 @@ class PullRequestsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def create_merge_infos
|
||||
get_relatived
|
||||
end
|
||||
|
||||
def show
|
||||
@user_permission = current_user.present? && current_user.logged? && (@issue.assigned_to_id == current_user.id || current_user.admin? )
|
||||
@issue_user = @issue.user
|
||||
|
@ -237,7 +256,9 @@ class PullRequestsController < ApplicationController
|
|||
assignee: current_user.try(:login),
|
||||
assignees: ["#{params[:assigned_login].to_s}"],
|
||||
labels: params[:issue_tag_ids],
|
||||
due_date: Time.now
|
||||
due_date: Time.now,
|
||||
fork_project_id: params[:fork_project_id],
|
||||
is_original: params[:is_original]
|
||||
})
|
||||
@issue_params = {
|
||||
author_id: current_user.id,
|
||||
|
|
|
@ -158,4 +158,8 @@ class Project < ApplicationRecord
|
|||
member&.roles&.last&.name || permission
|
||||
end
|
||||
|
||||
def fork_project
|
||||
Project.find_by(id: self.forked_from_project_id)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
class PullRequests::BranchesService < ApplicationService
|
||||
|
||||
attr_reader :user, :project
|
||||
|
||||
def initialize(user, project)
|
||||
@user = user
|
||||
@project = project
|
||||
end
|
||||
|
||||
def call
|
||||
all_branches = []
|
||||
user_name = user.try(:show_real_name)
|
||||
identifier = project.repository.try(:identifier)
|
||||
get_all_branches = Gitea::Repository::Branches::ListService.new(user, identifier).call
|
||||
all_branches = branch_lists(user_name,user.try(:login), identifier, get_all_branches) if get_all_branches && get_all_branches.size > 0
|
||||
return all_branches
|
||||
end
|
||||
|
||||
def branch_lists(user_name,user_login, identifier, branches)
|
||||
branches_array = []
|
||||
branches.each do |b|
|
||||
branch_params = {
|
||||
user_name: user_name,
|
||||
user_login: user_login,
|
||||
identifier: identifier,
|
||||
name: b["name"],
|
||||
can_merge: b["user_can_merge"],
|
||||
}
|
||||
branches_array.push(branch_params)
|
||||
end
|
||||
return branches_array
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,2 @@
|
|||
json.partial! "commons/success"
|
||||
json.partial! "pull_requests/merge_item"
|
|
@ -1,5 +1,9 @@
|
|||
json.partial! "commons/success"
|
||||
json.partial! "pull_requests/merge_item"
|
||||
json.extract! @pull_request, :id, :title, :body, :milestone,:head,:base
|
||||
# json.partial! "pull_requests/merge_item"
|
||||
json.fork_project_user @fork_project_user
|
||||
json.fork_project_identifier @fork_project_identifier
|
||||
json.project_author @project.owner.try(:show_real_name)
|
||||
json.project_name @project.repository.try(:identifier)
|
||||
json.extract! @pull_request, :id, :title, :body, :milestone,:head,:base,:is_original
|
||||
json.extract! @issue, :assigned_to_id, :fixed_version_id, :priority_id
|
||||
json.issue_tag_ids @issue.issue_tags_value.split(",")
|
||||
|
|
|
@ -16,6 +16,9 @@ json.issues do
|
|||
json.pull_request_head pr.head
|
||||
json.pull_request_base pr.base
|
||||
json.pull_request_staus pr.status == 1 ? "merged" : (pr.status == 2 ? "closed" : "open")
|
||||
json.is_original pr.is_original
|
||||
json.fork_project_id pr.fork_project_id
|
||||
json.pull_request_user pr.user.try(:show_real_name)
|
||||
|
||||
json.id issue.id
|
||||
json.name issue.subject
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
json.partial! "commons/success"
|
||||
json.partial! "pull_requests/merge_item"
|
||||
json.project_id @project.id
|
||||
json.branches @all_branches
|
||||
json.is_fork @is_fork
|
||||
json.projects_names @projects_names
|
||||
json.merge_projects @merge_projects
|
||||
# json.merge_branches @merge_branches
|
|
@ -1,9 +1,11 @@
|
|||
json.partial! "commons/success"
|
||||
json.project_name @project.name
|
||||
json.pr_time time_from_now(@pull_request.updated_at)
|
||||
|
||||
json.pull_request do
|
||||
json.extract! @pull_request, :id,:base, :head, :status
|
||||
json.extract! @pull_request, :id,:base, :head, :status,:fork_project_id, :is_original
|
||||
json.pull_request_staus @pull_request.status == 1 ? "merged" : (@pull_request.status == 2 ? "closed" : "open")
|
||||
json.pull_request_user @pull_request.user.try(:show_real_name)
|
||||
end
|
||||
|
||||
json.issue do
|
||||
|
|
|
@ -69,6 +69,8 @@ Rails.application.routes.draw do
|
|||
end
|
||||
collection do
|
||||
post :check_can_merge
|
||||
get :create_merge_infos
|
||||
get :get_branches
|
||||
end
|
||||
end
|
||||
resources :version_releases, only: [:index,:new, :create, :edit, :update, :destroy]
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
class AddOriginProjectIdToPullRequest < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :pull_requests, :fork_project_id, :integer
|
||||
add_column :pull_requests, :is_original, :boolean, default: false
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue