fix: api use restful and back data example

This commit is contained in:
yystopf 2021-08-06 16:58:04 +08:00
parent ca7dad0ebc
commit d9495f6822
14 changed files with 630 additions and 428 deletions

View File

@ -1159,16 +1159,12 @@ type ErrWebhookNotExist struct {
ID int64
}
// IsErrWebhookNotExist checks if an error is a ErrWebhookNotExist.
func IsErrWebhookNotExist(err error) bool {
_, ok := err.(ErrWebhookNotExist)
return ok
}
func IsErrHookTaskNotExist(err error) bool {
_, ok := err.(ErrWebhookNotExist)
return ok
}
func (err ErrWebhookNotExist) Error() string {
return fmt.Sprintf("webhook does not exist [id: %d]", err.ID)
}

View File

@ -2119,21 +2119,6 @@ func CopyLFS(ctx DBContext, newRepo, oldRepo *Repository) error {
return nil
}
//<<<<<<< HEAD
/////////////////////////////GetWiki
//func (repo *Repository) GetWikis(listOptions ListOptions) ([]*Repository, error) {
// if listOptions.Page == 0 {
// wikis := make([]*Repository, 0, repo.NumWikis)
// return wikis, x.Find(&wikis, &Repository{WikiID: repo.ID})
// }
//
// sess := listOptions.getPaginatedSession()
// wikis := make([]*Repository, 0, listOptions.PageSize)
// return wikis, sess.Find(&wikis, &Repository{WikiID: repo.ID})
//}
//>>>>>>> 3b5dff2e2323aa944690ad52574c3e3b389689ac
// GetForks returns all the forks of the repository
func (repo *Repository) GetForks(listOptions ListOptions) ([]*Repository, error) {

View File

@ -334,18 +334,6 @@ func getWebhook(bean *Webhook) (*Webhook, error) {
return bean, nil
}
func getHookTask(bean *HookTask) (*HookTask, error) {
has, err := x.Get(bean)
if err != nil {
return nil, err
} else if !has {
return nil, ErrWebhookNotExist{bean.ID}
}
return bean, nil
}
// GetWebhookByID returns webhook of repository by given ID.
func GetWebhookByID(id int64) (*Webhook, error) {
return getWebhook(&Webhook{
@ -360,12 +348,7 @@ func GetWebhookByRepoID(repoID, id int64) (*Webhook, error) {
RepoID: repoID,
})
}
func GetHookTaskByRepoID(repoID, id int64) (*HookTask, error) {
return getHookTask(&HookTask{
ID: id,
RepoID: repoID,
})
}
// GetWebhookByOrgID returns webhook of organization by given ID.
func GetWebhookByOrgID(orgID, id int64) (*Webhook, error) {
return getWebhook(&Webhook{
@ -397,17 +380,7 @@ func GetWebhooksByRepoID(repoID int64, listOptions ListOptions) ([]*Webhook, err
return webhooks, sess.Find(&webhooks, &Webhook{RepoID: repoID})
}
func GetHookTasksByRepoID(repoID int64, listOptions ListOptions) ([]*HookTask, error) {
if listOptions.Page == 0 {
hooktasks := make([]*HookTask, 0, 5)
return hooktasks,x.Find(&hooktasks, &HookTask{RepoID: repoID})
}
sess := listOptions.getPaginatedSession()
hooktasks := make([]*HookTask, 0, listOptions.PageSize)
return hooktasks, sess.Find(&hooktasks, &HookTask{RepoID: repoID})
}
// GetActiveWebhooksByOrgID returns all active webhooks for an organization.
func GetActiveWebhooksByOrgID(orgID int64) (ws []*Webhook, err error) {
return getActiveWebhooksByOrgID(x, orgID)
@ -783,6 +756,18 @@ func (t *HookTask) simpleMarshalJSON(v interface{}) string {
return string(p)
}
func GetHookTasksByRepoIDAndHookID(repoID int64, hookID int64, listOptions ListOptions) ([]*HookTask, error) {
if listOptions.Page == 0 {
hookTasks := make([]*HookTask, 0, 5)
return hookTasks, x.Find(&hookTasks, &HookTask{RepoID: repoID, HookID: hookID})
}
sess := listOptions.getPaginatedSession()
hookTasks := make([]*HookTask, 0, listOptions.PageSize)
return hookTasks, sess.Find(&hookTasks, &HookTask{RepoID: repoID, HookID: hookID})
}
// HookTasks returns a list of hook tasks by given conditions.
func HookTasks(hookID int64, page int) ([]*HookTask, error) {
tasks := make([]*HookTask, 0, setting.Webhook.PagingNum)

View File

@ -5,6 +5,7 @@
package convert
import (
"encoding/json"
"fmt"
"time"
@ -278,6 +279,36 @@ func ToHook(repoLink string, w *models.Webhook) *api.Hook {
}
}
func ToHookTask(t *models.HookTask) *api.HookTask {
config := map[string]string{
"url": t.URL,
"content_type": t.ContentType.Name(),
"http_method": t.HTTPMethod,
}
payloadContent := make(map[string]interface{})
requestContent := make(map[string]interface{})
responseContent := make(map[string]interface{})
_ = json.Unmarshal([]byte(t.PayloadContent), &payloadContent)
_ = json.Unmarshal([]byte(t.RequestContent), &requestContent)
_ = json.Unmarshal([]byte(t.ResponseContent), &responseContent)
return &api.HookTask{
ID: t.ID,
UUID: t.UUID,
Type: t.Type.Name(),
Config: config,
PayloadContent: payloadContent,
EventType: string(t.EventType),
IsSSL: t.IsSSL,
IsDelivered: t.IsDelivered,
Delivered: t.Delivered,
IsSucceed: t.IsSucceed,
RequestContent: requestContent,
ResponseContent: responseContent,
}
}
// ToGitHook convert git.Hook to api.GitHook
func ToGitHook(h *git.Hook) *api.GitHook {
return &api.GitHook{

View File

@ -35,6 +35,21 @@ type Hook struct {
// HookList represents a list of API hook.
type HookList []*Hook
type HookTask struct {
ID int64 `json:"id"`
UUID string `json:"uuid"`
Type string `json:"type"`
Config map[string]string `json:"config"`
PayloadContent map[string]interface{} `json:"payload_content"`
EventType string `json:"event_type"`
IsSSL bool `json:"is_ssl"`
IsDelivered bool `json:"is_delivered"`
Delivered int64 `json:"delivered"`
IsSucceed bool `json:"is_succeed"`
RequestContent map[string]interface{} `json:"request_info"`
ResponseContent map[string]interface{} `json:"response_content"`
}
// CreateHookOptionConfig has all config options in it
// required are "content_type" and "url" Required
type CreateHookOptionConfig map[string]string
@ -51,17 +66,7 @@ type CreateHookOption struct {
// default: false
Active bool `json:"active"`
}
type CreateHookTaskOption struct {
// required: true
// enum: dingtalk,discord,gitea,gogs,msteams,slack,telegram,feishu
Type string `json:"type" binding:"Required"`
//required: true
Config CreateHookOptionConfig `json:"config" binding:"Required"`
Events []string `json:"events"`
BranchFilter string `json:"branch_filter" binding:"GlobPattern"`
//default: false
Active bool `json:"active"`
}
// EditHookOption options when modify one hook
type EditHookOption struct {
Config map[string]string `json:"config"`

41
modules/structs/wiki.go Normal file
View File

@ -0,0 +1,41 @@
/*
* @Date: 2021-08-06 14:28:55
* @LastEditors: viletyy
* @LastEditTime: 2021-08-06 16:33:20
* @FilePath: /gitea-1120-rc1/modules/structs/wiki.go
*/
package structs
type WikiesResponse struct {
WikiMeta
}
type WikiMeta struct {
Name string `json:"name"`
Commit WikiCommit `json:"commit"`
}
type WikiCommit struct {
ID string `json:"id"`
Message string `json:"message"`
Author WikiUser `json:"author"`
Commiter WikiUser `json:"-"`
}
type WikiUser struct {
Name string `json:"name"`
Email string `json:"email"`
When int64 `json:"when"`
}
type WikiResponse struct {
WikiMeta
CommitCounts int64 `json:"commit_counts"`
Content string `json:"content"`
}
type WikiOption struct {
Name string `json:"name"`
Content string `json:"content"`
CommitMessage string `json:"commit_message"`
}

View File

@ -1,19 +1,24 @@
package wikis
/*
* @Date: 2021-08-06 09:53:43
* @LastEditors: viletyy
* @LastEditTime: 2021-08-06 16:55:28
* @FilePath: /gitea-1120-rc1/modules/wikies/wiki.go
*/
package wikies
import (
"io/ioutil"
"net/url"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
wiki_service "code.gitea.io/gitea/services/wiki"
"io/ioutil"
"net/url"
)
func FindWikiRepoCommit(ctx *context.APIContext) (*git.Repository, *git.Commit, error) {
wikiRepo, err := git.OpenRepository(ctx.Repo.Repository.WikiPath())
if err != nil {
ctx.ServerError("OpenRepository", err)
// ctx.ServerError("OpenRepository", err)
return nil, nil, err
}
@ -24,7 +29,6 @@ func FindWikiRepoCommit(ctx *context.APIContext) (*git.Repository, *git.Commit,
return wikiRepo, commit, nil
}
func WikiContentsByName(ctx *context.APIContext, commit *git.Commit, wikiName string) ([]byte, *git.TreeEntry, string, bool) {
pageFilename := wiki_service.NameToFilename(wikiName)
entry, err := findEntryForFile(commit, pageFilename)

View File

@ -65,6 +65,9 @@
package v1
import (
"net/http"
"strings"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/auth"
"code.gitea.io/gitea/modules/context"
@ -81,8 +84,6 @@ import (
_ "code.gitea.io/gitea/routers/api/v1/swagger" // for swagger generation
"code.gitea.io/gitea/routers/api/v1/user"
"code.gitea.io/gitea/routers/api/v1/viewfile"
"net/http"
"strings"
"gitea.com/macaron/binding"
"gitea.com/macaron/macaron"
@ -206,7 +207,7 @@ func reqBasicAuth() macaron.Handler {
return func(ctx *context.APIContext) {
if !ctx.Context.IsBasicAuth {
// fmt.Println("***********:",http.StatusUnauthorized)
// fmt.Println("***********:",http.StatusUnauthorized)
ctx.Context.Error(http.StatusUnauthorized)
return
}
@ -518,7 +519,6 @@ func mustNotBeArchived(ctx *context.APIContext) {
func RegisterRoutes(m *macaron.Macaron) {
bind := binding.Bind
//reqSignIn := context.Toggle(&context.ToggleOptions{SignInRequired: true})
// add by qiubing
reqRepoCodeReader := context.RequireRepoReader(models.UnitTypeCode)
// end by qiubing
@ -552,7 +552,6 @@ func RegisterRoutes(m *macaron.Macaron) {
Patch(notify.ReadThread)
}, reqToken())
m.Group("/users", func() {
m.Get("/search", user.Search)
@ -586,7 +585,6 @@ func RegisterRoutes(m *macaron.Macaron) {
})
}, reqToken())
//数据统计
m.Group("/activity", func() {
m.Get("", report.GetActivity)
@ -654,7 +652,6 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Combo("/repositories/:id", reqToken()).Get(repo.GetByID)
m.Group("/repos", func() {
m.Get("/search", repo.Search)
@ -673,32 +670,30 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/ext", viewfile.RepoRefByType(context.RepoRefBranch), viewfile.ViewFile)
m.Get("/branch/*", viewfile.RepoRefByType(context.RepoRefBranch), viewfile.ViewFile)
m.Get("/tag/*",viewfile.RepoRefByType(context.RepoRefTag), viewfile.ViewFile)
m.Get("/tag/*", viewfile.RepoRefByType(context.RepoRefTag), viewfile.ViewFile)
m.Get("/commit/*", viewfile.RepoRefByType(context.RepoRefCommit), viewfile.ViewFile)
//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),
}, reqToken())
m.Group("/count", func() {
m.Get("", viewfile.CommitCount) //****
m.Get("", viewfile.CommitCount) //****
})
m.Group("/releases", func() {
m.Get("/latest", viewfile.LatestRelease) //响应数据待确认 to do;
m.Get("/latest", viewfile.LatestRelease) //响应数据待确认 to do;
})
//
m.Group("/find", func() {
m.Get("", viewfile.FindFiles) //文件搜索 ****
m.Get("", viewfile.FindFiles) //文件搜索 ****
})
m.Group("/contributors", func() {
m.Get("", report.GetContributors) //获取仓库的所有构建者信息 ****
m.Get("", report.GetContributors) //获取仓库的所有构建者信息 ****
})
m.Combo("").Get(reqAnyRepoReader(), repo.Get).
Delete(reqToken(), reqOwner(), repo.Delete).
Patch(reqToken(), reqAdmin(), bind(api.EditRepoOption{}), context.RepoRef(), repo.Edit)
@ -706,16 +701,13 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Combo("/notifications").
Get(reqToken(), notify.ListRepoNotifications).
Put(reqToken(), notify.ReadRepoNotifications)
m.Group("/wiki", func() {
m.Group("/content", func() {
m.Get("/?:page",repo.WikiContent)
})
m.Get("/_pages", repo.WikiPages)
m.Group("", func() {
m.Get("/_new", repo.CreateNewWiki)
m.Get("/:page/_edit",repo.EditWiki)
m.Group("/wikies", func() {
m.Combo("").Get(repo.WikiList).
Post(bind(api.WikiOption{}), repo.CreateWiki)
m.Group("/:page", func() {
m.Combo("").Get(repo.GetWiki).
Patch(bind(api.WikiOption{}), repo.EditWiki).
Delete(repo.DeleteWiki)
})
})
m.Group("/hooks", func() {
@ -726,7 +718,7 @@ func RegisterRoutes(m *macaron.Macaron) {
Patch(bind(api.EditHookOption{}), repo.EditHook).
Delete(repo.DeleteHook)
m.Post("/tests", context.RepoRef(), repo.TestHook)
m.Get("/hooktasks",repo.HookTaskList)
m.Get("/hooktasks", repo.ListHookTask)
})
m.Group("/git", func() {
@ -971,8 +963,8 @@ func RegisterRoutes(m *macaron.Macaron) {
// Organizations
m.Get("/user/orgs", reqToken(), org.ListMyOrgs)
m.Get("/users/:username/orgs", org.ListUserOrgs)
// modified on 2021-01-14 begin 创建组织时返回默认的团队 begin
//m.Post("/orgs", reqToken(), bind(api.CreateOrgOption{}), org.Create)
// modified on 2021-01-14 begin 创建组织时返回默认的团队 begin
//m.Post("/orgs", reqToken(), bind(api.CreateOrgOption{}), org.Create)
m.Post("/orgs", reqToken(), bind(api.CreateOrgOption{}), org.CreateExt)
// modified on 2021-01-14 begin 创建组织时返回默认的团队 end

View File

@ -6,7 +6,6 @@
package repo
import (
"code.gitea.io/gitea/modules/setting"
_ "fmt"
"net/http"
@ -267,8 +266,8 @@ func DeleteHook(ctx *context.APIContext) {
ctx.Status(http.StatusNoContent)
}
func HookTaskList(ctx *context.APIContext){
// swagger:operation GET /repos/{owner}/{repo}/hooks/hooktasks repository repoGetHookTasks
func ListHookTask(ctx *context.APIContext) {
// swagger:operation GET /repos/{owner}/{repo}/hooks/{id}/hooktasks repository repoGetHookTasks
// ---
// summary: Get a hooktasks
// produces:
@ -284,36 +283,38 @@ func HookTaskList(ctx *context.APIContext){
// description: name of the repo
// type: string
// required: true
// - name: id
// in: path
// description: id of the hook
// type: integer
// format: int64
// required: true
// - 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/Hook"
// "404":
// "$ref": "#/responses/notFound"
//hooks, err := models.GetHookTasksByRepoID(ctx.Repo.Repository.ID, utils.GetListOptions(ctx))
repo := ctx.Repo
hookID := ctx.ParamsInt64(":id")
hook, err := utils.GetRepoHookTask(ctx, repo.Repository.ID, hookID)
// "$ref": "#/responses/HookTaskList"
hook, err := utils.GetRepoHook(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
if err != nil {
ctx.NotFound()
return
}
hookTasks, err := models.GetHookTasksByRepoIDAndHookID(ctx.Repo.Repository.ID, hook.ID, utils.GetListOptions(ctx))
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetHookTasksByRepoIDAndHookID", err)
return
}
//hooks, err := models.GetWebhooksByRepoID(ctx.Repo.Repository.ID, utils.GetListOptions(ctx))
//if err != nil {
// ctx.Error(http.StatusInternalServerError, "GetWebhooksByRepoID", err)
// return
//}
//apiHooks := make([]*models.HookTask,len(hooks))
//for i := range hooks {
// apiHooks[i] = convert.ToHook(ctx.Repo.RepoLink, hooks[i])
//}
//hookstasks := make(map[string]string)
//hookTasks := make([][]*models.HookTask, 0, setting.Webhook.PagingNum)
apiHookTasks := make([]*api.HookTask, len(hookTasks))
for i := range hookTasks {
apiHookTasks[i] = convert.ToHookTask(hookTasks[i])
}
hookTasks := utils.GetHookTasks(hook, setting.Webhook.PagingNum)
ctx.JSON(http.StatusOK, &hookTasks)
ctx.JSON(http.StatusOK, &apiHookTasks)
}

View File

@ -1,46 +1,21 @@
package repo
//
import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/markup/markdown"
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/wikis"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/wikies"
wiki_service "code.gitea.io/gitea/services/wiki"
//"fmt"
//"golang.org/x/sys/windows"
"net/http"
//"time"
)
type PageMeta struct {
Name string `json:"name"`
SubURL string `json:"sub_url"`
UpdatedUnix timeutil.TimeStamp `json:"updated_unix"`
}
type Wiki struct {
WikiRepo *git.Repository `json:"wiki_repo"`
//CommitID *git.Commit `json:"commit_id"`
Page []PageMeta `json:"page"`
}
type wiContent struct{
UserName string `json:"user_name"`
UserId int64 `json:"user_id"`
PageName string `json:"page_name"`
UpdateUnix timeutil.TimeStamp `json:"update_unix"`
CommitCounts int64 `json:"commit_counts"`
Content string `json:"content"`
}
func WikiPages(ctx *context.APIContext) {
// swagger:operation GET /repos/{owner}/{repo}/wiki/_pages wikipages
func WikiList(ctx *context.APIContext) {
// swagger:operation GET /repos/{owner}/{repo}/wikies repository repoWikiList
// ---
// summary: Get ListWikiPages
// summary: List the hooks in a repository
// produces:
// - application/json
// parameters:
@ -56,10 +31,13 @@ func WikiPages(ctx *context.APIContext) {
// required: true
// responses:
// "200":
// "$ref": "#/responses/Wiki/_page"
// "$ref": "#/responses/WikiList"
wikiRepo, commit, err := wikis.FindWikiRepoCommit(ctx)
wikiRepo, commit, err := wikies.FindWikiRepoCommit(ctx)
if err != nil {
ctx.JSON(http.StatusOK, []api.WikiesResponse{})
return
}
entries, err := commit.ListEntries()
if err != nil {
@ -67,10 +45,11 @@ func WikiPages(ctx *context.APIContext) {
wikiRepo.Close()
}
ctx.NotFound("ListEntries", err)
ctx.JSON(http.StatusOK, []api.WikiesResponse{})
return
}
pages := make([]PageMeta, 0, len(entries))
wikies := make([]api.WikiesResponse, 0, len(entries))
for _, entry := range entries {
if !entry.IsRegular() {
continue
@ -96,28 +75,34 @@ func WikiPages(ctx *context.APIContext) {
ctx.ServerError("WikiFilenameToName", err)
return
}
pages = append(pages,PageMeta{
Name: wikiName,
SubURL: wiki_service.NameToSubURL(wikiName),
UpdatedUnix: timeutil.TimeStamp(c.Author.When.Unix()),
wikies = append(wikies, api.WikiesResponse{
WikiMeta: api.WikiMeta{
Name: wikiName,
Commit: api.WikiCommit{
Author: api.WikiUser{
Name: c.Author.Name,
Email: c.Author.Email,
When: c.Author.When.Unix(),
},
Commiter: api.WikiUser{
Name: c.Committer.Name,
Email: c.Committer.Email,
When: c.Author.When.Unix(),
},
ID: c.ID.String(),
Message: c.Message(),
},
},
})
}
WikiPages := Wiki{
WikiRepo: wikiRepo,
//CommitID: commit,
Page: pages,
}
//wikiPages, _ := json.Marshal(WikiPages)
ctx.JSON(http.StatusOK,WikiPages)
ctx.JSON(http.StatusOK, wikies)
}
func WikiContent(ctx *context.APIContext){
// swagger:operation GET /repos/{owner}/{repo}/wiki/content/{pagename} wikiName Content
func GetWiki(ctx *context.APIContext) {
// swagger:operation GET /repos/{owner}/{repo}/wikies/{pagename} repository repoGetWiki
// ---
// summary: Get NameWiki Content
// summary: Get a Wiki
// produces:
// - application/json
// parameters:
@ -138,27 +123,18 @@ func WikiContent(ctx *context.APIContext){
// required: true
// responses:
// "200":
// "$ref": "#/responses/Wiki/content/wikipage"
// "$ref": "#/responses/Wiki"
wikiRepo, commit, _ := wikis.FindWikiRepoCommit(ctx)
wikiRepo, commit, _ := wikies.FindWikiRepoCommit(ctx)
//entries, err := commit.ListEntries()
//if err != nil {
// if wikiRepo != nil {
// wikiRepo.Close()
// }
//
// ctx.NotFound("ListEntries", err)
// return
//}
pageName := wiki_service.NormalizeWikiName(ctx.Params(":page"))
if len(pageName) == 0 {
pageName = "Home"
}
data, entry, pageFilename, noEntry := wikis.WikiContentsByName(ctx, commit, pageName)
data, entry, pageFilename, noEntry := wikies.WikiContentsByName(ctx, commit, pageName)
if noEntry {
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/_pages")
//ctx.ServerError("WikiContentsByName",error)
ctx.NotFound()
return
}
if entry == nil || ctx.Written() {
if wikiRepo != nil {
@ -166,7 +142,7 @@ func WikiContent(ctx *context.APIContext){
}
}
metas := ctx.Repo.Repository.ComposeDocumentMetas()
PagaContent := markdown.RenderWiki(data, ctx.Repo.RepoLink, metas)
PageContent := markdown.RenderWiki(data, ctx.Repo.RepoLink, metas)
c, err := wikiRepo.GetCommitByPath(entry.Name())
if err != nil {
if models.IsErrWikiInvalidFileName(err) {
@ -175,23 +151,61 @@ func WikiContent(ctx *context.APIContext){
}
commitsCount, _ := wikiRepo.FileCommitsCount("master", pageFilename)
WikiPageContent := wiContent{
UserName: ctx.User.Name,
UserId: ctx.User.ID,
PageName: pageName,
UpdateUnix: timeutil.TimeStamp(c.Author.When.Unix()),
wiki := api.WikiResponse{
WikiMeta: api.WikiMeta{
Name: pageName,
Commit: api.WikiCommit{
Author: api.WikiUser{
Name: c.Author.Name,
Email: c.Author.Email,
When: c.Author.When.Unix(),
},
Commiter: api.WikiUser{
Name: c.Committer.Name,
Email: c.Committer.Email,
When: c.Author.When.Unix(),
},
ID: c.ID.String(),
Message: c.Message(),
},
},
CommitCounts: commitsCount,
Content: PagaContent,
Content: PageContent,
}
ctx.JSON(http.StatusOK,WikiPageContent)
ctx.JSON(http.StatusOK, wiki)
}
func CreateWiki(ctx *context.APIContext) {
// swagger:operation POST /repos/{owner}/{repo}/wikis repository repoCreateWiki
// ---
// summary: Create a wiki in 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: body
// in: body
// schema:
// "$ref": "#/definitions/WikiOption"
// responses:
// "201":
// "$ref": "#/responses/Wiki"
}
func CreateNewWiki(ctx *context.APIContext){
// swagger:operation GET /repos/{owner}/{repo}/wiki/{pagename} Create a new Wikipage
func EditWiki(ctx *context.Context) {
// swagger:operation PATCH /repos/{owner}/{repo}/wikies/{pagename} repository repoEditWiki
// ---
// summary: wiki Content
// summary: Edit a wiki in a repository
// produces:
// - application/json
// parameters:
@ -207,27 +221,23 @@ func CreateNewWiki(ctx *context.APIContext){
// required: true
// - name: pagename
// in: path
// description: path of the dir, file, symlink or submodule in the repo
// description: name of the wiki
// type: string
// required: true
// - name: ref
// in: query
// description: "The name of the commit/branch/tag. Default the repositorys default branch (usually master)"
// type: string
// required: false
// - name: body
// in: body
// schema:
// "$ref": "#/definitions/WikiOption"
// responses:
// "200":
// "$ref": "#/responses/ContentsResponse"
// "404":
// "$ref": "#/responses/notFound"
// "$ref": "#/responses/Wiki"
}
func EditWiki(ctx *context.Context){
// swagger:operation GET /repos/{owner}/{repo}/wiki/{pagename}/_edit Edit wikipage
func DeleteWiki(ctx *context.Context) {
// swagger:operation DELETE /repos/{owner}/{repo}/wikies/{pagename} repository repoDeleteWiki
// ---
// summary: new wiki
// summary: Delete a wiki in a repository
// produces:
// - application/json
// parameters:
@ -247,7 +257,8 @@ func EditWiki(ctx *context.Context){
// type: string
// required: true
// responses:
// "200":
// "$ref": "#/responses/Wiki/pagename/_edit"
// "204":
// "$ref": "#/responses/empty"
// "404":
// "$ref": "#/responses/notFound"
}

View File

@ -23,6 +23,9 @@ type swaggerParameterBodies struct {
// in:body
DeleteEmailOption api.DeleteEmailOption
// in:body
WikiOption api.WikiOption
// in:body
CreateHookOption api.CreateHookOption
// in:body

View File

@ -85,6 +85,20 @@ type swaggerResponseReferenceList struct {
Body []api.Reference `json:"body"`
}
// Wiki
// swagger:response Wiki
type swaggerResponseWiki struct {
// in:body
Body api.WikiResponse `json:"body"`
}
// WikiList
// swagger:response WikiList
type swaggerResponseWikiList struct {
// in:body
Body api.WikiesResponse `json:"body"`
}
// Hook
// swagger:response Hook
type swaggerResponseHook struct {
@ -99,6 +113,13 @@ type swaggerResponseHookList struct {
Body []api.Hook `json:"body"`
}
// HookTaskList
// swagger:response HookTaskList
type swaggerResponseHookTaskList struct {
// in:body
Body []api.HookTask `json:"body"`
}
// GitHook
// swagger:response GitHook
type swaggerResponseGitHook struct {

View File

@ -8,7 +8,6 @@ import (
"encoding/json"
"net/http"
"strings"
"xorm.io/xorm"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
@ -50,85 +49,6 @@ func GetRepoHook(ctx *context.APIContext, repoID, hookID int64) (*models.Webhook
return w, nil
}
func GetRepoHookTask(ctx *context.APIContext, repoID, hookID int64) (*models.HookTask, error) {
w, err := models.GetHookTaskByRepoID(repoID, hookID)
if err != nil {
if models.IsErrHookTaskNotExist(err) {
ctx.NotFound()
} else {
ctx.Error(http.StatusInternalServerError, "GetHookTaskByID", err)
}
return nil, err
}
return w, nil
}
func GetHookTasks(w *models.HookTask, page int )([]*models.HookTask){
hook_id := w.HookID
//tasks := make([]*models.HookTask, 0, setting.Webhook.PagingNum)
hookTasks, _ := models.HookTasks(hook_id, page)
//tasks, _ = hookTasks, err
//for i := range tasks{
// tasks[i].ID = hookTasks[i].ID
// tasks[i].UUID = hookTasks[i].UUID
// tasks[i].URL = hookTasks[i].URL
// tasks[i].ContentType = hookTasks[i].ContentType
// tasks[i].RequestInfo = hookTasks[i].RequestInfo
// tasks[i].RequestContent = hookTasks[i].RequestContent
// tasks[i].HTTPMethod = hookTasks[i].HTTPMethod
// tasks[i].ResponseContent = hookTasks[i].ResponseContent
// tasks[i].ResponseInfo = hookTasks[i].ResponseInfo
//}
//
//
//if err != nil{
// fmt.Println("err ......")
//}
//t := append(tasks, hookTasks)
//tasks := make(map[string]string)
////hooktasks := make([]models.HookTask, len(hookTasks))
//tasks := append(hooktasks, hookTasks)
//HookTasks := make([]*models.HookTask, len(hookTasks))
//H := append(HookTasks, hookTasks)
return hookTasks
//return {
// //ID: w.ID,
// //Type: w.Type,
// //URL: w.URL,
// //Signature: w.Signature,
// //PayloadContent: w.PayloadContent,
// //
// //HTTPMethod: w.HTTPMethod,
// //ResponseContent: w.ResponseContent,
// //ResponseInfo: w.ResponseInfo,
// ID: w.ID,
// UUID: w.UUID,
// Type :w.Type,
// URL :w.URL,
// PayloadContent:w.PayloadContent,
// HTTPMethod : w.HTTPMethod,
// ContentType : w.ContentType,
// EventType : w.EventType,
// //IsSSL : w.IsSSL,
// //IsDelivered :w.IsDelivered,
// Delivered :w.Delivered,
// DeliveredString :w.DeliveredString,
// // History info.
// IsSucceed : w.IsSucceed,
// RequestContent : w.RequestContent,
// RequestInfo : w.RequestInfo,
// ResponseContent : w.ResponseContent,
// ResponseInfo : w.ResponseInfo,
//}
}
// CheckCreateHookOption check if a CreateHookOption form is valid. If invalid,
// write the appropriate error to `ctx`. Return whether the form is valid
func CheckCreateHookOption(ctx *context.APIContext, form *api.CreateHookOption) bool {
@ -376,29 +296,3 @@ func editHook(ctx *context.APIContext, form *api.EditHookOption, w *models.Webho
}
return true
}
var (
x *xorm.Engine
tables []interface{}
// HasEngine specifies if we have a xorm.Engine
HasEngine bool
)
func HookTaskList(ctx *context.APIContext,hookId int64, page int)([]*models.HookTask, error){
//tasks := make([]*models.HookTask,0,setting.Webhook.PagingNum)
tasks, err := models.HookTasks(hookId, page)
if err != nil{
if models.IsErrWebhookNotExist(err) {
ctx.NotFound()
}else{
ctx.Error(http.StatusInternalServerError, "HookTaskList", err)
}
return nil, err
}
return tasks, err
}

View File

@ -3856,42 +3856,6 @@
}
}
},
"/repos/{owner}/{repo}/hooks/hooktasks": {
"get": {
"produces": [
"application/json"
],
"tags": [
"repository"
],
"summary": "Get a hooktasks",
"operationId": "repoGetHookTasks",
"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/Hook"
},
"404": {
"$ref": "#/responses/notFound"
}
}
}
},
"/repos/{owner}/{repo}/hooks/{id}": {
"get": {
"produces": [
@ -4024,6 +3988,59 @@
}
}
},
"/repos/{owner}/{repo}/hooks/{id}/hooktasks": {
"get": {
"produces": [
"application/json"
],
"tags": [
"repository"
],
"summary": "Get a hooktasks",
"operationId": "repoGetHookTasks",
"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": "integer",
"format": "int64",
"description": "id of the hook",
"name": "id",
"in": "path",
"required": true
},
{
"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/HookTaskList"
}
}
}
},
"/repos/{owner}/{repo}/hooks/{id}/tests": {
"post": {
"produces": [
@ -8883,13 +8900,16 @@
}
}
},
"/repos/{owner}/{repo}/wiki/_pages": {
"/repos/{owner}/{repo}/wikies": {
"get": {
"produces": [
"application/json"
],
"summary": "Get ListWikiPages",
"operationId": "wikipages",
"tags": [
"repository"
],
"summary": "List the hooks in a repository",
"operationId": "repoWikiList",
"parameters": [
{
"type": "string",
@ -8908,21 +8928,21 @@
],
"responses": {
"200": {
"$ref": "#/responses/Wiki/_page"
"$ref": "#/responses/WikiList"
}
}
}
},
"/repos/{owner}/{repo}/wiki/content/{pagename}": {
"/repos/{owner}/{repo}/wikies/{pagename}": {
"get": {
"produces": [
"application/json"
],
"tags": [
"wikiName"
"repository"
],
"summary": "Get NameWiki Content",
"operationId": "Content",
"summary": "Get a Wiki",
"operationId": "repoGetWiki",
"parameters": [
{
"type": "string",
@ -8948,72 +8968,19 @@
],
"responses": {
"200": {
"$ref": "#/responses/Wiki/content/wikipage"
"$ref": "#/responses/Wiki"
}
}
}
},
"/repos/{owner}/{repo}/wiki/{pagename}": {
"get": {
},
"delete": {
"produces": [
"application/json"
],
"tags": [
"Create",
"a",
"new"
"repository"
],
"summary": "wiki Content",
"operationId": "Wikipage",
"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": "path of the dir, file, symlink or submodule in the repo",
"name": "pagename",
"in": "path",
"required": true
},
{
"type": "string",
"description": "The name of the commit/branch/tag. Default the repositorys default branch (usually master)",
"name": "ref",
"in": "query"
}
],
"responses": {
"200": {
"$ref": "#/responses/ContentsResponse"
},
"404": {
"$ref": "#/responses/notFound"
}
}
}
},
"/repos/{owner}/{repo}/wiki/{pagename}/_edit": {
"get": {
"produces": [
"application/json"
],
"tags": [
"Edit"
],
"summary": "new wiki",
"operationId": "wikipage",
"summary": "Delete a wiki in a repository",
"operationId": "repoDeleteWiki",
"parameters": [
{
"type": "string",
@ -9037,9 +9004,97 @@
"required": true
}
],
"responses": {
"204": {
"$ref": "#/responses/empty"
},
"404": {
"$ref": "#/responses/notFound"
}
}
},
"patch": {
"produces": [
"application/json"
],
"tags": [
"repository"
],
"summary": "Edit a wiki in a repository",
"operationId": "repoEditWiki",
"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 wiki",
"name": "pagename",
"in": "path",
"required": true
},
{
"name": "body",
"in": "body",
"schema": {
"$ref": "#/definitions/WikiOption"
}
}
],
"responses": {
"200": {
"$ref": "#/responses/Wiki/pagename/_edit"
"$ref": "#/responses/Wiki"
}
}
}
},
"/repos/{owner}/{repo}/wikis": {
"post": {
"produces": [
"application/json"
],
"tags": [
"repository"
],
"summary": "Create a wiki in a repository",
"operationId": "repoCreateWiki",
"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
},
{
"name": "body",
"in": "body",
"schema": {
"$ref": "#/definitions/WikiOption"
}
}
],
"responses": {
"201": {
"$ref": "#/responses/Wiki"
}
}
}
@ -13585,6 +13640,74 @@
},
"x-go-package": "code.gitea.io/gitea/modules/structs"
},
"HookTask": {
"type": "object",
"properties": {
"config": {
"type": "object",
"additionalProperties": {
"type": "string"
},
"x-go-name": "Config"
},
"delivered": {
"type": "integer",
"format": "int64",
"x-go-name": "Delivered"
},
"event_type": {
"type": "string",
"x-go-name": "EventType"
},
"id": {
"type": "integer",
"format": "int64",
"x-go-name": "ID"
},
"is_delivered": {
"type": "boolean",
"x-go-name": "IsDelivered"
},
"is_ssl": {
"type": "boolean",
"x-go-name": "IsSSL"
},
"is_succeed": {
"type": "boolean",
"x-go-name": "IsSucceed"
},
"payload_content": {
"type": "object",
"additionalProperties": {
"type": "object"
},
"x-go-name": "PayloadContent"
},
"request_info": {
"type": "object",
"additionalProperties": {
"type": "object"
},
"x-go-name": "RequestContent"
},
"response_content": {
"type": "object",
"additionalProperties": {
"type": "object"
},
"x-go-name": "ResponseContent"
},
"type": {
"type": "string",
"x-go-name": "Type"
},
"uuid": {
"type": "string",
"x-go-name": "UUID"
}
},
"x-go-package": "code.gitea.io/gitea/modules/structs"
},
"Identity": {
"description": "Identity for a person's identity like an author or committer",
"type": "object",
@ -15367,6 +15490,95 @@
}
},
"x-go-package": "code.gitea.io/gitea/modules/structs"
},
"WikiCommit": {
"type": "object",
"properties": {
"author": {
"$ref": "#/definitions/WikiUser"
},
"id": {
"type": "string",
"x-go-name": "ID"
},
"message": {
"type": "string",
"x-go-name": "Message"
}
},
"x-go-package": "code.gitea.io/gitea/modules/structs"
},
"WikiOption": {
"type": "object",
"properties": {
"commit_message": {
"type": "string",
"x-go-name": "CommitMessage"
},
"content": {
"type": "string",
"x-go-name": "Content"
},
"name": {
"type": "string",
"x-go-name": "Name"
}
},
"x-go-package": "code.gitea.io/gitea/modules/structs"
},
"WikiResponse": {
"type": "object",
"properties": {
"commit": {
"$ref": "#/definitions/WikiCommit"
},
"commit_counts": {
"type": "integer",
"format": "int64",
"x-go-name": "CommitCounts"
},
"content": {
"type": "string",
"x-go-name": "Content"
},
"name": {
"type": "string",
"x-go-name": "Name"
}
},
"x-go-package": "code.gitea.io/gitea/modules/structs"
},
"WikiUser": {
"type": "object",
"properties": {
"email": {
"type": "string",
"x-go-name": "Email"
},
"name": {
"type": "string",
"x-go-name": "Name"
},
"when": {
"type": "integer",
"format": "int64",
"x-go-name": "When"
}
},
"x-go-package": "code.gitea.io/gitea/modules/structs"
},
"WikiesResponse": {
"type": "object",
"properties": {
"commit": {
"$ref": "#/definitions/WikiCommit"
},
"name": {
"type": "string",
"x-go-name": "Name"
}
},
"x-go-package": "code.gitea.io/gitea/modules/structs"
}
},
"responses": {
@ -15630,6 +15842,15 @@
}
}
},
"HookTaskList": {
"description": "HookTaskList",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/HookTask"
}
}
},
"Issue": {
"description": "Issue",
"schema": {
@ -16009,6 +16230,18 @@
"$ref": "#/definitions/WatchInfo"
}
},
"Wiki": {
"description": "Wiki",
"schema": {
"$ref": "#/definitions/WikiResponse"
}
},
"WikiList": {
"description": "WikiList",
"schema": {
"$ref": "#/definitions/WikiesResponse"
}
},
"empty": {
"description": "APIEmpty is an empty response"
},
@ -16140,4 +16373,4 @@
"TOTPHeader": []
}
]
}
}