mirror of https://github.com/gogs/gogs.git
api: GitHub compliance (#4549)
* Add undocumented endpoint for /repositories/:id * GitHub API Compliancepull/4551/head
parent
3359b942b3
commit
51d7f1264b
|
@ -68,7 +68,7 @@ func (label *Label) APIFormat() *api.Label {
|
||||||
return &api.Label{
|
return &api.Label{
|
||||||
ID: label.ID,
|
ID: label.ID,
|
||||||
Name: label.Name,
|
Name: label.Name,
|
||||||
Color: label.Color,
|
Color: strings.TrimLeft(label.Color, "#"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +103,28 @@ func NewLabels(labels ...*Label) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// getLabelOfRepoByID returns a label by ID in given repository.
|
// getLabelOfRepoByName returns a label by Name in given repository.
|
||||||
|
// If pass repoID as 0, then ORM will ignore limitation of repository
|
||||||
|
// and can return arbitrary label with any valid ID.
|
||||||
|
func getLabelOfRepoByName(e Engine, repoID int64, labelName string) (*Label, error) {
|
||||||
|
if len(labelName) <= 0 {
|
||||||
|
return nil, ErrLabelNotExist{0, repoID}
|
||||||
|
}
|
||||||
|
|
||||||
|
l := &Label{
|
||||||
|
Name: labelName,
|
||||||
|
RepoID: repoID,
|
||||||
|
}
|
||||||
|
has, err := x.Get(l)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else if !has {
|
||||||
|
return nil, ErrLabelNotExist{0, l.RepoID}
|
||||||
|
}
|
||||||
|
return l, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// getLabelInRepoByID returns a label by ID in given repository.
|
||||||
// If pass repoID as 0, then ORM will ignore limitation of repository
|
// If pass repoID as 0, then ORM will ignore limitation of repository
|
||||||
// and can return arbitrary label with any valid ID.
|
// and can return arbitrary label with any valid ID.
|
||||||
func getLabelOfRepoByID(e Engine, repoID, labelID int64) (*Label, error) {
|
func getLabelOfRepoByID(e Engine, repoID, labelID int64) (*Label, error) {
|
||||||
|
@ -134,6 +155,11 @@ func GetLabelOfRepoByID(repoID, labelID int64) (*Label, error) {
|
||||||
return getLabelOfRepoByID(x, repoID, labelID)
|
return getLabelOfRepoByID(x, repoID, labelID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetLabelOfRepoByName returns a label by name in given repository.
|
||||||
|
func GetLabelOfRepoByName(repoID int64, labelName string) (*Label, error) {
|
||||||
|
return getLabelOfRepoByName(x, repoID, labelName)
|
||||||
|
}
|
||||||
|
|
||||||
// GetLabelsInRepoByIDs returns a list of labels by IDs in given repository,
|
// GetLabelsInRepoByIDs returns a list of labels by IDs in given repository,
|
||||||
// it silently ignores label IDs that are not belong to the repository.
|
// it silently ignores label IDs that are not belong to the repository.
|
||||||
func GetLabelsInRepoByIDs(repoID int64, labelIDs []int64) ([]*Label, error) {
|
func GetLabelsInRepoByIDs(repoID int64, labelIDs []int64) ([]*Label, error) {
|
||||||
|
|
|
@ -15,8 +15,8 @@ import (
|
||||||
|
|
||||||
"github.com/gogits/gogs/models"
|
"github.com/gogits/gogs/models"
|
||||||
"github.com/gogits/gogs/models/errors"
|
"github.com/gogits/gogs/models/errors"
|
||||||
"github.com/gogits/gogs/pkg/tool"
|
|
||||||
"github.com/gogits/gogs/pkg/setting"
|
"github.com/gogits/gogs/pkg/setting"
|
||||||
|
"github.com/gogits/gogs/pkg/tool"
|
||||||
)
|
)
|
||||||
|
|
||||||
func IsAPIPath(url string) bool {
|
func IsAPIPath(url string) bool {
|
||||||
|
@ -24,17 +24,20 @@ func IsAPIPath(url string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SignedInID returns the id of signed in user.
|
// SignedInID returns the id of signed in user.
|
||||||
func SignedInID(ctx *macaron.Context, sess session.Store) int64 {
|
func SignedInID(c *macaron.Context, sess session.Store) int64 {
|
||||||
if !models.HasEngine {
|
if !models.HasEngine {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check access token.
|
// Check access token.
|
||||||
if IsAPIPath(ctx.Req.URL.Path) {
|
if IsAPIPath(c.Req.URL.Path) {
|
||||||
tokenSHA := ctx.Query("token")
|
tokenSHA := c.Query("token")
|
||||||
|
if len(tokenSHA) <= 0 {
|
||||||
|
tokenSHA = c.Query("access_token")
|
||||||
|
}
|
||||||
if len(tokenSHA) == 0 {
|
if len(tokenSHA) == 0 {
|
||||||
// Well, check with header again.
|
// Well, check with header again.
|
||||||
auHead := ctx.Req.Header.Get("Authorization")
|
auHead := c.Req.Header.Get("Authorization")
|
||||||
if len(auHead) > 0 {
|
if len(auHead) > 0 {
|
||||||
auths := strings.Fields(auHead)
|
auths := strings.Fields(auHead)
|
||||||
if len(auths) == 2 && auths[0] == "token" {
|
if len(auths) == 2 && auths[0] == "token" {
|
||||||
|
|
|
@ -47,6 +47,7 @@ func ListUserIssues(c *context.APIContext) {
|
||||||
opts := models.IssuesOptions{
|
opts := models.IssuesOptions{
|
||||||
AssigneeID: c.User.ID,
|
AssigneeID: c.User.ID,
|
||||||
Page: c.QueryInt("page"),
|
Page: c.QueryInt("page"),
|
||||||
|
IsClosed: api.StateType(c.Query("state")) == api.STATE_CLOSED,
|
||||||
}
|
}
|
||||||
|
|
||||||
listIssues(c, &opts)
|
listIssues(c, &opts)
|
||||||
|
@ -54,8 +55,9 @@ func ListUserIssues(c *context.APIContext) {
|
||||||
|
|
||||||
func ListIssues(c *context.APIContext) {
|
func ListIssues(c *context.APIContext) {
|
||||||
opts := models.IssuesOptions{
|
opts := models.IssuesOptions{
|
||||||
RepoID: c.Repo.Repository.ID,
|
RepoID: c.Repo.Repository.ID,
|
||||||
Page: c.QueryInt("page"),
|
Page: c.QueryInt("page"),
|
||||||
|
IsClosed: api.StateType(c.Query("state")) == api.STATE_CLOSED,
|
||||||
}
|
}
|
||||||
|
|
||||||
listIssues(c, &opts)
|
listIssues(c, &opts)
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
package repo
|
package repo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/Unknwon/com"
|
||||||
|
|
||||||
api "github.com/gogits/go-gogs-client"
|
api "github.com/gogits/go-gogs-client"
|
||||||
|
|
||||||
"github.com/gogits/gogs/models"
|
"github.com/gogits/gogs/models"
|
||||||
|
@ -26,7 +28,14 @@ func ListLabels(c *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetLabel(c *context.APIContext) {
|
func GetLabel(c *context.APIContext) {
|
||||||
label, err := models.GetLabelOfRepoByID(c.Repo.Repository.ID, c.ParamsInt64(":id"))
|
var label *models.Label
|
||||||
|
var err error
|
||||||
|
idStr := c.Params(":id")
|
||||||
|
if id := com.StrTo(idStr).MustInt64(); id > 0 {
|
||||||
|
label, err = models.GetLabelOfRepoByID(c.Repo.Repository.ID, id)
|
||||||
|
} else {
|
||||||
|
label, err = models.GetLabelOfRepoByName(c.Repo.Repository.ID, idStr)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrLabelNotExist(err) {
|
if models.IsErrLabelNotExist(err) {
|
||||||
c.Status(404)
|
c.Status(404)
|
||||||
|
|
Loading…
Reference in New Issue