diff options
author | Job <LordChunk@users.noreply.github.com> | 2024-10-04 19:12:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-04 13:12:48 -0400 |
commit | 7e68bc88238104d2ee8b5a877fc1ad437f1778a4 (patch) | |
tree | d4fbb1c153f61417988705803a294201ab17a447 /routers/api/v1 | |
parent | 0bd75390f535c2f7f6422117476c953a178103ba (diff) | |
download | gitea-7e68bc88238104d2ee8b5a877fc1ad437f1778a4.tar.gz gitea-7e68bc88238104d2ee8b5a877fc1ad437f1778a4.zip |
Fix PR creation on forked repositories (#31863)
Resolves #20475
Diffstat (limited to 'routers/api/v1')
-rw-r--r-- | routers/api/v1/repo/pull.go | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 7eb4a8b8a2..4e3de77032 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -1124,9 +1124,20 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) // Check if current user has fork of repository or in the same repository. headRepo := repo_model.GetForkedRepo(ctx, headUser.ID, baseRepo.ID) if headRepo == nil && !isSameRepo { - log.Trace("parseCompareInfo[%d]: does not have fork or in same repository", baseRepo.ID) - ctx.NotFound("GetForkedRepo") - return nil, nil, nil, "", "" + err := baseRepo.GetBaseRepo(ctx) + if err != nil { + ctx.Error(http.StatusInternalServerError, "GetBaseRepo", err) + return nil, nil, nil, "", "" + } + + // Check if baseRepo's base repository is the same as headUser's repository. + if baseRepo.BaseRepo == nil || baseRepo.BaseRepo.OwnerID != headUser.ID { + log.Trace("parseCompareInfo[%d]: does not have fork or in same repository", baseRepo.ID) + ctx.NotFound("GetBaseRepo") + return nil, nil, nil, "", "" + } + // Assign headRepo so it can be used below. + headRepo = baseRepo.BaseRepo } var headGitRepo *git.Repository |