1
0
Эх сурвалжийг харах

api: EditWiki implementation (#5860)

Co-authored-by: Joe Chen <jc@unknwon.io>
Pavel M 3 жил өмнө
parent
commit
de3161155b

+ 1 - 1
internal/db/backup.go

@@ -89,7 +89,7 @@ func dumpTable(db *gorm.DB, table interface{}, w io.Writer) error {
 			return errors.Wrap(err, "encode JSON")
 		}
 	}
-	return nil
+	return rows.Err()
 }
 
 func dumpLegacyTables(dirPath string, verbose bool) error {

+ 1 - 0
internal/route/api/v1/api.go

@@ -355,6 +355,7 @@ func RegisterRoutes(m *macaron.Macaron) {
 				}, reqRepoWriter())
 
 				m.Patch("/issue-tracker", reqRepoWriter(), bind(api.EditIssueTrackerOption{}), repo.IssueTracker)
+				m.Patch("/wiki", reqRepoWriter(), bind(api.EditWikiOption{}), repo.Wiki)
 				m.Post("/mirror-sync", reqRepoWriter(), repo.MirrorSync)
 				m.Get("/editorconfig/:filename", context.RepoRef(), repo.GetEditorconfig)
 			}, repoAssignment())

+ 26 - 0
internal/route/api/v1/repo/repo.go

@@ -390,6 +390,32 @@ func IssueTracker(c *context.APIContext, form api.EditIssueTrackerOption) {
 	c.NoContent()
 }
 
+func Wiki(c *context.APIContext, form api.EditWikiOption) {
+	_, repo := parseOwnerAndRepo(c)
+	if c.Written() {
+		return
+	}
+
+	if form.AllowPublicWiki != nil {
+		repo.AllowPublicWiki = *form.AllowPublicWiki
+	}
+	if form.EnableExternalWiki != nil {
+		repo.EnableExternalWiki = *form.EnableExternalWiki
+	}
+	if form.EnableWiki != nil {
+		repo.EnableWiki = *form.EnableWiki
+	}
+	if form.ExternalWikiURL != nil {
+		repo.ExternalWikiURL = *form.ExternalWikiURL
+	}
+	if err := db.UpdateRepository(repo, false); err != nil {
+		c.Error(err, "update repository")
+		return
+	}
+
+	c.NoContent()
+}
+
 func MirrorSync(c *context.APIContext) {
 	_, repo := parseOwnerAndRepo(c)
 	if c.Written() {