forked from Gitlink/gitea-1120-rc1
Compare commits
33 Commits
hh_wmh_dev
...
master
Author | SHA1 | Date |
---|---|---|
|
3e9b0dc1c5 | |
|
de0f7764c7 | |
|
15882844c6 | |
|
d78a760be7 | |
|
06dd55c49f | |
|
9ee3486d44 | |
|
52232e2431 | |
|
c37047eeaf | |
|
bfbd16b7df | |
|
b82b5bf80b | |
|
796c78996b | |
|
705694ff88 | |
|
6270454d59 | |
|
04f3e061cb | |
|
8f47d8df52 | |
|
dfc39ebda0 | |
|
ad3ccfb22f | |
|
4e0a133712 | |
|
9f80111504 | |
|
20c13e8352 | |
|
71df4fdfa1 | |
|
20e2cb271e | |
|
fdfe572500 | |
|
86fb4bb8d8 | |
|
0c897c660f | |
|
2b54b5c39a | |
|
9d53ff793b | |
|
3072fc7e4e | |
|
b228c9f602 | |
|
94d7873f11 | |
|
a22ccad9f9 | |
|
30537e038a | |
|
611e58f5ae |
|
@ -96,6 +96,7 @@ func (r *Release) APIFormat() *api.Release {
|
|||
TagName: r.TagName,
|
||||
Target: r.Target,
|
||||
Title: r.Title,
|
||||
Sha1: r.Sha1,
|
||||
Note: r.Note,
|
||||
URL: r.APIURL(),
|
||||
HTMLURL: r.HTMLURL(),
|
||||
|
|
|
@ -278,7 +278,28 @@ func (ctx *APIContext) FileNameError(objs ...interface{}){
|
|||
"errors": errors,
|
||||
})
|
||||
}
|
||||
func (ctx *APIContext) SameFileNameError(objs ...interface{}){
|
||||
var message = "Same name exists"
|
||||
var errors []string
|
||||
|
||||
for _, obj := range objs {
|
||||
// Ignore nil
|
||||
if obj == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if err, ok := obj.(error); ok {
|
||||
errors = append(errors, err.Error())
|
||||
} else {
|
||||
message = obj.(string)
|
||||
}
|
||||
}
|
||||
ctx.JSON(500, map[string]interface{}{
|
||||
"message": message,
|
||||
"documentation_url": setting.API.SwaggerURL,
|
||||
"errors": errors,
|
||||
})
|
||||
}
|
||||
|
||||
func (ctx *APIContext) FileExistError(objs ...interface{}){
|
||||
var message = "file does not exist"
|
||||
|
|
|
@ -30,8 +30,19 @@ func ToEmail(email *models.EmailAddress) *api.Email {
|
|||
}
|
||||
}
|
||||
|
||||
type BranchKind int
|
||||
|
||||
const (
|
||||
None BranchKind = iota
|
||||
DefaultBranch
|
||||
ProtectedBranch
|
||||
OtherBranch
|
||||
)
|
||||
|
||||
// ToBranch convert a git.Commit and git.Branch to an api.Branch
|
||||
func ToBranch(repo *models.Repository, b *git.Branch, c *git.Commit, bp *models.ProtectedBranch, user *models.User, isRepoAdmin bool) (*api.Branch, error) {
|
||||
|
||||
var branchKind BranchKind
|
||||
if bp == nil {
|
||||
var hasPerm bool
|
||||
var err error
|
||||
|
@ -41,9 +52,15 @@ func ToBranch(repo *models.Repository, b *git.Branch, c *git.Commit, bp *models.
|
|||
return nil, err
|
||||
}
|
||||
}
|
||||
if b.Name == repo.DefaultBranch {
|
||||
branchKind = DefaultBranch
|
||||
} else {
|
||||
branchKind = OtherBranch
|
||||
}
|
||||
|
||||
return &api.Branch{
|
||||
Name: b.Name,
|
||||
CommitID: c.ID.String(), //add configure
|
||||
Commit: ToCommit(repo, c),
|
||||
Protected: false,
|
||||
RequiredApprovals: 0,
|
||||
|
@ -51,16 +68,28 @@ func ToBranch(repo *models.Repository, b *git.Branch, c *git.Commit, bp *models.
|
|||
StatusCheckContexts: []string{},
|
||||
UserCanPush: hasPerm,
|
||||
UserCanMerge: hasPerm,
|
||||
CommitTime: c.Author.When.Format(time.RFC3339),
|
||||
DefaultBranch: repo.DefaultBranch,
|
||||
BranchKind: int(branchKind),
|
||||
}, nil
|
||||
}
|
||||
if b.Name == repo.DefaultBranch {
|
||||
branchKind = DefaultBranch
|
||||
} else {
|
||||
branchKind = ProtectedBranch
|
||||
}
|
||||
|
||||
branch := &api.Branch{
|
||||
Name: b.Name,
|
||||
CommitID: c.ID.String(), // add configure
|
||||
Commit: ToCommit(repo, c),
|
||||
Protected: true,
|
||||
RequiredApprovals: bp.RequiredApprovals,
|
||||
EnableStatusCheck: bp.EnableStatusCheck,
|
||||
StatusCheckContexts: bp.StatusCheckContexts,
|
||||
CommitTime: c.Author.When.Format(time.RFC3339),
|
||||
DefaultBranch: repo.DefaultBranch,
|
||||
BranchKind: int(branchKind),
|
||||
}
|
||||
|
||||
if isRepoAdmin {
|
||||
|
@ -129,16 +158,42 @@ func ToBranchProtection(bp *models.ProtectedBranch) *api.BranchProtection {
|
|||
}
|
||||
|
||||
// ToTag convert a git.Tag to an api.Tag
|
||||
// func ToTag(repo *models.Repository, t *git.Tag) *api.Tag {
|
||||
// return &api.Tag{
|
||||
// Name: t.Name,
|
||||
// ID: t.ID.String(),
|
||||
// Commit: ToCommitMeta(repo, t),
|
||||
// ZipballURL: util.URLJoin(repo.HTMLURL(), "archive", t.Name+".zip"),
|
||||
// TarballURL: util.URLJoin(repo.HTMLURL(), "archive", t.Name+".tar.gz"),
|
||||
// }
|
||||
// }
|
||||
|
||||
func ToTag(repo *models.Repository, t *git.Tag) *api.Tag {
|
||||
return &api.Tag{
|
||||
Name: t.Name,
|
||||
ID: t.ID.String(),
|
||||
Commit: ToCommitMeta(repo, t),
|
||||
Commit: ToTagCommit(repo, t),
|
||||
Tagger: ToCommitUser(t.Tagger),
|
||||
Message: t.Message,
|
||||
ZipballURL: util.URLJoin(repo.HTMLURL(), "archive", t.Name+".zip"),
|
||||
TarballURL: util.URLJoin(repo.HTMLURL(), "archive", t.Name+".tar.gz"),
|
||||
}
|
||||
}
|
||||
|
||||
func ToTagCommit(repo *models.Repository, t *git.Tag) *api.TagCommit {
|
||||
commit, err := t.Commit()
|
||||
if err != nil {
|
||||
log.Error("Commit", err)
|
||||
return &api.TagCommit{}
|
||||
}
|
||||
return &api.TagCommit{
|
||||
CommitMeta: ToCommitMeta(repo, t),
|
||||
Commiter: ToCommitUser(commit.Committer),
|
||||
Author: ToCommitUser(commit.Author),
|
||||
Message: commit.CommitMessage,
|
||||
}
|
||||
}
|
||||
|
||||
// ToCommit convert a git.Commit to api.PayloadCommit
|
||||
func ToCommit(repo *models.Repository, c *git.Commit) *api.PayloadCommit {
|
||||
authorUsername := ""
|
||||
|
@ -424,6 +479,16 @@ func ToCommitMeta(repo *models.Repository, tag *git.Tag) *api.CommitMeta {
|
|||
}
|
||||
}
|
||||
|
||||
func ToCommitUserFolk(user *models.User) *api.CommitUser {
|
||||
return &api.CommitUser{
|
||||
Identity: api.Identity{
|
||||
Name: user.Name,
|
||||
Email: user.Email,
|
||||
},
|
||||
Date: user.CreatedUnix.AsTime().String(),
|
||||
}
|
||||
}
|
||||
|
||||
// ToTopicResponse convert from models.Topic to api.TopicResponse
|
||||
func ToTopicResponse(topic *models.Topic) *api.TopicResponse {
|
||||
return &api.TopicResponse{
|
||||
|
|
|
@ -5,7 +5,10 @@
|
|||
package convert
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/structs"
|
||||
|
||||
)
|
||||
|
||||
// ToCorrectPageSize makes sure page size is in allowed range.
|
||||
|
@ -17,3 +20,36 @@ func ToCorrectPageSize(size int) int {
|
|||
}
|
||||
return size
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ToGitServiceType return GitServiceType based on string
|
||||
func ToGitServiceType(value string) structs.GitServiceType {
|
||||
switch strings.ToLower(value) {
|
||||
case "github":
|
||||
return structs.GithubService
|
||||
case "gitea":
|
||||
return structs.GiteaService
|
||||
case "gitlab":
|
||||
return structs.GitlabService
|
||||
case "gogs":
|
||||
return structs.GogsService
|
||||
default:
|
||||
return structs.PlainGitService
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
func ToBranchType(index int) structs.BranchKind{
|
||||
switch(index){
|
||||
case 1:
|
||||
return structs.DefaultBranch
|
||||
case 2:
|
||||
return structs.ProtectedBranch
|
||||
case 3:
|
||||
return structs.OtherBranch
|
||||
default:
|
||||
return structs.None
|
||||
}
|
||||
}
|
|
@ -293,6 +293,11 @@ func CommitsCount(repoPath, revision string) (int64, error) {
|
|||
return commitsCount(repoPath, []string{revision}, []string{})
|
||||
}
|
||||
|
||||
// CommitsCountByFile returns number of total commits of unitl given revision and file
|
||||
func CommitsCountByFile(repoPath, revision, file string) (int64, error) {
|
||||
return commitsCount(repoPath, []string{revision}, []string{file})
|
||||
}
|
||||
|
||||
// CommitsCount returns number of total commits of until current revision.
|
||||
func (c *Commit) CommitsCount() (int64, error) {
|
||||
return CommitsCount(c.repo.Path, c.ID.String())
|
||||
|
@ -303,6 +308,11 @@ func (c *Commit) CommitsByRange(page, pageSize int) (*list.List, error) {
|
|||
return c.repo.commitsByRange(c.ID, page, pageSize)
|
||||
}
|
||||
|
||||
// CommitsByFileAndRange returns the specific page page commits before current revision and file, every page's number default by CommitsRangeSize
|
||||
func (c *Commit) CommitsByFileAndRange(file string, page, pageSize int) (*list.List, error) {
|
||||
return c.repo.CommitsByFileAndRange(c.ID.String(), file, page, pageSize)
|
||||
}
|
||||
|
||||
// CommitsBefore returns all the commits before current revision
|
||||
func (c *Commit) CommitsBefore() (*list.List, error) {
|
||||
return c.repo.getCommitsBefore(c.ID)
|
||||
|
|
|
@ -335,8 +335,8 @@ func (repo *Repository) FileCommitsCount(revision, file string) (int64, error) {
|
|||
}
|
||||
|
||||
// CommitsByFileAndRange return the commits according revison file and the page
|
||||
func (repo *Repository) CommitsByFileAndRange(revision, file string, page int) (*list.List, error) {
|
||||
stdout, err := NewCommand("log", revision, "--follow", "--skip="+strconv.Itoa((page-1)*50),
|
||||
func (repo *Repository) CommitsByFileAndRange(revision, file string, page, pageSize int) (*list.List, error) {
|
||||
stdout, err := NewCommand("log", revision, "--follow", "--skip="+strconv.Itoa((page-1)*pageSize),
|
||||
"--max-count="+strconv.Itoa(CommitsRangeSize), prettyLogFormat, "--", file).RunInDirBytes(repo.Path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -345,8 +345,8 @@ func (repo *Repository) CommitsByFileAndRange(revision, file string, page int) (
|
|||
}
|
||||
|
||||
// CommitsByFileAndRangeNoFollow return the commits according revison file and the page
|
||||
func (repo *Repository) CommitsByFileAndRangeNoFollow(revision, file string, page int) (*list.List, error) {
|
||||
stdout, err := NewCommand("log", revision, "--skip="+strconv.Itoa((page-1)*50),
|
||||
func (repo *Repository) CommitsByFileAndRangeNoFollow(revision, file string, page, pageSize int) (*list.List, error) {
|
||||
stdout, err := NewCommand("log", revision, "--skip="+strconv.Itoa((page-1)*pageSize),
|
||||
"--max-count="+strconv.Itoa(CommitsRangeSize), prettyLogFormat, "--", file).RunInDirBytes(repo.Path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -186,6 +186,16 @@ func (repo *Repository) GetTag(name string) (*Tag, error) {
|
|||
return tag, nil
|
||||
}
|
||||
|
||||
func (repo *Repository) GetTagCount() (int64, error) {
|
||||
stdout, err := NewCommand("tag").RunInDir(repo.Path)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
tagNames := strings.Split(strings.TrimRight(stdout, "\n"), "\n")
|
||||
return int64(len(tagNames)), nil
|
||||
}
|
||||
|
||||
// GetTagInfos returns all tag infos of the repository.
|
||||
func (repo *Repository) GetTagInfos(page, pageSize int) ([]*Tag, error) {
|
||||
// TODO this a slow implementation, makes one git command per tag
|
||||
|
|
|
@ -1,3 +1,11 @@
|
|||
/*
|
||||
* @Description: Do not edit
|
||||
* @Date: 2021-07-09 10:47:30
|
||||
* @LastEditors: viletyy
|
||||
* @Author: viletyy
|
||||
* @LastEditTime: 2021-09-27 16:46:33
|
||||
* @FilePath: /gitea-1120-rc1/modules/structs/release.go
|
||||
*/
|
||||
// Copyright 2016 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
@ -14,6 +22,7 @@ type Release struct {
|
|||
TagName string `json:"tag_name"`
|
||||
Target string `json:"target_commitish"`
|
||||
Title string `json:"name"`
|
||||
Sha1 string `json:"sha"`
|
||||
Note string `json:"body"`
|
||||
URL string `json:"url"`
|
||||
HTMLURL string `json:"html_url"`
|
||||
|
|
|
@ -5,12 +5,14 @@
|
|||
package structs
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Branch represents a repository branch
|
||||
type Branch struct {
|
||||
Name string `json:"name"`
|
||||
CommitID string `json:"commit_id"` // add configure
|
||||
Commit *PayloadCommit `json:"commit"`
|
||||
Protected bool `json:"protected"`
|
||||
RequiredApprovals int64 `json:"required_approvals"`
|
||||
|
@ -19,7 +21,56 @@ type Branch struct {
|
|||
UserCanPush bool `json:"user_can_push"`
|
||||
UserCanMerge bool `json:"user_can_merge"`
|
||||
EffectiveBranchProtectionName string `json:"effective_branch_protection_name"`
|
||||
CommitTime string `json:"commit_time"` // add configure
|
||||
DefaultBranch string `json:"default_branch"`
|
||||
BranchKind int `json:"branch_kind"`
|
||||
}
|
||||
type BranchKind int
|
||||
const (
|
||||
|
||||
None BranchKind = iota
|
||||
DefaultBranch
|
||||
ProtectedBranch
|
||||
OtherBranch
|
||||
)
|
||||
func (bk BranchKind) Name() string{
|
||||
return strings.ToLower(bk.Title())
|
||||
}
|
||||
func (bk BranchKind) Title() string {
|
||||
switch bk {
|
||||
case DefaultBranch:
|
||||
return "default"
|
||||
case ProtectedBranch:
|
||||
return "protected"
|
||||
case OtherBranch:
|
||||
return "other"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type BranchesSlice struct {
|
||||
|
||||
BranchName string `json:"branch_name"`
|
||||
// BranchKind int `json:"branch_kind"`
|
||||
Branches []Branch `json:"branches"`
|
||||
}
|
||||
|
||||
// sort by branchkind
|
||||
type SortBranch []Branch
|
||||
func (s SortBranch) Len() int { return len(s) }
|
||||
func (s SortBranch) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
func (s SortBranch) Less(i, j int) bool { return s[i].BranchKind < s[j].BranchKind}
|
||||
|
||||
// sort by CommiTime of the branch
|
||||
type SortBranchTime []Branch
|
||||
func (s SortBranchTime) Len() int { return len(s) }
|
||||
func (s SortBranchTime) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
func (s SortBranchTime) Less(i, j int) bool { return s[i].CommitTime > s[j].CommitTime}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// BranchProtection represents a branch protection for a repository
|
||||
type BranchProtection struct {
|
||||
|
|
|
@ -1,3 +1,11 @@
|
|||
/*
|
||||
* @Description: Do not edit
|
||||
* @Date: 2021-09-07 17:24:32
|
||||
* @LastEditors: viletyy
|
||||
* @Author: viletyy
|
||||
* @LastEditTime: 2021-09-29 10:16:48
|
||||
* @FilePath: /gitea-1120-rc1/modules/structs/repo_commit.go
|
||||
*/
|
||||
// Copyright 2018 The Gogs Authors. All rights reserved.
|
||||
// Copyright 2019 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
|
@ -38,6 +46,7 @@ type RepoCommit struct {
|
|||
}
|
||||
|
||||
// Commit contains information generated from a Git commit.
|
||||
type SortCommit []Commit
|
||||
type Commit struct {
|
||||
*CommitMeta
|
||||
HTMLURL string `json:"html_url"`
|
||||
|
@ -45,8 +54,19 @@ type Commit struct {
|
|||
Author *User `json:"author"`
|
||||
Committer *User `json:"committer"`
|
||||
Parents []*CommitMeta `json:"parents"`
|
||||
CommitDate string `json:"commit_date"`
|
||||
Branch string `json:"branch"`
|
||||
}
|
||||
|
||||
type CommitsSlice struct {
|
||||
CommitDate string `json:"commit_date"`
|
||||
Commits []Commit
|
||||
}
|
||||
|
||||
func (s SortCommit) Len() int { return len(s) }
|
||||
func (s SortCommit) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
func (s SortCommit) Less(i, j int) bool { return s[i].CommitDate > s[j].CommitDate }
|
||||
|
||||
// CommitDateOptions store dates for GIT_AUTHOR_DATE and GIT_COMMITTER_DATE
|
||||
type CommitDateOptions struct {
|
||||
// swagger:strfmt date-time
|
||||
|
|
|
@ -1,3 +1,11 @@
|
|||
/*
|
||||
* @Description: Do not edit
|
||||
* @Date: 2021-09-23 17:10:03
|
||||
* @LastEditors: viletyy
|
||||
* @Author: viletyy
|
||||
* @LastEditTime: 2021-09-24 17:45:38
|
||||
* @FilePath: /gitea-1120-rc1/modules/structs/repo_tag.go
|
||||
*/
|
||||
// Copyright 2019 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
@ -8,11 +16,20 @@ package structs
|
|||
type Tag struct {
|
||||
Name string `json:"name"`
|
||||
ID string `json:"id"`
|
||||
Commit *CommitMeta `json:"commit"`
|
||||
Commit *TagCommit `json:"commit"`
|
||||
Tagger *CommitUser `json:"tagger"`
|
||||
Message string `json:"message"`
|
||||
ZipballURL string `json:"zipball_url"`
|
||||
TarballURL string `json:"tarball_url"`
|
||||
}
|
||||
|
||||
type TagCommit struct {
|
||||
*CommitMeta
|
||||
Commiter *CommitUser `json:"commiter"`
|
||||
Author *CommitUser `json:"author"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// AnnotatedTag represents an annotated tag
|
||||
type AnnotatedTag struct {
|
||||
Tag string `json:"tag"`
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
/*
|
||||
* @Date: 2021-08-06 14:28:55
|
||||
* @LastEditors: viletyy
|
||||
* @LastEditTime: 2021-08-06 16:33:20
|
||||
* @LastEditTime: 2021-08-19 18:00:34
|
||||
* @FilePath: /gitea-1120-rc1/modules/structs/wiki.go
|
||||
*/
|
||||
package structs
|
||||
|
||||
type WikiesResponse struct {
|
||||
When int64 `json:"when"`
|
||||
type WikiesResponse struct {
|
||||
WikiMeta
|
||||
WikiCloneLink CloneLink `json:"wiki_clone_link"`
|
||||
WikiCloneLink CloneLink `json:"wiki_clone_link"`
|
||||
}
|
||||
|
||||
type WikiMeta struct {
|
||||
Name string `json:"name"`
|
||||
Commit WikiCommit `json:"commit"`
|
||||
Name string `json:"name"`
|
||||
Commit WikiCommit `json:"commit"`
|
||||
FirstCommit WikiCommit `json:"-"`
|
||||
//WikiCloneLink CloneLink `json:"wiki_clone_link"`
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ type WikiCommit struct {
|
|||
ID string `json:"id"`
|
||||
Message string `json:"message"`
|
||||
Author WikiUser `json:"author"`
|
||||
Commiter WikiUser `json:"commiter"`
|
||||
Commiter WikiUser `json:"-"`
|
||||
}
|
||||
|
||||
type WikiUser struct {
|
||||
|
@ -32,13 +32,11 @@ type WikiUser struct {
|
|||
}
|
||||
|
||||
type WikiResponse struct {
|
||||
RepoName string `json:"repo_name"`
|
||||
OwnerName string `json:"owner_name"`
|
||||
WikiMeta
|
||||
CommitCounts int64 `json:"commit_counts"`
|
||||
MdContent string `json:"md_content"`
|
||||
SimpleContent string `json:"simple_content"`
|
||||
WikiCloneLink CloneLink `json:"wiki_clone_link"`
|
||||
CommitCounts int64 `json:"commit_counts"`
|
||||
MdContent string `json:"md_content"`
|
||||
SimpleContent string `json:"simple_content"`
|
||||
WikiCloneLink CloneLink `json:"wiki_clone_link"`
|
||||
}
|
||||
|
||||
type WikiOption struct {
|
||||
|
@ -47,6 +45,6 @@ type WikiOption struct {
|
|||
CommitMessage string `json:"commit_message"`
|
||||
}
|
||||
type CloneLink struct {
|
||||
SSH string `json:"ssh"`
|
||||
HTTPS string `json:"https"`
|
||||
SSH string `json:"ssh"`
|
||||
HTTPS string `json:"https"`
|
||||
}
|
||||
|
|
|
@ -1,23 +1,26 @@
|
|||
/*
|
||||
* @Date: 2021-08-06 09:53:43
|
||||
* @LastEditors: viletyy
|
||||
* @LastEditTime: 2021-08-06 16:55:28
|
||||
* @LastEditTime: 2021-08-19 17:58:21
|
||||
* @FilePath: /gitea-1120-rc1/modules/wikies/wiki.go
|
||||
*/
|
||||
package wikies
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
repo_module "code.gitea.io/gitea/modules/repository"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/sync"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
"fmt"
|
||||
"github.com/unknwon/com"
|
||||
|
||||
//"github.com/unknwon/com"
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
//"code.gitea.io/gitea/modules/wikies"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
|
@ -25,14 +28,11 @@ import (
|
|||
wiki_service "code.gitea.io/gitea/services/wiki"
|
||||
)
|
||||
|
||||
|
||||
|
||||
var (
|
||||
reservedWikiNames = []string{"_pages", "_new", "_edit", "raw"}
|
||||
wikiWorkingPool = sync.NewExclusivePool()
|
||||
)
|
||||
|
||||
|
||||
func nameAllowed(name string) error {
|
||||
if util.IsStringInSlice(name, reservedWikiNames) {
|
||||
return models.ErrWikiReservedName{
|
||||
|
@ -54,7 +54,6 @@ func InitWiki(repo *models.Repository) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
|
||||
func FindWikiRepoCommit(ctx *context.APIContext) (*git.Repository, *git.Commit, error) {
|
||||
wikiRepo, err := git.OpenRepository(ctx.Repo.Repository.WikiPath())
|
||||
if err != nil {
|
||||
|
@ -113,14 +112,12 @@ func wikiContentsByEntry(ctx *context.APIContext, entry *git.TreeEntry) []byte {
|
|||
return content
|
||||
}
|
||||
|
||||
|
||||
func CreateWikiPage(doer *models.User, repo *models.Repository, wikiName, content, message string) error {
|
||||
return updateWikiPage(doer, repo, "", wikiName, content, message, true)
|
||||
}
|
||||
|
||||
|
||||
func EditWikiPage(doer *models.User, repo *models.Repository, oldWikiName,newWikiName, content, message string) error {
|
||||
return updateWikiPage(doer, repo, oldWikiName , newWikiName, content, message, false)
|
||||
func EditWikiPage(doer *models.User, repo *models.Repository, oldWikiName, newWikiName, content, message string) error {
|
||||
return updateWikiPage(doer, repo, oldWikiName, newWikiName, content, message, false)
|
||||
}
|
||||
func updateWikiPage(doer *models.User, repo *models.Repository, oldWikiName, newWikiName, content, message string, isNew bool) (err error) {
|
||||
if err = nameAllowed(newWikiName); err != nil {
|
||||
|
@ -261,7 +258,6 @@ func updateWikiPage(doer *models.User, repo *models.Repository, oldWikiName, new
|
|||
return nil
|
||||
}
|
||||
|
||||
|
||||
// NewWikiPost response for wiki create request
|
||||
func NewWikiPost(ctx *context.APIContext, form api.WikiOption) {
|
||||
ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page")
|
||||
|
@ -280,15 +276,12 @@ func NewWikiPost(ctx *context.APIContext, form api.WikiOption) {
|
|||
|
||||
if models.IsErrWikiReservedName(err) {
|
||||
ctx.Data["Err_Title"] = true
|
||||
fmt.Println("err1 ================== ",err)
|
||||
//ctx.RenderWithErr(ctx.Tr("repo.wiki.reserved_page", wikiName), tplWikiNew, &form)
|
||||
} else if models.IsErrWikiAlreadyExist(err) {
|
||||
ctx.Data["Err_Title"] = true
|
||||
fmt.Println("err2 ====================", err)
|
||||
//ctx.RenderWithErr(ctx.Tr("repo.wiki.page_already_exists"), tplWikiNew, &form)
|
||||
} else {
|
||||
//ctx.ServerError("AddWikiPage", err)
|
||||
fmt.Println("err3 =======",err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -302,7 +295,7 @@ func EditWikiPost(ctx *context.APIContext, form api.WikiOption) {
|
|||
oldWikiName := wiki_service.NormalizeWikiName(ctx.Params(":page"))
|
||||
newWikiName := wiki_service.NormalizeWikiName(form.Name)
|
||||
|
||||
newWikiName, _= url.QueryUnescape(newWikiName)
|
||||
//newWikiName, _= url.QueryUnescape(newWikiName)
|
||||
|
||||
if len(form.CommitMessage) == 0 {
|
||||
form.CommitMessage = ctx.Tr("repo.editor.update", form.Name)
|
||||
|
|
|
@ -89,11 +89,6 @@ import (
|
|||
"gitea.com/macaron/macaron"
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
func MustEnableWiki(ctx *context.Context) {
|
||||
if !ctx.Repo.CanRead(models.UnitTypeWiki) &&
|
||||
!ctx.Repo.CanRead(models.UnitTypeExternalWiki) {
|
||||
|
@ -703,8 +698,10 @@ func RegisterRoutes(m *macaron.Macaron) {
|
|||
//update by 2021-01-12 end 引用自定义包;
|
||||
|
||||
// alter on 2021/01/15
|
||||
m.Get("", viewfile.Readme) // reqRepoReader(models.UnitTypeCode),
|
||||
}, reqToken())
|
||||
m.Get("", viewfile.Readme) // reqRepoReader(models.UnitTypeCode),
|
||||
m.Get("/*", viewfile.ReadmeByPath) // reqRepoReader(models.UnitTypeCode),
|
||||
|
||||
})
|
||||
|
||||
m.Group("/count", func() {
|
||||
m.Get("", viewfile.CommitCount) //****
|
||||
|
@ -795,6 +792,7 @@ func RegisterRoutes(m *macaron.Macaron) {
|
|||
Post(reqToken(), reqRepoReader(models.UnitTypeCode), bind(api.CreateForkOption{}), repo.CreateFork)
|
||||
m.Group("/branches", func() {
|
||||
m.Get("", repo.ListBranches)
|
||||
m.Get("/branches_slice", repo.ListBranchesSlice)
|
||||
m.Get("/*", context.RepoRefByType(context.RepoRefBranch), repo.GetBranch)
|
||||
m.Delete("/*", reqRepoWriter(models.UnitTypeCode), context.RepoRefByType(context.RepoRefBranch), repo.DeleteBranch)
|
||||
m.Post("", reqRepoWriter(models.UnitTypeCode), bind(api.CreateBranchRepoOption{}), repo.CreateBranch)
|
||||
|
@ -951,11 +949,16 @@ func RegisterRoutes(m *macaron.Macaron) {
|
|||
}, reqRepoReader(models.UnitTypeCode))
|
||||
m.Group("/commits", func() {
|
||||
m.Get("", repo.GetAllCommits)
|
||||
|
||||
m.Group("/:ref", func() {
|
||||
m.Get("/status", repo.GetCombinedCommitStatusByRef)
|
||||
m.Get("/statuses", repo.GetCommitStatusesByRef)
|
||||
})
|
||||
}, reqRepoReader(models.UnitTypeCode))
|
||||
m.Get("/commits_slice", repo.GetAllCommitsSliceByTime)
|
||||
m.Group("/file_commits", func() {
|
||||
m.Get("/*", repo.GetFileAllCommits)
|
||||
})
|
||||
m.Group("/git", func() {
|
||||
m.Group("/commits", func() {
|
||||
m.Get("/:sha", repo.GetSingleCommit)
|
||||
|
|
|
@ -6,6 +6,10 @@
|
|||
package repo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sort"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
|
@ -14,8 +18,6 @@ import (
|
|||
"code.gitea.io/gitea/modules/repofiles"
|
||||
repo_module "code.gitea.io/gitea/modules/repository"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// GetBranch get a branch of a repository
|
||||
|
@ -45,8 +47,6 @@ func GetBranch(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$ref": "#/responses/Branch"
|
||||
|
||||
|
||||
|
||||
if ctx.Repo.TreePath != "" {
|
||||
// if TreePath != "", then URL contained extra slashes
|
||||
// (i.e. "master/subbranch" instead of "master"), so branch does
|
||||
|
@ -328,6 +328,92 @@ func ListBranches(ctx *context.APIContext) {
|
|||
ctx.JSON(http.StatusOK, &apiBranches)
|
||||
}
|
||||
|
||||
// ListBranches list all the branches of a repository
|
||||
func ListBranchesSlice(ctx *context.APIContext) {
|
||||
// swagger:operation GET /repos/{owner}/{repo}/branches/branches_slice repository repoListBranchesSlice
|
||||
// ---
|
||||
// summary: List a repository's branches, Group sort.
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
// in: path
|
||||
// description: name of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/BranchList"
|
||||
|
||||
//start:=time.Now()
|
||||
branches, err := repo_module.GetBranches(ctx.Repo.Repository)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetBranches", err)
|
||||
return
|
||||
}
|
||||
//fmt.Println("***************** *GetBranches:",time.Now().Sub(start)," ",branches,len(branches))
|
||||
|
||||
apiBranches := make([]*api.Branch, len(branches))
|
||||
|
||||
// add configure
|
||||
apiBranchesList := []api.Branch{}
|
||||
for i := range branches {
|
||||
c, err := branches[i].GetCommit()
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetCommit", err)
|
||||
return
|
||||
}
|
||||
//fmt.Println("****branches[i]:",branches[i])
|
||||
branchProtection, err := ctx.Repo.Repository.GetBranchProtection(branches[i].Name)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetBranchProtection", err)
|
||||
return
|
||||
}
|
||||
//fmt.Println("****branchProtection:",branchProtection)
|
||||
apiBranches[i], err = convert.ToBranch(ctx.Repo.Repository, branches[i], c, branchProtection, ctx.User, ctx.Repo.IsAdmin())
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "convert.ToBranch", err)
|
||||
return
|
||||
}
|
||||
apiBranchesList = append(apiBranchesList, *apiBranches[i])
|
||||
//fmt.Println("****apiBranches[i]:",apiBranches[i])
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, BranchesSliceByProtection(ctx, apiBranchesList))
|
||||
}
|
||||
|
||||
// branches slice. Group by protection
|
||||
|
||||
func BranchesSliceByProtection(ctx *context.APIContext, branchList []api.Branch) []api.BranchesSlice {
|
||||
// group by protection
|
||||
sort.Sort(api.SortBranch(branchList))
|
||||
branchSlice := make([]api.BranchesSlice, 0)
|
||||
i := 0
|
||||
var j int
|
||||
for {
|
||||
if i >= len(branchList) {
|
||||
break
|
||||
}
|
||||
for j = i + 1; j < len(branchList) && (branchList[i].BranchKind == branchList[j].BranchKind); j++ {
|
||||
}
|
||||
// get the same branches
|
||||
sameBranchSlice := branchList[i:j]
|
||||
// sort by time
|
||||
sort.Sort(api.SortBranchTime(sameBranchSlice))
|
||||
branchSlice = append(branchSlice, api.BranchesSlice{
|
||||
BranchName: convert.ToBranchType(branchList[i].BranchKind).Name(),
|
||||
Branches: sameBranchSlice,
|
||||
})
|
||||
i = j
|
||||
}
|
||||
return branchSlice
|
||||
}
|
||||
|
||||
// GetBranchProtection gets a branch protection
|
||||
func GetBranchProtection(ctx *context.APIContext) {
|
||||
// swagger:operation GET /repos/{owner}/{repo}/branch_protections/{name} repository repoGetBranchProtection
|
||||
|
|
|
@ -9,18 +9,19 @@ import (
|
|||
"fmt"
|
||||
"math"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/gitgraph"
|
||||
"code.gitea.io/gitea/services/gitdiff"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/validation"
|
||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||
"code.gitea.io/gitea/services/gitdiff"
|
||||
)
|
||||
|
||||
// GetSingleCommit get a commit via sha
|
||||
|
@ -83,6 +84,140 @@ func getCommit(ctx *context.APIContext, identifier string) {
|
|||
ctx.JSON(http.StatusOK, json)
|
||||
}
|
||||
|
||||
// GetFileCommits get all commits by path on a repository
|
||||
func GetFileAllCommits(ctx *context.APIContext) {
|
||||
// swagger:operation GET /repos/{owner}/{repo}/file_commits/{filepath} repository repoGetFileAllCommits
|
||||
// ---
|
||||
// summary: Get a list of all commits by filepath from a repository
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
// in: path
|
||||
// description: name of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: filepath
|
||||
// in: path
|
||||
// description: filepath of the file to get
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: sha
|
||||
// in: query
|
||||
// description: SHA or branch to start listing commits from (usually 'master')
|
||||
// type: string
|
||||
// - name: page
|
||||
// in: query
|
||||
// description: page number of results to return (1-based)
|
||||
// type: integer
|
||||
// - name: limit
|
||||
// in: query
|
||||
// description: page size of results
|
||||
// type: integer
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/FileCommitList"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
// "409":
|
||||
// "$ref": "#/responses/EmptyRepository"
|
||||
|
||||
if ctx.Repo.Repository.IsEmpty {
|
||||
ctx.JSON(http.StatusConflict, api.APIError{
|
||||
Message: "Git Repository is empty.",
|
||||
URL: setting.API.SwaggerURL,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
gitRepo, err := git.OpenRepository(ctx.Repo.Repository.RepoPath())
|
||||
if err != nil {
|
||||
ctx.ServerError("OpenRepository", err)
|
||||
return
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
|
||||
listOptions := utils.GetListOptions(ctx)
|
||||
if listOptions.Page <= 0 {
|
||||
listOptions.Page = 1
|
||||
}
|
||||
|
||||
if listOptions.PageSize > git.CommitsRangeSize {
|
||||
listOptions.PageSize = git.CommitsRangeSize
|
||||
}
|
||||
|
||||
sha := ctx.Query("sha")
|
||||
treePath := ctx.Params("*")
|
||||
var baseCommit *git.Commit
|
||||
var commitsCountTotal int64
|
||||
if len(sha) == 0 {
|
||||
head, err := gitRepo.GetHEADBranch()
|
||||
if err != nil {
|
||||
ctx.ServerError("GetHEADBranch", err)
|
||||
return
|
||||
}
|
||||
|
||||
baseCommit, err = gitRepo.GetBranchCommit(head.Name)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetCommit", err)
|
||||
return
|
||||
}
|
||||
commitsCountTotal, err = git.CommitsCountByFile(gitRepo.Path, head.Name, treePath)
|
||||
if err != nil {
|
||||
ctx.ServerError("CommitsCount", err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
baseCommit, err = gitRepo.GetCommit(sha)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetCommit", err)
|
||||
return
|
||||
}
|
||||
commitsCountTotal, err = git.CommitsCountByFile(gitRepo.Path, sha, treePath)
|
||||
if err != nil {
|
||||
ctx.ServerError("CommitsCount", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
pageCount := int(math.Ceil(float64(commitsCountTotal) / float64(listOptions.PageSize)))
|
||||
|
||||
commits, err := baseCommit.CommitsByFileAndRange(treePath, listOptions.Page, listOptions.PageSize)
|
||||
if err != nil {
|
||||
ctx.ServerError("CommitsByRange", err)
|
||||
return
|
||||
}
|
||||
|
||||
userCache := make(map[string]*models.User)
|
||||
apiCommits := make([]*api.Commit, commits.Len())
|
||||
i := 0
|
||||
for commitPointer := commits.Front(); commitPointer != nil; commitPointer = commitPointer.Next() {
|
||||
commit := commitPointer.Value.(*git.Commit)
|
||||
apiCommits[i], err = toCommit(ctx, ctx.Repo.Repository, commit, userCache)
|
||||
if err != nil {
|
||||
ctx.ServerError("toCommit", err)
|
||||
return
|
||||
}
|
||||
|
||||
i++
|
||||
}
|
||||
|
||||
ctx.Header().Set("X-Page", strconv.Itoa(listOptions.Page))
|
||||
ctx.Header().Set("X-PerPage", strconv.Itoa(listOptions.PageSize))
|
||||
ctx.Header().Set("X-Total", strconv.FormatInt(commitsCountTotal, 10))
|
||||
ctx.Header().Set("X-PageCount", strconv.Itoa(pageCount))
|
||||
ctx.Header().Set("X-HasMore", strconv.FormatBool(listOptions.Page < pageCount))
|
||||
ctx.SetLinkHeader(int(commitsCountTotal), listOptions.PageSize)
|
||||
ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", commitsCountTotal))
|
||||
|
||||
ctx.JSON(http.StatusOK, apiCommits)
|
||||
}
|
||||
|
||||
// GetAllCommits get all commits via
|
||||
func GetAllCommits(ctx *context.APIContext) {
|
||||
// swagger:operation GET /repos/{owner}/{repo}/commits repository repoGetAllCommits
|
||||
|
@ -189,7 +324,10 @@ func GetAllCommits(ctx *context.APIContext) {
|
|||
userCache := make(map[string]*models.User)
|
||||
|
||||
apiCommits := make([]*api.Commit, commits.Len())
|
||||
// =============================================================
|
||||
// apiCommitsList := []api.Commit{}
|
||||
|
||||
// =================================================================
|
||||
i := 0
|
||||
for commitPointer := commits.Front(); commitPointer != nil; commitPointer = commitPointer.Next() {
|
||||
commit := commitPointer.Value.(*git.Commit)
|
||||
|
@ -200,6 +338,7 @@ func GetAllCommits(ctx *context.APIContext) {
|
|||
ctx.ServerError("toCommit", err)
|
||||
return
|
||||
}
|
||||
// apiCommitsList = append(apiCommitsList,*apiCommits[i])
|
||||
|
||||
i++
|
||||
}
|
||||
|
@ -214,7 +353,168 @@ func GetAllCommits(ctx *context.APIContext) {
|
|||
ctx.SetLinkHeader(int(commitsCountTotal), listOptions.PageSize)
|
||||
ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", commitsCountTotal))
|
||||
|
||||
ctx.JSON(http.StatusOK, &apiCommits)
|
||||
ctx.JSON(http.StatusOK, apiCommits)
|
||||
}
|
||||
|
||||
// GetAllCommits get all commits via
|
||||
func GetAllCommitsSliceByTime(ctx *context.APIContext) {
|
||||
// swagger:operation GET /repos/{owner}/{repo}/commits_slice repository repoGetAllCommitsSlice
|
||||
// ---
|
||||
// summary: Get a list of all commits from a repository
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
// in: path
|
||||
// description: name of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: sha
|
||||
// in: query
|
||||
// description: SHA or branch to start listing commits from (usually 'master')
|
||||
// type: string
|
||||
// - name: page
|
||||
// in: query
|
||||
// description: page number of results to return (1-based)
|
||||
// type: integer
|
||||
// - name: limit
|
||||
// in: query
|
||||
// description: page size of results
|
||||
// type: integer
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/CommitList"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
// "409":
|
||||
// "$ref": "#/responses/EmptyRepository"
|
||||
|
||||
if ctx.Repo.Repository.IsEmpty {
|
||||
ctx.JSON(http.StatusConflict, api.APIError{
|
||||
Message: "Git Repository is empty.",
|
||||
URL: setting.API.SwaggerURL,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
gitRepo, err := git.OpenRepository(ctx.Repo.Repository.RepoPath())
|
||||
if err != nil {
|
||||
ctx.ServerError("OpenRepository", err)
|
||||
return
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
|
||||
listOptions := utils.GetListOptions(ctx)
|
||||
if listOptions.Page <= 0 {
|
||||
listOptions.Page = 1
|
||||
}
|
||||
|
||||
if listOptions.PageSize > git.CommitsRangeSize {
|
||||
listOptions.PageSize = git.CommitsRangeSize
|
||||
}
|
||||
|
||||
sha := ctx.Query("sha")
|
||||
|
||||
var baseCommit *git.Commit
|
||||
if len(sha) == 0 {
|
||||
// no sha supplied - use default branch
|
||||
head, err := gitRepo.GetHEADBranch()
|
||||
if err != nil {
|
||||
ctx.ServerError("GetHEADBranch", err)
|
||||
return
|
||||
}
|
||||
|
||||
baseCommit, err = gitRepo.GetBranchCommit(head.Name)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetCommit", err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
// get commit specified by sha
|
||||
baseCommit, err = gitRepo.GetCommit(sha)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetCommit", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Total commit count
|
||||
commitsCountTotal, err := baseCommit.CommitsCount()
|
||||
if err != nil {
|
||||
ctx.ServerError("GetCommitsCount", err)
|
||||
return
|
||||
}
|
||||
|
||||
pageCount := int(math.Ceil(float64(commitsCountTotal) / float64(listOptions.PageSize)))
|
||||
|
||||
// Query commits
|
||||
commits, err := baseCommit.CommitsByRange(listOptions.Page, listOptions.PageSize)
|
||||
if err != nil {
|
||||
ctx.ServerError("CommitsByRange", err)
|
||||
return
|
||||
}
|
||||
|
||||
userCache := make(map[string]*models.User)
|
||||
|
||||
apiCommits := make([]*api.Commit, commits.Len())
|
||||
apiCommitsList := []api.Commit{}
|
||||
i := 0
|
||||
for commitPointer := commits.Front(); commitPointer != nil; commitPointer = commitPointer.Next() {
|
||||
commit := commitPointer.Value.(*git.Commit)
|
||||
|
||||
// Create json struct
|
||||
apiCommits[i], err = toCommit(ctx, ctx.Repo.Repository, commit, userCache)
|
||||
if err != nil {
|
||||
ctx.ServerError("toCommit", err)
|
||||
return
|
||||
}
|
||||
apiCommitsList = append(apiCommitsList, *apiCommits[i])
|
||||
|
||||
i++
|
||||
}
|
||||
|
||||
// kept for backwards compatibility
|
||||
ctx.Header().Set("X-Page", strconv.Itoa(listOptions.Page))
|
||||
ctx.Header().Set("X-PerPage", strconv.Itoa(listOptions.PageSize))
|
||||
ctx.Header().Set("X-Total", strconv.FormatInt(commitsCountTotal, 10))
|
||||
ctx.Header().Set("X-PageCount", strconv.Itoa(pageCount))
|
||||
ctx.Header().Set("X-HasMore", strconv.FormatBool(listOptions.Page < pageCount))
|
||||
|
||||
ctx.SetLinkHeader(int(commitsCountTotal), listOptions.PageSize)
|
||||
ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", commitsCountTotal))
|
||||
|
||||
ctx.JSON(http.StatusOK, CommitSplitSlice(apiCommitsList))
|
||||
}
|
||||
|
||||
func CommitSplitSlice(CommitsList []api.Commit) []api.CommitsSlice {
|
||||
// sort by time
|
||||
sort.Sort(api.SortCommit(CommitsList))
|
||||
Commits := make([]api.CommitsSlice, 0)
|
||||
i := 0
|
||||
var j int
|
||||
for {
|
||||
if i >= len(CommitsList) {
|
||||
break
|
||||
}
|
||||
// Detect equal CommitData,
|
||||
for j = i + 1; j < len(CommitsList) && CommitsList[i].CommitDate == CommitsList[j].CommitDate; j++ {
|
||||
}
|
||||
// if equal, put commitdata in an array
|
||||
commitDate := CommitsList[i].CommitDate
|
||||
commitDatalist := CommitsList[i:j]
|
||||
i = j // variable value
|
||||
// get all the values,,,Commits
|
||||
Commits = append(Commits, api.CommitsSlice{
|
||||
CommitDate: commitDate,
|
||||
Commits: commitDatalist,
|
||||
})
|
||||
}
|
||||
return Commits
|
||||
}
|
||||
|
||||
func toCommit(ctx *context.APIContext, repo *models.Repository, commit *git.Commit, userCache map[string]*models.User) (*api.Commit, error) {
|
||||
|
@ -277,8 +577,9 @@ func toCommit(ctx *context.APIContext, repo *models.Repository, commit *git.Comm
|
|||
SHA: sha.String(),
|
||||
}
|
||||
}
|
||||
|
||||
commit.LoadBranchName()
|
||||
return &api.Commit{
|
||||
CommitDate: commit.Committer.When.Format("2006-01-02"), // new time format, year-moon-day
|
||||
CommitMeta: &api.CommitMeta{
|
||||
URL: repo.APIURL() + "/git/commits/" + commit.ID.String(),
|
||||
SHA: commit.ID.String(),
|
||||
|
@ -309,14 +610,16 @@ func toCommit(ctx *context.APIContext, repo *models.Repository, commit *git.Comm
|
|||
Author: apiAuthor,
|
||||
Committer: apiCommitter,
|
||||
Parents: apiParents,
|
||||
Branch: commit.Branch,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// add by qiubing
|
||||
// 获取 Graph
|
||||
func GetGraph(ctx *context.APIContext) {
|
||||
|
||||
if ctx.Repo.Repository.IsEmpty { // 项目是否为空
|
||||
ctx.JSON(409, api.APIError{
|
||||
ctx.JSON(http.StatusConflict, api.APIError{
|
||||
Message: "Git Repository is empty.",
|
||||
URL: setting.API.SwaggerURL,
|
||||
})
|
||||
|
@ -334,7 +637,7 @@ func GetGraph(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
ctx.JSON(200, &graph)
|
||||
ctx.JSON(http.StatusOK, &graph)
|
||||
}
|
||||
|
||||
// 获取 commit diff
|
||||
|
@ -350,7 +653,7 @@ func Diff(ctx *context.APIContext) {
|
|||
ctx.NotFound("GetDiffCommit", err)
|
||||
return
|
||||
}
|
||||
ctx.JSON(200, &diff)
|
||||
ctx.JSON(http.StatusOK, &diff)
|
||||
}
|
||||
|
||||
// 获取文件 blame 信息
|
||||
|
@ -415,7 +718,7 @@ func GetCommitsCount(ctx *context.APIContext) {
|
|||
ctx.ServerError("GetCommitsCount", err)
|
||||
return
|
||||
}
|
||||
ctx.JSON(200, &ctx.Repo)
|
||||
ctx.JSON(http.StatusOK, &ctx.Repo)
|
||||
}
|
||||
|
||||
// end by qiubing
|
||||
|
|
|
@ -57,6 +57,11 @@ func GetRawFile(ctx *context.APIContext) {
|
|||
// description: filepath of the file to get
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: ref
|
||||
// in: query
|
||||
// description: "The name of the commit/branch/tag. Default the repository’s default branch (usually master)"
|
||||
// type: string
|
||||
// required: false
|
||||
// responses:
|
||||
// 200:
|
||||
// description: success
|
||||
|
@ -68,7 +73,14 @@ func GetRawFile(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreePath)
|
||||
ref := ctx.QueryTrim("ref")
|
||||
|
||||
commit, err := ctx.Repo.GitRepo.GetCommit(ref)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetCommit", err)
|
||||
return
|
||||
}
|
||||
blob, err := commit.GetBlobByPath(ctx.Repo.TreePath)
|
||||
if err != nil {
|
||||
if git.IsErrNotExist(err) {
|
||||
ctx.NotFound()
|
||||
|
@ -528,8 +540,7 @@ func GetContents(ctx *context.APIContext) {
|
|||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
|
||||
start:=time.Now()
|
||||
start := time.Now()
|
||||
|
||||
if !canReadFiles(ctx.Repo) {
|
||||
ctx.Error(http.StatusInternalServerError, "GetContentsOrList", models.ErrUserDoesNotHaveAccessToRepo{
|
||||
|
@ -542,8 +553,8 @@ func GetContents(ctx *context.APIContext) {
|
|||
treePath := ctx.Params("*")
|
||||
ref := ctx.QueryTrim("ref")
|
||||
|
||||
fmt.Println("***GetContents.treePath:",treePath)
|
||||
fmt.Println("***GetContents.ref:",ref)
|
||||
fmt.Println("***GetContents.treePath:", treePath)
|
||||
fmt.Println("***GetContents.ref:", ref)
|
||||
if fileList, err := repofiles.GetContentsOrList(ctx.Repo.Repository, treePath, ref); err != nil {
|
||||
if git.IsErrNotExist(err) {
|
||||
ctx.NotFound("GetContentsOrList", err)
|
||||
|
@ -553,7 +564,7 @@ func GetContents(ctx *context.APIContext) {
|
|||
} else {
|
||||
ctx.JSON(http.StatusOK, fileList)
|
||||
}
|
||||
log.Info("*****************GetContents:%v",time.Now().Sub(start))
|
||||
log.Info("*****************GetContents:%v", time.Now().Sub(start))
|
||||
}
|
||||
|
||||
// add by qiubing
|
||||
|
|
|
@ -5,7 +5,10 @@
|
|||
package repo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
|
@ -56,6 +59,22 @@ func ListTags(ctx *context.APIContext) {
|
|||
apiTags[i] = convert.ToTag(ctx.Repo.Repository, tags[i])
|
||||
}
|
||||
|
||||
tagsCountTotal, err := ctx.Repo.GitRepo.GetTagCount()
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetTagCount", err)
|
||||
return
|
||||
}
|
||||
|
||||
pageCount := int(math.Ceil(float64(tagsCountTotal) / float64(listOpts.PageSize)))
|
||||
ctx.Header().Set("X-Page", strconv.Itoa(listOpts.Page))
|
||||
ctx.Header().Set("X-PerPage", strconv.Itoa(listOpts.PageSize))
|
||||
ctx.Header().Set("X-Total", strconv.FormatInt(tagsCountTotal, 10))
|
||||
ctx.Header().Set("X-PageCount", strconv.Itoa(pageCount))
|
||||
ctx.Header().Set("X-HasMore", strconv.FormatBool(listOpts.Page < pageCount))
|
||||
|
||||
ctx.SetLinkHeader(int(tagsCountTotal), listOpts.PageSize)
|
||||
ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", tagsCountTotal))
|
||||
|
||||
ctx.JSON(http.StatusOK, &apiTags)
|
||||
}
|
||||
|
||||
|
|
|
@ -2,15 +2,16 @@ package repo
|
|||
|
||||
//
|
||||
import (
|
||||
"net/http"
|
||||
"sort"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/markup/markdown"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
"code.gitea.io/gitea/modules/wikies"
|
||||
wiki_service "code.gitea.io/gitea/services/wiki"
|
||||
"net/http"
|
||||
"sort"
|
||||
|
||||
)
|
||||
|
||||
func WikiList(ctx *context.APIContext) {
|
||||
|
@ -59,7 +60,8 @@ func WikiList(ctx *context.APIContext) {
|
|||
if !entry.IsRegular() {
|
||||
continue
|
||||
}
|
||||
c, err := wikiRepo.GetCommitByPath(entry.Name())
|
||||
//c, err := wikiRepo.GetCommitByPath(entry.Name())
|
||||
lastCommit, firstCommit, err := wikiRepo.GetFirstAndLastCommitByPath("master", entry.Name())
|
||||
if err != nil {
|
||||
if wikiRepo != nil {
|
||||
wikiRepo.Close()
|
||||
|
@ -79,7 +81,6 @@ func WikiList(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
wikiesList = append(wikiesList, api.WikiesResponse{
|
||||
When: c.Author.When.Unix(),
|
||||
WikiCloneLink: api.CloneLink{
|
||||
HTTPS: wikiCloneLink.HTTPS,
|
||||
SSH: wikiCloneLink.SSH,
|
||||
|
@ -88,17 +89,31 @@ func WikiList(ctx *context.APIContext) {
|
|||
Name: wikiName,
|
||||
Commit: api.WikiCommit{
|
||||
Author: api.WikiUser{
|
||||
Name: c.Author.Name,
|
||||
Email: c.Author.Email,
|
||||
When: c.Author.When.Unix(),
|
||||
Name: lastCommit.Author.Name,
|
||||
Email: lastCommit.Author.Email,
|
||||
When: lastCommit.Author.When.Unix(),
|
||||
},
|
||||
Commiter: api.WikiUser{
|
||||
Name: c.Committer.Name,
|
||||
Email: c.Committer.Email,
|
||||
When: c.Committer.When.Unix(),
|
||||
Name: lastCommit.Committer.Name,
|
||||
Email: lastCommit.Committer.Email,
|
||||
When: lastCommit.Author.When.Unix(),
|
||||
},
|
||||
ID: c.ID.String(),
|
||||
Message: c.Message(),
|
||||
ID: lastCommit.ID.String(),
|
||||
Message: lastCommit.Message(),
|
||||
},
|
||||
FirstCommit: api.WikiCommit{
|
||||
Author: api.WikiUser{
|
||||
Name: firstCommit.Author.Name,
|
||||
Email: firstCommit.Author.Email,
|
||||
When: firstCommit.Author.When.Unix(),
|
||||
},
|
||||
Commiter: api.WikiUser{
|
||||
Name: firstCommit.Committer.Name,
|
||||
Email: firstCommit.Committer.Email,
|
||||
When: firstCommit.Author.When.Unix(),
|
||||
},
|
||||
ID: firstCommit.ID.String(),
|
||||
Message: firstCommit.Message(),
|
||||
},
|
||||
},
|
||||
})
|
||||
|
@ -106,7 +121,7 @@ func WikiList(ctx *context.APIContext) {
|
|||
|
||||
//根据创建时间,按最新的时间排序
|
||||
sort.Slice(wikiesList, func(i, j int) bool {
|
||||
return wikiesList[i].Commit.Commiter.When < wikiesList[j].Commit.Commiter.When
|
||||
return wikiesList[i].FirstCommit.Author.When > wikiesList[j].FirstCommit.Author.When
|
||||
})
|
||||
ctx.JSON(http.StatusOK, wikiesList)
|
||||
}
|
||||
|
@ -223,11 +238,28 @@ func CreateWiki(ctx *context.APIContext, form api.WikiOption) {
|
|||
ctx.FileNameError()
|
||||
return
|
||||
}
|
||||
OwnerName := ctx.Repo.Repository.OwnerName
|
||||
RepoName := ctx.Repo.Repository.Name
|
||||
repository := ctx.Repo.Repository
|
||||
wikiCloneLink := repository.CloneWikiLink()
|
||||
wikies.NewWikiPost(ctx, form)
|
||||
if util.IsEmptyString(form.Name) {
|
||||
//ctx.RenderWithErr(ctx.Tr("repo.issues.new.title_empty"), nil, form)
|
||||
return
|
||||
}
|
||||
|
||||
wikiName := wiki_service.NormalizeWikiName(form.Name)
|
||||
if len(form.CommitMessage) == 0 {
|
||||
form.CommitMessage = ctx.Tr("repo.editor.add", form.Name)
|
||||
}
|
||||
if err := wiki_service.AddWikiPage(ctx.User, ctx.Repo.Repository, wikiName, form.Content, form.CommitMessage); err != nil {
|
||||
|
||||
if models.IsErrWikiReservedName(err) {
|
||||
ctx.Error(http.StatusInternalServerError, "WikiNameIsReservedPage", "wiki名称是被保留的.")
|
||||
} else if models.IsErrWikiAlreadyExist(err) {
|
||||
ctx.Error(http.StatusConflict, "WikiNameAlreadyExist", "wiki名称已存在")
|
||||
} else {
|
||||
ctx.Error(http.StatusInternalServerError, "AddWikiPage", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
wikiRepo, commit, _ := wikies.FindWikiRepoCommit(ctx)
|
||||
data, entry, pageFilename, _ := wikies.WikiContentsByName(ctx, commit, form.Name)
|
||||
metas := ctx.Repo.Repository.ComposeDocumentMetas()
|
||||
|
@ -240,8 +272,6 @@ func CreateWiki(ctx *context.APIContext, form api.WikiOption) {
|
|||
}
|
||||
}
|
||||
wiki := api.WikiResponse{
|
||||
OwnerName: OwnerName,
|
||||
RepoName: RepoName,
|
||||
WikiCloneLink: api.CloneLink{
|
||||
HTTPS: wikiCloneLink.HTTPS,
|
||||
SSH: wikiCloneLink.SSH,
|
||||
|
@ -300,32 +330,46 @@ func EditWiki(ctx *context.APIContext, form api.WikiOption) {
|
|||
// "201":
|
||||
// "$ref": "#/responses/Wiki"
|
||||
|
||||
oldWikiName := wiki_service.NormalizeWikiName(ctx.Params(":page"))
|
||||
newWikiName := wiki_service.NormalizeWikiName(form.Name)
|
||||
err1 := wiki_service.CheckFile(newWikiName)
|
||||
if err1 != nil {
|
||||
ctx.FileNameError()
|
||||
return
|
||||
}
|
||||
|
||||
wikies.EditWikiPost(ctx, form)
|
||||
|
||||
OwnerName := ctx.Repo.Repository.OwnerName
|
||||
RepoName := ctx.Repo.Repository.Name
|
||||
|
||||
wikiRepo, commit, _ := wikies.FindWikiRepoCommit(ctx)
|
||||
data, entry, pageFilename, _ := wikies.WikiContentsByName(ctx, commit, form.Name) //
|
||||
metas := ctx.Repo.Repository.ComposeDocumentMetas()
|
||||
PageContent := markdown.RenderWiki(data, ctx.Repo.RepoLink, metas)
|
||||
commitsCount, _ := wikiRepo.FileCommitsCount("master", pageFilename)
|
||||
|
||||
if _, _, _, noEntry := wikies.WikiContentsByName(ctx, commit, oldWikiName); noEntry {
|
||||
ctx.Error(http.StatusNotFound, "WikiNotFound", "wiki不存在")
|
||||
return
|
||||
}
|
||||
|
||||
if _, _, _, noEntry := wikies.WikiContentsByName(ctx, commit, newWikiName); oldWikiName != newWikiName && !noEntry {
|
||||
ctx.Error(http.StatusConflict, "WikiNameAlreadyExist", "wiki名称已存在")
|
||||
return
|
||||
}
|
||||
|
||||
if len(form.CommitMessage) == 0 {
|
||||
form.CommitMessage = ctx.Tr("repo.editor.update", form.Name)
|
||||
}
|
||||
|
||||
if err := wiki_service.EditWikiPage(ctx.User, ctx.Repo.Repository, oldWikiName, newWikiName, form.Content, form.CommitMessage); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "EditWikiPage", err)
|
||||
return
|
||||
}
|
||||
_, newCommit, _ := wikies.FindWikiRepoCommit(ctx)
|
||||
data, entry, pageFilename, _ := wikies.WikiContentsByName(ctx, newCommit, newWikiName)
|
||||
c, err := wikiRepo.GetCommitByPath(entry.Name())
|
||||
if err != nil {
|
||||
if models.IsErrWikiInvalidFileName(err) {
|
||||
return
|
||||
}
|
||||
}
|
||||
metas := ctx.Repo.Repository.ComposeDocumentMetas()
|
||||
PageContent := markdown.RenderWiki(data, ctx.Repo.RepoLink, metas)
|
||||
commitsCount, _ := wikiRepo.FileCommitsCount("master", pageFilename)
|
||||
|
||||
wiki := api.WikiResponse{
|
||||
OwnerName: OwnerName,
|
||||
RepoName: RepoName,
|
||||
WikiMeta: api.WikiMeta{
|
||||
Name: form.Name,
|
||||
Commit: api.WikiCommit{
|
||||
|
|
|
@ -53,6 +53,21 @@ type swaggerResponseBranchProtectionList struct {
|
|||
// TagList
|
||||
// swagger:response TagList
|
||||
type swaggerResponseTagList struct {
|
||||
// The current page
|
||||
Page int `json:"X-Page"`
|
||||
|
||||
// Commits per page
|
||||
PerPage int `json:"X-PerPage"`
|
||||
|
||||
// Total commit count
|
||||
Total int `json:"X-Total"`
|
||||
|
||||
// Total number of pages
|
||||
PageCount int `json:"X-PageCount"`
|
||||
|
||||
// True if there is another page
|
||||
HasMore bool `json:"X-HasMore"`
|
||||
|
||||
// in:body
|
||||
Body []api.Tag `json:"body"`
|
||||
}
|
||||
|
@ -275,6 +290,28 @@ type swaggerCommitList struct {
|
|||
Body []api.Commit `json:"body"`
|
||||
}
|
||||
|
||||
// FileCommitList
|
||||
// swagger:response FileCommitList
|
||||
type swaggerFileCommitList struct {
|
||||
// The current page
|
||||
Page int `json:"X-Page"`
|
||||
|
||||
// Commits per page
|
||||
PerPage int `json:"X-PerPage"`
|
||||
|
||||
// Total commit count
|
||||
Total int `json:"X-Total"`
|
||||
|
||||
// Total number of pages
|
||||
PageCount int `json:"X-PageCount"`
|
||||
|
||||
// True if there is another page
|
||||
HasMore bool `json:"X-HasMore"`
|
||||
|
||||
// in: body
|
||||
Body []api.Commit `json:"body"`
|
||||
}
|
||||
|
||||
// EmptyRepository
|
||||
// swagger:response EmptyRepository
|
||||
type swaggerEmptyRepository struct {
|
||||
|
|
|
@ -2,6 +2,17 @@ package viewfile
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
gotemplate "html/template"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/charset"
|
||||
|
@ -13,32 +24,21 @@ import (
|
|||
"code.gitea.io/gitea/modules/repofiles"
|
||||
repo_module "code.gitea.io/gitea/modules/repository"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"gitea.com/macaron/macaron"
|
||||
gotemplate "html/template"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func Map2DTO(ctx *context.APIContext) (dto *ReadmeDTO) {
|
||||
dto=&ReadmeDTO{}
|
||||
dto.Type="file"
|
||||
dto.Encoding=ctx.Data["Encoding"].(string)
|
||||
dto.Size=ctx.Data["FileSize"].(int64)
|
||||
dto.Name=ctx.Repo.TreePath
|
||||
dto.Path=ctx.Repo.TreePath
|
||||
dto.Content=ctx.Data["FileContent"].(string)
|
||||
dto.Sha=ctx.Repo.CommitID
|
||||
dto = &ReadmeDTO{}
|
||||
dto.Type = "file"
|
||||
dto.Encoding = ctx.Data["Encoding"].(string)
|
||||
dto.Size = ctx.Data["FileSize"].(int64)
|
||||
dto.Name = ctx.Repo.TreePath
|
||||
dto.Path = ctx.Repo.TreePath
|
||||
dto.Content = ctx.Data["FileContent"].(string)
|
||||
dto.Sha = ctx.Repo.CommitID
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
// RepoRefByType handles repository reference name for a specific type
|
||||
// of repository reference
|
||||
func RepoRefByType(refType context.RepoRefType) macaron.Handler {
|
||||
|
@ -162,7 +162,6 @@ func RepoRefByType(refType context.RepoRefType) macaron.Handler {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
func getRefName(ctx *context.APIContext, pathType context.RepoRefType) string {
|
||||
path := ctx.Params("*")
|
||||
switch pathType {
|
||||
|
@ -198,7 +197,7 @@ func getRefName(ctx *context.APIContext, pathType context.RepoRefType) string {
|
|||
}
|
||||
return path
|
||||
default:
|
||||
ctx.Error(http.StatusBadRequest,"Unrecognized path type: %v", path)
|
||||
ctx.Error(http.StatusBadRequest, "Unrecognized path type: %v", path)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
@ -218,13 +217,11 @@ func getRefNameFromPath(ctx *context.APIContext, path string, isExist func(strin
|
|||
|
||||
func GetRefType() macaron.Handler {
|
||||
return func(ctx *context.APIContext) {
|
||||
ref:=ctx.ParamsInt64(":ref")
|
||||
fmt.Println("ref:",ref)
|
||||
ref := ctx.ParamsInt64(":ref")
|
||||
fmt.Println("ref:", ref)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
func CommitCount(ctx *context.APIContext) {
|
||||
// swagger:operation GET /repos/{owner}/{repo}/count repository Count
|
||||
// ---
|
||||
|
@ -253,7 +250,6 @@ func CommitCount(ctx *context.APIContext) {
|
|||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
|
||||
ref := ctx.QueryTrim("ref")
|
||||
if ref == "" {
|
||||
ref = ctx.Params(":ref")
|
||||
|
@ -281,18 +277,17 @@ func CommitCount(ctx *context.APIContext) {
|
|||
}()
|
||||
}
|
||||
|
||||
|
||||
// Get the commit object for the ref
|
||||
commit, err := ctx.Repo.GitRepo.GetCommit(ref)
|
||||
if err != nil || commit==nil{
|
||||
ctx.Error(http.StatusInternalServerError,"ctx.Repo.GitRepo.GetCommit", err)
|
||||
if err != nil || commit == nil {
|
||||
ctx.Error(http.StatusInternalServerError, "ctx.Repo.GitRepo.GetCommit", err)
|
||||
return
|
||||
}
|
||||
ctx.Repo.Commit=commit
|
||||
ctx.Repo.Commit = commit
|
||||
|
||||
CommitCount,err:=ctx.Repo.Commit.CommitsCount()
|
||||
if err !=nil {
|
||||
ctx.Error(http.StatusInternalServerError,"ctx.Repo.Commit.CommitsCount", err)
|
||||
CommitCount, err := ctx.Repo.Commit.CommitsCount()
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "ctx.Repo.Commit.CommitsCount", err)
|
||||
return
|
||||
}
|
||||
opts := models.FindReleasesOptions{
|
||||
|
@ -316,29 +311,28 @@ func CommitCount(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
tags,err:=ctx.Repo.GitRepo.GetTags()
|
||||
tags, err := ctx.Repo.GitRepo.GetTags()
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "ctx.Repo.GitRepo.GetTags", err)
|
||||
return
|
||||
}
|
||||
|
||||
dto:=&CountDTO{}
|
||||
dto.Branch.CommitCount=CommitCount
|
||||
dto.Branch.BranchName=ref
|
||||
dto.BranchCount=int64(len(branches))
|
||||
dto.TagCount=int64(len(tags))
|
||||
dto.ReleaseCount=ReleaseCount
|
||||
dto := &CountDTO{}
|
||||
dto.Branch.CommitCount = CommitCount
|
||||
dto.Branch.BranchName = ref
|
||||
dto.BranchCount = int64(len(branches))
|
||||
dto.TagCount = int64(len(tags))
|
||||
dto.ReleaseCount = ReleaseCount
|
||||
ctx.JSON(http.StatusOK, dto)
|
||||
}
|
||||
|
||||
|
||||
type CountDTO struct {
|
||||
Branch struct{
|
||||
CommitCount int64 `json:"commit_count"`
|
||||
BranchName string `json:"branch_name"`
|
||||
Branch struct {
|
||||
CommitCount int64 `json:"commit_count"`
|
||||
BranchName string `json:"branch_name"`
|
||||
} `json:"branch"`
|
||||
ReleaseCount int64 `json:"release_count"`
|
||||
TagCount int64 `json:"tag_count"`
|
||||
ReleaseCount int64 `json:"release_count"`
|
||||
TagCount int64 `json:"tag_count"`
|
||||
BranchCount int64 `json:"branch_count"`
|
||||
}
|
||||
|
||||
|
@ -383,7 +377,6 @@ func LatestRelease(ctx *context.APIContext) {
|
|||
}()
|
||||
}
|
||||
|
||||
|
||||
release, err := models.GetLatestReleaseByRepoIDExt(ctx.Repo.Repository.ID)
|
||||
//fmt.Println("****************ctx.Repo.Repository.ID:",ctx.Repo.Repository.ID," ",release," ",err)
|
||||
if err != nil {
|
||||
|
@ -400,11 +393,10 @@ func LatestRelease(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
release.Publisher.Passwd=""
|
||||
release.Publisher.Passwd = ""
|
||||
ctx.JSON(http.StatusOK, release)
|
||||
}
|
||||
|
||||
|
||||
func Readme(ctx *context.APIContext) {
|
||||
// swagger:operation GET /repos/{owner}/{repo}/readme repository readme
|
||||
// ---
|
||||
|
@ -433,115 +425,28 @@ func Readme(ctx *context.APIContext) {
|
|||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
ctx.Data["Encoding"]="base64"
|
||||
ctx.Data["Encoding"] = "base64"
|
||||
treePath := ctx.Repo.TreePath
|
||||
|
||||
ref:= ctx.QueryTrim("ref")
|
||||
ref := ctx.QueryTrim("ref")
|
||||
if ref == "" {
|
||||
ref= ctx.Params(":ref")
|
||||
if ref=="" {
|
||||
ref = ctx.Params(":ref")
|
||||
if ref == "" {
|
||||
ref = ctx.Repo.Repository.DefaultBranch
|
||||
}
|
||||
}
|
||||
fmt.Println("***ref:",ref)
|
||||
fmt.Println("***ref:", ref)
|
||||
|
||||
namedBlob,err:=getReadmeFileFromPathExt(ctx,treePath,ref)
|
||||
if err !=nil || namedBlob==nil{
|
||||
ctx.NotFound("getReadmeFileFromPath", err)
|
||||
namedBlob, err := getReadmeFileFromPathExt(ctx, treePath, ref)
|
||||
if err != nil || namedBlob == nil {
|
||||
ctx.NotFound("getReadmeFileFromPath", err)
|
||||
return
|
||||
}
|
||||
//fmt.Println("********getReadmeFileFromPathExt:",err," ",namedBlob)
|
||||
FoundFileItem:=namedBlob.name
|
||||
ctx.Repo.TreePath=FoundFileItem //找到指定文件;
|
||||
FoundFileItem := namedBlob.name
|
||||
ctx.Repo.TreePath = FoundFileItem //找到指定文件;
|
||||
|
||||
//fmt.Println("**** reqRepoReader(models.UnitTypeCode):",FoundFileItem)
|
||||
ctx.Data["PageIsViewCode"] = true
|
||||
if ctx.Repo.Repository.IsEmpty {
|
||||
ctx.NotFound("Home", fmt.Errorf(ctx.Tr("Repository is empty")))
|
||||
return
|
||||
}
|
||||
|
||||
title := ctx.Repo.Repository.Owner.Name + "/" + ctx.Repo.Repository.Name
|
||||
if len(ctx.Repo.Repository.Description) > 0 {
|
||||
title += ": " + ctx.Repo.Repository.Description
|
||||
}
|
||||
ctx.Data["Title"] = title
|
||||
|
||||
ctx.Repo.RepoLink=`/`+ctx.Repo.Owner.Name+`/`+ctx.Repo.Repository.Name
|
||||
|
||||
ctx.Repo.IsViewCommit=true //此处无实际意义;加上为了编译
|
||||
|
||||
branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
|
||||
treeLink := branchLink
|
||||
rawLink := ctx.Repo.RepoLink + "/raw/" + ctx.Repo.BranchNameSubURL()
|
||||
//fmt.Println("******rawLink:",rawLink)
|
||||
if len(ctx.Repo.TreePath) > 0 {
|
||||
treeLink += "/" + ctx.Repo.TreePath
|
||||
treeLink=strings.ReplaceAll(treeLink,"//","/")
|
||||
}
|
||||
|
||||
// Get current entry user currently looking at.
|
||||
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath)
|
||||
//fmt.Println("*********GetTreeEntryByPath:",entry," ",err)
|
||||
if err != nil {
|
||||
ctx.NotFound("Repo.Commit.GetTreeEntryByPath", err)
|
||||
return
|
||||
}
|
||||
if entry==nil {
|
||||
ctx.NotFound("Repo.Commit.GetTreeEntryByPath", err)
|
||||
return
|
||||
}
|
||||
renderFile(ctx, entry, treeLink, rawLink)
|
||||
//if ctx.Written() {
|
||||
// return
|
||||
//}
|
||||
|
||||
var treeNames []string
|
||||
paths := make([]string, 0, 5)
|
||||
if len(ctx.Repo.TreePath) > 0 {
|
||||
treeNames = strings.Split(ctx.Repo.TreePath, "/")
|
||||
fmt.Println("***treeNames:",treeNames)
|
||||
for i := range treeNames {
|
||||
paths = append(paths, strings.Join(treeNames[:i+1], "/"))
|
||||
fmt.Println("***paths:",paths)
|
||||
|
||||
}
|
||||
ctx.Data["HasParentPath"] = true
|
||||
if len(paths)-2 >= 0 {
|
||||
ctx.Data["ParentPath"] = "/" + paths[len(paths)-2]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ctx.Data["Paths"] = paths
|
||||
ctx.Data["TreeLink"] = treeLink
|
||||
ctx.Data["TreeNames"] = treeNames
|
||||
ctx.Data["BranchLink"] = branchLink
|
||||
|
||||
fmt.Println("***rawLink:",rawLink)
|
||||
fmt.Println("***paths:",paths)
|
||||
fmt.Println("***treeLink:",treeLink)
|
||||
fmt.Println("***treeNames:",treeNames)
|
||||
fmt.Println("***branchLink:",branchLink)
|
||||
|
||||
ctx.JSON(http.StatusOK, Map2DTO(ctx))
|
||||
|
||||
}
|
||||
|
||||
|
||||
func ViewFile(ctx *context.APIContext) {
|
||||
ctx.Data["Encoding"]="base64"
|
||||
|
||||
fmt.Println("*********viewFile.ctx.Repo.TreePath:",ctx.Repo.TreePath)
|
||||
namedBlob,err:=getReadmeFileFromPath(ctx.Repo.Commit,ctx.Repo.TreePath)
|
||||
if err !=nil || namedBlob==nil{
|
||||
ctx.NotFound("getReadmeFileFromPath", err)
|
||||
return
|
||||
}
|
||||
FoundFileItem:=namedBlob.name
|
||||
ctx.Repo.TreePath=FoundFileItem //找到指定文件;
|
||||
|
||||
fmt.Println("****getReadmeFileFromPath:",FoundFileItem)
|
||||
ctx.Data["PageIsViewCode"] = true
|
||||
if ctx.Repo.Repository.IsEmpty {
|
||||
ctx.NotFound("Home", fmt.Errorf(ctx.Tr("Repository is empty")))
|
||||
|
@ -554,7 +459,165 @@ func ViewFile(ctx *context.APIContext) {
|
|||
}
|
||||
ctx.Data["Title"] = title
|
||||
|
||||
ctx.Repo.RepoLink=`/`+ctx.Repo.Owner.Name+`/`+ctx.Repo.Repository.Name
|
||||
ctx.Repo.RepoLink = `/` + ctx.Repo.Owner.Name + `/` + ctx.Repo.Repository.Name
|
||||
|
||||
ctx.Repo.IsViewCommit = true //此处无实际意义;加上为了编译
|
||||
|
||||
branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
|
||||
treeLink := branchLink
|
||||
rawLink := ctx.Repo.RepoLink + "/raw/" + ctx.Repo.BranchNameSubURL()
|
||||
//fmt.Println("******rawLink:",rawLink)
|
||||
if len(ctx.Repo.TreePath) > 0 {
|
||||
treeLink += "/" + ctx.Repo.TreePath
|
||||
treeLink = strings.ReplaceAll(treeLink, "//", "/")
|
||||
}
|
||||
|
||||
// Get current entry user currently looking at.
|
||||
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath)
|
||||
//fmt.Println("*********GetTreeEntryByPath:",entry," ",err)
|
||||
if err != nil {
|
||||
ctx.NotFound("Repo.Commit.GetTreeEntryByPath", err)
|
||||
return
|
||||
}
|
||||
if entry == nil {
|
||||
ctx.NotFound("Repo.Commit.GetTreeEntryByPath", err)
|
||||
return
|
||||
}
|
||||
renderFile(ctx, entry, treeLink, rawLink)
|
||||
//if ctx.Written() {
|
||||
// return
|
||||
//}
|
||||
|
||||
var treeNames []string
|
||||
paths := make([]string, 0, 5)
|
||||
if len(ctx.Repo.TreePath) > 0 {
|
||||
treeNames = strings.Split(ctx.Repo.TreePath, "/")
|
||||
fmt.Println("***treeNames:", treeNames)
|
||||
for i := range treeNames {
|
||||
paths = append(paths, strings.Join(treeNames[:i+1], "/"))
|
||||
fmt.Println("***paths:", paths)
|
||||
|
||||
}
|
||||
ctx.Data["HasParentPath"] = true
|
||||
if len(paths)-2 >= 0 {
|
||||
ctx.Data["ParentPath"] = "/" + paths[len(paths)-2]
|
||||
}
|
||||
}
|
||||
|
||||
ctx.Data["Paths"] = paths
|
||||
ctx.Data["TreeLink"] = treeLink
|
||||
ctx.Data["TreeNames"] = treeNames
|
||||
ctx.Data["BranchLink"] = branchLink
|
||||
|
||||
fmt.Println("***rawLink:", rawLink)
|
||||
fmt.Println("***paths:", paths)
|
||||
fmt.Println("***treeLink:", treeLink)
|
||||
fmt.Println("***treeNames:", treeNames)
|
||||
fmt.Println("***branchLink:", branchLink)
|
||||
|
||||
ctx.JSON(http.StatusOK, Map2DTO(ctx))
|
||||
|
||||
}
|
||||
|
||||
/////////////
|
||||
func ReadmeByPath(ctx *context.APIContext) {
|
||||
// swagger:operation GET /repos/{owner}/{repo}/readme/{dir} repository readmePathContents
|
||||
// ---
|
||||
// summary: Gets the metadata and contents (if a file) of an entry in a repository, or a list of entries if a dir
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
// in: path
|
||||
// description: name of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: dir
|
||||
// in: path
|
||||
// description: name of the path
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: ref
|
||||
// in: query
|
||||
// description: "The name of the commit/branch/tag. Default the repository’s default branch (usually master)"
|
||||
// type: string
|
||||
// required: false
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/ContentsResponse"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
treePath := ctx.Params("*")
|
||||
ref := ctx.QueryTrim("ref")
|
||||
if ref == "" {
|
||||
ref = ctx.Params(":ref")
|
||||
if ref == "" {
|
||||
ref = ctx.Repo.Repository.DefaultBranch
|
||||
}
|
||||
}
|
||||
namedBlob, err := getReadmeFileFromPathExt(ctx, treePath, ref)
|
||||
if err != nil || namedBlob == nil {
|
||||
// ctx.NotFound("getReadmeFileFromPath", err)
|
||||
fileList, err1 := repofiles.GetContentsOrList(ctx.Repo.Repository, treePath, ref)
|
||||
if err1 != nil {
|
||||
if git.IsErrNotExist(err1) {
|
||||
ctx.NotFound("fileList", err1)
|
||||
return
|
||||
}
|
||||
ctx.Error(http.StatusInternalServerError, "GetFileListByPath", err)
|
||||
} else {
|
||||
ctx.JSON(http.StatusOK, fileList)
|
||||
}
|
||||
} else {
|
||||
FoundFileItem := namedBlob.name
|
||||
newTreePath := treePath + "/" + FoundFileItem
|
||||
|
||||
contents, err2 := repofiles.GetContents(ctx.Repo.Repository, newTreePath, ref, false)
|
||||
if err2 != nil {
|
||||
if git.IsErrNotExist(err2) {
|
||||
ctx.NotFound("GetReadmeContentByPath", err2)
|
||||
return
|
||||
}
|
||||
ctx.Error(http.StatusInternalServerError, "GetReadmeContentByPath", err)
|
||||
} else {
|
||||
ctx.JSON(http.StatusOK, contents)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func ViewFile(ctx *context.APIContext) {
|
||||
ctx.Data["Encoding"] = "base64"
|
||||
|
||||
fmt.Println("*********viewFile.ctx.Repo.TreePath:", ctx.Repo.TreePath)
|
||||
namedBlob, err := getReadmeFileFromPath(ctx.Repo.Commit, ctx.Repo.TreePath)
|
||||
if err != nil || namedBlob == nil {
|
||||
ctx.NotFound("getReadmeFileFromPath", err)
|
||||
return
|
||||
}
|
||||
FoundFileItem := namedBlob.name
|
||||
ctx.Repo.TreePath = FoundFileItem //找到指定文件;
|
||||
|
||||
fmt.Println("****getReadmeFileFromPath:", FoundFileItem)
|
||||
ctx.Data["PageIsViewCode"] = true
|
||||
if ctx.Repo.Repository.IsEmpty {
|
||||
ctx.NotFound("Home", fmt.Errorf(ctx.Tr("Repository is empty")))
|
||||
return
|
||||
}
|
||||
|
||||
title := ctx.Repo.Repository.Owner.Name + "/" + ctx.Repo.Repository.Name
|
||||
if len(ctx.Repo.Repository.Description) > 0 {
|
||||
title += ": " + ctx.Repo.Repository.Description
|
||||
}
|
||||
ctx.Data["Title"] = title
|
||||
|
||||
ctx.Repo.RepoLink = `/` + ctx.Repo.Owner.Name + `/` + ctx.Repo.Repository.Name
|
||||
|
||||
branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
|
||||
//fmt.Println("******branchLink:",branchLink)
|
||||
|
@ -576,13 +639,13 @@ func ViewFile(ctx *context.APIContext) {
|
|||
|
||||
// Get current entry user currently looking at.
|
||||
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath)
|
||||
fmt.Println("*********GetTreeEntryByPath:",entry," ",err)
|
||||
if err != nil {
|
||||
ctx.NotFound("Repo.Commit.GetTreeEntryByPath", err)
|
||||
fmt.Println("*********GetTreeEntryByPath:", entry, " ", err)
|
||||
if err != nil {
|
||||
ctx.NotFound("Repo.Commit.GetTreeEntryByPath", err)
|
||||
return
|
||||
}
|
||||
if entry==nil {
|
||||
ctx.NotFound("Repo.Commit.GetTreeEntryByPath", err)
|
||||
if entry == nil {
|
||||
ctx.NotFound("Repo.Commit.GetTreeEntryByPath", err)
|
||||
return
|
||||
}
|
||||
renderFile(ctx, entry, treeLink, rawLink)
|
||||
|
@ -594,10 +657,10 @@ func ViewFile(ctx *context.APIContext) {
|
|||
paths := make([]string, 0, 5)
|
||||
if len(ctx.Repo.TreePath) > 0 {
|
||||
treeNames = strings.Split(ctx.Repo.TreePath, "/")
|
||||
fmt.Println("***treeNames:",treeNames)
|
||||
fmt.Println("***treeNames:", treeNames)
|
||||
for i := range treeNames {
|
||||
paths = append(paths, strings.Join(treeNames[:i+1], "/"))
|
||||
fmt.Println("***paths:",paths)
|
||||
fmt.Println("***paths:", paths)
|
||||
|
||||
}
|
||||
ctx.Data["HasParentPath"] = true
|
||||
|
@ -606,17 +669,16 @@ func ViewFile(ctx *context.APIContext) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
ctx.Data["Paths"] = paths
|
||||
ctx.Data["TreeLink"] = treeLink
|
||||
ctx.Data["TreeNames"] = treeNames
|
||||
ctx.Data["BranchLink"] = branchLink
|
||||
|
||||
fmt.Println("***rawLink:",rawLink)
|
||||
fmt.Println("***paths:",paths)
|
||||
fmt.Println("***treeLink:",treeLink)
|
||||
fmt.Println("***treeNames:",treeNames)
|
||||
fmt.Println("***branchLink:",branchLink)
|
||||
fmt.Println("***rawLink:", rawLink)
|
||||
fmt.Println("***paths:", paths)
|
||||
fmt.Println("***treeLink:", treeLink)
|
||||
fmt.Println("***treeNames:", treeNames)
|
||||
fmt.Println("***branchLink:", branchLink)
|
||||
|
||||
ctx.JSON(http.StatusOK, Map2DTO(ctx))
|
||||
|
||||
|
@ -627,7 +689,7 @@ func renderFile(ctx *context.APIContext, entry *git.TreeEntry, treeLink, rawLink
|
|||
blob := entry.Blob()
|
||||
dataRc, err := blob.DataAsync()
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError,"DataAsync", err)
|
||||
ctx.Error(http.StatusInternalServerError, "DataAsync", err)
|
||||
return
|
||||
}
|
||||
defer dataRc.Close()
|
||||
|
@ -640,9 +702,9 @@ func renderFile(ctx *context.APIContext, entry *git.TreeEntry, treeLink, rawLink
|
|||
ctx.Data["FileName"] = blob.Name()
|
||||
ctx.Data["RawFileLink"] = rawLink + "/" + ctx.Repo.TreePath
|
||||
|
||||
Base64Encoding:=base64.StdEncoding
|
||||
if ctx.Data["Encoding"]=="base64url" {
|
||||
Base64Encoding=base64.RawURLEncoding
|
||||
Base64Encoding := base64.StdEncoding
|
||||
if ctx.Data["Encoding"] == "base64url" {
|
||||
Base64Encoding = base64.RawURLEncoding
|
||||
}
|
||||
buf := make([]byte, 1024)
|
||||
n, _ := dataRc.Read(buf)
|
||||
|
@ -657,11 +719,11 @@ func renderFile(ctx *context.APIContext, entry *git.TreeEntry, treeLink, rawLink
|
|||
if meta != nil {
|
||||
meta, err = ctx.Repo.Repository.GetLFSMetaObjectByOid(meta.Oid)
|
||||
if err != nil && err != models.ErrLFSObjectNotExist {
|
||||
ctx.Error(http.StatusInternalServerError,"GetLFSMetaObject", err)
|
||||
ctx.Error(http.StatusInternalServerError, "GetLFSMetaObject", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
fmt.Println("***setting.LFS.StartServer:",meta)
|
||||
fmt.Println("***setting.LFS.StartServer:", meta)
|
||||
if meta != nil {
|
||||
ctx.Data["IsLFSFile"] = true
|
||||
isLFSFile = true
|
||||
|
@ -670,7 +732,7 @@ func renderFile(ctx *context.APIContext, entry *git.TreeEntry, treeLink, rawLink
|
|||
var err error
|
||||
dataRc, err = lfs.ReadMetaObject(meta)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError,"ReadMetaObject", err)
|
||||
ctx.Error(http.StatusInternalServerError, "ReadMetaObject", err)
|
||||
return
|
||||
}
|
||||
defer dataRc.Close()
|
||||
|
@ -678,7 +740,7 @@ func renderFile(ctx *context.APIContext, entry *git.TreeEntry, treeLink, rawLink
|
|||
buf = make([]byte, 1024)
|
||||
n, err = dataRc.Read(buf)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError,"Data", err)
|
||||
ctx.Error(http.StatusInternalServerError, "Data", err)
|
||||
return
|
||||
}
|
||||
buf = buf[:n]
|
||||
|
@ -696,7 +758,7 @@ func renderFile(ctx *context.APIContext, entry *git.TreeEntry, treeLink, rawLink
|
|||
lfsLock, err := ctx.Repo.Repository.GetTreePathLock(ctx.Repo.TreePath)
|
||||
ctx.Data["LFSLock"] = lfsLock
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError,"GetTreePathLock", err)
|
||||
ctx.Error(http.StatusInternalServerError, "GetTreePathLock", err)
|
||||
return
|
||||
}
|
||||
if lfsLock != nil {
|
||||
|
@ -727,7 +789,7 @@ func renderFile(ctx *context.APIContext, entry *git.TreeEntry, treeLink, rawLink
|
|||
ctx.Data["MarkupType"] = markupType
|
||||
//ctx.Data["FileContent"] = string(markup.Render(blob.Name(), buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeDocumentMetas()))
|
||||
filenameBase64 := Base64Encoding.EncodeToString(buf)
|
||||
ctx.Data["FileContent"] =filenameBase64
|
||||
ctx.Data["FileContent"] = filenameBase64
|
||||
//fmt.Println("************FileContent1:",ctx.Data["FileContent"].(string))
|
||||
} else if readmeExist {
|
||||
ctx.Data["IsRenderedHTML"] = true
|
||||
|
@ -742,7 +804,7 @@ func renderFile(ctx *context.APIContext, entry *git.TreeEntry, treeLink, rawLink
|
|||
//ctx.Data["FileContent"] = highlight.File(lineNums, blob.Name(), buf)
|
||||
|
||||
filenameBase64 := Base64Encoding.EncodeToString(buf)
|
||||
ctx.Data["FileContent"] =filenameBase64
|
||||
ctx.Data["FileContent"] = filenameBase64
|
||||
//fmt.Println("************FileContent2:",ctx.Data["FileContent"].(string))
|
||||
}
|
||||
if !isLFSFile {
|
||||
|
@ -783,12 +845,12 @@ func renderFile(ctx *context.APIContext, entry *git.TreeEntry, treeLink, rawLink
|
|||
//ctx.Data["FileContent"] = string(markup.Render(blob.Name(), buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeDocumentMetas()))
|
||||
|
||||
filenameBase64 := Base64Encoding.EncodeToString(buf)
|
||||
ctx.Data["FileContent"] =filenameBase64
|
||||
fmt.Println("************FileContent3:",ctx.Data["FileContent"].(string))
|
||||
ctx.Data["FileContent"] = filenameBase64
|
||||
fmt.Println("************FileContent3:", ctx.Data["FileContent"].(string))
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
func safeURL(address string) string {
|
||||
u, err := url.Parse(address)
|
||||
if err != nil {
|
||||
|
@ -798,7 +860,6 @@ func safeURL(address string) string {
|
|||
return u.String()
|
||||
}
|
||||
|
||||
|
||||
func linesBytesCount(s []byte) int {
|
||||
nl := []byte{'\n'}
|
||||
n := bytes.Count(s, nl)
|
||||
|
@ -820,7 +881,6 @@ func linesBytesCount(s []byte) int {
|
|||
}
|
||||
*/
|
||||
|
||||
|
||||
// FIXME: There has to be a more efficient way of doing this
|
||||
func getReadmeFileFromPath(commit *git.Commit, treePath string) (*namedBlob, error) {
|
||||
|
||||
|
@ -897,13 +957,13 @@ func getReadmeFileFromPath(commit *git.Commit, treePath string) (*namedBlob, err
|
|||
// FIXME: There has to be a more efficient way of doing this
|
||||
func getReadmeFileFromPathExt(ctx *context.APIContext, treePath, ref string) (*namedBlob, error) {
|
||||
log.Info("*****************getReadmeFileFromPathExt.GetCommit:ref:%s treepath:%s", ref, treePath)
|
||||
var err error
|
||||
var err error
|
||||
if ctx.Repo.GitRepo == nil {
|
||||
repoPath := models.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
|
||||
ctx.Repo.GitRepo, err = git.OpenRepository(repoPath)
|
||||
if err != nil {
|
||||
ctx.ServerError("RepoRef Invalid repo "+repoPath, err)
|
||||
return nil,err
|
||||
return nil, err
|
||||
}
|
||||
// We opened it, we should close it
|
||||
defer func() {
|
||||
|
@ -914,7 +974,6 @@ func getReadmeFileFromPathExt(ctx *context.APIContext, treePath, ref string) (*n
|
|||
}()
|
||||
}
|
||||
|
||||
|
||||
// Get the commit object for the ref
|
||||
commit, err := ctx.Repo.GitRepo.GetCommit(ref)
|
||||
if err != nil {
|
||||
|
@ -922,7 +981,7 @@ func getReadmeFileFromPathExt(ctx *context.APIContext, treePath, ref string) (*n
|
|||
}
|
||||
//log.Info("********GetCommit:%v",commit)
|
||||
|
||||
ctx.Repo.Commit=commit
|
||||
ctx.Repo.Commit = commit
|
||||
|
||||
tree, err := commit.SubTree(treePath)
|
||||
if err != nil {
|
||||
|
@ -995,7 +1054,6 @@ func getReadmeFileFromPathExt(ctx *context.APIContext, treePath, ref string) (*n
|
|||
return readmeFile, nil
|
||||
}
|
||||
|
||||
|
||||
func FindFiles(ctx *context.APIContext) {
|
||||
// swagger:operation GET /repos/{owner}/{repo}/find repository find
|
||||
// ---
|
||||
|
@ -1030,23 +1088,23 @@ func FindFiles(ctx *context.APIContext) {
|
|||
// "$ref": "#/responses/notFound"
|
||||
|
||||
treePath := ctx.Repo.TreePath
|
||||
ref:= ctx.QueryTrim("ref")
|
||||
ref := ctx.QueryTrim("ref")
|
||||
if ref == "" {
|
||||
ref = ctx.Repo.Repository.DefaultBranch
|
||||
}
|
||||
fmt.Println("***ref:",ref)
|
||||
keyword:= ctx.QueryTrim("q")
|
||||
fmt.Println("***ref:", ref)
|
||||
keyword := ctx.QueryTrim("q")
|
||||
if keyword == "" {
|
||||
//keyword="README" //test
|
||||
}
|
||||
|
||||
FindList,err:=FindFileFromPathExt(ctx,treePath,ref,keyword)
|
||||
if err !=nil {
|
||||
ctx.NotFound("FindFiles", err)
|
||||
FindList, err := FindFileFromPathExt(ctx, treePath, ref, keyword)
|
||||
if err != nil {
|
||||
ctx.NotFound("FindFiles", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK,FindList)
|
||||
ctx.JSON(http.StatusOK, FindList)
|
||||
}
|
||||
|
||||
// TO DO
|
||||
|
@ -1056,7 +1114,7 @@ func FindFileFromPathExt(ctx *context.APIContext, treePath, ref, key string) (fi
|
|||
ctx.Repo.GitRepo, err = git.OpenRepository(repoPath)
|
||||
if err != nil {
|
||||
ctx.ServerError("RepoRef Invalid repo "+repoPath, err)
|
||||
return nil,err
|
||||
return nil, err
|
||||
}
|
||||
// We opened it, we should close it
|
||||
defer func() {
|
||||
|
@ -1067,14 +1125,12 @@ func FindFileFromPathExt(ctx *context.APIContext, treePath, ref, key string) (fi
|
|||
}()
|
||||
}
|
||||
|
||||
|
||||
// Get the commit object for the ref
|
||||
commit, err := ctx.Repo.GitRepo.GetCommit(ref)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
tree, err := commit.SubTree(treePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -1089,21 +1145,20 @@ func FindFileFromPathExt(ctx *context.APIContext, treePath, ref, key string) (fi
|
|||
return nil, err
|
||||
}
|
||||
|
||||
fileList =make([]*SearchFileItem,0,0)
|
||||
fileList = make([]*SearchFileItem, 0, 0)
|
||||
|
||||
for _, entry := range entries {
|
||||
if entry.IsDir() {
|
||||
continue
|
||||
}
|
||||
|
||||
fileName := filepath.Base(entry.Name())
|
||||
|
||||
fileName:=filepath.Base(entry.Name())
|
||||
|
||||
if strings.Contains(strings.ToLower(fileName),strings.ToLower(key)) || key=="" {
|
||||
if strings.Contains(strings.ToLower(fileName), strings.ToLower(key)) || key == "" {
|
||||
name := entry.Name()
|
||||
//isSymlink := entry.IsLink()
|
||||
//target := entry
|
||||
//_=target
|
||||
//_=target
|
||||
//
|
||||
//if isSymlink {
|
||||
// target, err = entry.FollowLinks()
|
||||
|
@ -1111,7 +1166,7 @@ func FindFileFromPathExt(ctx *context.APIContext, treePath, ref, key string) (fi
|
|||
// return nil, err
|
||||
// }
|
||||
//}
|
||||
treePath=name
|
||||
treePath = name
|
||||
selfURL, err := url.Parse(fmt.Sprintf("%s/contents/%s?ref=%s", ctx.Repo.Repository.APIURL(), treePath, ref))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -1129,15 +1184,14 @@ func FindFileFromPathExt(ctx *context.APIContext, treePath, ref, key string) (fi
|
|||
}
|
||||
htmlURLString := htmlURL.String()
|
||||
|
||||
|
||||
Item := &SearchFileItem{
|
||||
Name:fileName,
|
||||
Path:treePath,
|
||||
SHA:entry.ID.String(),
|
||||
Type:entry.Type(),
|
||||
Size:entry.Size(),
|
||||
URL:&selfURLString,
|
||||
HTMLURL:&htmlURLString,
|
||||
Name: fileName,
|
||||
Path: treePath,
|
||||
SHA: entry.ID.String(),
|
||||
Type: entry.Type(),
|
||||
Size: entry.Size(),
|
||||
URL: &selfURLString,
|
||||
HTMLURL: &htmlURLString,
|
||||
}
|
||||
|
||||
// Now populate the rest of the ContentsResponse based on entry type
|
||||
|
@ -1152,29 +1206,28 @@ func FindFileFromPathExt(ctx *context.APIContext, treePath, ref, key string) (fi
|
|||
} else if entry.IsSubModule() {
|
||||
Item.Type = string(repofiles.ContentTypeSubmodule)
|
||||
}
|
||||
fileList=append(fileList,Item)
|
||||
fileList = append(fileList, Item)
|
||||
}
|
||||
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
type SearchFileItem struct {
|
||||
Name string `json:"name"`
|
||||
Path string `json:"path"`
|
||||
SHA string `json:"sha"`
|
||||
// `type` will be `file`, `dir`, `symlink`, or `submodule`
|
||||
Type string `json:"type"`
|
||||
Size int64 `json:"size"`
|
||||
URL *string `json:"url"`
|
||||
HTMLURL *string `json:"html_url"`
|
||||
// GitURL *string `json:"git_url"`
|
||||
// DownloadURL *string `json:"download_url"`
|
||||
// // `submodule_git_url` is populated when `type` is `submodule`, otherwise null
|
||||
// SubmoduleGitURL *string `json:"submodule_git_url"`
|
||||
// Links *api.FileLinksResponse `json:"_links"`
|
||||
}
|
||||
Type string `json:"type"`
|
||||
Size int64 `json:"size"`
|
||||
URL *string `json:"url"`
|
||||
HTMLURL *string `json:"html_url"`
|
||||
// GitURL *string `json:"git_url"`
|
||||
// DownloadURL *string `json:"download_url"`
|
||||
// // `submodule_git_url` is populated when `type` is `submodule`, otherwise null
|
||||
// SubmoduleGitURL *string `json:"submodule_git_url"`
|
||||
// Links *api.FileLinksResponse `json:"_links"`
|
||||
}
|
||||
|
||||
func IsReadmeFileExt(name string, ext ...string) bool {
|
||||
name = strings.ToLower(name)
|
||||
|
@ -1189,7 +1242,6 @@ func IsReadmeFileExt(name string, ext ...string) bool {
|
|||
return name[:7] == "readme_zh."
|
||||
}
|
||||
|
||||
|
||||
type namedBlob struct {
|
||||
name string
|
||||
isSymlink bool
|
||||
|
@ -1197,13 +1249,13 @@ type namedBlob struct {
|
|||
}
|
||||
|
||||
type ReadmeDTO struct {
|
||||
Type string `json:"type"`
|
||||
Encoding string `json:"encoding"`
|
||||
Size int64 `json:"size"`
|
||||
Name string `json:"name"`
|
||||
Path string `json:"path"`
|
||||
Content string `json:"content"`
|
||||
Sha string `json:"sha"`
|
||||
Type string `json:"type"`
|
||||
Encoding string `json:"encoding"`
|
||||
Size int64 `json:"size"`
|
||||
Name string `json:"name"`
|
||||
Path string `json:"path"`
|
||||
Content string `json:"content"`
|
||||
Sha string `json:"sha"`
|
||||
//URL string `json:"url"`
|
||||
//GitURL string `json:"git_url"`
|
||||
//HTMLURL string `json:"html_url"`
|
||||
|
@ -1216,7 +1268,7 @@ type ReadmeDTO struct {
|
|||
}
|
||||
|
||||
type ReadmeResponeDTO struct {
|
||||
Msg string
|
||||
Code int
|
||||
Msg string
|
||||
Code int
|
||||
ReadmeDTO *ReadmeDTO
|
||||
}
|
||||
|
|
|
@ -179,7 +179,7 @@ func FileHistory(ctx *context.Context) {
|
|||
page = 1
|
||||
}
|
||||
|
||||
commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange(branchName, fileName, page)
|
||||
commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange(branchName, fileName, page, 50)
|
||||
if err != nil {
|
||||
ctx.ServerError("CommitsByFileAndRange", err)
|
||||
return
|
||||
|
|
|
@ -277,7 +277,7 @@ func renderRevisionPage(ctx *context.Context) (*git.Repository, *git.TreeEntry)
|
|||
}
|
||||
|
||||
// get Commit Count
|
||||
commitsHistory, err := wikiRepo.CommitsByFileAndRangeNoFollow("master", pageFilename, page)
|
||||
commitsHistory, err := wikiRepo.CommitsByFileAndRangeNoFollow("master", pageFilename, page, 50)
|
||||
if err != nil {
|
||||
if wikiRepo != nil {
|
||||
wikiRepo.Close()
|
||||
|
|
|
@ -76,6 +76,7 @@ func CheckFile(filename string) error {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// InitWiki initializes a wiki for repository,
|
||||
// it does nothing when repository already has wiki.
|
||||
func InitWiki(repo *models.Repository) error {
|
||||
|
|
|
@ -2443,6 +2443,39 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/repos/{owner}/{repo}/branches/branches_slice": {
|
||||
"get": {
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"repository"
|
||||
],
|
||||
"summary": "List a repository's branches, Group sort.",
|
||||
"operationId": "repoListBranchesSlice",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "owner of the repo",
|
||||
"name": "owner",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "name of the repo",
|
||||
"name": "repo",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"$ref": "#/responses/BranchList"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/repos/{owner}/{repo}/branches/{branch}": {
|
||||
"get": {
|
||||
"produces": [
|
||||
|
@ -2810,6 +2843,63 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/repos/{owner}/{repo}/commits_slice": {
|
||||
"get": {
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"repository"
|
||||
],
|
||||
"summary": "Get a list of all commits from a repository",
|
||||
"operationId": "repoGetAllCommitsSlice",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "owner of the repo",
|
||||
"name": "owner",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "name of the repo",
|
||||
"name": "repo",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "SHA or branch to start listing commits from (usually 'master')",
|
||||
"name": "sha",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "page number of results to return (1-based)",
|
||||
"name": "page",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "page size of results",
|
||||
"name": "limit",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"$ref": "#/responses/CommitList"
|
||||
},
|
||||
"404": {
|
||||
"$ref": "#/responses/notFound"
|
||||
},
|
||||
"409": {
|
||||
"$ref": "#/responses/EmptyRepository"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/repos/{owner}/{repo}/contents": {
|
||||
"get": {
|
||||
"produces": [
|
||||
|
@ -3196,6 +3286,70 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/repos/{owner}/{repo}/file_commits/{filepath}": {
|
||||
"get": {
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"repository"
|
||||
],
|
||||
"summary": "Get a list of all commits by filepath from a repository",
|
||||
"operationId": "repoGetFileAllCommits",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "owner of the repo",
|
||||
"name": "owner",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "name of the repo",
|
||||
"name": "repo",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "filepath of the file to get",
|
||||
"name": "filepath",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "SHA or branch to start listing commits from (usually 'master')",
|
||||
"name": "sha",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "page number of results to return (1-based)",
|
||||
"name": "page",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "page size of results",
|
||||
"name": "limit",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"$ref": "#/responses/FileCommitList"
|
||||
},
|
||||
"404": {
|
||||
"$ref": "#/responses/notFound"
|
||||
},
|
||||
"409": {
|
||||
"$ref": "#/responses/EmptyRepository"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/repos/{owner}/{repo}/find": {
|
||||
"get": {
|
||||
"produces": [
|
||||
|
@ -7609,6 +7763,12 @@
|
|||
"name": "filepath",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "The name of the commit/branch/tag. Default the repository’s default branch (usually master)",
|
||||
"name": "ref",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
|
@ -7663,6 +7823,55 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/repos/{owner}/{repo}/readme/{dir}": {
|
||||
"get": {
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"repository"
|
||||
],
|
||||
"summary": "Gets the metadata and contents (if a file) of an entry in a repository, or a list of entries if a dir",
|
||||
"operationId": "readmePathContents",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "owner of the repo",
|
||||
"name": "owner",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "name of the repo",
|
||||
"name": "repo",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "name of the path",
|
||||
"name": "dir",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "The name of the commit/branch/tag. Default the repository’s default branch (usually master)",
|
||||
"name": "ref",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"$ref": "#/responses/ContentsResponse"
|
||||
},
|
||||
"404": {
|
||||
"$ref": "#/responses/notFound"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/repos/{owner}/{repo}/releases": {
|
||||
"get": {
|
||||
"produces": [
|
||||
|
@ -11303,9 +11512,26 @@
|
|||
"description": "Branch represents a repository branch",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"branch_kind": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"x-go-name": "BranchKind"
|
||||
},
|
||||
"commit": {
|
||||
"$ref": "#/definitions/PayloadCommit"
|
||||
},
|
||||
"commit_id": {
|
||||
"type": "string",
|
||||
"x-go-name": "CommitID"
|
||||
},
|
||||
"commit_time": {
|
||||
"type": "string",
|
||||
"x-go-name": "CommitTime"
|
||||
},
|
||||
"default_branch": {
|
||||
"type": "string",
|
||||
"x-go-name": "DefaultBranch"
|
||||
},
|
||||
"effective_branch_protection_name": {
|
||||
"type": "string",
|
||||
"x-go-name": "EffectiveBranchProtectionName"
|
||||
|
@ -11530,14 +11756,21 @@
|
|||
},
|
||||
"Commit": {
|
||||
"type": "object",
|
||||
"title": "Commit contains information generated from a Git commit.",
|
||||
"properties": {
|
||||
"author": {
|
||||
"$ref": "#/definitions/User"
|
||||
},
|
||||
"branch": {
|
||||
"type": "string",
|
||||
"x-go-name": "Branch"
|
||||
},
|
||||
"commit": {
|
||||
"$ref": "#/definitions/RepoCommit"
|
||||
},
|
||||
"commit_date": {
|
||||
"type": "string",
|
||||
"x-go-name": "CommitDate"
|
||||
},
|
||||
"committer": {
|
||||
"$ref": "#/definitions/User"
|
||||
},
|
||||
|
@ -14773,6 +15006,10 @@
|
|||
"format": "date-time",
|
||||
"x-go-name": "PublishedAt"
|
||||
},
|
||||
"sha": {
|
||||
"type": "string",
|
||||
"x-go-name": "Sha1"
|
||||
},
|
||||
"tag_name": {
|
||||
"type": "string",
|
||||
"x-go-name": "TagName"
|
||||
|
@ -15158,16 +15395,23 @@
|
|||
"type": "object",
|
||||
"properties": {
|
||||
"commit": {
|
||||
"$ref": "#/definitions/CommitMeta"
|
||||
"$ref": "#/definitions/TagCommit"
|
||||
},
|
||||
"id": {
|
||||
"type": "string",
|
||||
"x-go-name": "ID"
|
||||
},
|
||||
"message": {
|
||||
"type": "string",
|
||||
"x-go-name": "Message"
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"x-go-name": "Name"
|
||||
},
|
||||
"tagger": {
|
||||
"$ref": "#/definitions/CommitUser"
|
||||
},
|
||||
"tarball_url": {
|
||||
"type": "string",
|
||||
"x-go-name": "TarballURL"
|
||||
|
@ -15179,6 +15423,30 @@
|
|||
},
|
||||
"x-go-package": "code.gitea.io/gitea/modules/structs"
|
||||
},
|
||||
"TagCommit": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"author": {
|
||||
"$ref": "#/definitions/CommitUser"
|
||||
},
|
||||
"commiter": {
|
||||
"$ref": "#/definitions/CommitUser"
|
||||
},
|
||||
"message": {
|
||||
"type": "string",
|
||||
"x-go-name": "Message"
|
||||
},
|
||||
"sha": {
|
||||
"type": "string",
|
||||
"x-go-name": "SHA"
|
||||
},
|
||||
"url": {
|
||||
"type": "string",
|
||||
"x-go-name": "URL"
|
||||
}
|
||||
},
|
||||
"x-go-package": "code.gitea.io/gitea/modules/structs"
|
||||
},
|
||||
"Team": {
|
||||
"description": "Team represents a team in an organization",
|
||||
"type": "object",
|
||||
|
@ -15506,9 +15774,6 @@
|
|||
"WikiCommit": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"_": {
|
||||
"$ref": "#/definitions/WikiUser"
|
||||
},
|
||||
"author": {
|
||||
"$ref": "#/definitions/WikiUser"
|
||||
},
|
||||
|
@ -15560,14 +15825,6 @@
|
|||
"type": "string",
|
||||
"x-go-name": "Name"
|
||||
},
|
||||
"owner_name": {
|
||||
"type": "string",
|
||||
"x-go-name": "OwnerName"
|
||||
},
|
||||
"repo_name": {
|
||||
"type": "string",
|
||||
"x-go-name": "RepoName"
|
||||
},
|
||||
"simple_content": {
|
||||
"type": "string",
|
||||
"x-go-name": "SimpleContent"
|
||||
|
@ -15607,11 +15864,6 @@
|
|||
"type": "string",
|
||||
"x-go-name": "Name"
|
||||
},
|
||||
"when": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"x-go-name": "When"
|
||||
},
|
||||
"wiki_clone_link": {
|
||||
"$ref": "#/definitions/CloneLink"
|
||||
}
|
||||
|
@ -15799,6 +16051,41 @@
|
|||
"$ref": "#/definitions/APIError"
|
||||
}
|
||||
},
|
||||
"FileCommitList": {
|
||||
"description": "FileCommitList",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/Commit"
|
||||
}
|
||||
},
|
||||
"headers": {
|
||||
"X-HasMore": {
|
||||
"type": "boolean",
|
||||
"description": "True if there is another page"
|
||||
},
|
||||
"X-Page": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"description": "The current page"
|
||||
},
|
||||
"X-PageCount": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"description": "Total number of pages"
|
||||
},
|
||||
"X-PerPage": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"description": "Commits per page"
|
||||
},
|
||||
"X-Total": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"description": "Total commit count"
|
||||
}
|
||||
}
|
||||
},
|
||||
"FileDeleteResponse": {
|
||||
"description": "FileDeleteResponse",
|
||||
"schema": {
|
||||
|
@ -16191,6 +16478,32 @@
|
|||
"items": {
|
||||
"$ref": "#/definitions/Tag"
|
||||
}
|
||||
},
|
||||
"headers": {
|
||||
"X-HasMore": {
|
||||
"type": "boolean",
|
||||
"description": "True if there is another page"
|
||||
},
|
||||
"X-Page": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"description": "The current page"
|
||||
},
|
||||
"X-PageCount": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"description": "Total number of pages"
|
||||
},
|
||||
"X-PerPage": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"description": "Commits per page"
|
||||
},
|
||||
"X-Total": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"description": "Total commit count"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Team": {
|
||||
|
@ -16411,4 +16724,4 @@
|
|||
"TOTPHeader": []
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue