forked from Gitlink/gitea-1120-rc1
Generate swagger json (#1402)
- Generate swagger.json into public/ - Add swagger-ui auto-installation - Add footer link to local swagger-ui - Add /swagger url for using app url. - Fix Swagger-UI version via git tag
This commit is contained in:
parent
bb5f694fc5
commit
3edb0c5894
11
Makefile
11
Makefile
|
@ -54,6 +54,9 @@ generate:
|
||||||
@hash go-bindata > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
@hash go-bindata > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
||||||
go get -u github.com/jteeuwen/go-bindata/...; \
|
go get -u github.com/jteeuwen/go-bindata/...; \
|
||||||
fi
|
fi
|
||||||
|
@hash swagger > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
||||||
|
go get -u github.com/go-swagger/go-swagger/cmd/swagger; \
|
||||||
|
fi
|
||||||
go generate $(PACKAGES)
|
go generate $(PACKAGES)
|
||||||
|
|
||||||
.PHONY: errcheck
|
.PHONY: errcheck
|
||||||
|
@ -184,5 +187,13 @@ stylesheets: public/css/index.css
|
||||||
public/css/index.css: $(STYLESHEETS)
|
public/css/index.css: $(STYLESHEETS)
|
||||||
lessc $< $@
|
lessc $< $@
|
||||||
|
|
||||||
|
.PHONY: swagger-ui
|
||||||
|
swagger-ui:
|
||||||
|
rm -Rf public/assets/swagger-ui
|
||||||
|
git clone --depth=10 -b v3.0.7 --single-branch https://github.com/swagger-api/swagger-ui.git /tmp/swagger-ui
|
||||||
|
mv /tmp/swagger-ui/dist public/assets/swagger-ui
|
||||||
|
rm -Rf /tmp/swagger-ui
|
||||||
|
sed -i "s;http://petstore.swagger.io/v2/swagger.json;../../swagger.v1.json;g" public/assets/swagger-ui/index.html
|
||||||
|
|
||||||
.PHONY: assets
|
.PHONY: assets
|
||||||
assets: javascripts stylesheets
|
assets: javascripts stylesheets
|
||||||
|
|
|
@ -84,16 +84,27 @@ func (repos MirrorRepositoryList) LoadAttributes() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SearchRepoOptions holds the search options
|
// SearchRepoOptions holds the search options
|
||||||
|
// swagger:parameters repoSearch
|
||||||
type SearchRepoOptions struct {
|
type SearchRepoOptions struct {
|
||||||
Keyword string
|
// Keyword to search
|
||||||
OwnerID int64
|
//
|
||||||
Searcher *User //ID of the person who's seeking
|
// in: query
|
||||||
OrderBy string
|
Keyword string `json:"q"`
|
||||||
Private bool // Include private repositories in results
|
// Owner in we search search
|
||||||
Starred bool
|
//
|
||||||
Page int
|
// in: query
|
||||||
IsProfile bool
|
OwnerID int64 `json:"uid"`
|
||||||
PageSize int // Can be smaller than or equal to setting.ExplorePagingNum
|
Searcher *User `json:"-"` //ID of the person who's seeking
|
||||||
|
OrderBy string `json:"-"`
|
||||||
|
Private bool `json:"-"` // Include private repositories in results
|
||||||
|
Starred bool `json:"-"`
|
||||||
|
Page int `json:"-"`
|
||||||
|
IsProfile bool `json:"-"`
|
||||||
|
// Limit of result
|
||||||
|
//
|
||||||
|
// maximum: setting.ExplorePagingNum
|
||||||
|
// in: query
|
||||||
|
PageSize int `json:"limit"` // Can be smaller than or equal to setting.ExplorePagingNum
|
||||||
}
|
}
|
||||||
|
|
||||||
// SearchRepositoryByName takes keyword and part of repository name to search,
|
// SearchRepositoryByName takes keyword and part of repository name to search,
|
||||||
|
|
|
@ -23,6 +23,34 @@ type APIContext struct {
|
||||||
Org *APIOrganization
|
Org *APIOrganization
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// APIError is error format response
|
||||||
|
// swagger:response error
|
||||||
|
type APIError struct {
|
||||||
|
Message string `json:"message"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// APIValidationError is error format response related to input validation
|
||||||
|
// swagger:response validationError
|
||||||
|
type APIValidationError struct {
|
||||||
|
Message string `json:"message"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
//APIEmpty is a empty response
|
||||||
|
// swagger:response empty
|
||||||
|
type APIEmpty struct{}
|
||||||
|
|
||||||
|
//APIForbiddenError is a forbidden error response
|
||||||
|
// swagger:response forbidden
|
||||||
|
type APIForbiddenError struct {
|
||||||
|
APIError
|
||||||
|
}
|
||||||
|
|
||||||
|
//APINotFound is a not found empty response
|
||||||
|
// swagger:response notFound
|
||||||
|
type APINotFound struct{}
|
||||||
|
|
||||||
// Error responses error message to client with given message.
|
// Error responses error message to client with given message.
|
||||||
// If status is 500, also it prints error to log.
|
// If status is 500, also it prints error to log.
|
||||||
func (ctx *APIContext) Error(status int, title string, obj interface{}) {
|
func (ctx *APIContext) Error(status int, title string, obj interface{}) {
|
||||||
|
@ -37,9 +65,9 @@ func (ctx *APIContext) Error(status int, title string, obj interface{}) {
|
||||||
log.Error(4, "%s: %s", title, message)
|
log.Error(4, "%s: %s", title, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(status, map[string]string{
|
ctx.JSON(status, APIError{
|
||||||
"message": message,
|
Message: message,
|
||||||
"url": base.DocURL,
|
URL: base.DocURL,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 445 B |
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
|
@ -0,0 +1,93 @@
|
||||||
|
<!-- HTML for static distribution bundle build -->
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Swagger UI</title>
|
||||||
|
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" >
|
||||||
|
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
|
||||||
|
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
|
||||||
|
<style>
|
||||||
|
html
|
||||||
|
{
|
||||||
|
box-sizing: border-box;
|
||||||
|
overflow: -moz-scrollbars-vertical;
|
||||||
|
overflow-y: scroll;
|
||||||
|
}
|
||||||
|
*,
|
||||||
|
*:before,
|
||||||
|
*:after
|
||||||
|
{
|
||||||
|
box-sizing: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin:0;
|
||||||
|
background: #fafafa;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="position:absolute;width:0;height:0">
|
||||||
|
<defs>
|
||||||
|
<symbol viewBox="0 0 20 20" id="unlocked">
|
||||||
|
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V6h2v-.801C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8z"></path>
|
||||||
|
</symbol>
|
||||||
|
|
||||||
|
<symbol viewBox="0 0 20 20" id="locked">
|
||||||
|
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8zM12 8H8V5.199C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8z"/>
|
||||||
|
</symbol>
|
||||||
|
|
||||||
|
<symbol viewBox="0 0 20 20" id="close">
|
||||||
|
<path d="M14.348 14.849c-.469.469-1.229.469-1.697 0L10 11.819l-2.651 3.029c-.469.469-1.229.469-1.697 0-.469-.469-.469-1.229 0-1.697l2.758-3.15-2.759-3.152c-.469-.469-.469-1.228 0-1.697.469-.469 1.228-.469 1.697 0L10 8.183l2.651-3.031c.469-.469 1.228-.469 1.697 0 .469.469.469 1.229 0 1.697l-2.758 3.152 2.758 3.15c.469.469.469 1.229 0 1.698z"/>
|
||||||
|
</symbol>
|
||||||
|
|
||||||
|
<symbol viewBox="0 0 20 20" id="large-arrow">
|
||||||
|
<path d="M13.25 10L6.109 2.58c-.268-.27-.268-.707 0-.979.268-.27.701-.27.969 0l7.83 7.908c.268.271.268.709 0 .979l-7.83 7.908c-.268.271-.701.27-.969 0-.268-.269-.268-.707 0-.979L13.25 10z"/>
|
||||||
|
</symbol>
|
||||||
|
|
||||||
|
<symbol viewBox="0 0 20 20" id="large-arrow-down">
|
||||||
|
<path d="M17.418 6.109c.272-.268.709-.268.979 0s.271.701 0 .969l-7.908 7.83c-.27.268-.707.268-.979 0l-7.908-7.83c-.27-.268-.27-.701 0-.969.271-.268.709-.268.979 0L10 13.25l7.418-7.141z"/>
|
||||||
|
</symbol>
|
||||||
|
|
||||||
|
|
||||||
|
<symbol viewBox="0 0 24 24" id="jump-to">
|
||||||
|
<path d="M19 7v4H5.83l3.58-3.59L8 6l-6 6 6 6 1.41-1.41L5.83 13H21V7z"/>
|
||||||
|
</symbol>
|
||||||
|
|
||||||
|
<symbol viewBox="0 0 24 24" id="expand">
|
||||||
|
<path d="M10 18h4v-2h-4v2zM3 6v2h18V6H3zm3 7h12v-2H6v2z"/>
|
||||||
|
</symbol>
|
||||||
|
|
||||||
|
</defs>
|
||||||
|
</svg>
|
||||||
|
|
||||||
|
<div id="swagger-ui"></div>
|
||||||
|
|
||||||
|
<script src="./swagger-ui-bundle.js"> </script>
|
||||||
|
<script src="./swagger-ui-standalone-preset.js"> </script>
|
||||||
|
<script>
|
||||||
|
window.onload = function() {
|
||||||
|
// Build a system
|
||||||
|
const ui = SwaggerUIBundle({
|
||||||
|
url: "../../swagger.v1.json",
|
||||||
|
dom_id: '#swagger-ui',
|
||||||
|
presets: [
|
||||||
|
SwaggerUIBundle.presets.apis,
|
||||||
|
SwaggerUIStandalonePreset
|
||||||
|
],
|
||||||
|
plugins: [
|
||||||
|
SwaggerUIBundle.plugins.DownloadUrl
|
||||||
|
],
|
||||||
|
layout: "StandaloneLayout"
|
||||||
|
})
|
||||||
|
|
||||||
|
window.ui = ui
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
|
@ -0,0 +1,83 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en-US">
|
||||||
|
<body onload="run()">
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
<script>
|
||||||
|
'use strict';
|
||||||
|
function run () {
|
||||||
|
var oauth2 = window.opener.swaggerUIRedirectOauth2;
|
||||||
|
var sentState = oauth2.state;
|
||||||
|
var isValid, qp;
|
||||||
|
|
||||||
|
qp = (window.location.hash || location.search).substring(1);
|
||||||
|
|
||||||
|
qp = qp ? JSON.parse('{"' + qp.replace(/&/g, '","').replace(/=/g, '":"') + '"}',
|
||||||
|
function (key, value) {
|
||||||
|
return key === "" ? value : decodeURIComponent(value)
|
||||||
|
}
|
||||||
|
) : {}
|
||||||
|
|
||||||
|
isValid = qp.state === sentState
|
||||||
|
|
||||||
|
if (oauth2.auth.schema.get("flow") === "accessCode" && !oauth2.auth.code) {
|
||||||
|
if (!isValid) {
|
||||||
|
oauth2.errCb({
|
||||||
|
authId: oauth2.auth.name,
|
||||||
|
source: "auth",
|
||||||
|
level: "warning",
|
||||||
|
message: "Authorization may be unsafe, passed state was changed in server Passed state wasn't returned from auth server"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (qp.code) {
|
||||||
|
delete oauth2.state;
|
||||||
|
oauth2.auth.code = qp.code;
|
||||||
|
createForm(oauth2.auth, qp).submit();
|
||||||
|
} else {
|
||||||
|
oauth2.errCb({
|
||||||
|
authId: oauth2.auth.name,
|
||||||
|
source: "auth",
|
||||||
|
level: "error",
|
||||||
|
message: "Authorization failed: no accessCode came from the server"
|
||||||
|
});
|
||||||
|
window.close();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid});
|
||||||
|
window.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function createForm(auth, qp) {
|
||||||
|
var form = document.createElement("form");
|
||||||
|
var schema = auth.schema;
|
||||||
|
var action = schema.get("tokenUrl");
|
||||||
|
var name, input;
|
||||||
|
|
||||||
|
var fields = {
|
||||||
|
code: qp.code,
|
||||||
|
"redirect_uri": location.protocol + "//" + location.host + location.pathname,
|
||||||
|
"grant_type": "authorization_code",
|
||||||
|
"client_secret": auth.clientSecret,
|
||||||
|
"client_id": auth.clientId
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( name in fields ) {
|
||||||
|
input = document.createElement("input");
|
||||||
|
input.name = name;
|
||||||
|
input.value = fields[name];
|
||||||
|
input.type = "hidden";
|
||||||
|
form.appendChild(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
form.method = "POST";
|
||||||
|
form.action = action;
|
||||||
|
|
||||||
|
document.body.appendChild(form);
|
||||||
|
|
||||||
|
return form;
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1 @@
|
||||||
|
{"version":3,"file":"swagger-ui-bundle.js","sources":["webpack:///swagger-ui-bundle.js"],"mappings":"AAAA;AAu/FA;AA6+FA;;;;;;;;;;;;;;;;;;;;;;;;;;AA0dA;;;;;;AAoIA;AAk7FA;AAmtCA;;;;;AA0uIA;AA+4IA;AAm9FA;AA2rGA;AA8lFA;AA2nFA;AAu9CA;AAyhDA;AAqrCA;AAy4EA;AA8/GA;;;;;;;;;;;;;;AA+mJA;AA4mIA;AAquJA;AAwsHA;AAinGA;AAmiEA;AAy4DA;AAm2DA;AA0nBA;;;;;;AA4iFA;AAk0FA;;;;;AA23CA;AA2qFA;AAw2CA;AAglCA;AA0/CA;AAykFA;AA+1FA;;;;;;;;;AAk4CA;AA2zIA;AAk4DA;AAolDA","sourceRoot":""}
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1 @@
|
||||||
|
{"version":3,"file":"swagger-ui-standalone-preset.js","sources":["webpack:///swagger-ui-standalone-preset.js"],"mappings":"AAAA;;;;;AA4QA;AAitGA","sourceRoot":""}
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1 @@
|
||||||
|
{"version":3,"file":"swagger-ui.css","sources":[],"mappings":"","sourceRoot":""}
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1 @@
|
||||||
|
{"version":3,"file":"swagger-ui.js","sources":["webpack:///swagger-ui.js"],"mappings":"AAAA;;;;;;AA4wCA;AAoyHA;AAuxHA;AAy4FA;AA8rCA;AAugCA;AA+hCA;AA24BA","sourceRoot":""}
|
File diff suppressed because it is too large
Load Diff
|
@ -2,6 +2,31 @@
|
||||||
// Use of this source code is governed by a MIT-style
|
// Use of this source code is governed by a MIT-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
//go:generate swagger generate spec -o ../../../public/swagger.v1.json
|
||||||
|
//go:generate sed -i "s;\".ref\": \"#/definitions/GPGKey\";\"type\": \"object\";g" ../../../public/swagger.v1.json
|
||||||
|
|
||||||
|
// Package v1 Gitea API.
|
||||||
|
//
|
||||||
|
// This provide API interface to communicate with this Gitea instance.
|
||||||
|
//
|
||||||
|
// Terms Of Service:
|
||||||
|
//
|
||||||
|
// there are no TOS at this moment, use at your own risk we take no responsibility
|
||||||
|
//
|
||||||
|
// Schemes: http, https
|
||||||
|
// BasePath: /api/v1
|
||||||
|
// Version: 1.1.1
|
||||||
|
// License: MIT http://opensource.org/licenses/MIT
|
||||||
|
//
|
||||||
|
// Consumes:
|
||||||
|
// - application/json
|
||||||
|
// - text/plain
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
// - text/html
|
||||||
|
//
|
||||||
|
// swagger:meta
|
||||||
package v1
|
package v1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
@ -13,8 +13,19 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Markdown render markdown document to HTML
|
// Markdown render markdown document to HTML
|
||||||
// see https://github.com/gogits/go-gogs-client/wiki/Miscellaneous#render-an-arbitrary-markdown-document
|
|
||||||
func Markdown(ctx *context.APIContext, form api.MarkdownOption) {
|
func Markdown(ctx *context.APIContext, form api.MarkdownOption) {
|
||||||
|
// swagger:route POST /markdown renderMarkdown
|
||||||
|
//
|
||||||
|
// Consumes:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - text/html
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 200: MarkdownRender
|
||||||
|
// 422: validationError
|
||||||
|
|
||||||
if ctx.HasAPIError() {
|
if ctx.HasAPIError() {
|
||||||
ctx.Error(422, "", ctx.GetErrMsg())
|
ctx.Error(422, "", ctx.GetErrMsg())
|
||||||
return
|
return
|
||||||
|
@ -40,8 +51,18 @@ func Markdown(ctx *context.APIContext, form api.MarkdownOption) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarkdownRaw render raw markdown HTML
|
// MarkdownRaw render raw markdown HTML
|
||||||
// see https://github.com/gogits/go-gogs-client/wiki/Miscellaneous#render-a-markdown-document-in-raw-mode
|
|
||||||
func MarkdownRaw(ctx *context.APIContext) {
|
func MarkdownRaw(ctx *context.APIContext) {
|
||||||
|
// swagger:route POST /markdown/raw renderMarkdownRaw
|
||||||
|
//
|
||||||
|
// Consumes:
|
||||||
|
// - text/plain
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - text/html
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 200: MarkdownRender
|
||||||
|
// 422: validationError
|
||||||
body, err := ctx.Req.Body().Bytes()
|
body, err := ctx.Req.Body().Bytes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(422, "", err)
|
ctx.Error(422, "", err)
|
||||||
|
|
|
@ -12,5 +12,17 @@ import (
|
||||||
|
|
||||||
// Version shows the version of the Gitea server
|
// Version shows the version of the Gitea server
|
||||||
func Version(ctx *context.APIContext) {
|
func Version(ctx *context.APIContext) {
|
||||||
|
// swagger:route GET /version getVersion
|
||||||
|
//
|
||||||
|
// Return Gitea running version.
|
||||||
|
//
|
||||||
|
// This show current running Gitea application version.
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 200: ServerVersion
|
||||||
|
|
||||||
ctx.JSON(200, &gitea.ServerVersion{Version: setting.AppVer})
|
ctx.JSON(200, &gitea.ServerVersion{Version: setting.AppVer})
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,8 +14,16 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// ListHooks list all hooks of a repository
|
// ListHooks list all hooks of a repository
|
||||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories#list-hooks
|
|
||||||
func ListHooks(ctx *context.APIContext) {
|
func ListHooks(ctx *context.APIContext) {
|
||||||
|
// swagger:route GET /repos/{username}/{reponame}/hooks
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 200: apiHooks
|
||||||
|
// 500: error
|
||||||
|
|
||||||
hooks, err := models.GetWebhooksByRepoID(ctx.Repo.Repository.ID)
|
hooks, err := models.GetWebhooksByRepoID(ctx.Repo.Repository.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(500, "GetWebhooksByRepoID", err)
|
ctx.Error(500, "GetWebhooksByRepoID", err)
|
||||||
|
@ -41,8 +49,20 @@ func GetHook(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateHook create a hook for a repository
|
// CreateHook create a hook for a repository
|
||||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories#create-a-hook
|
|
||||||
func CreateHook(ctx *context.APIContext, form api.CreateHookOption) {
|
func CreateHook(ctx *context.APIContext, form api.CreateHookOption) {
|
||||||
|
// swagger:route POST /repos/{username}/{reponame}/hooks
|
||||||
|
//
|
||||||
|
// Consumes:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 200: apiHook
|
||||||
|
// 422: validationError
|
||||||
|
// 500: error
|
||||||
|
|
||||||
if !utils.CheckCreateHookOption(ctx, &form) {
|
if !utils.CheckCreateHookOption(ctx, &form) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -50,14 +70,33 @@ func CreateHook(ctx *context.APIContext, form api.CreateHookOption) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// EditHook modify a hook of a repository
|
// EditHook modify a hook of a repository
|
||||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories#edit-a-hook
|
|
||||||
func EditHook(ctx *context.APIContext, form api.EditHookOption) {
|
func EditHook(ctx *context.APIContext, form api.EditHookOption) {
|
||||||
|
// swagger:route PATCH /repos/{username}/{reponame}/hooks/{id}
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 200: apiHook //TODO
|
||||||
|
// 422: validationError
|
||||||
|
// 500: error
|
||||||
|
|
||||||
hookID := ctx.ParamsInt64(":id")
|
hookID := ctx.ParamsInt64(":id")
|
||||||
utils.EditRepoHook(ctx, &form, hookID)
|
utils.EditRepoHook(ctx, &form, hookID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteHook delete a hook of a repository
|
// DeleteHook delete a hook of a repository
|
||||||
func DeleteHook(ctx *context.APIContext) {
|
func DeleteHook(ctx *context.APIContext) {
|
||||||
|
// swagger:route DELETE /repos/{username}/{reponame}/hooks/{id}
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 204: empty
|
||||||
|
// 404: notFound
|
||||||
|
// 500: error
|
||||||
|
|
||||||
if err := models.DeleteWebhookByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")); err != nil {
|
if err := models.DeleteWebhookByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")); err != nil {
|
||||||
if models.IsErrWebhookNotExist(err) {
|
if models.IsErrWebhookNotExist(err) {
|
||||||
ctx.Status(404)
|
ctx.Status(404)
|
||||||
|
|
|
@ -18,8 +18,16 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Search repositories via options
|
// Search repositories via options
|
||||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories#search-repositories
|
|
||||||
func Search(ctx *context.APIContext) {
|
func Search(ctx *context.APIContext) {
|
||||||
|
// swagger:route GET /repos/search repoSearch
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 200: SearchResults
|
||||||
|
// 500: SearchError
|
||||||
|
|
||||||
opts := &models.SearchRepoOptions{
|
opts := &models.SearchRepoOptions{
|
||||||
Keyword: strings.Trim(ctx.Query("q"), " "),
|
Keyword: strings.Trim(ctx.Query("q"), " "),
|
||||||
OwnerID: ctx.QueryInt64("uid"),
|
OwnerID: ctx.QueryInt64("uid"),
|
||||||
|
@ -33,9 +41,9 @@ func Search(ctx *context.APIContext) {
|
||||||
} else {
|
} else {
|
||||||
u, err := models.GetUserByID(opts.OwnerID)
|
u, err := models.GetUserByID(opts.OwnerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, map[string]interface{}{
|
ctx.JSON(500, api.SearchError{
|
||||||
"ok": false,
|
OK: false,
|
||||||
"error": err.Error(),
|
Error: err.Error(),
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -48,9 +56,9 @@ func Search(ctx *context.APIContext) {
|
||||||
|
|
||||||
repos, count, err := models.SearchRepositoryByName(opts)
|
repos, count, err := models.SearchRepositoryByName(opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, map[string]interface{}{
|
ctx.JSON(500, api.SearchError{
|
||||||
"ok": false,
|
OK: false,
|
||||||
"error": err.Error(),
|
Error: err.Error(),
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -63,26 +71,26 @@ func Search(ctx *context.APIContext) {
|
||||||
results := make([]*api.Repository, len(repos))
|
results := make([]*api.Repository, len(repos))
|
||||||
for i, repo := range repos {
|
for i, repo := range repos {
|
||||||
if err = repo.GetOwner(); err != nil {
|
if err = repo.GetOwner(); err != nil {
|
||||||
ctx.JSON(500, map[string]interface{}{
|
ctx.JSON(500, api.SearchError{
|
||||||
"ok": false,
|
OK: false,
|
||||||
"error": err.Error(),
|
Error: err.Error(),
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
accessMode, err := models.AccessLevel(userID, repo)
|
accessMode, err := models.AccessLevel(userID, repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, map[string]interface{}{
|
ctx.JSON(500, api.SearchError{
|
||||||
"ok": false,
|
OK: false,
|
||||||
"error": err.Error(),
|
Error: err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
results[i] = repo.APIFormat(accessMode)
|
results[i] = repo.APIFormat(accessMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.SetLinkHeader(int(count), setting.API.MaxResponseItems)
|
ctx.SetLinkHeader(int(count), setting.API.MaxResponseItems)
|
||||||
ctx.JSON(200, map[string]interface{}{
|
ctx.JSON(200, api.SearchResults{
|
||||||
"ok": true,
|
OK: true,
|
||||||
"data": results,
|
Data: results,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,6 +137,20 @@ func Create(ctx *context.APIContext, opt api.CreateRepoOption) {
|
||||||
|
|
||||||
// CreateOrgRepo create one repository of the organization
|
// CreateOrgRepo create one repository of the organization
|
||||||
func CreateOrgRepo(ctx *context.APIContext, opt api.CreateRepoOption) {
|
func CreateOrgRepo(ctx *context.APIContext, opt api.CreateRepoOption) {
|
||||||
|
// swagger:route POST /org/{org}/repos createOrgRepo
|
||||||
|
//
|
||||||
|
// Consumes:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 201: Repository
|
||||||
|
// 422: validationError
|
||||||
|
// 403: forbidden
|
||||||
|
// 500: error
|
||||||
|
|
||||||
org, err := models.GetOrgByName(ctx.Params(":org"))
|
org, err := models.GetOrgByName(ctx.Params(":org"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrUserNotExist(err) {
|
if models.IsErrUserNotExist(err) {
|
||||||
|
@ -147,8 +169,20 @@ func CreateOrgRepo(ctx *context.APIContext, opt api.CreateRepoOption) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Migrate migrate remote git repository to gitea
|
// Migrate migrate remote git repository to gitea
|
||||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories#migrate
|
|
||||||
func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) {
|
func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) {
|
||||||
|
// swagger:route POST /repos/migrate
|
||||||
|
//
|
||||||
|
// Consumes:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 201: Repository
|
||||||
|
// 422: validationError
|
||||||
|
// 500: error
|
||||||
|
|
||||||
ctxUser := ctx.User
|
ctxUser := ctx.User
|
||||||
// Not equal means context user is an organization,
|
// Not equal means context user is an organization,
|
||||||
// or is another user/organization if current user is admin.
|
// or is another user/organization if current user is admin.
|
||||||
|
@ -220,8 +254,16 @@ func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get one repository
|
// Get one repository
|
||||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories#get
|
|
||||||
func Get(ctx *context.APIContext) {
|
func Get(ctx *context.APIContext) {
|
||||||
|
// swagger:route GET /repos/{username}/{reponame}
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 200: Repository
|
||||||
|
// 500: error
|
||||||
|
|
||||||
repo := ctx.Repo.Repository
|
repo := ctx.Repo.Repository
|
||||||
access, err := models.AccessLevel(ctx.User.ID, repo)
|
access, err := models.AccessLevel(ctx.User.ID, repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -233,6 +275,15 @@ func Get(ctx *context.APIContext) {
|
||||||
|
|
||||||
// GetByID returns a single Repository
|
// GetByID returns a single Repository
|
||||||
func GetByID(ctx *context.APIContext) {
|
func GetByID(ctx *context.APIContext) {
|
||||||
|
// swagger:route GET /repositories/{id}
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 200: Repository
|
||||||
|
// 500: error
|
||||||
|
|
||||||
repo, err := models.GetRepositoryByID(ctx.ParamsInt64(":id"))
|
repo, err := models.GetRepositoryByID(ctx.ParamsInt64(":id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrRepoNotExist(err) {
|
if models.IsErrRepoNotExist(err) {
|
||||||
|
@ -252,8 +303,17 @@ func GetByID(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete one repository
|
// Delete one repository
|
||||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories#delete
|
|
||||||
func Delete(ctx *context.APIContext) {
|
func Delete(ctx *context.APIContext) {
|
||||||
|
// swagger:route DELETE /repos/{username}/{reponame}
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 204: empty
|
||||||
|
// 403: forbidden
|
||||||
|
// 500: error
|
||||||
|
|
||||||
if !ctx.Repo.IsAdmin() {
|
if !ctx.Repo.IsAdmin() {
|
||||||
ctx.Error(403, "", "Must have admin rights")
|
ctx.Error(403, "", "Must have admin rights")
|
||||||
return
|
return
|
||||||
|
|
|
@ -12,8 +12,16 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// ListAccessTokens list all the access tokens
|
// ListAccessTokens list all the access tokens
|
||||||
// see https://github.com/gogits/go-gogs-client/wiki/Users#list-access-tokens-for-a-user
|
|
||||||
func ListAccessTokens(ctx *context.APIContext) {
|
func ListAccessTokens(ctx *context.APIContext) {
|
||||||
|
// swagger:route GET /users/{username}/tokens userGetTokens
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 200: AccessTokenList
|
||||||
|
// 500: error
|
||||||
|
|
||||||
tokens, err := models.ListAccessTokens(ctx.User.ID)
|
tokens, err := models.ListAccessTokens(ctx.User.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(500, "ListAccessTokens", err)
|
ctx.Error(500, "ListAccessTokens", err)
|
||||||
|
@ -31,8 +39,19 @@ func ListAccessTokens(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateAccessToken create access tokens
|
// CreateAccessToken create access tokens
|
||||||
// see https://github.com/gogits/go-gogs-client/wiki/Users#create-a-access-token
|
|
||||||
func CreateAccessToken(ctx *context.APIContext, form api.CreateAccessTokenOption) {
|
func CreateAccessToken(ctx *context.APIContext, form api.CreateAccessTokenOption) {
|
||||||
|
// swagger:route POST /users/{username} /tokens userCreateToken
|
||||||
|
//
|
||||||
|
// Consumes:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 200: AccessToken
|
||||||
|
// 500: error
|
||||||
|
|
||||||
t := &models.AccessToken{
|
t := &models.AccessToken{
|
||||||
UID: ctx.User.ID,
|
UID: ctx.User.ID,
|
||||||
Name: form.Name,
|
Name: form.Name,
|
||||||
|
|
|
@ -30,12 +30,29 @@ func listUserFollowers(ctx *context.APIContext, u *models.User) {
|
||||||
|
|
||||||
// ListMyFollowers list all my followers
|
// ListMyFollowers list all my followers
|
||||||
func ListMyFollowers(ctx *context.APIContext) {
|
func ListMyFollowers(ctx *context.APIContext) {
|
||||||
|
// swagger:route GET /user/followers userCurrentListFollowers
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 200: UserList
|
||||||
|
// 500: error
|
||||||
|
|
||||||
listUserFollowers(ctx, ctx.User)
|
listUserFollowers(ctx, ctx.User)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListFollowers list user's followers
|
// ListFollowers list user's followers
|
||||||
// see https://github.com/gogits/go-gogs-client/wiki/Users-Followers#list-followers-of-a-user
|
|
||||||
func ListFollowers(ctx *context.APIContext) {
|
func ListFollowers(ctx *context.APIContext) {
|
||||||
|
// swagger:route GET /users/:username/followers userListFollowers
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 200: UserList
|
||||||
|
// 500: error
|
||||||
|
|
||||||
u := GetUserByParams(ctx)
|
u := GetUserByParams(ctx)
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return
|
||||||
|
@ -54,12 +71,29 @@ func listUserFollowing(ctx *context.APIContext, u *models.User) {
|
||||||
|
|
||||||
// ListMyFollowing list all my followings
|
// ListMyFollowing list all my followings
|
||||||
func ListMyFollowing(ctx *context.APIContext) {
|
func ListMyFollowing(ctx *context.APIContext) {
|
||||||
|
// swagger:route GET /user/following userCurrentListFollowing
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 200: UserList
|
||||||
|
// 500: error
|
||||||
|
|
||||||
listUserFollowing(ctx, ctx.User)
|
listUserFollowing(ctx, ctx.User)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListFollowing list user's followings
|
// ListFollowing list user's followings
|
||||||
// see https://github.com/gogits/go-gogs-client/wiki/Users-Followers#list-users-followed-by-another-user
|
|
||||||
func ListFollowing(ctx *context.APIContext) {
|
func ListFollowing(ctx *context.APIContext) {
|
||||||
|
// swagger:route GET /users/{username}/following userListFollowing
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 200: UserList
|
||||||
|
// 500: error
|
||||||
|
|
||||||
u := GetUserByParams(ctx)
|
u := GetUserByParams(ctx)
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return
|
||||||
|
@ -76,8 +110,13 @@ func checkUserFollowing(ctx *context.APIContext, u *models.User, followID int64)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckMyFollowing check if the repo is followed by me
|
// CheckMyFollowing check if the repo is followed by me
|
||||||
// see https://github.com/gogits/go-gogs-client/wiki/Users-Followers#check-if-you-are-following-a-user
|
|
||||||
func CheckMyFollowing(ctx *context.APIContext) {
|
func CheckMyFollowing(ctx *context.APIContext) {
|
||||||
|
// swagger:route GET /user/following/{username} userCurrentCheckFollowing
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 204: empty
|
||||||
|
// 404: notFound
|
||||||
|
|
||||||
target := GetUserByParams(ctx)
|
target := GetUserByParams(ctx)
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return
|
||||||
|
@ -86,8 +125,13 @@ func CheckMyFollowing(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckFollowing check if the repo is followed by user
|
// CheckFollowing check if the repo is followed by user
|
||||||
// see https://github.com/gogits/go-gogs-client/wiki/Users-Followers#check-if-one-user-follows-another
|
|
||||||
func CheckFollowing(ctx *context.APIContext) {
|
func CheckFollowing(ctx *context.APIContext) {
|
||||||
|
// swagger:route GET /users/{username}/following/:target userCheckFollowing
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 204: empty
|
||||||
|
// 404: notFound
|
||||||
|
|
||||||
u := GetUserByParams(ctx)
|
u := GetUserByParams(ctx)
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return
|
||||||
|
@ -100,8 +144,13 @@ func CheckFollowing(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Follow follow one repository
|
// Follow follow one repository
|
||||||
// see https://github.com/gogits/go-gogs-client/wiki/Users-Followers#follow-a-user
|
|
||||||
func Follow(ctx *context.APIContext) {
|
func Follow(ctx *context.APIContext) {
|
||||||
|
// swagger:route PUT /user/following/{username} userCurrentPutFollow
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 204: empty
|
||||||
|
// 500: error
|
||||||
|
|
||||||
target := GetUserByParams(ctx)
|
target := GetUserByParams(ctx)
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return
|
||||||
|
@ -114,8 +163,13 @@ func Follow(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unfollow unfollow one repository
|
// Unfollow unfollow one repository
|
||||||
// see https://github.com/gogits/go-gogs-client/wiki/Users-Followers#unfollow-a-user
|
|
||||||
func Unfollow(ctx *context.APIContext) {
|
func Unfollow(ctx *context.APIContext) {
|
||||||
|
// swagger:route DELETE /user/following/{username} userCurrentDeleteFollow
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 204: empty
|
||||||
|
// 500: error
|
||||||
|
|
||||||
target := GetUserByParams(ctx)
|
target := GetUserByParams(ctx)
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return
|
||||||
|
|
|
@ -34,6 +34,15 @@ func listGPGKeys(ctx *context.APIContext, uid int64) {
|
||||||
|
|
||||||
//ListGPGKeys get the GPG key list of a user
|
//ListGPGKeys get the GPG key list of a user
|
||||||
func ListGPGKeys(ctx *context.APIContext) {
|
func ListGPGKeys(ctx *context.APIContext) {
|
||||||
|
// swagger:route GET /users/{username}/gpg_keys userListGPGKeys
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 200: GPGKeyList
|
||||||
|
// 500: error
|
||||||
|
|
||||||
user := GetUserByParams(ctx)
|
user := GetUserByParams(ctx)
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return
|
||||||
|
@ -43,11 +52,30 @@ func ListGPGKeys(ctx *context.APIContext) {
|
||||||
|
|
||||||
//ListMyGPGKeys get the GPG key list of the logged user
|
//ListMyGPGKeys get the GPG key list of the logged user
|
||||||
func ListMyGPGKeys(ctx *context.APIContext) {
|
func ListMyGPGKeys(ctx *context.APIContext) {
|
||||||
|
// swagger:route GET /user/gpg_keys userCurrentListGPGKeys
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 200: GPGKeyList
|
||||||
|
// 500: error
|
||||||
|
|
||||||
listGPGKeys(ctx, ctx.User.ID)
|
listGPGKeys(ctx, ctx.User.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
//GetGPGKey get the GPG key based on a id
|
//GetGPGKey get the GPG key based on a id
|
||||||
func GetGPGKey(ctx *context.APIContext) {
|
func GetGPGKey(ctx *context.APIContext) {
|
||||||
|
// swagger:route GET /user/gpg_keys/{id} userCurrentGetGPGKey
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 200: GPGKey
|
||||||
|
// 404: notFound
|
||||||
|
// 500: error
|
||||||
|
|
||||||
key, err := models.GetGPGKeyByID(ctx.ParamsInt64(":id"))
|
key, err := models.GetGPGKeyByID(ctx.ParamsInt64(":id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrGPGKeyNotExist(err) {
|
if models.IsErrGPGKeyNotExist(err) {
|
||||||
|
@ -72,11 +100,34 @@ func CreateUserGPGKey(ctx *context.APIContext, form api.CreateGPGKeyOption, uid
|
||||||
|
|
||||||
//CreateGPGKey associate a GPG key to the current user
|
//CreateGPGKey associate a GPG key to the current user
|
||||||
func CreateGPGKey(ctx *context.APIContext, form api.CreateGPGKeyOption) {
|
func CreateGPGKey(ctx *context.APIContext, form api.CreateGPGKeyOption) {
|
||||||
|
// swagger:route POST /user/gpg_keys userCurrentPostGPGKey
|
||||||
|
//
|
||||||
|
// Consumes:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 201: GPGKey
|
||||||
|
// 422: validationError
|
||||||
|
// 500: error
|
||||||
|
|
||||||
CreateUserGPGKey(ctx, form, ctx.User.ID)
|
CreateUserGPGKey(ctx, form, ctx.User.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
//DeleteGPGKey remove a GPG key associated to the current user
|
//DeleteGPGKey remove a GPG key associated to the current user
|
||||||
func DeleteGPGKey(ctx *context.APIContext) {
|
func DeleteGPGKey(ctx *context.APIContext) {
|
||||||
|
// swagger:route DELETE /user/gpg_keys/{id} userCurrentDeleteGPGKey
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 204: empty
|
||||||
|
// 403: forbidden
|
||||||
|
// 500: error
|
||||||
|
|
||||||
if err := models.DeleteGPGKey(ctx.User, ctx.ParamsInt64(":id")); err != nil {
|
if err := models.DeleteGPGKey(ctx.User, ctx.ParamsInt64(":id")); err != nil {
|
||||||
if models.IsErrGPGKeyAccessDenied(err) {
|
if models.IsErrGPGKeyAccessDenied(err) {
|
||||||
ctx.Error(403, "", "You do not have access to this key")
|
ctx.Error(403, "", "You do not have access to this key")
|
||||||
|
|
|
@ -54,14 +54,30 @@ func listPublicKeys(ctx *context.APIContext, uid int64) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListMyPublicKeys list all my public keys
|
// ListMyPublicKeys list all my public keys
|
||||||
// see https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#list-your-public-keys
|
|
||||||
func ListMyPublicKeys(ctx *context.APIContext) {
|
func ListMyPublicKeys(ctx *context.APIContext) {
|
||||||
|
// swagger:route GET /user/keys userCurrentListKeys
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 200: PublicKeyList
|
||||||
|
// 500: error
|
||||||
|
|
||||||
listPublicKeys(ctx, ctx.User.ID)
|
listPublicKeys(ctx, ctx.User.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListPublicKeys list all user's public keys
|
// ListPublicKeys list all user's public keys
|
||||||
// see https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#list-public-keys-for-a-user
|
|
||||||
func ListPublicKeys(ctx *context.APIContext) {
|
func ListPublicKeys(ctx *context.APIContext) {
|
||||||
|
// swagger:route GET /users/{username}/keys userListKeys
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 200: PublicKeyList
|
||||||
|
// 500: error
|
||||||
|
|
||||||
user := GetUserByParams(ctx)
|
user := GetUserByParams(ctx)
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return
|
||||||
|
@ -70,8 +86,17 @@ func ListPublicKeys(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPublicKey get one public key
|
// GetPublicKey get one public key
|
||||||
// see https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#get-a-single-public-key
|
|
||||||
func GetPublicKey(ctx *context.APIContext) {
|
func GetPublicKey(ctx *context.APIContext) {
|
||||||
|
// swagger:route GET /user/keys/{id} userCurrentGetKey
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 200: PublicKey
|
||||||
|
// 404: notFound
|
||||||
|
// 500: error
|
||||||
|
|
||||||
key, err := models.GetPublicKeyByID(ctx.ParamsInt64(":id"))
|
key, err := models.GetPublicKeyByID(ctx.ParamsInt64(":id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrKeyNotExist(err) {
|
if models.IsErrKeyNotExist(err) {
|
||||||
|
@ -104,14 +129,35 @@ func CreateUserPublicKey(ctx *context.APIContext, form api.CreateKeyOption, uid
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreatePublicKey create one public key for me
|
// CreatePublicKey create one public key for me
|
||||||
// see https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#create-a-public-key
|
|
||||||
func CreatePublicKey(ctx *context.APIContext, form api.CreateKeyOption) {
|
func CreatePublicKey(ctx *context.APIContext, form api.CreateKeyOption) {
|
||||||
|
// swagger:route POST /user/keys userCurrentPostKey
|
||||||
|
//
|
||||||
|
// Consumes:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 201: PublicKey
|
||||||
|
// 422: validationError
|
||||||
|
// 500: error
|
||||||
|
|
||||||
CreateUserPublicKey(ctx, form, ctx.User.ID)
|
CreateUserPublicKey(ctx, form, ctx.User.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeletePublicKey delete one public key of mine
|
// DeletePublicKey delete one public key of mine
|
||||||
// see https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#delete-a-public-key
|
|
||||||
func DeletePublicKey(ctx *context.APIContext) {
|
func DeletePublicKey(ctx *context.APIContext) {
|
||||||
|
// swagger:route DELETE /user/keys/{id} userCurrentDeleteKey
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 204: empty
|
||||||
|
// 403: forbidden
|
||||||
|
// 500: error
|
||||||
|
|
||||||
if err := models.DeletePublicKey(ctx.User, ctx.ParamsInt64(":id")); err != nil {
|
if err := models.DeletePublicKey(ctx.User, ctx.ParamsInt64(":id")); err != nil {
|
||||||
if models.IsErrKeyAccessDenied(err) {
|
if models.IsErrKeyAccessDenied(err) {
|
||||||
ctx.Error(403, "", "You do not have access to this key")
|
ctx.Error(403, "", "You do not have access to this key")
|
||||||
|
|
|
@ -36,6 +36,15 @@ func listUserRepos(ctx *context.APIContext, u *models.User) {
|
||||||
|
|
||||||
// ListUserRepos - list the repos owned and accessible by the given user.
|
// ListUserRepos - list the repos owned and accessible by the given user.
|
||||||
func ListUserRepos(ctx *context.APIContext) {
|
func ListUserRepos(ctx *context.APIContext) {
|
||||||
|
// swagger:route GET /users/{username}/repos userListRepos
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 200: RepositoryList
|
||||||
|
// 500: error
|
||||||
|
|
||||||
user := GetUserByParams(ctx)
|
user := GetUserByParams(ctx)
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return
|
||||||
|
@ -44,8 +53,16 @@ func ListUserRepos(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListMyRepos - list the repositories owned by you.
|
// ListMyRepos - list the repositories owned by you.
|
||||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories#list-your-repositories
|
|
||||||
func ListMyRepos(ctx *context.APIContext) {
|
func ListMyRepos(ctx *context.APIContext) {
|
||||||
|
// swagger:route GET /user/repos userCurrentListRepos
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 200: RepositoryList
|
||||||
|
// 500: error
|
||||||
|
|
||||||
listUserRepos(ctx, ctx.User)
|
listUserRepos(ctx, ctx.User)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,15 @@ func getStarredRepos(userID int64, private bool) ([]*api.Repository, error) {
|
||||||
// GetStarredRepos returns the repos that the user specified by the APIContext
|
// GetStarredRepos returns the repos that the user specified by the APIContext
|
||||||
// has starred
|
// has starred
|
||||||
func GetStarredRepos(ctx *context.APIContext) {
|
func GetStarredRepos(ctx *context.APIContext) {
|
||||||
|
// swagger:route GET /users/{username}/starred userListStarred
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 200: RepositoryList
|
||||||
|
// 500: error
|
||||||
|
|
||||||
user := GetUserByParams(ctx)
|
user := GetUserByParams(ctx)
|
||||||
private := user.ID == ctx.User.ID
|
private := user.ID == ctx.User.ID
|
||||||
repos, err := getStarredRepos(user.ID, private)
|
repos, err := getStarredRepos(user.ID, private)
|
||||||
|
@ -44,6 +53,15 @@ func GetStarredRepos(ctx *context.APIContext) {
|
||||||
|
|
||||||
// GetMyStarredRepos returns the repos that the authenticated user has starred
|
// GetMyStarredRepos returns the repos that the authenticated user has starred
|
||||||
func GetMyStarredRepos(ctx *context.APIContext) {
|
func GetMyStarredRepos(ctx *context.APIContext) {
|
||||||
|
// swagger:route GET /user/starred userCurrentListStarred
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 200: RepositoryList
|
||||||
|
// 500: error
|
||||||
|
|
||||||
repos, err := getStarredRepos(ctx.User.ID, true)
|
repos, err := getStarredRepos(ctx.User.ID, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(500, "getStarredRepos", err)
|
ctx.Error(500, "getStarredRepos", err)
|
||||||
|
@ -53,6 +71,12 @@ func GetMyStarredRepos(ctx *context.APIContext) {
|
||||||
|
|
||||||
// IsStarring returns whether the authenticated is starring the repo
|
// IsStarring returns whether the authenticated is starring the repo
|
||||||
func IsStarring(ctx *context.APIContext) {
|
func IsStarring(ctx *context.APIContext) {
|
||||||
|
// swagger:route GET /user/starred/{username}/{reponame} userCurrentCheckStarring
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 204: empty
|
||||||
|
// 404: notFound
|
||||||
|
|
||||||
if models.IsStaring(ctx.User.ID, ctx.Repo.Repository.ID) {
|
if models.IsStaring(ctx.User.ID, ctx.Repo.Repository.ID) {
|
||||||
ctx.Status(204)
|
ctx.Status(204)
|
||||||
} else {
|
} else {
|
||||||
|
@ -62,6 +86,12 @@ func IsStarring(ctx *context.APIContext) {
|
||||||
|
|
||||||
// Star the repo specified in the APIContext, as the authenticated user
|
// Star the repo specified in the APIContext, as the authenticated user
|
||||||
func Star(ctx *context.APIContext) {
|
func Star(ctx *context.APIContext) {
|
||||||
|
// swagger:route PUT /user/starred/{username}/{reponame} userCurrentPutStar
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 204: empty
|
||||||
|
// 500: error
|
||||||
|
|
||||||
err := models.StarRepo(ctx.User.ID, ctx.Repo.Repository.ID, true)
|
err := models.StarRepo(ctx.User.ID, ctx.Repo.Repository.ID, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(500, "StarRepo", err)
|
ctx.Error(500, "StarRepo", err)
|
||||||
|
@ -72,6 +102,12 @@ func Star(ctx *context.APIContext) {
|
||||||
|
|
||||||
// Unstar the repo specified in the APIContext, as the authenticated user
|
// Unstar the repo specified in the APIContext, as the authenticated user
|
||||||
func Unstar(ctx *context.APIContext) {
|
func Unstar(ctx *context.APIContext) {
|
||||||
|
// swagger:route DELETE /user/starred/{username}/{reponame} userCurrentDeleteStar
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 204: empty
|
||||||
|
// 500: error
|
||||||
|
|
||||||
err := models.StarRepo(ctx.User.ID, ctx.Repo.Repository.ID, false)
|
err := models.StarRepo(ctx.User.ID, ctx.Repo.Repository.ID, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(500, "StarRepo", err)
|
ctx.Error(500, "StarRepo", err)
|
||||||
|
|
|
@ -17,6 +17,15 @@ import (
|
||||||
|
|
||||||
// Search search users
|
// Search search users
|
||||||
func Search(ctx *context.APIContext) {
|
func Search(ctx *context.APIContext) {
|
||||||
|
// swagger:route GET /users/search userSearch
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 200: UserList
|
||||||
|
// 500: error
|
||||||
|
|
||||||
opts := &models.SearchUserOptions{
|
opts := &models.SearchUserOptions{
|
||||||
Keyword: strings.Trim(ctx.Query("q"), " "),
|
Keyword: strings.Trim(ctx.Query("q"), " "),
|
||||||
Type: models.UserTypeIndividual,
|
Type: models.UserTypeIndividual,
|
||||||
|
@ -56,6 +65,16 @@ func Search(ctx *context.APIContext) {
|
||||||
|
|
||||||
// GetInfo get user's information
|
// GetInfo get user's information
|
||||||
func GetInfo(ctx *context.APIContext) {
|
func GetInfo(ctx *context.APIContext) {
|
||||||
|
// swagger:route GET /users/{username} userGet
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 200: User
|
||||||
|
// 404: notFound
|
||||||
|
// 500: error
|
||||||
|
|
||||||
u, err := models.GetUserByName(ctx.Params(":username"))
|
u, err := models.GetUserByName(ctx.Params(":username"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrUserNotExist(err) {
|
if models.IsErrUserNotExist(err) {
|
||||||
|
@ -75,5 +94,13 @@ func GetInfo(ctx *context.APIContext) {
|
||||||
|
|
||||||
// GetAuthenticatedUser get curent user's information
|
// GetAuthenticatedUser get curent user's information
|
||||||
func GetAuthenticatedUser(ctx *context.APIContext) {
|
func GetAuthenticatedUser(ctx *context.APIContext) {
|
||||||
|
// swagger:route GET /user userGetCurrent
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 200: User
|
||||||
|
|
||||||
ctx.JSON(200, ctx.User.APIFormat())
|
ctx.JSON(200, ctx.User.APIFormat())
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,15 @@ func getWatchedRepos(userID int64, private bool) ([]*api.Repository, error) {
|
||||||
|
|
||||||
// GetWatchedRepos returns the repos that the user specified in ctx is watching
|
// GetWatchedRepos returns the repos that the user specified in ctx is watching
|
||||||
func GetWatchedRepos(ctx *context.APIContext) {
|
func GetWatchedRepos(ctx *context.APIContext) {
|
||||||
|
// swagger:route GET /users/{username}/subscriptions userListSubscriptions
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 200: RepositoryList
|
||||||
|
// 500: error
|
||||||
|
|
||||||
user := GetUserByParams(ctx)
|
user := GetUserByParams(ctx)
|
||||||
private := user.ID == ctx.User.ID
|
private := user.ID == ctx.User.ID
|
||||||
repos, err := getWatchedRepos(user.ID, private)
|
repos, err := getWatchedRepos(user.ID, private)
|
||||||
|
@ -44,6 +53,15 @@ func GetWatchedRepos(ctx *context.APIContext) {
|
||||||
|
|
||||||
// GetMyWatchedRepos returns the repos that the authenticated user is watching
|
// GetMyWatchedRepos returns the repos that the authenticated user is watching
|
||||||
func GetMyWatchedRepos(ctx *context.APIContext) {
|
func GetMyWatchedRepos(ctx *context.APIContext) {
|
||||||
|
// swagger:route GET /user/subscriptions userCurrentListSubscriptions
|
||||||
|
//
|
||||||
|
// Produces:
|
||||||
|
// - application/json
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 200: RepositoryList
|
||||||
|
// 500: error
|
||||||
|
|
||||||
repos, err := getWatchedRepos(ctx.User.ID, true)
|
repos, err := getWatchedRepos(ctx.User.ID, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(500, "getWatchedRepos", err)
|
ctx.Error(500, "getWatchedRepos", err)
|
||||||
|
@ -54,6 +72,12 @@ func GetMyWatchedRepos(ctx *context.APIContext) {
|
||||||
// IsWatching returns whether the authenticated user is watching the repo
|
// IsWatching returns whether the authenticated user is watching the repo
|
||||||
// specified in ctx
|
// specified in ctx
|
||||||
func IsWatching(ctx *context.APIContext) {
|
func IsWatching(ctx *context.APIContext) {
|
||||||
|
// swagger:route GET /repos/{username}/{reponame}/subscription userCurrentCheckSubscription
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 200: WatchInfo
|
||||||
|
// 404: notFound
|
||||||
|
|
||||||
if models.IsWatching(ctx.User.ID, ctx.Repo.Repository.ID) {
|
if models.IsWatching(ctx.User.ID, ctx.Repo.Repository.ID) {
|
||||||
ctx.JSON(200, api.WatchInfo{
|
ctx.JSON(200, api.WatchInfo{
|
||||||
Subscribed: true,
|
Subscribed: true,
|
||||||
|
@ -70,6 +94,12 @@ func IsWatching(ctx *context.APIContext) {
|
||||||
|
|
||||||
// Watch the repo specified in ctx, as the authenticated user
|
// Watch the repo specified in ctx, as the authenticated user
|
||||||
func Watch(ctx *context.APIContext) {
|
func Watch(ctx *context.APIContext) {
|
||||||
|
// swagger:route PUT /repos/{username}/{reponame}/subscription userCurrentPutSubscription
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 200: WatchInfo
|
||||||
|
// 500: error
|
||||||
|
|
||||||
err := models.WatchRepo(ctx.User.ID, ctx.Repo.Repository.ID, true)
|
err := models.WatchRepo(ctx.User.ID, ctx.Repo.Repository.ID, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(500, "WatchRepo", err)
|
ctx.Error(500, "WatchRepo", err)
|
||||||
|
@ -88,6 +118,12 @@ func Watch(ctx *context.APIContext) {
|
||||||
|
|
||||||
// Unwatch the repo specified in ctx, as the authenticated user
|
// Unwatch the repo specified in ctx, as the authenticated user
|
||||||
func Unwatch(ctx *context.APIContext) {
|
func Unwatch(ctx *context.APIContext) {
|
||||||
|
// swagger:route DELETE /repos/{username}/{reponame}/subscription userCurrentDeleteSubscription
|
||||||
|
//
|
||||||
|
// Responses:
|
||||||
|
// 204: empty
|
||||||
|
// 500: error
|
||||||
|
|
||||||
err := models.WatchRepo(ctx.User.ID, ctx.Repo.Repository.ID, false)
|
err := models.WatchRepo(ctx.User.ID, ctx.Repo.Repository.ID, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(500, "UnwatchRepo", err)
|
ctx.Error(500, "UnwatchRepo", err)
|
||||||
|
|
|
@ -20,6 +20,8 @@ import (
|
||||||
const (
|
const (
|
||||||
// tplHome home page template
|
// tplHome home page template
|
||||||
tplHome base.TplName = "home"
|
tplHome base.TplName = "home"
|
||||||
|
// tplSwagger swagger page template
|
||||||
|
tplSwagger base.TplName = "swagger"
|
||||||
// tplExploreRepos explore repositories page template
|
// tplExploreRepos explore repositories page template
|
||||||
tplExploreRepos base.TplName = "explore/repos"
|
tplExploreRepos base.TplName = "explore/repos"
|
||||||
// tplExploreUsers explore users page template
|
// tplExploreUsers explore users page template
|
||||||
|
@ -51,6 +53,11 @@ func Home(ctx *context.Context) {
|
||||||
ctx.HTML(200, tplHome)
|
ctx.HTML(200, tplHome)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Swagger render swagger-ui page
|
||||||
|
func Swagger(ctx *context.Context) {
|
||||||
|
ctx.HTML(200, tplSwagger)
|
||||||
|
}
|
||||||
|
|
||||||
// RepoSearchOptions when calling search repositories
|
// RepoSearchOptions when calling search repositories
|
||||||
type RepoSearchOptions struct {
|
type RepoSearchOptions struct {
|
||||||
Ranger func(*models.SearchRepoOptions) (models.RepositoryList, int64, error)
|
Ranger func(*models.SearchRepoOptions) (models.RepositoryList, int64, error)
|
||||||
|
|
|
@ -146,6 +146,7 @@ func RegisterRoutes(m *macaron.Macaron) {
|
||||||
return ""
|
return ""
|
||||||
})
|
})
|
||||||
m.Get("/", ignSignIn, routers.Home)
|
m.Get("/", ignSignIn, routers.Home)
|
||||||
|
m.Get("/swagger", ignSignIn, routers.Swagger)
|
||||||
m.Group("/explore", func() {
|
m.Group("/explore", func() {
|
||||||
m.Get("", func(ctx *context.Context) {
|
m.Get("", func(ctx *context.Context) {
|
||||||
ctx.Redirect(setting.AppSubURL + "/explore/repos")
|
ctx.Redirect(setting.AppSubURL + "/explore/repos")
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<a href="{{AppSubUrl}}/assets/librejs/librejs.html" data-jslicense="1">Javascript licenses</a>
|
<a href="{{AppSubUrl}}/assets/librejs/librejs.html" data-jslicense="1">Javascript licenses</a>
|
||||||
|
<a href="{{AppSubUrl}}/swagger">API</a>
|
||||||
<a target="_blank" rel="noopener" href="https://gitea.io">{{.i18n.Tr "website"}}</a>
|
<a target="_blank" rel="noopener" href="https://gitea.io">{{.i18n.Tr "website"}}</a>
|
||||||
{{if (or .ShowFooterVersion .PageIsAdmin)}}<span class="version">{{GoVer}}</span>{{end}}
|
{{if (or .ShowFooterVersion .PageIsAdmin)}}<span class="version">{{GoVer}}</span>{{end}}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -0,0 +1,93 @@
|
||||||
|
<!-- HTML for static distribution bundle build -->
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Swagger UI</title>
|
||||||
|
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" type="text/css" href="{{AppSubUrl}}/assets/swagger-ui/swagger-ui.css" >
|
||||||
|
<link rel="icon" type="image/png" href="{{AppSubUrl}}/assets/swagger-ui/favicon-32x32.png" sizes="32x32" />
|
||||||
|
<link rel="icon" type="image/png" href="{{AppSubUrl}}/assets/swagger-ui/favicon-16x16.png" sizes="16x16" />
|
||||||
|
<style>
|
||||||
|
html
|
||||||
|
{
|
||||||
|
box-sizing: border-box;
|
||||||
|
overflow: -moz-scrollbars-vertical;
|
||||||
|
overflow-y: scroll;
|
||||||
|
}
|
||||||
|
*,
|
||||||
|
*:before,
|
||||||
|
*:after
|
||||||
|
{
|
||||||
|
box-sizing: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin:0;
|
||||||
|
background: #fafafa;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="position:absolute;width:0;height:0">
|
||||||
|
<defs>
|
||||||
|
<symbol viewBox="0 0 20 20" id="unlocked">
|
||||||
|
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V6h2v-.801C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8z"></path>
|
||||||
|
</symbol>
|
||||||
|
|
||||||
|
<symbol viewBox="0 0 20 20" id="locked">
|
||||||
|
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8zM12 8H8V5.199C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8z"/>
|
||||||
|
</symbol>
|
||||||
|
|
||||||
|
<symbol viewBox="0 0 20 20" id="close">
|
||||||
|
<path d="M14.348 14.849c-.469.469-1.229.469-1.697 0L10 11.819l-2.651 3.029c-.469.469-1.229.469-1.697 0-.469-.469-.469-1.229 0-1.697l2.758-3.15-2.759-3.152c-.469-.469-.469-1.228 0-1.697.469-.469 1.228-.469 1.697 0L10 8.183l2.651-3.031c.469-.469 1.228-.469 1.697 0 .469.469.469 1.229 0 1.697l-2.758 3.152 2.758 3.15c.469.469.469 1.229 0 1.698z"/>
|
||||||
|
</symbol>
|
||||||
|
|
||||||
|
<symbol viewBox="0 0 20 20" id="large-arrow">
|
||||||
|
<path d="M13.25 10L6.109 2.58c-.268-.27-.268-.707 0-.979.268-.27.701-.27.969 0l7.83 7.908c.268.271.268.709 0 .979l-7.83 7.908c-.268.271-.701.27-.969 0-.268-.269-.268-.707 0-.979L13.25 10z"/>
|
||||||
|
</symbol>
|
||||||
|
|
||||||
|
<symbol viewBox="0 0 20 20" id="large-arrow-down">
|
||||||
|
<path d="M17.418 6.109c.272-.268.709-.268.979 0s.271.701 0 .969l-7.908 7.83c-.27.268-.707.268-.979 0l-7.908-7.83c-.27-.268-.27-.701 0-.969.271-.268.709-.268.979 0L10 13.25l7.418-7.141z"/>
|
||||||
|
</symbol>
|
||||||
|
|
||||||
|
|
||||||
|
<symbol viewBox="0 0 24 24" id="jump-to">
|
||||||
|
<path d="M19 7v4H5.83l3.58-3.59L8 6l-6 6 6 6 1.41-1.41L5.83 13H21V7z"/>
|
||||||
|
</symbol>
|
||||||
|
|
||||||
|
<symbol viewBox="0 0 24 24" id="expand">
|
||||||
|
<path d="M10 18h4v-2h-4v2zM3 6v2h18V6H3zm3 7h12v-2H6v2z"/>
|
||||||
|
</symbol>
|
||||||
|
|
||||||
|
</defs>
|
||||||
|
</svg>
|
||||||
|
|
||||||
|
<div id="swagger-ui"></div>
|
||||||
|
|
||||||
|
<script src="{{AppSubUrl}}/assets/swagger-ui/swagger-ui-bundle.js"> </script>
|
||||||
|
<script src="{{AppSubUrl}}/assets/swagger-ui/swagger-ui-standalone-preset.js"> </script>
|
||||||
|
<script>
|
||||||
|
window.onload = function() {
|
||||||
|
// Build a system
|
||||||
|
const ui = SwaggerUIBundle({
|
||||||
|
url: "{{AppUrl}}swagger.v1.json",
|
||||||
|
dom_id: '#swagger-ui',
|
||||||
|
presets: [
|
||||||
|
SwaggerUIBundle.presets.apis,
|
||||||
|
SwaggerUIStandalonePreset
|
||||||
|
],
|
||||||
|
plugins: [
|
||||||
|
SwaggerUIBundle.plugins.DownloadUrl
|
||||||
|
],
|
||||||
|
layout: "StandaloneLayout"
|
||||||
|
})
|
||||||
|
|
||||||
|
window.ui = ui
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
|
@ -4,15 +4,47 @@
|
||||||
|
|
||||||
package gitea
|
package gitea
|
||||||
|
|
||||||
// MarkdownOption markdown options
|
// SearchResults results of search
|
||||||
type MarkdownOption struct {
|
// swagger:response SearchResults
|
||||||
Text string
|
type SearchResults struct {
|
||||||
Mode string
|
OK bool `json:"ok"`
|
||||||
Context string
|
Data []*Repository `json:"data"`
|
||||||
Wiki bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SearchError error of failing search
|
||||||
|
// swagger:response SearchError
|
||||||
|
type SearchError struct {
|
||||||
|
OK bool `json:"ok"`
|
||||||
|
Error string `json:"error"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarkdownOption markdown options
|
||||||
|
// swagger:parameters renderMarkdown
|
||||||
|
type MarkdownOption struct {
|
||||||
|
// Text markdown to render
|
||||||
|
//
|
||||||
|
// in: body
|
||||||
|
Text string
|
||||||
|
// Mode to render
|
||||||
|
//
|
||||||
|
// in: body
|
||||||
|
Mode string
|
||||||
|
// Context to render
|
||||||
|
//
|
||||||
|
// in: body
|
||||||
|
Context string
|
||||||
|
// Is it a wiki page ?
|
||||||
|
//
|
||||||
|
// in: body
|
||||||
|
Wiki bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarkdownRender is a rendered markdown document
|
||||||
|
// swagger:response MarkdownRender
|
||||||
|
type MarkdownRender string
|
||||||
|
|
||||||
// ServerVersion wraps the version of the server
|
// ServerVersion wraps the version of the server
|
||||||
|
// swagger:response ServerVersion
|
||||||
type ServerVersion struct {
|
type ServerVersion struct {
|
||||||
Version string
|
Version string
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ type Permission struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Repository represents a API repository.
|
// Repository represents a API repository.
|
||||||
|
// swagger:response Repository
|
||||||
type Repository struct {
|
type Repository struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Owner *User `json:"owner"`
|
Owner *User `json:"owner"`
|
||||||
|
@ -42,6 +43,10 @@ type Repository struct {
|
||||||
Permissions *Permission `json:"permissions,omitempty"`
|
Permissions *Permission `json:"permissions,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RepositoryList represents a list of API repository.
|
||||||
|
// swagger:response RepositoryList
|
||||||
|
type RepositoryList []*Repository
|
||||||
|
|
||||||
// ListMyRepos lists all repositories for the authenticated user that has access to.
|
// ListMyRepos lists all repositories for the authenticated user that has access to.
|
||||||
func (c *Client) ListMyRepos() ([]*Repository, error) {
|
func (c *Client) ListMyRepos() ([]*Repository, error) {
|
||||||
repos := make([]*Repository, 0, 10)
|
repos := make([]*Repository, 0, 10)
|
||||||
|
@ -61,14 +66,37 @@ func (c *Client) ListOrgRepos(org string) ([]*Repository, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateRepoOption options when creating repository
|
// CreateRepoOption options when creating repository
|
||||||
|
//swagger:parameters createOrgRepo
|
||||||
type CreateRepoOption struct {
|
type CreateRepoOption struct {
|
||||||
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(100)"`
|
// Name of the repository to create
|
||||||
|
//
|
||||||
|
// in: body
|
||||||
|
// unique: true
|
||||||
|
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(100)"`
|
||||||
|
// Description of the repository to create
|
||||||
|
//
|
||||||
|
// in: body
|
||||||
Description string `json:"description" binding:"MaxSize(255)"`
|
Description string `json:"description" binding:"MaxSize(255)"`
|
||||||
Private bool `json:"private"`
|
// Is the repository to create private ?
|
||||||
AutoInit bool `json:"auto_init"`
|
//
|
||||||
Gitignores string `json:"gitignores"`
|
// in: body
|
||||||
License string `json:"license"`
|
Private bool `json:"private"`
|
||||||
Readme string `json:"readme"`
|
// Init the repository to create ?
|
||||||
|
//
|
||||||
|
// in: body
|
||||||
|
AutoInit bool `json:"auto_init"`
|
||||||
|
// Gitignores to use
|
||||||
|
//
|
||||||
|
// in: body
|
||||||
|
Gitignores string `json:"gitignores"`
|
||||||
|
// License to use
|
||||||
|
//
|
||||||
|
// in: body
|
||||||
|
License string `json:"license"`
|
||||||
|
// Readme of the repository to create
|
||||||
|
//
|
||||||
|
// in: body
|
||||||
|
Readme string `json:"readme"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateRepo creates a repository for authenticated user.
|
// CreateRepo creates a repository for authenticated user.
|
||||||
|
|
|
@ -34,9 +34,20 @@ func (c *Client) GetDeployKey(user, repo string, keyID int64) (*DeployKey, error
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateKeyOption options when create deploy key
|
// CreateKeyOption options when create deploy key
|
||||||
|
// swagger:parameters userCurrentPostKey
|
||||||
type CreateKeyOption struct {
|
type CreateKeyOption struct {
|
||||||
|
// Title of the key to add
|
||||||
|
//
|
||||||
|
// in: body
|
||||||
|
// required: true
|
||||||
|
// unique: true
|
||||||
Title string `json:"title" binding:"Required"`
|
Title string `json:"title" binding:"Required"`
|
||||||
Key string `json:"key" binding:"Required"`
|
// An armored SSH key to add
|
||||||
|
//
|
||||||
|
// in: body
|
||||||
|
// required: true
|
||||||
|
// unique: true
|
||||||
|
Key string `json:"key" binding:"Required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateDeployKey options when create one deploy key
|
// CreateDeployKey options when create one deploy key
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// WatchInfo represents a API watch status of one repository
|
// WatchInfo represents a API watch status of one repository
|
||||||
|
// swagger:response WatchInfo
|
||||||
type WatchInfo struct {
|
type WatchInfo struct {
|
||||||
Subscribed bool `json:"subscribed"`
|
Subscribed bool `json:"subscribed"`
|
||||||
Ignored bool `json:"ignored"`
|
Ignored bool `json:"ignored"`
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// User represents a API user.
|
// User represents a API user.
|
||||||
|
// swagger:response User
|
||||||
type User struct {
|
type User struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
UserName string `json:"login"`
|
UserName string `json:"login"`
|
||||||
|
@ -18,6 +19,10 @@ type User struct {
|
||||||
AvatarURL string `json:"avatar_url"`
|
AvatarURL string `json:"avatar_url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UserList represents a list of API user.
|
||||||
|
// swagger:response UserList
|
||||||
|
type UserList []*User
|
||||||
|
|
||||||
// MarshalJSON implements the json.Marshaler interface for User, adding field(s) for backward compatibility
|
// MarshalJSON implements the json.Marshaler interface for User, adding field(s) for backward compatibility
|
||||||
func (u User) MarshalJSON() ([]byte, error) {
|
func (u User) MarshalJSON() ([]byte, error) {
|
||||||
// Re-declaring User to avoid recursion
|
// Re-declaring User to avoid recursion
|
||||||
|
|
|
@ -18,11 +18,16 @@ func BasicAuthEncode(user, pass string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AccessToken represents a API access token.
|
// AccessToken represents a API access token.
|
||||||
|
// swagger:response AccessToken
|
||||||
type AccessToken struct {
|
type AccessToken struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Sha1 string `json:"sha1"`
|
Sha1 string `json:"sha1"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AccessTokenList represents a list of API access token.
|
||||||
|
// swagger:response AccessTokenList
|
||||||
|
type AccessTokenList []*AccessToken
|
||||||
|
|
||||||
// ListAccessTokens lista all the access tokens of user
|
// ListAccessTokens lista all the access tokens of user
|
||||||
func (c *Client) ListAccessTokens(user, pass string) ([]*AccessToken, error) {
|
func (c *Client) ListAccessTokens(user, pass string) ([]*AccessToken, error) {
|
||||||
tokens := make([]*AccessToken, 0, 10)
|
tokens := make([]*AccessToken, 0, 10)
|
||||||
|
@ -31,6 +36,7 @@ func (c *Client) ListAccessTokens(user, pass string) ([]*AccessToken, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateAccessTokenOption options when create access token
|
// CreateAccessTokenOption options when create access token
|
||||||
|
// swagger:parameters userCreateToken
|
||||||
type CreateAccessTokenOption struct {
|
type CreateAccessTokenOption struct {
|
||||||
Name string `json:"name" binding:"Required"`
|
Name string `json:"name" binding:"Required"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,12 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GPGKeyList represents a list of GPGKey
|
||||||
|
// swagger:response GPGKeyList
|
||||||
|
type GPGKeyList []*GPGKey
|
||||||
|
|
||||||
// GPGKey a user GPG key to sign commit and tag in repository
|
// GPGKey a user GPG key to sign commit and tag in repository
|
||||||
|
// swagger:response GPGKey
|
||||||
type GPGKey struct {
|
type GPGKey struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
PrimaryKeyID string `json:"primary_key_id"`
|
PrimaryKeyID string `json:"primary_key_id"`
|
||||||
|
@ -28,13 +33,20 @@ type GPGKey struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GPGKeyEmail a email attache to a GPGKey
|
// GPGKeyEmail a email attache to a GPGKey
|
||||||
|
// swagger:model GPGKeyEmail
|
||||||
type GPGKeyEmail struct {
|
type GPGKeyEmail struct {
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Verified bool `json:"verified"`
|
Verified bool `json:"verified"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateGPGKeyOption options create user GPG key
|
// CreateGPGKeyOption options create user GPG key
|
||||||
|
// swagger:parameters userCurrentPostGPGKey
|
||||||
type CreateGPGKeyOption struct {
|
type CreateGPGKeyOption struct {
|
||||||
|
// An armored GPG key to add
|
||||||
|
//
|
||||||
|
// in: body
|
||||||
|
// required: true
|
||||||
|
// unique: true
|
||||||
ArmoredKey string `json:"armored_public_key" binding:"Required"`
|
ArmoredKey string `json:"armored_public_key" binding:"Required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,12 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// PublicKeyList represents a list of PublicKey
|
||||||
|
// swagger:response PublicKeyList
|
||||||
|
type PublicKeyList []*PublicKey
|
||||||
|
|
||||||
// PublicKey publickey is a user key to push code to repository
|
// PublicKey publickey is a user key to push code to repository
|
||||||
|
// swagger:response PublicKey
|
||||||
type PublicKey struct {
|
type PublicKey struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
|
|
|
@ -9,10 +9,10 @@
|
||||||
"revisionTime": "2017-04-26T13:12:33Z"
|
"revisionTime": "2017-04-26T13:12:33Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "xACJysFK1sK/D5655EpU48mw2vo=",
|
"checksumSHA1": "vdziKobpPIkU/dLvSI8n7eWrIIE=",
|
||||||
"path": "code.gitea.io/sdk/gitea",
|
"path": "code.gitea.io/sdk/gitea",
|
||||||
"revision": "0c3a0b0b5ea6edfb5bf3a4c81ebda6d207ecdfad",
|
"revision": "d2f87fd3f9f2887b9f15112cec8d7f53b2825147",
|
||||||
"revisionTime": "2017-04-27T00:40:26Z"
|
"revisionTime": "2017-04-30T15:33:16Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "IyfS7Rbl6OgR83QR7TOfKdDCq+M=",
|
"checksumSHA1": "IyfS7Rbl6OgR83QR7TOfKdDCq+M=",
|
||||||
|
|
Loading…
Reference in New Issue