mirror of https://github.com/gogits/gogs.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
170 lines
3.6 KiB
170 lines
3.6 KiB
9 years ago
|
// Copyright 2016 The Gogs Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
|
package repo
|
||
|
|
||
|
import (
|
||
|
api "github.com/gogits/go-gogs-client"
|
||
|
|
||
|
"github.com/gogits/gogs/models"
|
||
8 years ago
|
"github.com/gogits/gogs/models/errors"
|
||
8 years ago
|
"github.com/gogits/gogs/pkg/context"
|
||
9 years ago
|
)
|
||
|
|
||
8 years ago
|
func ListIssueLabels(c *context.APIContext) {
|
||
|
issue, err := models.GetIssueByIndex(c.Repo.Repository.ID, c.ParamsInt64(":index"))
|
||
9 years ago
|
if err != nil {
|
||
8 years ago
|
if errors.IsIssueNotExist(err) {
|
||
8 years ago
|
c.Status(404)
|
||
9 years ago
|
} else {
|
||
8 years ago
|
c.Error(500, "GetIssueByIndex", err)
|
||
9 years ago
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
|
apiLabels := make([]*api.Label, len(issue.Labels))
|
||
|
for i := range issue.Labels {
|
||
8 years ago
|
apiLabels[i] = issue.Labels[i].APIFormat()
|
||
9 years ago
|
}
|
||
8 years ago
|
c.JSON(200, &apiLabels)
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
func AddIssueLabels(c *context.APIContext, form api.IssueLabelsOption) {
|
||
|
if !c.Repo.IsWriter() {
|
||
|
c.Status(403)
|
||
9 years ago
|
return
|
||
|
}
|
||
|
|
||
8 years ago
|
issue, err := models.GetIssueByIndex(c.Repo.Repository.ID, c.ParamsInt64(":index"))
|
||
9 years ago
|
if err != nil {
|
||
8 years ago
|
if errors.IsIssueNotExist(err) {
|
||
8 years ago
|
c.Status(404)
|
||
9 years ago
|
} else {
|
||
8 years ago
|
c.Error(500, "GetIssueByIndex", err)
|
||
9 years ago
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
8 years ago
|
labels, err := models.GetLabelsInRepoByIDs(c.Repo.Repository.ID, form.Labels)
|
||
9 years ago
|
if err != nil {
|
||
8 years ago
|
c.Error(500, "GetLabelsInRepoByIDs", err)
|
||
9 years ago
|
return
|
||
|
}
|
||
|
|
||
8 years ago
|
if err = issue.AddLabels(c.User, labels); err != nil {
|
||
|
c.Error(500, "AddLabels", err)
|
||
9 years ago
|
return
|
||
9 years ago
|
}
|
||
|
|
||
9 years ago
|
labels, err = models.GetLabelsByIssueID(issue.ID)
|
||
9 years ago
|
if err != nil {
|
||
8 years ago
|
c.Error(500, "GetLabelsByIssueID", err)
|
||
9 years ago
|
return
|
||
|
}
|
||
|
|
||
9 years ago
|
apiLabels := make([]*api.Label, len(labels))
|
||
|
for i := range labels {
|
||
8 years ago
|
apiLabels[i] = issue.Labels[i].APIFormat()
|
||
9 years ago
|
}
|
||
8 years ago
|
c.JSON(200, &apiLabels)
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
func DeleteIssueLabel(c *context.APIContext) {
|
||
|
if !c.Repo.IsWriter() {
|
||
|
c.Status(403)
|
||
9 years ago
|
return
|
||
|
}
|
||
|
|
||
8 years ago
|
issue, err := models.GetIssueByIndex(c.Repo.Repository.ID, c.ParamsInt64(":index"))
|
||
9 years ago
|
if err != nil {
|
||
8 years ago
|
if errors.IsIssueNotExist(err) {
|
||
8 years ago
|
c.Status(404)
|
||
9 years ago
|
} else {
|
||
8 years ago
|
c.Error(500, "GetIssueByIndex", err)
|
||
9 years ago
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
8 years ago
|
label, err := models.GetLabelOfRepoByID(c.Repo.Repository.ID, c.ParamsInt64(":id"))
|
||
9 years ago
|
if err != nil {
|
||
9 years ago
|
if models.IsErrLabelNotExist(err) {
|
||
8 years ago
|
c.Error(422, "", err)
|
||
9 years ago
|
} else {
|
||
8 years ago
|
c.Error(500, "GetLabelInRepoByID", err)
|
||
9 years ago
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
9 years ago
|
if err := models.DeleteIssueLabel(issue, label); err != nil {
|
||
8 years ago
|
c.Error(500, "DeleteIssueLabel", err)
|
||
9 years ago
|
return
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
c.Status(204)
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
func ReplaceIssueLabels(c *context.APIContext, form api.IssueLabelsOption) {
|
||
|
if !c.Repo.IsWriter() {
|
||
|
c.Status(403)
|
||
9 years ago
|
return
|
||
|
}
|
||
|
|
||
8 years ago
|
issue, err := models.GetIssueByIndex(c.Repo.Repository.ID, c.ParamsInt64(":index"))
|
||
9 years ago
|
if err != nil {
|
||
8 years ago
|
if errors.IsIssueNotExist(err) {
|
||
8 years ago
|
c.Status(404)
|
||
9 years ago
|
} else {
|
||
8 years ago
|
c.Error(500, "GetIssueByIndex", err)
|
||
9 years ago
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
8 years ago
|
labels, err := models.GetLabelsInRepoByIDs(c.Repo.Repository.ID, form.Labels)
|
||
9 years ago
|
if err != nil {
|
||
8 years ago
|
c.Error(500, "GetLabelsInRepoByIDs", err)
|
||
9 years ago
|
return
|
||
|
}
|
||
|
|
||
9 years ago
|
if err := issue.ReplaceLabels(labels); err != nil {
|
||
8 years ago
|
c.Error(500, "ReplaceLabels", err)
|
||
9 years ago
|
return
|
||
|
}
|
||
|
|
||
9 years ago
|
labels, err = models.GetLabelsByIssueID(issue.ID)
|
||
|
if err != nil {
|
||
8 years ago
|
c.Error(500, "GetLabelsByIssueID", err)
|
||
9 years ago
|
return
|
||
|
}
|
||
|
|
||
|
apiLabels := make([]*api.Label, len(labels))
|
||
|
for i := range labels {
|
||
8 years ago
|
apiLabels[i] = issue.Labels[i].APIFormat()
|
||
9 years ago
|
}
|
||
8 years ago
|
c.JSON(200, &apiLabels)
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
func ClearIssueLabels(c *context.APIContext) {
|
||
|
if !c.Repo.IsWriter() {
|
||
|
c.Status(403)
|
||
9 years ago
|
return
|
||
|
}
|
||
|
|
||
8 years ago
|
issue, err := models.GetIssueByIndex(c.Repo.Repository.ID, c.ParamsInt64(":index"))
|
||
9 years ago
|
if err != nil {
|
||
8 years ago
|
if errors.IsIssueNotExist(err) {
|
||
8 years ago
|
c.Status(404)
|
||
9 years ago
|
} else {
|
||
8 years ago
|
c.Error(500, "GetIssueByIndex", err)
|
||
9 years ago
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
8 years ago
|
if err := issue.ClearLabels(c.User); err != nil {
|
||
|
c.Error(500, "ClearLabels", err)
|
||
9 years ago
|
return
|
||
|
}
|
||
|
|
||
8 years ago
|
c.Status(204)
|
||
9 years ago
|
}
|