Move serv hook functionality & drop GitLogger (#6993)
* Move hook functionality internally * Internalise serv logic * Remove old internal paths * finally remove the gitlogger * Disallow push on archived repositories * fix lint error * Update modules/private/key.go * Update routers/private/hook.go * Update routers/private/hook.go * Update routers/private/hook.go * Updated routers/private/serv.go * Fix LFS Locks over SSH * rev-list needs to be run by the hook process * fixup * Improve git test * Ensure that the lfs files are created with a different prefix * Reduce the replication in git_test.go * slight refactor * Remove unnecessary "/" * Restore ensureAnonymousClone * Restore ensureAnonymousClone * Run rev-list on server side * Try passing in the alternative directories instead * Mark test as skipped * Improve git test * Ensure that the lfs files are created with a different prefix * Reduce the replication in git_test.go * Remove unnecessary "/"
This commit is contained in:
@ -10,11 +10,8 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/httplib"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
)
|
||||
|
||||
@ -51,49 +48,3 @@ func newInternalRequest(url, method string) *httplib.Request {
|
||||
}
|
||||
return req
|
||||
}
|
||||
|
||||
// CheckUnitUser check whether user could visit the unit of this repository
|
||||
func CheckUnitUser(userID, repoID int64, isAdmin bool, unitType models.UnitType) (*models.AccessMode, error) {
|
||||
reqURL := setting.LocalURL + fmt.Sprintf("api/internal/repositories/%d/user/%d/checkunituser?isAdmin=%t&unitType=%d", repoID, userID, isAdmin, unitType)
|
||||
log.GitLogger.Trace("CheckUnitUser: %s", reqURL)
|
||||
|
||||
resp, err := newInternalRequest(reqURL, "GET").Response()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("Failed to CheckUnitUser: %s", decodeJSONError(resp).Err)
|
||||
}
|
||||
|
||||
var a models.AccessMode
|
||||
if err := json.NewDecoder(resp.Body).Decode(&a); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &a, nil
|
||||
}
|
||||
|
||||
// GetRepositoryByOwnerAndName returns the repository by given ownername and reponame.
|
||||
func GetRepositoryByOwnerAndName(ownerName, repoName string) (*models.Repository, error) {
|
||||
reqURL := setting.LocalURL + fmt.Sprintf("api/internal/repo/%s/%s", url.PathEscape(ownerName), url.PathEscape(repoName))
|
||||
log.GitLogger.Trace("GetRepositoryByOwnerAndName: %s", reqURL)
|
||||
|
||||
resp, err := newInternalRequest(reqURL, "GET").Response()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("Failed to get repository: %s", decodeJSONError(resp).Err)
|
||||
}
|
||||
|
||||
var repo models.Repository
|
||||
if err := json.NewDecoder(resp.Body).Decode(&repo); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &repo, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user