From 1fa44535bbd51c0f4fef3dd686b261d7cf83f815 Mon Sep 17 00:00:00 2001 From: jasder Date: Tue, 12 Oct 2021 18:36:14 +0800 Subject: [PATCH 01/11] =?UTF-8?q?FIX=20=E6=9B=B4=E6=96=B0pulls=E7=9A=84api?= =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 31 + app/docs/slate/source/includes/_pulls.md | 501 ++++++++++++ public/docs/api.html | 961 ++++++++++++++++++++++- 3 files changed, 1492 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5250040e..ecb743b91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,35 @@ # Changelog +## [v3.2.0](https://forgeplus.trustie.net/projects/jasder/forgeplus/releases) - 2021-06-09 + +### ENHANCEMENTS + * ADD 集成邮件和平台站内信等通知系统 + * Fix 代码库二级页面-优化文件子目录浏览功能(#50388) + * Fix 代码库二级页面-优化commit提交详情页页面排版及数据显示(#50372) + * Fix 代码库二级页面-优化commit提交信息列表页加载方式和数据排序功能(#50348) + * Fix 代码库二级页面-优化创建发行版功能(#50346) + * Fix 代码库二级页面-优化标签列表页功能(#50344) + * Fix 代码库二级页面-优化发行版本列表页功能(#50345) + * Fix 代码库二级页面-优化分支列表页功能(#50343) + * Fix 其他问题优化(#51581) (#51343) (#51108) + +--- + +### BUGFIXES + * Fix 发行版—标签跳转链接错误(#51666) + * Fix 文件预览报错(#51660) + * Fix 标签创建时间显示错误(#51658) + * Fix 分支列表中头像显示问题(#51656) + * Fix 文本信息过长(#51630) (#51626) + * Fix 版本库中附件下载400(#51625) + * Fix loading页面优化(#51588) + * Fix 提交详情页面优化(#51577) + * Fix 修复易修复制功能(#51569) + * Fix 修复新建发行版用户信息显示错误的问题(#51665) + * Fix 修复查看文件详细信息报错的问题(#51561) + * Fix 修复提交记录中时间显示格式问题(#51526) + * Fix 组织下项目更加更新时间倒序排序(#50833) + + ## [v3.1.0](https://forgeplus.trustie.net/projects/jasder/forgeplus/releases) - 2021-06-09 * ENHANCEMENTS diff --git a/app/docs/slate/source/includes/_pulls.md b/app/docs/slate/source/includes/_pulls.md index 1df50f6bf..b9ad3b0ba 100644 --- a/app/docs/slate/source/includes/_pulls.md +++ b/app/docs/slate/source/includes/_pulls.md @@ -1 +1,502 @@ # Pulls + + +## Get a pull request +获取合并请求详情接口 + +> 示例: + +```shell +curl -X GET http://localhost:3000/api/Jasder/gitlink/pulls/88.json +``` + +```javascript +await octokit.request('GET /api/Jasder/gitlink/pulls/88.json') +``` + +### HTTP 请求 +`GET /api/:owner/:repo/pulls/:id.json` + +### 请求参数: +参数 | 必选 | 默认 | 类型 | 字段说明 +--------- | ------- | ------- | -------- | ---------- +|owner |是| |string |用户登录名 | +|repo |是| |string |项目标识identifier | +|id |是| | integer | pull id值 | + + + + +> 返回的JSON示例: + +```json +{ + "status": 0, + "message": "响应成功", + "project_name": "Gitlink", + "identifier": "forgeplus", + "project_identifier": "forgeplus", + "pr_time": "52分钟前", + "commits_count": 229, + "files_count": 328, + "comments_count": 0, + "comments_total_count": 0, + "pull_request": { + "id": 1189, + "base": "master", + "head": "develop", + "status": 0, + "fork_project_id": null, + "is_original": false, + "pull_request_staus": "open", + "fork_project_user": null, + "create_user": "jasder", + "mergeable": true, + "state": "open" + }, + "issue": { + "id": 51888, + "subject": "FIx release v3.2.0", + "description": null, + "is_private": false, + "branch_name": null, + "project_author_name": "Gitlink", + "closed_on": "", + "created_at": "2021-10-12 15:51", + "assign_user_name": "victor", + "assign_user_login": "moshenglv", + "author_name": "段甲生", + "author_login": "jasder", + "author_picture": "images/avatars/User/36480?t=1615520120", + "issue_status": "新增", + "priority": "正常", + "version": null, + "issue_tags": null + }, + "conflict_files": [] +} +``` + +## 获取pull request文件列表 +获取pull request文件列表 + +> 示例: + +```shell +curl -X GET \ +http://localhost:3000/api/Jason/gitlink/pulls/1/files.json +``` + +```javascript +await octokit.request('GET /api/jasder/gitlink/pulls/1/files.json') +``` + +### HTTP 请求 +`GET /api/:owner/:repo/pulls/:id/files.json` + +### 请求参数: +|参数名|必选|类型|说明| +|-|-|-|-| +|owner |是|string |用户登录名 | +|repo |是|string |project's identifier | +|id |是|int |pull request's id | + + +### 返回字段说明: +参数 | 类型 | 字段说明 +--------- | ----------- | ----------- +|-|-|-| +|files_count |int|文件更改的总数量| +|total_addition |int|添加代码总行数| +|total_deletion |int|删除代码总行数| +|files |array|| +|-- sha |string|commit's sha value| +|-- name |string|当前文件名| +|-- old_name |string| 修改之前的文件名称,与name相同的话,说明文件名未更改| +|-- addition |int|文件添加的行数| +|-- deletion |int|文件删除的行数| +|-- type |int|文件类型, 1: 表示该文件只添加了内容,2: 表示该文件内容有修改, 3: 表示文件被删除或者改文件只删除了内容| +|-- isCreated |boolean|当前文件是否为新增文件, true: 是, false: 否| +|-- isDeleted |boolean|当前文件是否被删除, true: 是,false: 否| +|-- isBin |boolean|当前文件是否为二进制文件,true: 是,false: 否| +|-- isLFSFile |boolean|当前文件是否为LFS文件,true: 是,false: 否| +|-- isRenamed |boolean|当前文件是否被重命名,true: 是,false: 否| +|-- sections |array|| +|---- fileName |string|文件名称| +|---- lines |array|| +|------ leftIdx |string|文件变动之前所在行数| +|------ rightIdx |string|文件更改后所在行数| +|------ type |string|文件变更类型,1: 新增,2: 修改, 3: 删除, 4: diff统计信息| +|------ content |string|文件变更的内容| +|------ sectionInfo |object|| +|-------- path |string|文件相对仓库的路径| +|-------- lastLeftIdx |int|| +|-------- lastRightIdx |int|| +|-------- leftHunkSize |int|文件变更之前的行数| +|-------- rightHunkSize |int|文件变更之后的行数(及当前页面编辑器显示的总行数)| +|-------- leftIdx |int|文件变更之前所在行数| +|-------- rightIdx |int|文件变更之后所在行数(即:页面编辑器开始显示的行数)| + + + +> 返回的JSON示例: + +```json +{ + "files_count": 6, + "total_addition": 447, + "total_deletion": 0, + "files": [ + { + "sha": "xefenisnii", + "name": "文件.txt", + "old_name": "文件.txt", + "index": 6, + "addition": 2, + "deletion": 0, + "type": 1, + "isCreated": true, + "isDeleted": false, + "isBin": false, + "isLFSFile": false, + "isRenamed": false, + "isSubmodule": false, + "sections": [ + { + "fileName": "文件.txt", + "name": "", + "lines": [ + { + "leftIdx": 0, + "rightIdx": 0, + "type": 4, + "content": "@@ -0,0 +1,2 @@", + "sectionInfo": { + "path": null, + "lastLeftIdx": null, + "lastRightIdx": null, + "leftIdx": 0, + "rightIdx": 0, + "leftHunkSize": null, + "rightHunkSize": null + } + }, + { + "leftIdx": 0, + "rightIdx": 1, + "type": 2, + "content": "+用例图一致性更新", + "sectionInfo": null + }, + { + "leftIdx": 0, + "rightIdx": 2, + "type": 2, + "content": "+工程文件直接上传会有文件缺失,现在压缩后上传", + "sectionInfo": null + } + ] + } + ] + } + ] +} +``` + + +## 获取pull request的commits列表 +获取pull request的commits列表 + +> 示例: + +```shell +curl -X GET http://localhost:3000/api/jasder/jasder_test/pulls/1/commits.json +``` + +```javascript +await octokit.request('GET /api/jasder/jasder_test/pulls/1/commits.json') +``` + +### HTTP 请求 +`GET /api/:owner/:repo/pulls/:id/commits.json` + +### 请求参数: +|参数名|必选|类型|说明| +|-|-|-|-| +|owner |是|string |用户登录名 | +|repo |是|string |project's identifier | +|id |是|int |pull request's id | + + +### 返回字段说明: +参数 | 类型 | 字段说明 +--------- | ----------- | ----------- +|commits_count |int|commits总数量| +|commits |array|| +|-- author |object|项目作者| +|---- login |string|用户login| +|---- name |string|用户姓名| +|---- image_url |string|用户头像| +|-- committer |object|commit提交用户| +|---- login |string|用户login| +|---- name |string|用户姓名| +|---- image_url |string|用户头像| +|-- timestamp |int|commit的unix时间戳| +|-- time_from_now|string|commit’s 提交时间距当前时间的时间值| +|-- message |string|commit说明信息| +|-- sha |string|commit’s sha值| + + +> 返回的JSON示例: + +```json +{ + "commits_count": 1, + "commits": [ + { + "author": { + "id": 36480, + "login": "jasder", + "name": "段甲生", + "image_url": "avatars/User/b" + }, + "committer": { + "id": 36480, + "login": "jasder", + "name": "段甲生", + "image_url": "avatars/User/b" + }, + "timestamp": 1604382982, + "time_from_now": "3小时前", + "message": "add some file\n* Add the tag list page to the release page\n* Apply suggestions from code review\n* Add the tags list view\n* Add the delete tag way on ui\n* Not delete tag and clear message when delete a release\n", + "sha": "8f5faee0d3b3be1b8063e84da0c79dd75327b968" + } + ] +} +``` + +## Compare two commits +Compare two commits + +> 示例: + +```shell +curl -X GET \ +http://localhost:3000/api/Jason/test-txt/compare/master...develop + +curl -X GET \ +http://localhost:3000/api/Jason/test-txt/compare/master...Jason/test-txt:develop +``` + +```javascript +await octokit.request('GET /api/Jason/test-txt/compare/master...Jason/test-txt:develop') +``` + +### HTTP 请求 +`GET /api/:owner/:repo/compare/{base}...{head}.json` + +### 请求参数: +|参数名|必选|类型|说明| +|-|-|-|-| +|owner |是|string |用户登录名 | +|repo |是|string |project's identifier | +|base |是|string |pull request's id | +|head |是|string |pull request's id | + + +### 返回字段说明: +参数 | 类型 | 字段说明 +--------- | ----------- | ----------- +|-|-|-| +|commits_count |int|commits总数量| +|commits |array|| +|-- author |object|项目作者| +|---- login |string|用户login| +|---- name |string|用户姓名| +|---- image_url |string|用户头像| +|-- committer |object|commit提交用户| +|---- login |string|用户login| +|---- name |string|用户姓名| +|---- image_url |string|用户头像| +|-- timestamp |int|commit的unix时间戳| +|-- time_from_now|string|commit’s 提交时间距当前时间的时间值| +|-- message |string|commit说明信息| +|-- sha |string|commit’s sha值| +|diff |object|| +|-- files_count |int|文件更改的总数量| +|-- total_addition |int|添加代码总行数| +|-- total_deletion |int|删除代码总行数| +|-- files |Array|| +|-- sha |string|commit's sha | +|-- name |string|当前文件名| +|-- old_name |string| 修改之前的文件名称,与name相同的话,说明文件名未更改| +|-- addition |int|文件添加的行数| +|-- deletion |int|文件删除的行数| +|-- type |int|文件类型, 1: 表示该文件只添加了内容,2: 表示该文件内容有修改, 3: 表示文件被删除或者改文件只删除了内容| +|-- isCreated |boolean|当前文件是否为新增文件, true: 是, false: 否| +|-- isDeleted |boolean|当前文件是否被删除, true: 是,false: 否| +|-- isBin |boolean|当前文件是否为二进制文件,true: 是,false: 否| +|-- isLFSFile |boolean|当前文件是否为LFS文件,true: 是,false: 否| +|-- isRenamed |boolean|当前文件是否被重命名,true: 是,false: 否| +|-- sections |array|| +|---- fileName |string|文件名称| +|---- lines |array|| +|------ leftIdx |string|文件变动之前所在行数| +|------ rightIdx |string|文件更改后所在行数| +|------ type |string|文件变更类型,1: 内容未改动,2: 添加, 3: 删除, 4: diff统计信息| +|------ content |string|文件变更的内容| +|------ sectionInfo |object|| +|-------- path |string|文件相对仓库的路径| +|-------- lastLeftIdx |int|| +|-------- lastRightIdx |int|| +|-------- leftHunkSize |int|文件变更之前的行数| +|-------- rightHunkSize |int|文件变更之后的行数(及当前页面编辑器显示的总行数)| +|-------- leftIdx |int|文件变更之前所在行数| +|-------- rightIdx |int|文件变更之后所在行数| + +> 返回的JSON示例: + +```json +{ + "commits_count": 1, + "commits": [ + { + "author": { + "id": 36480, + "login": "jasder", + "name": "段甲生", + "image_url": "avatars/User/b" + }, + "committer": { + "id": 36480, + "login": "jasder", + "name": "段甲生", + "image_url": "avatars/User/b" + }, + "timestamp": 1604382982, + "time_from_now": "4小时前", + "message": "add some file\n* Add the tag list page to the release page\n* Apply suggestions from code review\n* Add the tags list view\n* Add the delete tag way on ui\n* Not delete tag and clear message when delete a release\n", + "sha": "8f5faee0d3b3be1b8063e84da0c79dd75327b968" + } + ], + "diff": { + "files_count": 6, + "total_addition": 447, + "total_deletion": 0, + "files": [ + { + "name": "build.go", + "old_name": "build.go", + "index": 1, + "addition": 33, + "deletion": 0, + "type": 1, + "isCreated": true, + "isDeleted": false, + "isBin": false, + "isLFSFile": false, + "isRenamed": false, + "isSubmodule": false, + "sections": [ + { + "fileName": "build.go", + "name": "", + "lines": [ + { + "leftIdx": 0, + "rightIdx": 0, + "type": 4, + "content": "@@ -0,0 +1,33 @@", + "sectionInfo": { + "path": "build.go", + "lastLeftIdx": 0, + "lastRightIdx": 0, + "leftIdx": 0, + "rightIdx": 1, + "leftHunkSize": 0, + "rightHunkSize": 33 + } + }, + { + "leftIdx": 0, + "rightIdx": 1, + "type": 2, + "content": "+// Copyright 2020 The Gitea Authors. All rights reserved.", + "sectionInfo": null + } + ] + } + ] + } + ] + } +``` + + +## List pull requests +获取合并请求列表 + +> 示例: + +```shell +curl -X GET http://localhost:3000/api/Jasder/gitlink/pulls.json +``` + +```javascript +await octokit.request('GET /api/Jasder/gitlink/pulls.json') +``` + +### HTTP 请求 +`GET /api/:owner/:repo/pulls.json` + +### 请求参数: +参数 | 必选 | 默认 | 类型 | 字段说明 +--------- | ------- | ------- | -------- | ---------- +|owner |是| |string |用户登录名 | +|repo |是| |string |项目标识identifier | + + + + +> 返回的JSON示例: + +```json +{ + "status": 0, + "message": "响应成功", + "open_count": 4, + "close_count": 51, + "merged_issues_size": 123, + "search_count": 4, + "limit": null, + "user_admin_or_member": true, + "user_admin_or_developer": true, + "project_name": "Gitlink", + "project_author_name": "Gitlink", + "issues": [ + { + "pull_request_id": 1189, + "pull_request_status": 0, + "pull_request_head": "develop", + "pull_request_base": "master", + "pull_request_staus": "open", + "is_original": false, + "fork_project_id": null, + "fork_project_identifier": null, + "fork_project_user": null, + "id": 51888, + "name": "FIx release v3.2.0", + "pr_time": "59分钟前", + "assign_user_name": "victor", + "assign_user_login": "moshenglv", + "author_name": "段甲生", + "author_login": "jasder", + "avatar_url": "images/avatars/User/36480?t=1615520120", + "priority": "正常", + "version": null, + "journals_count": 0, + "issue_tags": null + } + ] +} +``` \ No newline at end of file diff --git a/public/docs/api.html b/public/docs/api.html index ef03d978f..8368e8fae 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -533,6 +533,23 @@
  • Pulls +
  • Issues @@ -8909,7 +8926,949 @@ http://localhost:3000/api/yystopf/ceshi/webhooks/3/test.json -

    Pulls

    Issues

    Organizations

    Teams

    Errors

    +

    Pulls

    Get a pull request

    +

    获取合并请求详情接口

    + +
    +

    示例:

    +
    +
    curl -X GET http://localhost:3000/api/Jasder/gitlink/pulls/88.json
    +
    await octokit.request('GET /api/Jasder/gitlink/pulls/88.json')
    +

    HTTP 请求

    +

    GET /api/:owner/:repo/pulls/:id.json

    +

    请求参数:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    idintegerpull id值
    + +
    +

    返回的JSON示例:

    +
    +
    {
    +    "status": 0,
    +    "message": "响应成功",
    +    "project_name": "Gitlink",
    +    "identifier": "forgeplus",
    +    "project_identifier": "forgeplus",
    +    "pr_time": "52分钟前",
    +    "commits_count": 229,
    +    "files_count": 328,
    +    "comments_count": 0,
    +    "comments_total_count": 0,
    +    "pull_request": {
    +        "id": 1189,
    +        "base": "master",
    +        "head": "develop",
    +        "status": 0,
    +        "fork_project_id": null,
    +        "is_original": false,
    +        "pull_request_staus": "open",
    +        "fork_project_user": null,
    +        "create_user": "jasder",
    +        "mergeable": true,
    +        "state": "open"
    +    },
    +    "issue": {
    +        "id": 51888,
    +        "subject": "FIx release v3.2.0",
    +        "description": null,
    +        "is_private": false,
    +        "branch_name": null,
    +        "project_author_name": "Gitlink",
    +        "closed_on": "",
    +        "created_at": "2021-10-12 15:51",
    +        "assign_user_name": "victor",
    +        "assign_user_login": "moshenglv",
    +        "author_name": "段甲生",
    +        "author_login": "jasder",
    +        "author_picture": "images/avatars/User/36480?t=1615520120",
    +        "issue_status": "新增",
    +        "priority": "正常",
    +        "version": null,
    +        "issue_tags": null
    +    },
    +    "conflict_files": []
    +}
    +

    获取pull request文件列表

    +

    获取pull request文件列表

    + +
    +

    示例:

    +
    +
    curl -X GET \
    +http://localhost:3000/api/Jason/gitlink/pulls/1/files.json 
    +
    await octokit.request('GET /api/jasder/gitlink/pulls/1/files.json')
    +

    HTTP 请求

    +

    GET /api/:owner/:repo/pulls/:id/files.json

    +

    请求参数:

    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数名必选类型说明
    ownerstring用户登录名
    repostringproject's identifier
    idintpull request's id
    +

    返回字段说明:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数类型字段说明
    ---
    files_countint文件更改的总数量
    total_additionint添加代码总行数
    total_deletionint删除代码总行数
    filesarray
    -- shastringcommit's sha value
    -- namestring当前文件名
    -- old_namestring修改之前的文件名称,与name相同的话,说明文件名未更改
    -- additionint文件添加的行数
    -- deletionint文件删除的行数
    -- typeint文件类型, 1: 表示该文件只添加了内容,2: 表示该文件内容有修改, 3: 表示文件被删除或者改文件只删除了内容
    -- isCreatedboolean当前文件是否为新增文件, true: 是, false: 否
    -- isDeletedboolean当前文件是否被删除, true: 是,false: 否
    -- isBinboolean当前文件是否为二进制文件,true: 是,false: 否
    -- isLFSFileboolean当前文件是否为LFS文件,true: 是,false: 否
    -- isRenamedboolean当前文件是否被重命名,true: 是,false: 否
    -- sectionsarray
    ---- fileNamestring文件名称
    ---- linesarray
    ------ leftIdxstring文件变动之前所在行数
    ------ rightIdxstring文件更改后所在行数
    ------ typestring文件变更类型,1: 新增,2: 修改, 3: 删除, 4: diff统计信息
    ------ contentstring文件变更的内容
    ------ sectionInfoobject
    -------- pathstring文件相对仓库的路径
    -------- lastLeftIdxint
    -------- lastRightIdxint
    -------- leftHunkSizeint文件变更之前的行数
    -------- rightHunkSizeint文件变更之后的行数(及当前页面编辑器显示的总行数)
    -------- leftIdxint文件变更之前所在行数
    -------- rightIdxint文件变更之后所在行数(即:页面编辑器开始显示的行数)
    + +
    +

    返回的JSON示例:

    +
    +
    {
    +  "files_count": 6,
    +  "total_addition": 447,
    +  "total_deletion": 0,
    +  "files": [
    +    {
    +      "sha": "xefenisnii",
    +      "name": "文件.txt",
    +      "old_name": "文件.txt",
    +      "index": 6,
    +      "addition": 2,
    +      "deletion": 0,
    +      "type": 1,
    +      "isCreated": true,
    +      "isDeleted": false,
    +      "isBin": false,
    +      "isLFSFile": false,
    +      "isRenamed": false,
    +      "isSubmodule": false,
    +      "sections": [
    +        {
    +          "fileName": "文件.txt",
    +          "name": "",
    +          "lines": [
    +            {
    +              "leftIdx": 0,
    +              "rightIdx": 0,
    +              "type": 4,
    +              "content": "@@ -0,0 +1,2 @@",
    +              "sectionInfo": {
    +                "path": null,
    +                "lastLeftIdx": null,
    +                "lastRightIdx": null,
    +                "leftIdx": 0,
    +                "rightIdx": 0,
    +                "leftHunkSize": null,
    +                "rightHunkSize": null
    +              }
    +            },
    +            {
    +              "leftIdx": 0,
    +              "rightIdx": 1,
    +              "type": 2,
    +              "content": "+用例图一致性更新",
    +              "sectionInfo": null
    +            },
    +            {
    +              "leftIdx": 0,
    +              "rightIdx": 2,
    +              "type": 2,
    +              "content": "+工程文件直接上传会有文件缺失,现在压缩后上传",
    +              "sectionInfo": null
    +            }
    +          ]
    +        }
    +      ]
    +    }
    +  ]
    +}
    +

    获取pull request的commits列表

    +

    获取pull request的commits列表

    + +
    +

    示例:

    +
    +
    curl -X GET http://localhost:3000/api/jasder/jasder_test/pulls/1/commits.json
    +
    await octokit.request('GET /api/jasder/jasder_test/pulls/1/commits.json')
    +

    HTTP 请求

    +

    GET /api/:owner/:repo/pulls/:id/commits.json

    +

    请求参数:

    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数名必选类型说明
    ownerstring用户登录名
    repostringproject's identifier
    idintpull request's id
    +

    返回字段说明:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数类型字段说明
    commits_countintcommits总数量
    commitsarray
    -- authorobject项目作者
    ---- loginstring用户login
    ---- namestring用户姓名
    ---- image_urlstring用户头像
    -- committerobjectcommit提交用户
    ---- loginstring用户login
    ---- namestring用户姓名
    ---- image_urlstring用户头像
    -- timestampintcommit的unix时间戳
    -- time_from_nowstringcommit’s 提交时间距当前时间的时间值
    -- messagestringcommit说明信息
    -- shastringcommit’s sha值
    + +
    +

    返回的JSON示例:

    +
    +
    {
    +  "commits_count": 1,
    +  "commits": [
    +    {
    +      "author": {
    +        "id": 36480,
    +        "login": "jasder",
    +        "name": "段甲生",
    +        "image_url": "avatars/User/b"
    +      },
    +      "committer": {
    +        "id": 36480,
    +        "login": "jasder",
    +        "name": "段甲生",
    +        "image_url": "avatars/User/b"
    +      },
    +      "timestamp": 1604382982,
    +      "time_from_now": "3小时前",
    +      "message": "add some file\n* Add the tag list page to the release page\n* Apply suggestions from code review\n* Add the tags list view\n* Add the delete tag way on ui\n* Not delete tag and clear message when delete a release\n",
    +      "sha": "8f5faee0d3b3be1b8063e84da0c79dd75327b968"
    +    }
    +  ]
    +}
    +

    Compare two commits

    +

    Compare two commits

    + +
    +

    示例:

    +
    +
    curl -X GET \
    +http://localhost:3000/api/Jason/test-txt/compare/master...develop
    +
    +curl -X GET \
    +http://localhost:3000/api/Jason/test-txt/compare/master...Jason/test-txt:develop
    +
    await octokit.request('GET /api/Jason/test-txt/compare/master...Jason/test-txt:develop')
    +

    HTTP 请求

    +

    GET /api/:owner/:repo/compare/{base}...{head}.json

    +

    请求参数:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数名必选类型说明
    ownerstring用户登录名
    repostringproject's identifier
    basestringpull request's id
    headstringpull request's id
    +

    返回字段说明:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数类型字段说明
    ---
    commits_countintcommits总数量
    commitsarray
    -- authorobject项目作者
    ---- loginstring用户login
    ---- namestring用户姓名
    ---- image_urlstring用户头像
    -- committerobjectcommit提交用户
    ---- loginstring用户login
    ---- namestring用户姓名
    ---- image_urlstring用户头像
    -- timestampintcommit的unix时间戳
    -- time_from_nowstringcommit’s 提交时间距当前时间的时间值
    -- messagestringcommit说明信息
    -- shastringcommit’s sha值
    diffobject
    -- files_countint文件更改的总数量
    -- total_additionint添加代码总行数
    -- total_deletionint删除代码总行数
    -- filesArray
    -- shastringcommit's sha
    -- namestring当前文件名
    -- old_namestring修改之前的文件名称,与name相同的话,说明文件名未更改
    -- additionint文件添加的行数
    -- deletionint文件删除的行数
    -- typeint文件类型, 1: 表示该文件只添加了内容,2: 表示该文件内容有修改, 3: 表示文件被删除或者改文件只删除了内容
    -- isCreatedboolean当前文件是否为新增文件, true: 是, false: 否
    -- isDeletedboolean当前文件是否被删除, true: 是,false: 否
    -- isBinboolean当前文件是否为二进制文件,true: 是,false: 否
    -- isLFSFileboolean当前文件是否为LFS文件,true: 是,false: 否
    -- isRenamedboolean当前文件是否被重命名,true: 是,false: 否
    -- sectionsarray
    ---- fileNamestring文件名称
    ---- linesarray
    ------ leftIdxstring文件变动之前所在行数
    ------ rightIdxstring文件更改后所在行数
    ------ typestring文件变更类型,1: 内容未改动,2: 添加, 3: 删除, 4: diff统计信息
    ------ contentstring文件变更的内容
    ------ sectionInfoobject
    -------- pathstring文件相对仓库的路径
    -------- lastLeftIdxint
    -------- lastRightIdxint
    -------- leftHunkSizeint文件变更之前的行数
    -------- rightHunkSizeint文件变更之后的行数(及当前页面编辑器显示的总行数)
    -------- leftIdxint文件变更之前所在行数
    -------- rightIdxint文件变更之后所在行数
    + +
    +

    返回的JSON示例:

    +
    +
    {
    +  "commits_count": 1,
    +  "commits": [
    +    {
    +      "author": {
    +        "id": 36480,
    +        "login": "jasder",
    +        "name": "段甲生",
    +        "image_url": "avatars/User/b"
    +      },
    +      "committer": {
    +        "id": 36480,
    +        "login": "jasder",
    +        "name": "段甲生",
    +        "image_url": "avatars/User/b"
    +      },
    +      "timestamp": 1604382982,
    +      "time_from_now": "4小时前",
    +      "message": "add some file\n* Add the tag list page to the release page\n* Apply suggestions from code review\n* Add the tags list view\n* Add the delete tag way on ui\n* Not delete tag and clear message when delete a release\n",
    +      "sha": "8f5faee0d3b3be1b8063e84da0c79dd75327b968"
    +    }
    +  ],
    +  "diff": {
    +    "files_count": 6,
    +    "total_addition": 447,
    +    "total_deletion": 0,
    +    "files": [
    +      {
    +        "name": "build.go",
    +        "old_name": "build.go",
    +        "index": 1,
    +        "addition": 33,
    +        "deletion": 0,
    +        "type": 1,
    +        "isCreated": true,
    +        "isDeleted": false,
    +        "isBin": false,
    +        "isLFSFile": false,
    +        "isRenamed": false,
    +        "isSubmodule": false,
    +        "sections": [
    +          {
    +            "fileName": "build.go",
    +            "name": "",
    +            "lines": [
    +              {
    +                "leftIdx": 0,
    +                "rightIdx": 0,
    +                "type": 4,
    +                "content": "@@ -0,0 +1,33 @@",
    +                "sectionInfo": {
    +                  "path": "build.go",
    +                  "lastLeftIdx": 0,
    +                  "lastRightIdx": 0,
    +                  "leftIdx": 0,
    +                  "rightIdx": 1,
    +                  "leftHunkSize": 0,
    +                  "rightHunkSize": 33
    +                }
    +              },
    +              {
    +                "leftIdx": 0,
    +                "rightIdx": 1,
    +                "type": 2,
    +                "content": "+// Copyright 2020 The Gitea Authors. All rights reserved.",
    +                "sectionInfo": null
    +              }
    +            ]
    +          }
    +        ]
    +      }
    +    ]
    +  }
    +

    List pull requests

    +

    获取合并请求列表

    + +
    +

    示例:

    +
    +
    curl -X GET http://localhost:3000/api/Jasder/gitlink/pulls.json
    +
    await octokit.request('GET /api/Jasder/gitlink/pulls.json')
    +

    HTTP 请求

    +

    GET /api/:owner/:repo/pulls.json

    +

    请求参数:

    + + + + + + + + + + + + + + + + + + + + + + + +
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    + +
    +

    返回的JSON示例:

    +
    +
    {
    +  "status": 0,
    +  "message": "响应成功",
    +  "open_count": 4,
    +  "close_count": 51,
    +  "merged_issues_size": 123,
    +  "search_count": 4,
    +  "limit": null,
    +  "user_admin_or_member": true,
    +  "user_admin_or_developer": true,
    +  "project_name": "Gitlink",
    +  "project_author_name": "Gitlink",
    +  "issues": [
    +    {
    +      "pull_request_id": 1189,
    +      "pull_request_status": 0,
    +      "pull_request_head": "develop",
    +      "pull_request_base": "master",
    +      "pull_request_staus": "open",
    +      "is_original": false,
    +      "fork_project_id": null,
    +      "fork_project_identifier": null,
    +      "fork_project_user": null,
    +      "id": 51888,
    +      "name": "FIx release v3.2.0",
    +      "pr_time": "59分钟前",
    +      "assign_user_name": "victor",
    +      "assign_user_login": "moshenglv",
    +      "author_name": "段甲生",
    +      "author_login": "jasder",
    +      "avatar_url": "images/avatars/User/36480?t=1615520120",
    +      "priority": "正常",
    +      "version": null,
    +      "journals_count": 0,
    +      "issue_tags": null
    +    }
    +  ]
    +}
    +

    Issues

    Organizations

    Teams

    Errors

    From 2587ccea2810ea6d7cbe8aa85ae277f5d8d1a940 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 13 Oct 2021 11:23:43 +0800 Subject: [PATCH 02/11] add: pr compare exist pr --- app/controllers/compare_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/compare_controller.rb b/app/controllers/compare_controller.rb index 6dc9baade..8e8e3ec91 100644 --- a/app/controllers/compare_controller.rb +++ b/app/controllers/compare_controller.rb @@ -24,7 +24,7 @@ class CompareController < ApplicationController @exist_pullrequest = @project.pull_requests.where(is_original: false, head: @base, base: @head, status: 0).take end if @exist_pullrequest.present? - return -2, "在这些分支之间的合并请求已存在:#{@exist_pullrequest.try(:title)}" + return -2, "在这些分支之间的合并请求已存在:#{@exist_pullrequest.try(:title)}" else if @compare_result["Commits"].blank? && @compare_result["Diff"].blank? return -2, "分支内容相同,无需创建合并请求" From 8ba1198b4ac8543d5c8b0b784165f8b8b533219c Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 14 Oct 2021 16:38:12 +0800 Subject: [PATCH 03/11] fix: pr files commits count --- app/views/pull_requests/show.json.jbuilder | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/pull_requests/show.json.jbuilder b/app/views/pull_requests/show.json.jbuilder index 5c30bd172..ee6563965 100644 --- a/app/views/pull_requests/show.json.jbuilder +++ b/app/views/pull_requests/show.json.jbuilder @@ -3,8 +3,8 @@ json.project_name @project.name json.identifier @project.identifier json.project_identifier @project.identifier json.pr_time time_from_now(@pull_request.updated_at) -json.commits_count @pull_request.commits_count -json.files_count @pull_request.files_count +json.commits_count @gitea_pull["commit_num"] +json.files_count @gitea_pull["changed_files"] json.comments_count @issue.journals.parent_journals.size json.comments_total_count @issue.get_journals_size From 3d8b19fa7379638ab5dff9fcb3929c3a1e11cbbc Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 14 Oct 2021 16:59:43 +0800 Subject: [PATCH 04/11] fix: edit pr fork project info --- app/controllers/pull_requests_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index fe04dd5e5..1a31704b2 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -69,9 +69,9 @@ class PullRequestsController < ApplicationController end def edit - @fork_project_user_name = @project&.fork_project&.owner.try(:show_real_name) - @fork_project_user = @project&.fork_project&.owner.try(:login) - @fork_project_identifier = @project&.fork_project&.repository.try(:identifier) + @fork_project_user_name = @pull_request&.fork_project&.owner.try(:show_real_name) + @fork_project_user = @pull_request&.fork_project&.owner.try(:login) + @fork_project_identifier = @pull_request&.fork_project&.repository.try(:identifier) end def update From 119883042281d10bef72309e8596e2e3602ab2ae Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 12 Oct 2021 16:41:01 +0800 Subject: [PATCH 05/11] add: project permit change identifier --- app/controllers/projects_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index bea2b429c..e4ad2f136 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -229,7 +229,7 @@ class ProjectsController < ApplicationController private def project_params - params.permit(:user_id, :name, :description, :repository_name, :website, :lesson_url, :default_branch, + params.permit(:user_id, :name, :description, :repository_name, :website, :lesson_url, :default_branch, :identifier, :project_category_id, :project_language_id, :license_id, :ignore_id, :private) end From 018745c062e1067ed1b9dd5938bc632f28fa838e Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 12 Oct 2021 17:08:25 +0800 Subject: [PATCH 06/11] add: project permit change identifier --- app/controllers/projects_controller.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index e4ad2f136..95d9bc1ac 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -139,11 +139,12 @@ class ProjectsController < ApplicationController gitea_params = { private: private, default_branch: @project.default_branch, - website: @project.website + website: @project.website, + name: @project.identifier } if [true, false].include? private - Gitea::Repository::UpdateService.call(@owner, @project.identifier, gitea_params) - @project.repository.update_column(:hidden, private) + Gitea::Repository::UpdateService.call(@owner, @project&.repository&.identifier, gitea_params) + @project.repository.update_attributes({hidden: private, identifier: @project.identifier}) end end SendTemplateMessageJob.perform_later('ProjectSettingChanged', current_user.id, @project&.id, @project.previous_changes.slice(:name, :description, :project_category_id, :project_language_id, :is_public)) From 00100e59c451471b17cff059b2a4147f028e329e Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 12 Oct 2021 17:15:50 +0800 Subject: [PATCH 07/11] add: project permit change identifier --- app/controllers/projects_controller.rb | 6 ++---- app/services/gitea/repository/update_service.rb | 3 ++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 95d9bc1ac..25d8b8d76 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -142,10 +142,8 @@ class ProjectsController < ApplicationController website: @project.website, name: @project.identifier } - if [true, false].include? private - Gitea::Repository::UpdateService.call(@owner, @project&.repository&.identifier, gitea_params) - @project.repository.update_attributes({hidden: private, identifier: @project.identifier}) - end + gitea_repo = Gitea::Repository::UpdateService.call(@owner, @project&.repository&.identifier, gitea_params) + @project.repository.update_attributes({hidden: gitea_repo["private"], identifier: gitea_repo["name"]}) end SendTemplateMessageJob.perform_later('ProjectSettingChanged', current_user.id, @project&.id, @project.previous_changes.slice(:name, :description, :project_category_id, :project_language_id, :is_public)) end diff --git a/app/services/gitea/repository/update_service.rb b/app/services/gitea/repository/update_service.rb index 0d27922b8..6c4eff1b3 100644 --- a/app/services/gitea/repository/update_service.rb +++ b/app/services/gitea/repository/update_service.rb @@ -19,7 +19,8 @@ class Gitea::Repository::UpdateService < Gitea::ClientService end def call - patch(url, data_params) + response = patch(url, data_params) + render_200_response(response) end private From 98a45eb05cc30b6cb0e02817606324ef9fc732f8 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 14 Oct 2021 14:25:00 +0800 Subject: [PATCH 08/11] fix: update repository identifier valid --- app/controllers/projects_controller.rb | 4 ++-- app/forms/projects/update_form.rb | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 25d8b8d76..54ae85ca0 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -127,9 +127,9 @@ class ProjectsController < ApplicationController Gitea::Repository::UpdateService.call(@owner, @project.identifier, gitea_params) else validate_params = project_params.slice(:name, :description, - :project_category_id, :project_language_id, :private) + :project_category_id, :project_language_id, :private, :identifier) - Projects::UpdateForm.new(validate_params).validate! + Projects::UpdateForm.new(validate_params.merge(user_id: @project.user_id)).validate! private = @project.forked_from_project.present? ? !@project.forked_from_project.is_public : params[:private] || false diff --git a/app/forms/projects/update_form.rb b/app/forms/projects/update_form.rb index 0cd2c9459..9ccc611cf 100644 --- a/app/forms/projects/update_form.rb +++ b/app/forms/projects/update_form.rb @@ -1,11 +1,12 @@ class Projects::UpdateForm < BaseForm - attr_accessor :name, :description, :project_category_id, :project_language_id, :private + attr_accessor :name, :description, :project_category_id, :project_language_id, :private, :identifier, :user_id validates :name, presence: true validates :name, length: { maximum: 50 } validates :description, length: { maximum: 200 } validate do check_project_category(project_category_id) check_project_language(project_language_id) + check_repository_name(user_id, identifier) unless identifier.blank? end end From 79b394d29162cb777ebaa7427961d3883bd38d0b Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 14 Oct 2021 15:30:00 +0800 Subject: [PATCH 09/11] fix: projecttrend show rule --- app/controllers/project_trends_controller.rb | 9 ++++----- app/models/pull_request.rb | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/controllers/project_trends_controller.rb b/app/controllers/project_trends_controller.rb index dc1ffbdb4..621a30d51 100644 --- a/app/controllers/project_trends_controller.rb +++ b/app/controllers/project_trends_controller.rb @@ -14,14 +14,13 @@ class ProjectTrendsController < ApplicationController project_trends = project_trends.where("created_at between ? and ?",(Time.now.beginning_of_day - check_time.days), Time.now.end_of_day) end - @project_open_issues_count = project_trends.where(trend_type: "Issue", action_type: "create").size @project_close_issues_count = project_trends.where(trend_type: "Issue", action_type: "close").size - @project_issues_count = @project_open_issues_count + @project_close_issues_count + @project_issues_count = project_trends.where(trend_type: "Issue", action_type: "create").size + @project_open_issues_count = @project_issues_count - @project_close_issues_count @project_pr_count = project_trends.where(trend_type: "PullRequest", action_type: "close").size - @project_new_pr_count = project_trends.where(trend_type: "PullRequest", action_type: "create").size - @project_pr_all_count = @project_pr_count + @project_new_pr_count - + @project_pr_all_count = project_trends.where(trend_type: "PullRequest", action_type: "create").size + @project_new_pr_count = @project_pr_all_count - @project_pr_count if check_type.present? project_trends = project_trends.where(trend_type: check_type.to_s.strip) end diff --git a/app/models/pull_request.rb b/app/models/pull_request.rb index ce0cb04ad..14b893556 100644 --- a/app/models/pull_request.rb +++ b/app/models/pull_request.rb @@ -54,7 +54,7 @@ class PullRequest < ApplicationRecord Project.find_by(id: self.fork_project_id) end - def bind_gitea_pull_request!(gitea_pull_number, gitea_pull_id) + def bind_gitea_pull_request!(gitea_pull_number, gitea_pull_id=gitea_pull_number) update_columns( gitea_number: gitea_pull_number, gitea_id: gitea_pull_id) From ffa0715374475ee24659cd969e2262f9c648fdd7 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 14 Oct 2021 18:31:27 +0800 Subject: [PATCH 10/11] fix --- app/controllers/pull_requests_controller.rb | 2 +- app/models/pull_request.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index 1a31704b2..8f3df5546 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -58,7 +58,7 @@ class PullRequestsController < ApplicationController ActiveRecord::Base.transaction do @pull_request, @gitea_pull_request = PullRequests::CreateService.call(current_user, @owner, @project, params) if @gitea_pull_request[:status] == :success - @pull_request.bind_gitea_pull_request!(@gitea_pull_request[:body]["number"]) + @pull_request.bind_gitea_pull_request!(@gitea_pull_request[:body]["number"], @gitea_pull_request[:body]["id"]) SendTemplateMessageJob.perform_later('PullRequestAssigned', current_user.id, @pull_request&.id) SendTemplateMessageJob.perform_later('ProjectPullRequest', current_user.id, @pull_request&.id) else diff --git a/app/models/pull_request.rb b/app/models/pull_request.rb index 14b893556..ce0cb04ad 100644 --- a/app/models/pull_request.rb +++ b/app/models/pull_request.rb @@ -54,7 +54,7 @@ class PullRequest < ApplicationRecord Project.find_by(id: self.fork_project_id) end - def bind_gitea_pull_request!(gitea_pull_number, gitea_pull_id=gitea_pull_number) + def bind_gitea_pull_request!(gitea_pull_number, gitea_pull_id) update_columns( gitea_number: gitea_pull_number, gitea_id: gitea_pull_id) From 2a09fadf712e05d473154bd36f99d7743d17e82b Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 15 Oct 2021 14:36:50 +0800 Subject: [PATCH 11/11] fix: change projec trend rule and fix data --- app/controllers/issues_controller.rb | 12 ++++++++ app/controllers/project_trends_controller.rb | 12 ++++++-- app/controllers/pull_requests_controller.rb | 4 ++- app/models/project_trend.rb | 3 +- lib/tasks/refactor_project_trend.rake | 30 ++++++++++++++++++++ 5 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 lib/tasks/refactor_project_trend.rake diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index bfa15aa50..f16edbb38 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -216,6 +216,12 @@ class IssuesController < ApplicationController if @issue.previous_changes[:due_date].present? previous_changes.merge!(due_date: [@issue.previous_changes[:due_date][0].to_s, @issue.previous_changes[:due_date][1].to_s]) end + if @issue.previous_changes[:status_id].present? && @issue.previous_changes[:status_id][1] == 5 + @issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: ProjectTrend::CLOSE) + end + if @issue.previous_changes[:status_id].present? && @issue.previous_changes[:status_id][0] == 5 + @issue.project_trends.where(action_type: ProjectTrend::CLOSE).destroy_all + end SendTemplateMessageJob.perform_later('IssueChanged', current_user.id, @issue&.id, previous_changes) SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id) if @issue.previous_changes[:assigned_to_id].present? end @@ -338,6 +344,12 @@ class IssuesController < ApplicationController if i.previous_changes[:due_date].present? previous_changes.merge!(due_date: [i.previous_changes[:due_date][0].to_s, i.previous_changes[:due_date][1].to_s]) end + if i.previous_changes[:status_id].present? && i.previous_changes[:status_id][1] == 5 + i.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: ProjectTrend::CLOSE) + end + if i.previous_changes[:status_id].present? && i.previous_changes[:status_id][0] == 5 + i.project_trends.where(action_type: ProjectTrend::CLOSE).destroy_all + end SendTemplateMessageJob.perform_later('IssueChanged', current_user.id, i&.id, previous_changes) SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, i&.id) if i.previous_changes[:assigned_to_id].present? end diff --git a/app/controllers/project_trends_controller.rb b/app/controllers/project_trends_controller.rb index 621a30d51..66702608d 100644 --- a/app/controllers/project_trends_controller.rb +++ b/app/controllers/project_trends_controller.rb @@ -3,7 +3,7 @@ class ProjectTrendsController < ApplicationController before_action :check_project_public def index - project_trends = @project.project_trends.includes(:user, trend: :user) + project_trends = @project.project_trends.preload(:user, trend: :user) check_time = params[:time] #时间的筛选 check_type = params[:type] #动态类型的筛选,目前已知的有 Issue, PullRequest, Version @@ -18,7 +18,7 @@ class ProjectTrendsController < ApplicationController @project_issues_count = project_trends.where(trend_type: "Issue", action_type: "create").size @project_open_issues_count = @project_issues_count - @project_close_issues_count - @project_pr_count = project_trends.where(trend_type: "PullRequest", action_type: "close").size + @project_pr_count = project_trends.where(trend_type: "PullRequest", action_type: ["close", "merge"]).size @project_pr_all_count = project_trends.where(trend_type: "PullRequest", action_type: "create").size @project_new_pr_count = @project_pr_all_count - @project_pr_count if check_type.present? @@ -26,7 +26,13 @@ class ProjectTrendsController < ApplicationController end if check_status.present? - project_trends = project_trends.where(action_type: check_status.to_s.strip) + if check_status == "delay" || check_status == "close" + project_trends = project_trends.where(action_type: ["close", "merge"]) + else + project_trends = project_trends.where(action_type: ["create"]).where.not(trend_id: project_trends.where(action_type: ["close", "merge"]).pluck(:trend_id)) + end + else + project_trends = project_trends.where(action_type: "create") end project_trends = project_trends.order("created_at desc") diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index 8f3df5546..ac3968aad 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -130,6 +130,7 @@ class PullRequestsController < ApplicationController begin colsed = PullRequests::CloseService.call(@owner, @repository, @pull_request, current_user) if colsed === true + @pull_request.project_trends.create!(user: current_user, project: @project,action_type: ProjectTrend::CLOSE) SendTemplateMessageJob.perform_later('PullRequestClosed', current_user.id, @pull_request.id) normal_status(1, "已拒绝") else @@ -171,7 +172,8 @@ class PullRequestsController < ApplicationController end if success_condition && @pull_request.merge! - @pull_request.project_trend_status! + # @pull_request.project_trend_status! + @pull_request.project_trends.create!(user: current_user, project: @project,action_type: ProjectTrend::MERGE) @issue&.custom_journal_detail("merge", "", "该合并请求已被合并", current_user&.id) SendTemplateMessageJob.perform_later('PullRequestMerged', current_user.id, @pull_request.id) normal_status(1, "合并成功") diff --git a/app/models/project_trend.rb b/app/models/project_trend.rb index 8c55c4f94..7642e1dfb 100644 --- a/app/models/project_trend.rb +++ b/app/models/project_trend.rb @@ -20,7 +20,8 @@ class ProjectTrend < ApplicationRecord CLOSE = 'close' CREATE = 'create' - + MERGE = 'merge' + belongs_to :project belongs_to :trend, polymorphic: true, optional: true belongs_to :user diff --git a/lib/tasks/refactor_project_trend.rake b/lib/tasks/refactor_project_trend.rake new file mode 100644 index 000000000..e2092d028 --- /dev/null +++ b/lib/tasks/refactor_project_trend.rake @@ -0,0 +1,30 @@ +namespace :refactor_project_trend do + desc "refactor project trend data record" + + task issue_and_pull_request: :environment do + puts "========DELETE all old data begin========" + old_data_count = ProjectTrend.where(trend_type: ["PullRequest","Issue"]).destroy_all.size + puts "========DELETE all old data #{old_data_count}========" + puts "========DELETE all old data end========" + puts "========CREATE new issue data begin========" + issue_count = 0 + Issue.issue_issue.find_each do |issue| + issue_count += 1 + issue.project_trends.create(user_id: issue.assigned_to_id || issue.author_id, project_id: issue.project_id, action_type: ProjectTrend::CLOSE, created_at: issue.updated_on) if issue.status_id == 5 + issue.project_trends.create(user_id: issue.author_id, project_id: issue.project_id, action_type: ProjectTrend::CREATE, created_at: issue.created_on) + end + puts "========CREATE new issue data #{issue_count}========" + puts "========CREATE new issue data end========" + puts "========CREATE new pull_request data begin========" + pull_request_count = 0 + PullRequest.find_each do |pull_request| + pull_request_count += 1 + pull_request.project_trends.create(user_id: pull_request.user_id, project_id: pull_request.project_id, action_type: ProjectTrend::MERGE, created_at: pull_request.updated_at) if pull_request.status == PullRequest::MERGED + pull_request.project_trends.create(user_id: pull_request.user_id, project_id: pull_request.project_id, action_type: ProjectTrend::CLOSE, created_at: pull_request.updated_at) if pull_request.status == PullRequest::CLOSED + pull_request.project_trends.create(user_id: pull_request.user_id, project_id: pull_request.project_id, action_type: ProjectTrend::CREATE, created_at: pull_request.created_at) + end + puts "========CREATE new pull_request data #{pull_request_count}========" + puts "========CREATE new pull_request data end========" + + end +end \ No newline at end of file