feat: add /repos/{owner}/{repo}/git/trees/{tree_sha endpoint
This commit is contained in:
parent
c607400951
commit
d132946e40
|
@ -214,6 +214,42 @@ func convertCommitFile(file *gitea.ChangedFile) *github.CommitFile {
|
|||
}
|
||||
}
|
||||
|
||||
func convertGitTree(tree *gitea.GitTreeResponse) *github.Tree {
|
||||
if tree == nil {
|
||||
return &github.Tree{}
|
||||
}
|
||||
return &github.Tree{
|
||||
SHA: stringPtr(tree.SHA),
|
||||
Truncated: boolPtr(tree.Truncated),
|
||||
Entries: convertGitEntries(tree.Entries),
|
||||
}
|
||||
}
|
||||
|
||||
func convertGitEntries(entries []gitea.GitEntry) []*github.TreeEntry {
|
||||
if entries == nil {
|
||||
return make([]*github.TreeEntry, 0)
|
||||
}
|
||||
var ghEntries []*github.TreeEntry
|
||||
for _, entry := range entries {
|
||||
ghEntries = append(ghEntries, convertGitEntry(&entry))
|
||||
}
|
||||
return ghEntries
|
||||
}
|
||||
|
||||
func convertGitEntry(s *gitea.GitEntry) *github.TreeEntry {
|
||||
if s == nil {
|
||||
return &github.TreeEntry{}
|
||||
}
|
||||
return &github.TreeEntry{
|
||||
Path: stringPtr(s.Path),
|
||||
Mode: stringPtr(s.Mode),
|
||||
Type: stringPtr(s.Type),
|
||||
Size: intPtr(int(s.Size)),
|
||||
SHA: stringPtr(s.SHA),
|
||||
URL: stringPtr(s.URL),
|
||||
}
|
||||
}
|
||||
|
||||
func translatePrAction(action structs.HookIssueAction) string {
|
||||
translatedAction := ""
|
||||
|
||||
|
|
|
@ -134,6 +134,36 @@ func (r restApi) getClientOrError(w http.ResponseWriter) *gitea.Client {
|
|||
return client
|
||||
}
|
||||
|
||||
func (r restApi) handlerGetTree(w http.ResponseWriter, request *http.Request) {
|
||||
vars := mux.Vars(request)
|
||||
owner := vars["owner"]
|
||||
repo := vars["repo"]
|
||||
treeSha := vars["tree_sha"]
|
||||
recursive := false
|
||||
|
||||
if request.URL.Query().Has("recursive") {
|
||||
recursive = true
|
||||
}
|
||||
|
||||
client := r.getClientOrError(w)
|
||||
|
||||
if client == nil {
|
||||
return
|
||||
}
|
||||
|
||||
tree, r2, err := client.GetTrees(owner, repo, treeSha, recursive)
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to get tree", http.StatusInternalServerError)
|
||||
r.logger.Error("Failed to get tree", zap.Error(err))
|
||||
return
|
||||
}
|
||||
|
||||
treeResponse := convertGitTree(tree)
|
||||
|
||||
r.sendPagingHeaders(w, r2)
|
||||
r.respond(w, http.StatusOK, treeResponse)
|
||||
}
|
||||
|
||||
func setupRestRoutes(params RouteParams) {
|
||||
logger := params.Logger
|
||||
cfg := params.Config
|
||||
|
@ -143,6 +173,7 @@ func setupRestRoutes(params RouteParams) {
|
|||
|
||||
setupRoutes := func(r *mux.Router) {
|
||||
r.HandleFunc("/repos/{owner}/{repo}/pulls/{pull_number}/files", restApi.handlerGetPullRequestFiles).Methods("GET")
|
||||
r.HandleFunc("/repos/{owner}/{repo}/git/trees/{tree_sha}", restApi.handlerGetTree).Methods("GET")
|
||||
}
|
||||
|
||||
restRouter := r.PathPrefix("/api").Subrouter()
|
||||
|
|
Loading…
Reference in New Issue