浏览代码

api/repo: support edit repository issue tracker (gogs/go-gogs-client#94)

Unknwon 6 年之前
父节点
当前提交
e1b3a25008
共有 5 个文件被更改,包括 40 次插入2 次删除
  1. 1 1
      gogs.go
  2. 5 0
      pkg/context/api.go
  3. 2 0
      routes/api/v1/api.go
  4. 31 0
      routes/api/v1/repo/repo.go
  5. 1 1
      templates/.VERSION

+ 1 - 1
gogs.go

@@ -16,7 +16,7 @@ import (
 	"github.com/gogs/gogs/pkg/setting"
 )
 
-const APP_VER = "0.11.72.1201"
+const APP_VER = "0.11.73.1202"
 
 func init() {
 	setting.AppVer = APP_VER

+ 5 - 0
pkg/context/api.go

@@ -44,6 +44,11 @@ func (c *APIContext) Error(status int, title string, obj interface{}) {
 	})
 }
 
+// NoContent renders the 204 response.
+func (c *APIContext) NoContent() {
+	c.Status(http.StatusNoContent)
+}
+
 // NotFound renders the 404 response.
 func (c *APIContext) NotFound() {
 	c.Status(http.StatusNotFound)

+ 2 - 0
routes/api/v1/api.go

@@ -293,6 +293,8 @@ func RegisterRoutes(m *macaron.Macaron) {
 						Patch(reqRepoWriter(), bind(api.EditMilestoneOption{}), repo.EditMilestone).
 						Delete(reqRepoWriter(), repo.DeleteMilestone)
 				})
+
+				m.Patch("/issue-tracker", bind(api.EditIssueTrackerOption{}), repo.IssueTracker)
 				m.Post("/mirror-sync", repo.MirrorSync)
 				m.Get("/editorconfig/:filename", context.RepoRef(), repo.GetEditorconfig)
 			}, repoAssignment())

+ 31 - 0
routes/api/v1/repo/repo.go

@@ -291,6 +291,7 @@ func Migrate(c *context.APIContext, f form.MigrateRepo) {
 	c.JSON(201, repo.APIFormat(&api.Permission{true, true, true}))
 }
 
+// FIXME: Inject to *context.APIContext
 func parseOwnerAndRepo(c *context.APIContext) (*models.User, *models.Repository) {
 	owner, err := models.GetUserByName(c.Params(":username"))
 	if err != nil {
@@ -373,6 +374,36 @@ func ListForks(c *context.APIContext) {
 	c.JSON(200, &apiForks)
 }
 
+func IssueTracker(c *context.APIContext, form api.EditIssueTrackerOption) {
+	_, repo := parseOwnerAndRepo(c)
+	if c.Written() {
+		return
+	}
+
+	if form.EnableIssues != nil {
+		repo.EnableIssues = *form.EnableIssues
+	}
+	if form.EnableExternalTracker != nil {
+		repo.EnableExternalTracker = *form.EnableExternalTracker
+	}
+	if form.ExternalTrackerURL != nil {
+		repo.ExternalTrackerURL = *form.ExternalTrackerURL
+	}
+	if form.TrackerURLFormat != nil {
+		repo.ExternalTrackerFormat = *form.TrackerURLFormat
+	}
+	if form.TrackerIssueStyle != nil {
+		repo.ExternalTrackerStyle = *form.TrackerIssueStyle
+	}
+
+	if err := models.UpdateRepository(repo, false); err != nil {
+		c.ServerError("UpdateRepository", err)
+		return
+	}
+
+	c.NoContent()
+}
+
 func MirrorSync(c *context.APIContext) {
 	_, repo := parseOwnerAndRepo(c)
 	if c.Written() {

+ 1 - 1
templates/.VERSION

@@ -1 +1 @@
-0.11.72.1201
+0.11.73.1202