Skip to content

Commit ba75319

Browse files
lunnytechknowlogick
authored andcommitted
fix clone wiki failed via ssh (#5503)
1 parent ccea916 commit ba75319

File tree

4 files changed

+76
-4
lines changed

4 files changed

+76
-4
lines changed

cmd/serv.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,15 @@ func runServ(c *cli.Context) error {
144144
}()
145145
}
146146

147-
isUncyclo := false
148-
unitType := models.UnitTypeCode
147+
var (
148+
isUncyclo bool
149+
unitType = models.UnitTypeCode
150+
unitName = "code"
151+
)
149152
if strings.HasSuffix(reponame, ".wiki") {
150153
isUncyclo = true
151154
unitType = models.UnitTypeUncyclo
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 isUncyclo {
307-
if err = repo.InitUncyclo(); err != nil {
311+
if err = private.InitUncyclo(repo.ID); err != nil {
308312
fail("Internal error", "Failed to init wiki repo: %v", err)
309313
}
310314
}

modules/private/wiki.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
// InitUncyclo initwiki via repo id
15+
func InitUncyclo(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("InitUncyclo: %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+
}

routers/private/internal.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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", InitUncyclo)
8586
m.Post("/push/update", PushUpdate)
8687
m.Get("/protectedbranch/:pbid/:userid", CanUserPush)
8788
m.Get("/repo/:owner/:repo", GetRepositoryByOwnerAndName)

routers/private/wiki.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
// InitUncyclo initilizes wiki via repo id
14+
func InitUncyclo(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.InitUncyclo()
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+
}

0 commit comments

Comments
 (0)