forked from Gitlink/forgeplus
ADD get a commit api
This commit is contained in:
parent
181bb05d4a
commit
a8c3328bd6
201
README.md
201
README.md
|
@ -1825,18 +1825,19 @@ http://localhost:3000/api/repositories/89/commits.json | jq
|
||||||
|
|
||||||
## 获取某个提交记录(包含diff)
|
## 获取某个提交记录(包含diff)
|
||||||
```
|
```
|
||||||
GET /api/repositories/:id/commits/:sha
|
GET /api/:owner/:repo/commits/:sha
|
||||||
```
|
```
|
||||||
*示例*
|
*示例*
|
||||||
```
|
```
|
||||||
curl -X GET \
|
curl -X GET \
|
||||||
http://localhost:3000/api/repositories/5845/commits/b0c4a4a1487d53acebf2addc544b29938cad12df.json | jq
|
http://localhost:3000/api/jasder/repo/commits/b0c4a4a1487d53acebf2addc544b29938cad12df.json | jq
|
||||||
```
|
```
|
||||||
*请求参数说明:*
|
*请求参数说明:*
|
||||||
|
|
||||||
|参数名|必选|类型|说明|
|
|参数名|必选|类型|说明|
|
||||||
|-|-|-|-|
|
|-|-|-|-|
|
||||||
|id |是|int |仓库repository的id |
|
|owner |是|string |仓库拥有者 |
|
||||||
|
|repo |是|string |仓库的identifier值 |
|
||||||
|sha |否|string |git的ref或者是提交记录commit的sha标识 |
|
|sha |否|string |git的ref或者是提交记录commit的sha标识 |
|
||||||
|
|
||||||
|
|
||||||
|
@ -1909,161 +1910,77 @@ http://localhost:3000/api/repositories/5845/commits/b0c4a4a1487d53acebf2addc544b
|
||||||
返回值
|
返回值
|
||||||
```
|
```
|
||||||
{
|
{
|
||||||
"additions": 243,
|
"files_count": 6,
|
||||||
"deletions": 32,
|
"total_addition": 447,
|
||||||
"sha": "c6c17ad47d6dbe4369d559847197b37b4090a46e",
|
"total_deletion": 0,
|
||||||
"url": "http://localhost:3000/api/repositories/5845/commits/c6c17ad47d6dbe4369d559847197b37b4090a46e.json",
|
|
||||||
"commit": {
|
"commit": {
|
||||||
|
"sha": "8f5faee0d3b3be1b8063e84da0c79dd75327b968",
|
||||||
|
"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",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "GitHub",
|
"name": "Jasder",
|
||||||
"email": "noreply@github.com",
|
"email": "2053003901@@qq.com",
|
||||||
"date": "2020-05-20T20:15:27+08:00"
|
"date": "2020-11-03T13:56:22+08:00"
|
||||||
},
|
},
|
||||||
"committer": {
|
"committer": {
|
||||||
"name": "GitHub",
|
"name": "Jasder",
|
||||||
"email": "noreply@github.com",
|
"email": "2053003901@@qq.com",
|
||||||
"date": "2020-05-20T20:15:27+08:00"
|
"date": "2020-11-03T13:56:22+08:00"
|
||||||
}
|
},
|
||||||
|
"timestamp": 1604382982,
|
||||||
|
"time_from_now": "3天前"
|
||||||
},
|
},
|
||||||
"author": null,
|
"author": null,
|
||||||
"committer": null,
|
"committer": null,
|
||||||
"parents": [
|
"parents": [
|
||||||
{
|
{
|
||||||
"sha": "c8b8cfd85e375ad376833d04b9ca499bf9da355b",
|
"sha": "c7f5b90725f30d8ad840a026773f9df92debc3af"
|
||||||
"url": "http://localhost:3003//api/repositories/intelligent-test-platform/commits/c8b8cfd85e375ad376833d04b9ca499bf9da355b"
|
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"sha": "b0c4a4a1487d53acebf2addc544b29938cad12df",
|
|
||||||
"url": "http://localhost:3003//api/repositories/intelligent-test-platform/commits/b0c4a4a1487d53acebf2addc544b29938cad12df"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"files": [
|
"files": [
|
||||||
{
|
{
|
||||||
"Name": "Dockerfile",
|
"name": "build.go",
|
||||||
"OldName": "Dockerfile",
|
"old_name": "build.go",
|
||||||
"Index": 1,
|
"index": 1,
|
||||||
"Addition": 11,
|
"addition": 33,
|
||||||
"Deletion": 0,
|
"deletion": 0,
|
||||||
"Type": 1,
|
"type": 1,
|
||||||
"IsCreated": true,
|
"isCreated": true,
|
||||||
"IsDeleted": false,
|
"isDeleted": false,
|
||||||
"IsBin": false,
|
"isBin": false,
|
||||||
"IsLFSFile": false,
|
"isLFSFile": false,
|
||||||
"IsRenamed": false,
|
"isRenamed": false,
|
||||||
"IsSubmodule": false,
|
"isSubmodule": false,
|
||||||
"Sections": [
|
"sections": [
|
||||||
{
|
{
|
||||||
"Name": "",
|
"fileName": "build.go",
|
||||||
"Lines": [
|
"name": "",
|
||||||
|
"lines": [
|
||||||
{
|
{
|
||||||
"LeftIdx": 0,
|
"leftIdx": 0,
|
||||||
"RightIdx": 0,
|
"rightIdx": 0,
|
||||||
"Type": 4,
|
"type": 4,
|
||||||
"Content": "@@ -0,0 +1,11 @@",
|
"content": "@@ -0,0 +1,33 @@",
|
||||||
"Comments": null,
|
"sectionInfo": {
|
||||||
"SectionInfo": {
|
"path": "build.go",
|
||||||
"Path": "Dockerfile",
|
"lastLeftIdx": 0,
|
||||||
"LastLeftIdx": 0,
|
"lastRightIdx": 0,
|
||||||
"LastRightIdx": 0,
|
"leftIdx": 0,
|
||||||
"LeftIdx": 0,
|
"rightIdx": 1,
|
||||||
"RightIdx": 1,
|
"leftHunkSize": 0,
|
||||||
"LeftHunkSize": 0,
|
"rightHunkSize": 33
|
||||||
"RightHunkSize": 11
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"LeftIdx": 0,
|
"leftIdx": 0,
|
||||||
"RightIdx": 1,
|
"rightIdx": 1,
|
||||||
"Type": 2,
|
"type": 2,
|
||||||
"Content": "+FROM adoptopenjdk/maven-openjdk8:latest",
|
"content": "+// Copyright 2020 The Gitea Authors. All rights reserved.",
|
||||||
"Comments": null,
|
"sectionInfo": null
|
||||||
"SectionInfo": null
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"LeftIdx": 0,
|
|
||||||
"RightIdx": 2,
|
|
||||||
"Type": 2,
|
|
||||||
"Content": "+",
|
|
||||||
"Comments": null,
|
|
||||||
"SectionInfo": null
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"LeftIdx": 0,
|
|
||||||
"RightIdx": 3,
|
|
||||||
"Type": 2,
|
|
||||||
"Content": "+ADD ./target/markov-demo-0.0.1-SNAPSHOT.jar /usr/local/markov-demo-0.0.1-SNAPSHOT.jar",
|
|
||||||
"Comments": null,
|
|
||||||
"SectionInfo": null
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"LeftIdx": 0,
|
|
||||||
"RightIdx": 4,
|
|
||||||
"Type": 2,
|
|
||||||
"Content": "+",
|
|
||||||
"Comments": null,
|
|
||||||
"SectionInfo": null
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"LeftIdx": 0,
|
|
||||||
"RightIdx": 5,
|
|
||||||
"Type": 2,
|
|
||||||
"Content": "+# Add docker-compose-wait tool -------------------",
|
|
||||||
"Comments": null,
|
|
||||||
"SectionInfo": null
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"LeftIdx": 0,
|
|
||||||
"RightIdx": 6,
|
|
||||||
"Type": 2,
|
|
||||||
"Content": "+ENV WAIT_VERSION 2.7.2",
|
|
||||||
"Comments": null,
|
|
||||||
"SectionInfo": null
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"LeftIdx": 0,
|
|
||||||
"RightIdx": 7,
|
|
||||||
"Type": 2,
|
|
||||||
"Content": "+ADD https://github.com/ufoscout/docker-compose-wait/releases/download/$WAIT_VERSION/wait /wait",
|
|
||||||
"Comments": null,
|
|
||||||
"SectionInfo": null
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"LeftIdx": 0,
|
|
||||||
"RightIdx": 8,
|
|
||||||
"Type": 2,
|
|
||||||
"Content": "+RUN chmod +x /wait",
|
|
||||||
"Comments": null,
|
|
||||||
"SectionInfo": null
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"LeftIdx": 0,
|
|
||||||
"RightIdx": 9,
|
|
||||||
"Type": 2,
|
|
||||||
"Content": "+",
|
|
||||||
"Comments": null,
|
|
||||||
"SectionInfo": null
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"LeftIdx": 0,
|
|
||||||
"RightIdx": 10,
|
|
||||||
"Type": 2,
|
|
||||||
"Content": "+EXPOSE 8080",
|
|
||||||
"Comments": null,
|
|
||||||
"SectionInfo": null
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"LeftIdx": 0,
|
|
||||||
"RightIdx": 11,
|
|
||||||
"Type": 2,
|
|
||||||
"Content": "+ENTRYPOINT [ \"java\", \"-jar\", \"/usr/local/markov-demo-0.0.1-SNAPSHOT.jar\" ]",
|
|
||||||
"Comments": null,
|
|
||||||
"SectionInfo": null
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
"IsIncomplete": false
|
|
||||||
}
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
---
|
---
|
||||||
|
@ -2549,7 +2466,7 @@ GET /api/:owner/:repo/pulls/:id/files.json
|
||||||
*示例*
|
*示例*
|
||||||
```
|
```
|
||||||
curl -X GET \
|
curl -X GET \
|
||||||
http://localhost:3000/api/Jason/repo/1/files.json | jq
|
http://localhost:3000/api/Jason/repo/pulls/1/files.json | jq
|
||||||
```
|
```
|
||||||
*请求参数说明:*
|
*请求参数说明:*
|
||||||
|
|
||||||
|
@ -2730,10 +2647,10 @@ GET /api/:owner/:repo/compare/{base}...{head}.json
|
||||||
*示例*
|
*示例*
|
||||||
```
|
```
|
||||||
curl -X GET \
|
curl -X GET \
|
||||||
http://localhost:3003/api/v1/repos/Jason/test-txt/compare/master...develop | jq
|
http://localhost:3000/api/Jason/test-txt/compare/master...develop | jq
|
||||||
|
|
||||||
curl -X GET \
|
curl -X GET \
|
||||||
http://localhost:3003/api/v1/repos/jasder/test-txt/compare/master...Jason/test-txt:develop
|
http://localhost:3000/api/ysfns/test-txt/compare/master...Jason/test-txt:develop
|
||||||
```
|
```
|
||||||
*请求参数说明:*
|
*请求参数说明:*
|
||||||
|
|
||||||
|
@ -2782,7 +2699,7 @@ http://localhost:3003/api/v1/repos/jasder/test-txt/compare/master...Jason/test-t
|
||||||
|---- lines |array||
|
|---- lines |array||
|
||||||
|------ leftIdx |string|文件变动之前所在行数|
|
|------ leftIdx |string|文件变动之前所在行数|
|
||||||
|------ rightIdx |string|文件更改后所在行数|
|
|------ rightIdx |string|文件更改后所在行数|
|
||||||
|------ type |string|文件变更类型,1: 新增,2: 修改, 3: 删除, 4: diff统计信息|
|
|------ type |string|文件变更类型,1: 内容未改动,2: 添加, 3: 删除, 4: diff统计信息|
|
||||||
|------ content |string|文件变更的内容|
|
|------ content |string|文件变更的内容|
|
||||||
|------ sectionInfo |object||
|
|------ sectionInfo |object||
|
||||||
|-------- path |string|文件相对仓库的路径|
|
|-------- path |string|文件相对仓库的路径|
|
||||||
|
@ -2791,7 +2708,7 @@ http://localhost:3003/api/v1/repos/jasder/test-txt/compare/master...Jason/test-t
|
||||||
|-------- leftHunkSize |int|文件变更之前的行数|
|
|-------- leftHunkSize |int|文件变更之前的行数|
|
||||||
|-------- rightHunkSize |int|文件变更之后的行数(及当前页面编辑器显示的总行数)|
|
|-------- rightHunkSize |int|文件变更之后的行数(及当前页面编辑器显示的总行数)|
|
||||||
|-------- leftIdx |int|文件变更之前所在行数|
|
|-------- leftIdx |int|文件变更之前所在行数|
|
||||||
|-------- rightIdx |int|文件变更之后所在行数(即:页面编辑器开始显示的行数)|
|
|-------- rightIdx |int|文件变更之后所在行数|
|
||||||
|
|
||||||
返回值
|
返回值
|
||||||
```json
|
```json
|
||||||
|
|
|
@ -82,11 +82,12 @@ class RepositoriesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def commit
|
def commit
|
||||||
@commit = Gitea::Repository::Commits::GetService.new(@repository.user.login, @repository.identifier, params[:sha], current_user.gitea_token).call
|
@commit = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, params[:sha], current_user.gitea_token)
|
||||||
|
@commit_diff = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, params[:sha], current_user.gitea_token, {diff: true})
|
||||||
end
|
end
|
||||||
|
|
||||||
def tags
|
def tags
|
||||||
@tags = Gitea::Repository::Tags::ListService.new(current_user&.gitea_token, @project.owner.login, @project.identifier, {page: params[:page], limit: params[:limit]}).call
|
@tags = Gitea::Repository::Tags::ListService.call(current_user&.gitea_token, @project.owner.login, @project.identifier, {page: params[:page], limit: params[:limit]})
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
# Get a single commit from a repository
|
# Get a single commit from a repository
|
||||||
class Gitea::Repository::Commits::GetService < Gitea::ClientService
|
class Gitea::Repository::Commits::GetService < Gitea::ClientService
|
||||||
attr_reader :token, :owner, :repo, :sha, :custom
|
attr_reader :token, :owner, :repo, :sha, :hash
|
||||||
|
|
||||||
# sha: the commit hash
|
# sha: the commit hash
|
||||||
# ex: Gitea::Repository::Commits::GetService.new(@repo.user.login, repo.identifier, params[:sha], current_user.gitea_token)
|
# ex: Gitea::Repository::Commits::GetService.new(@repo.user.login, repo.identifier, params[:sha], current_user.gitea_token)
|
||||||
# TODO custom参数用于判断调用哪个api
|
# TODO custom参数用于判断调用哪个api
|
||||||
def initialize(owner, repo, sha, token, custom=false)
|
def initialize(owner, repo, sha, token, hash={})
|
||||||
@token = token
|
@token = token
|
||||||
@owner = owner
|
@owner = owner
|
||||||
@sha = sha
|
@sha = sha
|
||||||
@repo = repo
|
@repo = repo
|
||||||
@custom = custom
|
@hash = hash
|
||||||
end
|
end
|
||||||
|
|
||||||
def call
|
def call
|
||||||
|
@ -24,10 +24,10 @@ class Gitea::Repository::Commits::GetService < Gitea::ClientService
|
||||||
end
|
end
|
||||||
|
|
||||||
def url
|
def url
|
||||||
if custom
|
if hash[:diff]
|
||||||
# TODO
|
# TODO
|
||||||
# 平台自己编写的gitea接口,后续可能会通过提交pr的形式合并到gitea原有的接口上
|
# 平台自己编写的gitea接口,后续可能会通过提交pr的形式合并到gitea原有的接口上
|
||||||
"/repos/#{owner}/#{repo}/commits/diff/#{sha}".freeze
|
"/repos/#{owner}/#{repo}/commits/#{sha}/diff".freeze
|
||||||
else
|
else
|
||||||
"/repos/#{owner}/#{repo}/git/commits/#{sha}".freeze
|
"/repos/#{owner}/#{repo}/git/commits/#{sha}".freeze
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,27 +1,11 @@
|
||||||
json.key_format! camelize: :lower
|
# json.key_format! camelize: :lower
|
||||||
json.additions @commit['commit_diff']['TotalAddition']
|
json.files_count @commit_diff['NumFiles']
|
||||||
json.deletions @commit['commit_diff']['TotalDeletion']
|
json.total_addition @commit_diff['TotalAddition']
|
||||||
json.sha @commit['sha']
|
json.total_deletion @commit_diff['TotalDeletion']
|
||||||
json.url request.url
|
json.files @commit_diff['Files'], partial: 'pull_requests/diff_file', as: :file
|
||||||
json.commit do
|
|
||||||
@commit['commit'].delete('url')
|
|
||||||
json.author @commit['commit']['author']
|
|
||||||
json.committer @commit['commit']['committer']
|
|
||||||
json.message @commit['commit']['message']
|
|
||||||
json.tree do
|
|
||||||
@commit['commit']['tree']['sha']
|
|
||||||
end
|
|
||||||
end
|
|
||||||
json.author do
|
|
||||||
json.partial! 'commit_author', user: render_commit_author(@commit['author'])
|
|
||||||
end
|
|
||||||
json.committer do
|
|
||||||
json.partial! 'commit_author', user: render_commit_author(@commit['committer'])
|
|
||||||
end
|
|
||||||
|
|
||||||
|
json.partial! 'commit', commit: @commit, project: @project
|
||||||
json.parents @commit['parents'] do |parent|
|
json.parents @commit['parents'] do |parent|
|
||||||
json.sha parent['sha']
|
json.sha parent['sha']
|
||||||
json.url EduSetting.get('host_name') + commit_repository_path(@repo, parent['sha'])
|
# json.url EduSetting.get('host_name') + commit_repository_path(@repo, parent['sha'])
|
||||||
end
|
end
|
||||||
|
|
||||||
json.files @commit['commit_diff']['Files']
|
|
||||||
|
|
Loading…
Reference in New Issue