Skip to content

Commit

Permalink
Use repo user to fetch branches (#4339)
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerty287 authored and pull[bot] committed Dec 17, 2024
1 parent cb7258a commit b92c25f
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions server/api/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,17 +362,22 @@ func GetRepoPermissions(c *gin.Context) {
func GetRepoBranches(c *gin.Context) {
_store := store.FromContext(c)
repo := session.Repo(c)
user := session.User(c)
_forge, err := server.Config.Services.Manager.ForgeFromRepo(repo)
if err != nil {
log.Error().Err(err).Msg("Cannot get forge from repo")
c.AbortWithStatus(http.StatusInternalServerError)
return
}

forge.Refresh(c, _forge, _store, user)
repoUser, err := _store.GetUser(repo.UserID)
if err != nil {
handleDBError(c, err)
return
}

forge.Refresh(c, _forge, _store, repoUser)

branches, err := _forge.Branches(c, user, repo, session.Pagination(c))
branches, err := _forge.Branches(c, repoUser, repo, session.Pagination(c))
if err != nil {
log.Error().Err(err).Msg("failed to load branches")
c.String(http.StatusInternalServerError, "failed to load branches: %s", err)
Expand All @@ -396,17 +401,22 @@ func GetRepoBranches(c *gin.Context) {
func GetRepoPullRequests(c *gin.Context) {
_store := store.FromContext(c)
repo := session.Repo(c)
user := session.User(c)
_forge, err := server.Config.Services.Manager.ForgeFromRepo(repo)
if err != nil {
log.Error().Err(err).Msg("Cannot get forge from repo")
c.AbortWithStatus(http.StatusInternalServerError)
return
}

forge.Refresh(c, _forge, _store, user)
repoUser, err := _store.GetUser(repo.UserID)
if err != nil {
handleDBError(c, err)
return
}

forge.Refresh(c, _forge, _store, repoUser)

prs, err := _forge.PullRequests(c, user, repo, session.Pagination(c))
prs, err := _forge.PullRequests(c, repoUser, repo, session.Pagination(c))
if err != nil {
_ = c.AbortWithError(http.StatusInternalServerError, err)
return
Expand Down

0 comments on commit b92c25f

Please sign in to comment.