Merge branch 'dev_trustie' of http://gitea.trustie.net/jasder/forgeplus into dev_trustie

This commit is contained in:
sylor_huang@126.com 2020-05-22 14:51:39 +08:00
commit 6dcd325031
6 changed files with 30 additions and 22 deletions

View File

@ -461,31 +461,21 @@ http://localhost:3000/api/projects/migrate | jq
"name": "ni项目" "name": "ni项目"
} }
``` ```
---
#### 手动同步镜像 #### 手动同步镜像
``` ```
POST api/repositories/:id/sync_mirror POST api/repositories/:id/sync_mirror
``` ```
*示例* *示例*
``` ```
curl -X POST \ curl -X POST http://localhost:3000/api/repositories/1244/sync_mirror | jq
-d "user_id=36401" \
http://localhost:3000/api/repositories/1244/sync_mirror | jq
``` ```
*请求参数说明:* *请求参数说明:*
|参数名|必选|类型|说明| |参数名|必选|类型|说明|
|-|-|-|-| |-|-|-|-|
|user_id |是|int |用户id或者组织id | |id |是|int |仓库id |
|name |是|string |项目名称 |
|clone_addr |是|string |镜像项目clone地址 |
|description |否|string |项目描述 |
|repository_name |是|string |仓库名称, 只含有数字、字母、下划线不能以下划线开头和结尾,且唯一 |
|project_category_id|是|int |项目类别id |
|project_language_id|是|int |项目语言id |
|is_mirror |否|boolean|是否设置为镜像, true false默认为否 |
|auth_username |否|string|镜像源仓库的登录用户名 |
|auth_password |否|string|镜像源仓库的登录秘密 |
|private |否|boolean|项目是否私有, true为私有false: 非私有,默认为公开 |
*返回参数说明:* *返回参数说明:*

View File

@ -208,13 +208,14 @@ class IssuesController < ApplicationController
if params[:status_id].to_i == 5 if params[:status_id].to_i == 5
@issue.issue_times.update_all(end_time: Time.now) @issue.issue_times.update_all(end_time: Time.now)
@issue.update_closed_issues_count_in_project!
end end
if @issue.issue_type.to_s == "2" if @issue.issue_type.to_s == "2"
#表示修改token值 #表示修改token值
if @issue.saved_change_to_attribute("token") if @issue.saved_change_to_attribute("token")
last_token = @issue.token_was last_token = @issue.token_was
change_token = last_token - @issue.token change_token = last_token - @issue.token
change_type = change_token > 0 ? "addToken" : "minusToken" change_type = change_token > 0 ? "addToken" : "minusToken"
change_params = { change_params = {
change_type: change_type, change_type: change_type,
@ -222,7 +223,7 @@ class IssuesController < ApplicationController
}.merge(tokens_params(@proeject)) }.merge(tokens_params(@proeject))
ChangeTokenJob.perform_later(change_params) ChangeTokenJob.perform_later(change_params)
end end
end end
@issue.create_journal_detail(change_files, issue_files, issue_file_ids, current_user&.id) @issue.create_journal_detail(change_files, issue_files, issue_file_ids, current_user&.id)
@ -433,6 +434,6 @@ class IssuesController < ApplicationController
reponame: project.try(:identifer), reponame: project.try(:identifer),
username: current_user.try(:login) username: current_user.try(:login)
} }
end end
end end

View File

@ -25,6 +25,7 @@ class Issue < ApplicationRecord
scope :issue_index_includes, ->{includes(:user,:tracker, :priority, :version, :issue_status, :journals, :issue_times)} scope :issue_index_includes, ->{includes(:user,:tracker, :priority, :version, :issue_status, :journals, :issue_times)}
after_update :change_versions_count after_update :change_versions_count
after_destroy :update_closed_issues_count_in_project!
def get_assign_user def get_assign_user
@ -102,4 +103,8 @@ class Issue < ApplicationRecord
end end
end end
def update_closed_issues_count_in_project!
self.project.decrement!(:closed_issues_count)
end
end end

View File

@ -118,9 +118,6 @@ class Project < ApplicationRecord
members.select(:id).size members.select(:id).size
end end
def issues_count
issues.select(:id).size
end
def can_visited? def can_visited?
is_public? || User.current.admin? || member?(User.current) is_public? || User.current.admin? || member?(User.current)
@ -138,4 +135,8 @@ class Project < ApplicationRecord
self.pull_requests.select(:user_id).pluck(:user_id).uniq.size self.pull_requests.select(:user_id).pluck(:user_id).uniq.size
end end
def open_issues_count
issues_count - closed_issues_count
end
end end

View File

@ -26,5 +26,5 @@ json.array! @entries do |entry|
json.content entry['content'] json.content entry['content']
json.target entry['target'] json.target entry['target']
end end
json.commit entry['commit'] json.commit entry['latest_commit']
end end

View File

@ -0,0 +1,11 @@
class AddClosedIssuesCountToProjects < ActiveRecord::Migration[5.2]
def change
add_column :projects, :closed_issues_count, :integer, default: 0
projects = Project.joins(:issues).where('status_id = 5').select("projects.id, count('issues.id') as closed_issues_count").group("projects.id")
projects.each do |pro|
project = Project.find pro.id
project.update_column(:closed_issues_count, pro.closed_issues_count) if project.closed_issues_count == 0
end
end
end