更改: 返回旧版参数
This commit is contained in:
parent
5a5c6d062f
commit
7cc49acd7e
|
|
@ -2,15 +2,18 @@ package convert
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/organization"
|
"code.gitea.io/gitea/models/organization"
|
||||||
"code.gitea.io/gitea/models/repo"
|
"code.gitea.io/gitea/models/repo"
|
||||||
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
"code.gitea.io/gitea/models/webhook"
|
"code.gitea.io/gitea/models/webhook"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/modules/git"
|
"code.gitea.io/gitea/modules/git"
|
||||||
"code.gitea.io/gitea/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
gitea_convert "code.gitea.io/gitea/services/convert"
|
gitea_convert "code.gitea.io/gitea/services/convert"
|
||||||
|
"code.gitea.io/gitea/services/gitdiff"
|
||||||
api "code.gitlink.org.cn/Gitlink/gitea_hat.git/modules/structs"
|
api "code.gitlink.org.cn/Gitlink/gitea_hat.git/modules/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -92,3 +95,28 @@ func ToHookTask(t *webhook.HookTask) *api.HookTask {
|
||||||
ResponseContent: responseContent,
|
ResponseContent: responseContent,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ToChangedFile(f *gitdiff.DiffFile, repo *repo_model.Repository, commit string) *api.ChangedFile {
|
||||||
|
|
||||||
|
file := &api.ChangedFile{
|
||||||
|
Filename: f.GetDiffFileName(),
|
||||||
|
OldName: f.OldName,
|
||||||
|
Index: f.Index,
|
||||||
|
Type: f.Type,
|
||||||
|
IsBin: f.IsBin,
|
||||||
|
IsCreated: f.IsCreated,
|
||||||
|
IsDeleted: f.IsDeleted,
|
||||||
|
IsLFSFile: f.IsLFSFile,
|
||||||
|
IsRenamed: f.IsRenamed,
|
||||||
|
IsSubmodule: f.IsSubmodule,
|
||||||
|
Additions: f.Addition,
|
||||||
|
Deletions: f.Deletion,
|
||||||
|
Changes: f.Addition + f.Deletion,
|
||||||
|
Sha: commit,
|
||||||
|
HTMLURL: fmt.Sprint(repo.HTMLURL(), "/src/commit/", commit, "/", util.PathEscapeSegments(f.GetDiffFileName())),
|
||||||
|
ContentsURL: fmt.Sprint(repo.APIURL(), "/contents/", util.PathEscapeSegments(f.GetDiffFileName()), "?ref=", commit),
|
||||||
|
RawURL: fmt.Sprint(repo.HTMLURL(), "/raw/commit/", commit, "/", util.PathEscapeSegments(f.GetDiffFileName())),
|
||||||
|
}
|
||||||
|
|
||||||
|
return file
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
gitea_api "code.gitea.io/gitea/modules/structs"
|
gitea_api "code.gitea.io/gitea/modules/structs"
|
||||||
|
"code.gitea.io/gitea/services/gitdiff"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PullRequest struct {
|
type PullRequest struct {
|
||||||
|
|
@ -39,3 +40,23 @@ type PullRequest struct {
|
||||||
CommitNum int `json:"commit_num"`
|
CommitNum int `json:"commit_num"`
|
||||||
ChangedFiles int `json:"changed_files"`
|
ChangedFiles int `json:"changed_files"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ChangedFile struct {
|
||||||
|
Filename string `json:"filename"`
|
||||||
|
OldName string `json:"old_name"`
|
||||||
|
Index int `json:"index"`
|
||||||
|
Type gitdiff.DiffFileType `json:"type"`
|
||||||
|
IsBin bool `json:"is_bin"`
|
||||||
|
IsCreated bool `json:"is_created"`
|
||||||
|
IsDeleted bool `json:"is_deleted"`
|
||||||
|
IsLFSFile bool `json:"is_lfs_file"`
|
||||||
|
IsRenamed bool `json:"is_renamed"`
|
||||||
|
IsSubmodule bool `json:"is_submodule"`
|
||||||
|
Additions int `json:"additions"`
|
||||||
|
Deletions int `json:"deletions"`
|
||||||
|
Changes int `json:"changes"`
|
||||||
|
Sha string `json:"sha"`
|
||||||
|
HTMLURL string `json:"html_url,omitempty"`
|
||||||
|
ContentsURL string `json:"contents_url,omitempty"`
|
||||||
|
RawURL string `json:"raw_url,omitempty"`
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ import (
|
||||||
"code.gitea.io/gitea/services/gitdiff"
|
"code.gitea.io/gitea/services/gitdiff"
|
||||||
hat_convert "code.gitlink.org.cn/Gitlink/gitea_hat.git/modules/convert"
|
hat_convert "code.gitlink.org.cn/Gitlink/gitea_hat.git/modules/convert"
|
||||||
hat_git "code.gitlink.org.cn/Gitlink/gitea_hat.git/modules/git"
|
hat_git "code.gitlink.org.cn/Gitlink/gitea_hat.git/modules/git"
|
||||||
|
hat_api "code.gitlink.org.cn/Gitlink/gitea_hat.git/modules/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetAllCommitsSliceByTime(ctx *context.APIContext) {
|
func GetAllCommitsSliceByTime(ctx *context.APIContext) {
|
||||||
|
|
@ -358,11 +359,10 @@ func GetCommitFiles(ctx *context.APIContext) {
|
||||||
lenFiles = 0
|
lenFiles = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
apiFiles := make([]*api.ChangedFile, 0, lenFiles)
|
apiFiles := make([]*hat_api.ChangedFile, 0, lenFiles)
|
||||||
for i := start; i < end; i++ {
|
for i := start; i < end; i++ {
|
||||||
apiFiles = append(apiFiles, convert.ToChangedFile(diff.Files[i], ctx.Repo.Repository, commitID))
|
apiFiles = append(apiFiles, hat_convert.ToChangedFile(diff.Files[i], ctx.Repo.Repository, commitID))
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.SetLinkHeader(totalNumberOfFiles, listOptions.PageSize)
|
ctx.SetLinkHeader(totalNumberOfFiles, listOptions.PageSize)
|
||||||
ctx.SetTotalCountHeader(int64(totalNumberOfFiles))
|
ctx.SetTotalCountHeader(int64(totalNumberOfFiles))
|
||||||
|
|
||||||
|
|
@ -372,7 +372,15 @@ func GetCommitFiles(ctx *context.APIContext) {
|
||||||
ctx.RespHeader().Set("X-HasMore", strconv.FormatBool(listOptions.Page < totalNumberOfPages))
|
ctx.RespHeader().Set("X-HasMore", strconv.FormatBool(listOptions.Page < totalNumberOfPages))
|
||||||
ctx.AppendAccessControlExposeHeaders("X-Page", "X-PerPage", "X-PageCount", "X-HasMore")
|
ctx.AppendAccessControlExposeHeaders("X-Page", "X-PerPage", "X-PageCount", "X-HasMore")
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, &apiFiles)
|
ctx.JSON(http.StatusOK, struct {
|
||||||
|
Files []*hat_api.ChangedFile `json:"files"`
|
||||||
|
TotalAddition int `json:"total_addition"`
|
||||||
|
TotalDeletion int `json:"total_deletion"`
|
||||||
|
}{
|
||||||
|
Files: apiFiles,
|
||||||
|
TotalAddition: diff.TotalAddition,
|
||||||
|
TotalDeletion: diff.TotalDeletion,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetCommitFilesByPath(ctx *context.APIContext) {
|
func GetCommitFilesByPath(ctx *context.APIContext) {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,9 @@ package repo
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -14,6 +16,7 @@ import (
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
"code.gitea.io/gitea/models/unit"
|
"code.gitea.io/gitea/models/unit"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
|
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||||
"code.gitea.io/gitea/services/gitdiff"
|
"code.gitea.io/gitea/services/gitdiff"
|
||||||
|
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
|
|
@ -28,6 +31,7 @@ import (
|
||||||
notify_service "code.gitea.io/gitea/services/notify"
|
notify_service "code.gitea.io/gitea/services/notify"
|
||||||
pull_service "code.gitea.io/gitea/services/pull"
|
pull_service "code.gitea.io/gitea/services/pull"
|
||||||
hat_convert "code.gitlink.org.cn/Gitlink/gitea_hat.git/modules/convert"
|
hat_convert "code.gitlink.org.cn/Gitlink/gitea_hat.git/modules/convert"
|
||||||
|
hat_api "code.gitlink.org.cn/Gitlink/gitea_hat.git/modules/structs"
|
||||||
hat_pull_service "code.gitlink.org.cn/Gitlink/gitea_hat.git/services/pull"
|
hat_pull_service "code.gitlink.org.cn/Gitlink/gitea_hat.git/services/pull"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -391,16 +395,59 @@ func GetPullFiles(ctx *context.APIContext) {
|
||||||
ctx.ServerError("GetDiff", err)
|
ctx.ServerError("GetDiff", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
isNew := ctx.FormString("isNew")
|
||||||
|
if isNew != "" {
|
||||||
|
listOptions := utils.GetListOptions(ctx)
|
||||||
|
|
||||||
fileDiff := struct {
|
totalNumberOfFiles := diff.NumFiles
|
||||||
*gitdiff.Diff
|
totalNumberOfPages := int(math.Ceil(float64(totalNumberOfFiles) / float64(listOptions.PageSize)))
|
||||||
LatestSha string
|
|
||||||
}{
|
start, end := listOptions.GetStartEnd()
|
||||||
Diff: diff,
|
|
||||||
LatestSha: endCommitID,
|
if end > totalNumberOfFiles {
|
||||||
|
end = totalNumberOfFiles
|
||||||
|
}
|
||||||
|
|
||||||
|
lenFiles := end - start
|
||||||
|
if lenFiles < 0 {
|
||||||
|
lenFiles = 0
|
||||||
|
}
|
||||||
|
apiFiles := make([]*hat_api.ChangedFile, 0, lenFiles)
|
||||||
|
for i := start; i < end; i++ {
|
||||||
|
apiFiles = append(apiFiles, hat_convert.ToChangedFile(diff.Files[i], ctx.Repo.Repository, headCommitID))
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.SetLinkHeader(totalNumberOfFiles, listOptions.PageSize)
|
||||||
|
ctx.SetTotalCountHeader(int64(totalNumberOfFiles))
|
||||||
|
|
||||||
|
ctx.RespHeader().Set("X-Page", strconv.Itoa(listOptions.Page))
|
||||||
|
ctx.RespHeader().Set("X-PerPage", strconv.Itoa(listOptions.PageSize))
|
||||||
|
ctx.RespHeader().Set("X-PageCount", strconv.Itoa(totalNumberOfPages))
|
||||||
|
ctx.RespHeader().Set("X-HasMore", strconv.FormatBool(listOptions.Page < totalNumberOfPages))
|
||||||
|
ctx.AppendAccessControlExposeHeaders("X-Page", "X-PerPage", "X-PageCount", "X-HasMore")
|
||||||
|
ctx.JSON(http.StatusOK, struct {
|
||||||
|
Files []*hat_api.ChangedFile `json:"files"`
|
||||||
|
TotalAddition int `json:"total_addition"`
|
||||||
|
TotalDeletion int `json:"total_deletion"`
|
||||||
|
}{
|
||||||
|
Files: apiFiles,
|
||||||
|
TotalAddition: diff.TotalAddition,
|
||||||
|
TotalDeletion: diff.TotalDeletion,
|
||||||
|
})
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
fileDiff := struct {
|
||||||
|
*gitdiff.Diff
|
||||||
|
LatestSha string
|
||||||
|
}{
|
||||||
|
Diff: diff,
|
||||||
|
LatestSha: endCommitID,
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.JSON(http.StatusOK, fileDiff)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, fileDiff)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPullFilesByPath(ctx *context.APIContext) {
|
func GetPullFilesByPath(ctx *context.APIContext) {
|
||||||
|
|
|
||||||
|
|
@ -19,11 +19,11 @@ import (
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
repo_module "code.gitea.io/gitea/modules/repository"
|
repo_module "code.gitea.io/gitea/modules/repository"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
|
||||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||||
"code.gitea.io/gitea/services/convert"
|
|
||||||
"code.gitea.io/gitea/services/gitdiff"
|
"code.gitea.io/gitea/services/gitdiff"
|
||||||
|
hat_convert "code.gitlink.org.cn/Gitlink/gitea_hat.git/modules/convert"
|
||||||
hat_git "code.gitlink.org.cn/Gitlink/gitea_hat.git/modules/git"
|
hat_git "code.gitlink.org.cn/Gitlink/gitea_hat.git/modules/git"
|
||||||
|
hat_api "code.gitlink.org.cn/Gitlink/gitea_hat.git/modules/structs"
|
||||||
hat_repo_service "code.gitlink.org.cn/Gitlink/gitea_hat.git/services/repository"
|
hat_repo_service "code.gitlink.org.cn/Gitlink/gitea_hat.git/services/repository"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -179,9 +179,9 @@ func CompareFiles(ctx *context.APIContext) {
|
||||||
lenFiles = 0
|
lenFiles = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
apiFiles := make([]*api.ChangedFile, 0, lenFiles)
|
apiFiles := make([]*hat_api.ChangedFile, 0, lenFiles)
|
||||||
for i := start; i < end; i++ {
|
for i := start; i < end; i++ {
|
||||||
apiFiles = append(apiFiles, convert.ToChangedFile(diff.Files[i], ctx.Repo.Repository, headCommitID))
|
apiFiles = append(apiFiles, hat_convert.ToChangedFile(diff.Files[i], ctx.Repo.Repository, headCommitID))
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.SetLinkHeader(totalNumberOfFiles, listOptions.PageSize)
|
ctx.SetLinkHeader(totalNumberOfFiles, listOptions.PageSize)
|
||||||
|
|
@ -193,7 +193,15 @@ func CompareFiles(ctx *context.APIContext) {
|
||||||
ctx.RespHeader().Set("X-HasMore", strconv.FormatBool(listOptions.Page < totalNumberOfPages))
|
ctx.RespHeader().Set("X-HasMore", strconv.FormatBool(listOptions.Page < totalNumberOfPages))
|
||||||
ctx.AppendAccessControlExposeHeaders("X-Page", "X-PerPage", "X-PageCount", "X-HasMore")
|
ctx.AppendAccessControlExposeHeaders("X-Page", "X-PerPage", "X-PageCount", "X-HasMore")
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, &apiFiles)
|
ctx.JSON(http.StatusOK, struct {
|
||||||
|
Files []*hat_api.ChangedFile `json:"files"`
|
||||||
|
TotalAddition int `json:"total_addition"`
|
||||||
|
TotalDeletion int `json:"total_deletion"`
|
||||||
|
}{
|
||||||
|
Files: apiFiles,
|
||||||
|
TotalAddition: diff.TotalAddition,
|
||||||
|
TotalDeletion: diff.TotalDeletion,
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -253,7 +261,7 @@ func ParseCompareInfo(ctx *context.APIContext) (*user_model.User, *repo_model.Re
|
||||||
if shaFrom == "" || shaTo == "" {
|
if shaFrom == "" || shaTo == "" {
|
||||||
infos = []string{baseRepo.DefaultBranch, baseRepo.DefaultBranch}
|
infos = []string{baseRepo.DefaultBranch, baseRepo.DefaultBranch}
|
||||||
} else {
|
} else {
|
||||||
infos = []string{shaFrom, shaTo}
|
infos = []string{shaTo, shaFrom}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Data["BaseName"] = baseRepo.OwnerName
|
ctx.Data["BaseName"] = baseRepo.OwnerName
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue