diff --git a/Gemfile b/Gemfile
index 37687e78d..a4c7c2414 100644
--- a/Gemfile
+++ b/Gemfile
@@ -135,4 +135,4 @@ gem 'doorkeeper'
gem 'doorkeeper-jwt'
-gem 'gitea-client', '~> 0.9.4'
\ No newline at end of file
+gem 'gitea-client', '~> 0.10.1'
\ No newline at end of file
diff --git a/app/controllers/api/v1/projects/commits_controller.rb b/app/controllers/api/v1/projects/commits_controller.rb
index 873dd4d93..a1545ae6f 100644
--- a/app/controllers/api/v1/projects/commits_controller.rb
+++ b/app/controllers/api/v1/projects/commits_controller.rb
@@ -1,5 +1,10 @@
class Api::V1::Projects::CommitsController < Api::V1::BaseController
- before_action :require_public_and_member_above, only: [:diff]
+ before_action :require_public_and_member_above, only: [:index, :diff]
+
+ def index
+ @result_object = Api::V1::Projects::Commits::ListService.call(@project, {page: page, limit: limit, sha: params[:sha]}, current_user&.gitea_token)
+ puts @result_object
+ end
def diff
@result_object = Api::V1::Projects::Commits::DiffService.call(@project, params[:sha], current_user&.gitea_token)
diff --git a/app/docs/slate/source/includes/_repositories.md b/app/docs/slate/source/includes/_repositories.md
index 2b3ca1326..c760fc624 100644
--- a/app/docs/slate/source/includes/_repositories.md
+++ b/app/docs/slate/source/includes/_repositories.md
@@ -1413,6 +1413,89 @@ await octokit.request('GET /api/v1/yystopf/csfjkkj/git/blobs/80dd40214a586223123
Success Data.
+## 获取仓库提交列表
+根据分支名、标签、commit ID来获取提交列表
+
+> 示例:
+
+```shell
+curl -X GET \
+-d "sha=master" \
+-d "page=1" \
+-d "limit=1" \
+http://localhost:3000/api/v1/yystopf/csfjkkj/commits.json
+```
+
+```javascript
+await octokit.request('GET /api/v1/yystopf/csfjkkj/commits.json')
+```
+
+### HTTP 请求
+`GET /api/v1/:owner/:repo/commits.json`
+
+### 请求参数:
+参数 | 必选 | 默认 | 类型 | 字段说明
+--------- | ------- | ------- | -------- | ----------
+|owner|是| | string |用户登录名 |
+|repo |是| | string |项目标识identifier |
+|sha |否| | string |分支名、标签名或Commit ID|
+|page |否| | int |页码|
+|limit|否| | int |每页数量|
+### 返回字段说明:
+参数 | 类型 | 字段说明
+--------- | ----------- | -----------
+|total_count|int|提交总数|
+|commits.sha|string|提交ID|
+|commits.author|object|提交作者|
+|commits.committer|object|提交者|
+|commits.commit_message|string|提交信息|
+|commits.parent_shas|array|提交父节点ID|
+|commits.files|array|提交文件|
+|commits.commit_date|string|提交日期|
+|commits.commit_time|string|提交时间|
+|commits.branch|string|提交分支|
+
+
+> 返回的JSON示例:
+
+```json
+{
+ "total_count": 12,
+ "commits": [
+ {
+ "sha": "86c62a1e91c07b58b8aa6c89b94856d89c0f7e55",
+ "author": {
+ "id": null,
+ "login": "viletyy",
+ "name": "viletyy",
+ "type": null,
+ "image_url": "system/lets/letter_avatars/2/V/39_141_222/120.png"
+ },
+ "committer": {
+ "id": null,
+ "login": "viletyy",
+ "name": "viletyy",
+ "type": null,
+ "image_url": "system/lets/letter_avatars/2/V/39_141_222/120.png"
+ },
+ "commit_message": "fix\n",
+ "parent_shas": [
+ "411e4d259785241f1bd14faf99ca24fd1b802f2a"
+ ],
+ "files": [
+ "hd.txt"
+ ],
+ "commit_date": "2022-07-05",
+ "commit_time": "2022-07-05 11:00:45",
+ "branch": "hh_ceshi"
+ }
+ ]
+}
+```
+
+
## 获取单个提交的blame信息
根据commit ID获取blame信息
diff --git a/app/services/api/v1/projects/commits/list_service.rb b/app/services/api/v1/projects/commits/list_service.rb
new file mode 100644
index 000000000..17818554c
--- /dev/null
+++ b/app/services/api/v1/projects/commits/list_service.rb
@@ -0,0 +1,38 @@
+class Api::V1::Projects::Commits::ListService < ApplicationService
+
+ attr_reader :project, :sha, :page, :limit, :owner, :repo, :token
+ attr_accessor :gitea_data
+
+ def initialize(project, params, token=nil)
+ @project = project
+ @sha = params[:sha]
+ @page = params[:page] || 1
+ @limit = params[:limit] || 15
+ @owner = project&.owner.login
+ @repo = project&.identifier
+ @token = token
+ end
+
+ def call
+ load_gitea_data
+
+ gitea_data
+ end
+
+ private
+ def request_params
+ param = {
+ access_token: token,
+ page: page,
+ limit: limit
+ }
+ param.merge!(sha: sha) if sha.present?
+
+ param
+ end
+
+ def load_gitea_data
+ @gitea_data = $gitea_client.get_repos_commits_by_owner_repo(owner, repo, {query: request_params}) rescue nil
+ raise Error, '获取提交列表失败!' unless @gitea_data.is_a?(Hash)
+ end
+end
\ No newline at end of file
diff --git a/app/views/api/v1/projects/commits/index.json.jbuilder b/app/views/api/v1/projects/commits/index.json.jbuilder
new file mode 100644
index 000000000..aa13845a1
--- /dev/null
+++ b/app/views/api/v1/projects/commits/index.json.jbuilder
@@ -0,0 +1,17 @@
+json.total_count @result_object[:total_data].to_i
+json.commits @result_object[:data].each do |commit|
+ json.sha commit['sha']
+ json.author do
+ json.partial! 'api/v1/users/commit_user', locals: { user: render_cache_commit_author(commit['commit']['author']), name: commit['commit']['author']['name'] }
+ end
+
+ json.committer do
+ json.partial! 'api/v1/users/commit_user', locals: { user: render_cache_commit_author(commit['commit']['committer']), name: commit['commit']['committer']['name'] }
+ end
+ json.commit_message commit['commit']['message']
+ json.parent_shas commit['parents'].map{|x|x['sha']}
+ json.files commit['files'].map{|f|f['filename']}
+ json.commit_date commit['commit_date']
+ json.commit_time commit['commit']['committer']['date'].to_time.strftime("%Y-%m-%d %H:%M:%S")
+ json.branch commit['branch']
+end
\ No newline at end of file
diff --git a/config/routes/api.rb b/config/routes/api.rb
index fc07a9862..9c71ea800 100644
--- a/config/routes/api.rb
+++ b/config/routes/api.rb
@@ -32,7 +32,7 @@ defaults format: :json do
get :all
end
end
-
+ resources :commits, only: [:index]
get '/commits/:sha/diff', to: 'commits#diff'
get '/git/blobs/:sha', to: 'git#blobs'
get '/git/trees/:sha', to: 'git#trees'
diff --git a/public/docs/api.html b/public/docs/api.html
index 505ab44cf..f3e56574f 100644
--- a/public/docs/api.html
+++ b/public/docs/api.html
@@ -553,6 +553,9 @@
获取仓库blobs内容
+
+ 获取仓库提交列表
+
获取单个提交的blame信息
@@ -9665,6 +9668,165 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/git/trees/80dd40214a58622312393b2ae
+获取仓库提交列表
+根据分支名、标签、commit ID来获取提交列表
+
+
+示例:
+
+curl -X GET \
+-d "sha=master" \
+-d "page=1" \
+-d "limit=1" \
+http://localhost:3000/api/v1/yystopf/csfjkkj/commits.json
+
await octokit.request('GET /api/v1/yystopf/csfjkkj/commits.json')
+
HTTP 请求
+GET /api/v1/:owner/:repo/commits.json
+请求参数:
+
+
+| 参数 |
+必选 |
+默认 |
+类型 |
+字段说明 |
+
+
+
+| owner |
+是 |
+ |
+string |
+用户登录名 |
+
+
+| repo |
+是 |
+ |
+string |
+项目标识identifier |
+
+
+| sha |
+否 |
+ |
+string |
+分支名、标签名或Commit ID |
+
+
+| page |
+否 |
+ |
+int |
+页码 |
+
+
+| limit |
+否 |
+ |
+int |
+每页数量 |
+
+
+返回字段说明:
+
+
+| 参数 |
+类型 |
+字段说明 |
+
+
+
+| total_count |
+int |
+提交总数 |
+
+
+| commits.sha |
+string |
+提交ID |
+
+
+| commits.author |
+object |
+提交作者 |
+
+
+| commits.committer |
+object |
+提交者 |
+
+
+| commits.commit_message |
+string |
+提交信息 |
+
+
+| commits.parent_shas |
+array |
+提交父节点ID |
+
+
+| commits.files |
+array |
+提交文件 |
+
+
+| commits.commit_date |
+string |
+提交日期 |
+
+
+| commits.commit_time |
+string |
+提交时间 |
+
+
+| commits.branch |
+string |
+提交分支 |
+
+
+
+
+返回的JSON示例:
+
+{
+ "total_count": 12,
+ "commits": [
+ {
+ "sha": "86c62a1e91c07b58b8aa6c89b94856d89c0f7e55",
+ "author": {
+ "id": null,
+ "login": "viletyy",
+ "name": "viletyy",
+ "type": null,
+ "image_url": "system/lets/letter_avatars/2/V/39_141_222/120.png"
+ },
+ "committer": {
+ "id": null,
+ "login": "viletyy",
+ "name": "viletyy",
+ "type": null,
+ "image_url": "system/lets/letter_avatars/2/V/39_141_222/120.png"
+ },
+ "commit_message": "fix\n",
+ "parent_shas": [
+ "411e4d259785241f1bd14faf99ca24fd1b802f2a"
+ ],
+ "files": [
+ "hd.txt"
+ ],
+ "commit_date": "2022-07-05",
+ "commit_time": "2022-07-05 11:00:45",
+ "branch": "hh_ceshi"
+ }
+ ]
+}
+
+
获取单个提交的blame信息
根据commit ID获取blame信息
@@ -9673,9 +9835,9 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/git/trees/80dd40214a58622312393b2ae
curl -X GET http://localhost:3000/api/v1/yystopf/csfjkkj/commits/80dd40214a58622312393b2ae693756a4781fab2/diff.json
await octokit.request('GET /api/v1/yystopf/csfjkkj/commits/80dd40214a58622312393b2ae693756a4781fab2/diff.json')
-
HTTP 请求
+HTTP 请求
GET /api/v1/:owner/:repo/commits/:sha/diff.json
-请求参数:
+请求参数:
| 参数 |
@@ -9707,7 +9869,7 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/git/trees/80dd40214a58622312393b2ae
提交记录id |
-返回字段说明:
+返回字段说明:
| 参数 |
@@ -9933,9 +10095,9 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/git/trees/80dd40214a58622312393b2ae
-d "to=master" \
http://localhost:3000/api/v1/yystopf/csfjkkj/compare.json
await octokit.request('GET /api/v1/yystopf/csfjkkj/compare.json')
-
HTTP 请求
+HTTP 请求
GET /api/v1/:owner/:repo/compare.json
-请求参数:
+请求参数:
| 参数 |
@@ -9974,7 +10136,7 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/compare.json
目标分支、标签、commitID |
-返回字段说明:
+返回字段说明:
| 参数 |
@@ -10259,9 +10421,9 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/compare.json
curl -X GET \
http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json
await octokit.request('GET /api/v1/yystopf/ceshi/webhooks.json')
-
HTTP 请求
+HTTP 请求
GET /api/v1/:owner/:repo/webhooks.json
-请求参数:
+请求参数:
| 参数 |
@@ -10286,7 +10448,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json
项目标识identifier |
-返回字段说明:
+返回字段说明:
| 参数 |
@@ -10379,9 +10541,9 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json
curl -X GET \
http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3.json
await octokit.request('GET /api/v1/yystopf/ceshi/webhooks/3.json')
-
HTTP 请求
+HTTP 请求
GET /api/v1/:owner/:repo/webhooks/:id.json
-请求参数:
+请求参数:
| 参数 |
@@ -10413,7 +10575,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3.json
webhook ID |
-返回字段说明:
+返回字段说明:
| 参数 |
@@ -10536,9 +10698,9 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3.json
curl -X POST \
http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json
await octokit.request('POST /api/v1/yystopf/ceshi/webhooks.json')
-
HTTP 请求
+HTTP 请求
POST /api/v1/:owner/:repo/webhooks.json
-请求参数:
+请求参数:
| 参数 |
@@ -10663,7 +10825,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json
"branch_filter": "*",
"events": ["push"]
}
-返回字段说明:
+返回字段说明:
| 参数 |
@@ -10742,9 +10904,9 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json
curl -X PATCH \
http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
await octokit.request('PATCH /api/v1/yystopf/ceshi/webhooks/7.json')
-
HTTP 请求
+HTTP 请求
PATCH /api/v1/:owner/:repo/webhooks/68.json
-请求参数:
+请求参数:
| 参数 |
@@ -10876,7 +11038,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
"branch_filter": "*",
"events": ["push"]
}
-返回字段说明:
+返回字段说明:
返回的JSON示例:
@@ -10911,9 +11073,9 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
curl -X DELETE \
http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
await octokit.request('DELETE /api/v1/yystopf/ceshi/webhooks/7.json')
-
HTTP 请求
+HTTP 请求
DELETE /api/v1/:owner/:repo/webhooks/:id.json
-请求参数:
+请求参数:
| 参数 |
@@ -10945,7 +11107,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
webhook id |
-返回字段说明:
+返回字段说明:
返回的JSON示例:
@@ -10966,9 +11128,9 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
curl -X GET \
http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/hooktasks.json
await octokit.request('GET /api/v1/yystopf/ceshi/webhooks/3/hooktasks.json')
-
HTTP 请求
+HTTP 请求
GET /api/v1/:owner/:repo/webhooks/:id/hooktasks.json
-请求参数:
+请求参数:
| 参数 |
@@ -11000,7 +11162,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/hooktasks.json
webhook ID |
-返回字段说明:
+返回字段说明:
| 参数 |
@@ -11237,9 +11399,9 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/hooktasks.json
curl -X POST \
http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/tests.json
await octokit.request('POST /api/v1/yystopf/ceshi/webhooks/3/tests.json')
-
HTTP 请求
+HTTP 请求
POST /api/v1/:owner/:repo/webhooks/:id/tests.json
-请求参数:
+请求参数:
| 参数 |
@@ -11271,7 +11433,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/tests.json
webhook ID |
-返回字段说明:
+返回字段说明:
返回的JSON示例: