File tree Expand file tree Collapse file tree 4 files changed +76
-4
lines changed Expand file tree Collapse file tree 4 files changed +76
-4
lines changed Original file line number Diff line number Diff line change @@ -144,11 +144,15 @@ func runServ(c *cli.Context) error {
144144 }()
145145 }
146146
147- isWiki := false
148- unitType := models .UnitTypeCode
147+ var (
148+ isWiki bool
149+ unitType = models .UnitTypeCode
150+ unitName = "code"
151+ )
149152 if strings .HasSuffix (reponame , ".wiki" ) {
150153 isWiki = true
151154 unitType = models .UnitTypeWiki
155+ unitName = "wiki"
152156 reponame = reponame [:len (reponame )- 5 ]
153157 }
154158
@@ -245,7 +249,7 @@ func runServ(c *cli.Context) error {
245249 clientMessage = "You do not have sufficient authorization for this action"
246250 }
247251 fail (clientMessage ,
248- "User %s does not have level %v access to repository %s" ,
252+ "User %s does not have level %v access to repository %s's " + unitName ,
249253 user .Name , requestedMode , repoPath )
250254 }
251255
@@ -304,7 +308,7 @@ func runServ(c *cli.Context) error {
304308 gitcmd = exec .Command (verb , repoPath )
305309 }
306310 if isWiki {
307- if err = repo .InitWiki (); err != nil {
311+ if err = private .InitWiki (repo . ID ); err != nil {
308312 fail ("Internal error" , "Failed to init wiki repo: %v" , err )
309313 }
310314 }
Original file line number Diff line number Diff line change 1+ // Copyright 2018 The Gitea Authors. All rights reserved.
2+ // Use of this source code is governed by a MIT-style
3+ // license that can be found in the LICENSE file.
4+
5+ package private
6+
7+ import (
8+ "fmt"
9+
10+ "code.gitea.io/gitea/modules/log"
11+ "code.gitea.io/gitea/modules/setting"
12+ )
13+
14+ // InitWiki initwiki via repo id
15+ func InitWiki (repoID int64 ) error {
16+ // Ask for running deliver hook and test pull request tasks.
17+ reqURL := setting .LocalURL + fmt .Sprintf ("api/internal/repositories/%d/wiki/init" , repoID )
18+ log .GitLogger .Trace ("InitWiki: %s" , reqURL )
19+
20+ resp , err := newInternalRequest (reqURL , "GET" ).Response ()
21+ if err != nil {
22+ return err
23+ }
24+
25+ defer resp .Body .Close ()
26+
27+ // All 2XX status codes are accepted and others will return an error
28+ if resp .StatusCode / 100 != 2 {
29+ return fmt .Errorf ("Failed to init wiki: %s" , decodeJSONError (resp ).Err )
30+ }
31+
32+ return nil
33+ }
Original file line number Diff line number Diff line change @@ -82,6 +82,7 @@ func RegisterRoutes(m *macaron.Macaron) {
8282 m .Post ("/repositories/:repoid/keys/:keyid/update" , UpdateDeployKey )
8383 m .Get ("/repositories/:repoid/user/:userid/checkunituser" , CheckUnitUser )
8484 m .Get ("/repositories/:repoid/has-keys/:keyid" , HasDeployKey )
85+ m .Get ("/repositories/:repoid/wiki/init" , InitWiki )
8586 m .Post ("/push/update" , PushUpdate )
8687 m .Get ("/protectedbranch/:pbid/:userid" , CanUserPush )
8788 m .Get ("/repo/:owner/:repo" , GetRepositoryByOwnerAndName )
Original file line number Diff line number Diff line change 1+ // Copyright 2017 The Gitea Authors. All rights reserved.
2+ // Use of this source code is governed by a MIT-style
3+ // license that can be found in the LICENSE file.
4+
5+ package private
6+
7+ import (
8+ "code.gitea.io/gitea/models"
9+
10+ macaron "gopkg.in/macaron.v1"
11+ )
12+
13+ // InitWiki initilizes wiki via repo id
14+ func InitWiki (ctx * macaron.Context ) {
15+ repoID := ctx .ParamsInt64 ("repoid" )
16+
17+ repo , err := models .GetRepositoryByID (repoID )
18+ if err != nil {
19+ ctx .JSON (500 , map [string ]interface {}{
20+ "err" : err .Error (),
21+ })
22+ return
23+ }
24+
25+ err = repo .InitWiki ()
26+ if err != nil {
27+ ctx .JSON (500 , map [string ]interface {}{
28+ "err" : err .Error (),
29+ })
30+ return
31+ }
32+
33+ ctx .Status (202 )
34+ }
You can’t perform that action at this time.
0 commit comments