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,13 +1,12 @@
|
|||
/*
|
||||
* @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"`
|
||||
WikiMeta
|
||||
WikiCloneLink CloneLink `json:"wiki_clone_link"`
|
||||
}
|
||||
|
@ -15,6 +14,7 @@ type WikiesResponse struct {
|
|||
type WikiMeta struct {
|
||||
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,8 +32,6 @@ 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"`
|
||||
|
|
|
@ -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,12 +112,10 @@ 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)
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -704,7 +699,9 @@ func RegisterRoutes(m *macaron.Macaron) {
|
|||
|
||||
// alter on 2021/01/15
|
||||
m.Get("", viewfile.Readme) // reqRepoReader(models.UnitTypeCode),
|
||||
}, reqToken())
|
||||
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,7 +540,6 @@ func GetContents(ctx *context.APIContext) {
|
|||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
|
||||
start := time.Now()
|
||||
|
||||
if !canReadFiles(ctx.Repo) {
|
||||
|
|
|
@ -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,17 +24,7 @@ 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) {
|
||||
|
@ -38,7 +39,6 @@ func Map2DTO(ctx *context.APIContext) (dto *ReadmeDTO) {
|
|||
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 {
|
||||
|
@ -223,8 +222,6 @@ func GetRefType() macaron.Handler {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
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,7 +277,6 @@ func CommitCount(ctx *context.APIContext) {
|
|||
}()
|
||||
}
|
||||
|
||||
|
||||
// Get the commit object for the ref
|
||||
commit, err := ctx.Repo.GitRepo.GetCommit(ref)
|
||||
if err != nil || commit == nil {
|
||||
|
@ -331,7 +326,6 @@ func CommitCount(ctx *context.APIContext) {
|
|||
ctx.JSON(http.StatusOK, dto)
|
||||
}
|
||||
|
||||
|
||||
type CountDTO struct {
|
||||
Branch struct {
|
||||
CommitCount int64 `json:"commit_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 {
|
||||
|
@ -404,7 +397,6 @@ func LatestRelease(ctx *context.APIContext) {
|
|||
ctx.JSON(http.StatusOK, release)
|
||||
}
|
||||
|
||||
|
||||
func Readme(ctx *context.APIContext) {
|
||||
// swagger:operation GET /repos/{owner}/{repo}/readme repository readme
|
||||
// ---
|
||||
|
@ -512,7 +504,6 @@ func Readme(ctx *context.APIContext) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
ctx.Data["Paths"] = paths
|
||||
ctx.Data["TreeLink"] = treeLink
|
||||
ctx.Data["TreeNames"] = treeNames
|
||||
|
@ -528,6 +519,78 @@ func Readme(ctx *context.APIContext) {
|
|||
|
||||
}
|
||||
|
||||
/////////////
|
||||
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"
|
||||
|
@ -606,7 +669,6 @@ func ViewFile(ctx *context.APIContext) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
ctx.Data["Paths"] = paths
|
||||
ctx.Data["TreeLink"] = treeLink
|
||||
ctx.Data["TreeNames"] = treeNames
|
||||
|
@ -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) {
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
// ---
|
||||
|
@ -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
|
||||
|
@ -1096,7 +1152,6 @@ func FindFileFromPathExt(ctx *context.APIContext, treePath, ref, key string) (fi
|
|||
continue
|
||||
}
|
||||
|
||||
|
||||
fileName := filepath.Base(entry.Name())
|
||||
|
||||
if strings.Contains(strings.ToLower(fileName), strings.ToLower(key)) || key == "" {
|
||||
|
@ -1129,7 +1184,6 @@ func FindFileFromPathExt(ctx *context.APIContext, treePath, ref, key string) (fi
|
|||
}
|
||||
htmlURLString := htmlURL.String()
|
||||
|
||||
|
||||
Item := &SearchFileItem{
|
||||
Name: fileName,
|
||||
Path: treePath,
|
||||
|
@ -1159,7 +1213,6 @@ func FindFileFromPathExt(ctx *context.APIContext, treePath, ref, key string) (fi
|
|||
return
|
||||
}
|
||||
|
||||
|
||||
type SearchFileItem struct {
|
||||
Name string `json:"name"`
|
||||
Path string `json:"path"`
|
||||
|
@ -1189,7 +1242,6 @@ func IsReadmeFileExt(name string, ext ...string) bool {
|
|||
return name[:7] == "readme_zh."
|
||||
}
|
||||
|
||||
|
||||
type namedBlob struct {
|
||||
name string
|
||||
isSymlink bool
|
||||
|
|
|
@ -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": {
|
||||
|
|
Loading…
Reference in New Issue