fix clone wiki failed via ssh (#5503)
This commit is contained in:
parent
ccea91652f
commit
ba75319157
4 changed files with 76 additions and 4 deletions
12
cmd/serv.go
12
cmd/serv.go
|
@ -144,11 +144,15 @@ func runServ(c *cli.Context) error {
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
isWiki := false
|
var (
|
||||||
unitType := models.UnitTypeCode
|
isWiki bool
|
||||||
|
unitType = models.UnitTypeCode
|
||||||
|
unitName = "code"
|
||||||
|
)
|
||||||
if strings.HasSuffix(reponame, ".wiki") {
|
if strings.HasSuffix(reponame, ".wiki") {
|
||||||
isWiki = true
|
isWiki = true
|
||||||
unitType = models.UnitTypeWiki
|
unitType = models.UnitTypeWiki
|
||||||
|
unitName = "wiki"
|
||||||
reponame = reponame[:len(reponame)-5]
|
reponame = reponame[:len(reponame)-5]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,7 +249,7 @@ func runServ(c *cli.Context) error {
|
||||||
clientMessage = "You do not have sufficient authorization for this action"
|
clientMessage = "You do not have sufficient authorization for this action"
|
||||||
}
|
}
|
||||||
fail(clientMessage,
|
fail(clientMessage,
|
||||||
"User %s does not have level %v access to repository %s",
|
"User %s does not have level %v access to repository %s's "+unitName,
|
||||||
user.Name, requestedMode, repoPath)
|
user.Name, requestedMode, repoPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -304,7 +308,7 @@ func runServ(c *cli.Context) error {
|
||||||
gitcmd = exec.Command(verb, repoPath)
|
gitcmd = exec.Command(verb, repoPath)
|
||||||
}
|
}
|
||||||
if isWiki {
|
if isWiki {
|
||||||
if err = repo.InitWiki(); err != nil {
|
if err = private.InitWiki(repo.ID); err != nil {
|
||||||
fail("Internal error", "Failed to init wiki repo: %v", err)
|
fail("Internal error", "Failed to init wiki repo: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
33
modules/private/wiki.go
Normal file
33
modules/private/wiki.go
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
// Copyright 2018 The Gitea 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 private
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/modules/log"
|
||||||
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
)
|
||||||
|
|
||||||
|
// InitWiki initwiki via repo id
|
||||||
|
func InitWiki(repoID int64) error {
|
||||||
|
// Ask for running deliver hook and test pull request tasks.
|
||||||
|
reqURL := setting.LocalURL + fmt.Sprintf("api/internal/repositories/%d/wiki/init", repoID)
|
||||||
|
log.GitLogger.Trace("InitWiki: %s", reqURL)
|
||||||
|
|
||||||
|
resp, err := newInternalRequest(reqURL, "GET").Response()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
// All 2XX status codes are accepted and others will return an error
|
||||||
|
if resp.StatusCode/100 != 2 {
|
||||||
|
return fmt.Errorf("Failed to init wiki: %s", decodeJSONError(resp).Err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -82,6 +82,7 @@ func RegisterRoutes(m *macaron.Macaron) {
|
||||||
m.Post("/repositories/:repoid/keys/:keyid/update", UpdateDeployKey)
|
m.Post("/repositories/:repoid/keys/:keyid/update", UpdateDeployKey)
|
||||||
m.Get("/repositories/:repoid/user/:userid/checkunituser", CheckUnitUser)
|
m.Get("/repositories/:repoid/user/:userid/checkunituser", CheckUnitUser)
|
||||||
m.Get("/repositories/:repoid/has-keys/:keyid", HasDeployKey)
|
m.Get("/repositories/:repoid/has-keys/:keyid", HasDeployKey)
|
||||||
|
m.Get("/repositories/:repoid/wiki/init", InitWiki)
|
||||||
m.Post("/push/update", PushUpdate)
|
m.Post("/push/update", PushUpdate)
|
||||||
m.Get("/protectedbranch/:pbid/:userid", CanUserPush)
|
m.Get("/protectedbranch/:pbid/:userid", CanUserPush)
|
||||||
m.Get("/repo/:owner/:repo", GetRepositoryByOwnerAndName)
|
m.Get("/repo/:owner/:repo", GetRepositoryByOwnerAndName)
|
||||||
|
|
34
routers/private/wiki.go
Normal file
34
routers/private/wiki.go
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
// Copyright 2017 The Gitea 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 private
|
||||||
|
|
||||||
|
import (
|
||||||
|
"code.gitea.io/gitea/models"
|
||||||
|
|
||||||
|
macaron "gopkg.in/macaron.v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
// InitWiki initilizes wiki via repo id
|
||||||
|
func InitWiki(ctx *macaron.Context) {
|
||||||
|
repoID := ctx.ParamsInt64("repoid")
|
||||||
|
|
||||||
|
repo, err := models.GetRepositoryByID(repoID)
|
||||||
|
if err != nil {
|
||||||
|
ctx.JSON(500, map[string]interface{}{
|
||||||
|
"err": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = repo.InitWiki()
|
||||||
|
if err != nil {
|
||||||
|
ctx.JSON(500, map[string]interface{}{
|
||||||
|
"err": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.Status(202)
|
||||||
|
}
|
Loading…
Reference in a new issue