mirror of
https://codeberg.org/crowci/crow.git
synced 2025-09-12 01:51:01 +03:00
Access repos by their ids (#1691)
closes #1295 closes #648 # TODO - [x] add new routes with `:repoID` - [x] load repo in middleware using `:repoID` if present - [x] update UI routes `:owner/:name` to `:repoID` - [x] load repos using id in UI - [x] add lookup endpoint `:owner/:name` to `:repoID` - [x] redirect `:owner/:name` to `:repoID` in UI - [x] use badge with `:repoID` route in UI - [x] update `woodpecker-go` - [x] check cli - [x] add migrations / deprecation notes - [x] check if #648 got solved directly - [x] Test - [x] create repo - [x] repo pages - [x] ui redirects - [x] forge status links
This commit is contained in:
@@ -17,6 +17,7 @@ package session
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -44,14 +45,28 @@ func Repo(c *gin.Context) *model.Repo {
|
||||
func SetRepo() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
var (
|
||||
_store = store.FromContext(c)
|
||||
owner = c.Param("owner")
|
||||
name = c.Param("name")
|
||||
user = User(c)
|
||||
_store = store.FromContext(c)
|
||||
owner = c.Param("owner")
|
||||
name = c.Param("name")
|
||||
_repoID = c.Param("repo_id")
|
||||
user = User(c)
|
||||
)
|
||||
|
||||
repo, err := _store.GetRepoName(owner + "/" + name)
|
||||
if err == nil {
|
||||
var repo *model.Repo
|
||||
var err error
|
||||
if _repoID != "" {
|
||||
var repoID int64
|
||||
repoID, err = strconv.ParseInt(_repoID, 10, 64)
|
||||
if err != nil {
|
||||
c.AbortWithStatus(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
repo, err = _store.GetRepo(repoID)
|
||||
} else {
|
||||
repo, err = _store.GetRepoName(owner + "/" + name)
|
||||
}
|
||||
|
||||
if repo != nil {
|
||||
c.Set("repo", repo)
|
||||
c.Next()
|
||||
return
|
||||
@@ -64,15 +79,17 @@ func SetRepo() gin.HandlerFunc {
|
||||
err.Error(),
|
||||
)
|
||||
|
||||
if user != nil {
|
||||
if errors.Is(err, types.RecordNotExist) {
|
||||
c.AbortWithStatus(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
_ = c.AbortWithError(http.StatusInternalServerError, err)
|
||||
} else {
|
||||
if user == nil {
|
||||
c.AbortWithStatus(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
if errors.Is(err, types.RecordNotExist) {
|
||||
c.AbortWithStatus(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
_ = c.AbortWithError(http.StatusInternalServerError, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user