Use repo user to fetch branches (#4339)

This commit is contained in:
qwerty287 2024-11-08 15:05:17 +02:00 committed by GitHub
parent ac1962bb7b
commit d72c26c08c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -362,7 +362,6 @@ func GetRepoPermissions(c *gin.Context) {
func GetRepoBranches(c *gin.Context) { func GetRepoBranches(c *gin.Context) {
_store := store.FromContext(c) _store := store.FromContext(c)
repo := session.Repo(c) repo := session.Repo(c)
user := session.User(c)
_forge, err := server.Config.Services.Manager.ForgeFromRepo(repo) _forge, err := server.Config.Services.Manager.ForgeFromRepo(repo)
if err != nil { if err != nil {
log.Error().Err(err).Msg("Cannot get forge from repo") log.Error().Err(err).Msg("Cannot get forge from repo")
@ -370,9 +369,15 @@ func GetRepoBranches(c *gin.Context) {
return return
} }
forge.Refresh(c, _forge, _store, user) repoUser, err := _store.GetUser(repo.UserID)
if err != nil {
handleDBError(c, err)
return
}
branches, err := _forge.Branches(c, user, repo, session.Pagination(c)) forge.Refresh(c, _forge, _store, repoUser)
branches, err := _forge.Branches(c, repoUser, repo, session.Pagination(c))
if err != nil { if err != nil {
log.Error().Err(err).Msg("failed to load branches") log.Error().Err(err).Msg("failed to load branches")
c.String(http.StatusInternalServerError, "failed to load branches: %s", err) c.String(http.StatusInternalServerError, "failed to load branches: %s", err)
@ -396,7 +401,6 @@ func GetRepoBranches(c *gin.Context) {
func GetRepoPullRequests(c *gin.Context) { func GetRepoPullRequests(c *gin.Context) {
_store := store.FromContext(c) _store := store.FromContext(c)
repo := session.Repo(c) repo := session.Repo(c)
user := session.User(c)
_forge, err := server.Config.Services.Manager.ForgeFromRepo(repo) _forge, err := server.Config.Services.Manager.ForgeFromRepo(repo)
if err != nil { if err != nil {
log.Error().Err(err).Msg("Cannot get forge from repo") log.Error().Err(err).Msg("Cannot get forge from repo")
@ -404,9 +408,15 @@ func GetRepoPullRequests(c *gin.Context) {
return return
} }
forge.Refresh(c, _forge, _store, user) repoUser, err := _store.GetUser(repo.UserID)
if err != nil {
handleDBError(c, err)
return
}
prs, err := _forge.PullRequests(c, user, repo, session.Pagination(c)) forge.Refresh(c, _forge, _store, repoUser)
prs, err := _forge.PullRequests(c, repoUser, repo, session.Pagination(c))
if err != nil { if err != nil {
_ = c.AbortWithError(http.StatusInternalServerError, err) _ = c.AbortWithError(http.StatusInternalServerError, err)
return return