forked from Gitlink/gitea_hat
新增:新增Readme
This commit is contained in:
parent
da9cd18f74
commit
c85cdbbcc4
|
@ -0,0 +1,74 @@
|
||||||
|
<p align="center">
|
||||||
|
<a href="" rel="noopener">
|
||||||
|
<img width=360px height=62px src="https://forum.trustie.net/api/attachments/373016" alt="Project logo"></a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h3 align="center">Gitea GitLink版本</h3>
|
||||||
|
|
||||||
|
<div align="center">
|
||||||
|
|
||||||
|
[]()
|
||||||
|
[](https://www.gitlink.org.cn/Gitlink/gitea_hat/issues)
|
||||||
|
[](https://www.gitlink.org.cn/Gitlink/gitea_hat/pulls)
|
||||||
|
[](/LICENSE)
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
<p align="center"> 此版本为GitLink平台使用的Git服务,该服务基于Gitea进行开发。
|
||||||
|
<br>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
## 📝 目录
|
||||||
|
|
||||||
|
- [📝 目录](#-目录)
|
||||||
|
- [🧐 关于](#-关于)
|
||||||
|
- [编译](#编译)
|
||||||
|
- [运行](#运行)
|
||||||
|
- [接口文档](#接口文档)
|
||||||
|
- [⛏️ 使用](#️-使用)
|
||||||
|
|
||||||
|
## 🧐 关于
|
||||||
|
|
||||||
|
该项目是为了方便平台后续Gitea版本的升级,将个性化接口部分从项目中抽离出来的项目,模块定义遵循gitea规则。
|
||||||
|
|
||||||
|
## 编译
|
||||||
|
|
||||||
|
类Linux平台,在项目根目录运行:
|
||||||
|
```shell
|
||||||
|
# 编译Linux 64位可执行程序
|
||||||
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o gitea main.go
|
||||||
|
|
||||||
|
# 编译Windows 64位可执行程序
|
||||||
|
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o gitea main.go
|
||||||
|
|
||||||
|
# 编译mac 64位可执行程序
|
||||||
|
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o gitea main.go
|
||||||
|
```
|
||||||
|
|
||||||
|
Win平台,在项目根目录运行:
|
||||||
|
```shell
|
||||||
|
# 编译Linux 64位可执行程序
|
||||||
|
SET CGO_ENABLED=0
|
||||||
|
SET GOOS=linux
|
||||||
|
SET GOARCH=amd64
|
||||||
|
go build -o gitea main.go
|
||||||
|
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
## 运行
|
||||||
|
|
||||||
|
在项目根目录下运行:
|
||||||
|
|
||||||
|
```
|
||||||
|
./gitea -p 10082
|
||||||
|
```
|
||||||
|
|
||||||
|
## 接口文档
|
||||||
|
- [ApiDoc](https://www.apifox.cn/apidoc/project-1808982) - 接口文档
|
||||||
|
|
||||||
|
## ⛏️ 使用
|
||||||
|
|
||||||
|
- [Gitea](https://gitea.io/zh-cn/) - Gitea
|
|
@ -0,0 +1,5 @@
|
||||||
|
package structs
|
||||||
|
|
||||||
|
type BranchNameSet struct {
|
||||||
|
BranchName []*string `json:"branch_name"`
|
||||||
|
}
|
|
@ -2,13 +2,18 @@ package hat
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
access_model "code.gitea.io/gitea/models/perm/access"
|
||||||
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
"code.gitea.io/gitea/modules/web"
|
"code.gitea.io/gitea/modules/web"
|
||||||
"code.gitea.io/gitea/routers/api/v1/misc"
|
"code.gitea.io/gitea/routers/api/v1/misc"
|
||||||
"code.gitea.io/gitea/services/auth"
|
"code.gitea.io/gitea/services/auth"
|
||||||
|
"code.gitlink.org.cn/Gitlink/gitea_hat.git/routers/hat/repo"
|
||||||
"github.com/go-chi/cors"
|
"github.com/go-chi/cors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -41,12 +46,15 @@ func Routers() *web.Route {
|
||||||
SignInRequired: setting.Service.RequireSignInView,
|
SignInRequired: setting.Service.RequireSignInView,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
m.Use(context.ToggleAPI(&context.ToggleOptions{
|
|
||||||
SignInRequired: setting.Service.RequireSignInView,
|
|
||||||
}))
|
|
||||||
|
|
||||||
m.Group("", func() {
|
m.Group("", func() {
|
||||||
m.Get("/version", misc.Version)
|
m.Get("/version", misc.Version)
|
||||||
|
m.Group("/repos", func() {
|
||||||
|
m.Group("/{username}/{reponame}", func() {
|
||||||
|
m.Get("/branch_name_set", context.ReferencesGitRepo(), repo.BranchNameSet)
|
||||||
|
|
||||||
|
m.Get("/tag_name_set", context.ReferencesGitRepo(), repo.TagNameSet)
|
||||||
|
}, repoAssignment())
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
return m
|
return m
|
||||||
|
@ -75,3 +83,70 @@ func buildAuthGroup() *auth.Group {
|
||||||
|
|
||||||
return group
|
return group
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func repoAssignment() func(ctx *context.APIContext) {
|
||||||
|
return func(ctx *context.APIContext) {
|
||||||
|
userName := ctx.Params("username")
|
||||||
|
repoName := ctx.Params("reponame")
|
||||||
|
|
||||||
|
var (
|
||||||
|
owner *user_model.User
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
|
// Check if the user is the same as the repository owner.
|
||||||
|
if ctx.IsSigned && ctx.Doer.LowerName == strings.ToLower(userName) {
|
||||||
|
owner = ctx.Doer
|
||||||
|
} else {
|
||||||
|
owner, err = user_model.GetUserByName(ctx, userName)
|
||||||
|
if err != nil {
|
||||||
|
if user_model.IsErrUserNotExist(err) {
|
||||||
|
if redirectUserID, err := user_model.LookupUserRedirect(userName); err == nil {
|
||||||
|
context.RedirectToUser(ctx.Context, userName, redirectUserID)
|
||||||
|
} else if user_model.IsErrUserRedirectNotExist(err) {
|
||||||
|
ctx.NotFound("GetUserByName", err)
|
||||||
|
} else {
|
||||||
|
ctx.Error(http.StatusInternalServerError, "LookupUserRedirect", err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ctx.Repo.Owner = owner
|
||||||
|
ctx.ContextUser = owner
|
||||||
|
|
||||||
|
// Get repository.
|
||||||
|
repo, err := repo_model.GetRepositoryByName(owner.ID, repoName)
|
||||||
|
if err != nil {
|
||||||
|
if repo_model.IsErrRepoNotExist(err) {
|
||||||
|
redirectRepoID, err := repo_model.LookupRedirect(owner.ID, repoName)
|
||||||
|
if err == nil {
|
||||||
|
context.RedirectToRepo(ctx.Context, redirectRepoID)
|
||||||
|
} else if repo_model.IsErrRedirectNotExist(err) {
|
||||||
|
ctx.NotFound()
|
||||||
|
} else {
|
||||||
|
ctx.Error(http.StatusInternalServerError, "LookupRepoRedirect", err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ctx.Error(http.StatusInternalServerError, "GetRepositoryByName", err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
repo.Owner = owner
|
||||||
|
ctx.Repo.Repository = repo
|
||||||
|
|
||||||
|
ctx.Repo.Permission, err = access_model.GetUserRepoPermission(ctx, repo, ctx.Doer)
|
||||||
|
if err != nil {
|
||||||
|
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !ctx.Repo.HasAccess() {
|
||||||
|
ctx.NotFound()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -8,30 +8,31 @@ import (
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func BranchNameSet(ctx *context.APIContext) {
|
||||||
|
|
||||||
|
searchName := ctx.Params("name")
|
||||||
|
branches, _, err := ctx.Repo.GitRepo.GetBranches(0, 0) //get count of the branch
|
||||||
|
if err != nil {
|
||||||
|
ctx.ServerError("GetBranches", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if searchName == "" {
|
||||||
|
ctx.JSON(http.StatusOK, branches)
|
||||||
|
} else {
|
||||||
|
var branchNameSet []string
|
||||||
|
for _, branch := range branches {
|
||||||
|
|
||||||
|
log.Info("branch is \n", branch)
|
||||||
|
if strings.Contains(branch.Name, searchName) {
|
||||||
|
branchNameSet = append(branchNameSet, branch.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ctx.JSON(http.StatusOK, branchNameSet)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TagNameSet(ctx *context.APIContext) {
|
func TagNameSet(ctx *context.APIContext) {
|
||||||
// swagger:operation GET /repos/{owner}/{repo}/tag_name_set repository repoTagNameSet
|
|
||||||
// ---
|
|
||||||
// summary: List a repository's tag name***
|
|
||||||
// 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: name
|
|
||||||
// in: query
|
|
||||||
// description: name of the tag
|
|
||||||
// type: string
|
|
||||||
// responses:
|
|
||||||
// "200":
|
|
||||||
// "$ref": "#/responses/BranchNameSet"
|
|
||||||
|
|
||||||
searchName := ctx.Params("name")
|
searchName := ctx.Params("name")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue