pull/36105/head
Lunny Xiao 2025-12-10 11:07:46 +07:00
parent 229b20b6e9
commit 8a83a64ebf
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
2 changed files with 40 additions and 28 deletions

@ -1099,22 +1099,28 @@ func parseCompareInfo(ctx *context.APIContext, compareParam string) (result *par
}
}
if compareReq.HeadRepoName == "" {
headRepo = repo_model.GetForkedRepo(ctx, headUser.ID, baseRepo.ID)
if headRepo == nil && headUser.ID != baseRepo.OwnerID {
err = baseRepo.GetBaseRepo(ctx)
if err != nil {
ctx.APIErrorInternal(err)
return nil, nil
}
if headUser.ID == baseRepo.OwnerID {
headRepo = baseRepo
} else {
// TODO: forked's fork
headRepo = repo_model.GetForkedRepo(ctx, headUser.ID, baseRepo.ID)
if headRepo == nil {
// TODO: based's base?
err = baseRepo.GetBaseRepo(ctx)
if err != nil {
ctx.APIErrorInternal(err)
return 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.APIErrorNotFound("GetBaseRepo")
return 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.APIErrorNotFound("GetBaseRepo")
return nil, nil
}
// Assign headRepo so it can be used below.
headRepo = baseRepo.BaseRepo
}
// Assign headRepo so it can be used below.
headRepo = baseRepo.BaseRepo
}
} else {
if compareReq.HeadOwner == ctx.Repo.Owner.Name && compareReq.HeadRepoName == ctx.Repo.Repository.Name {

@ -226,22 +226,28 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo {
}
}
if compareReq.HeadRepoName == "" {
ci.HeadRepo = repo_model.GetForkedRepo(ctx, ci.HeadUser.ID, baseRepo.ID)
if ci.HeadRepo == nil && ci.HeadUser.ID != baseRepo.OwnerID {
err = baseRepo.GetBaseRepo(ctx)
if err != nil {
ctx.ServerError("GetBaseRepo", err)
return nil
}
if ci.HeadUser.ID == baseRepo.OwnerID {
ci.HeadRepo = baseRepo
} else {
// TODO: forked's fork
ci.HeadRepo = repo_model.GetForkedRepo(ctx, ci.HeadUser.ID, baseRepo.ID)
if ci.HeadRepo == nil {
// TODO: based's base?
err = baseRepo.GetBaseRepo(ctx)
if err != nil {
ctx.ServerError("GetBaseRepo", err)
return nil
}
// Check if baseRepo's base repository is the same as headUser's repository.
if baseRepo.BaseRepo == nil || baseRepo.BaseRepo.OwnerID != ci.HeadUser.ID {
log.Trace("parseCompareInfo[%d]: does not have fork or in same repository", baseRepo.ID)
ctx.NotFound(nil)
return nil
// Check if baseRepo's base repository is the same as headUser's repository.
if baseRepo.BaseRepo == nil || baseRepo.BaseRepo.OwnerID != ci.HeadUser.ID {
log.Trace("parseCompareInfo[%d]: does not have fork or in same repository", baseRepo.ID)
ctx.NotFound(nil)
return nil
}
// Assign headRepo so it can be used below.
ci.HeadRepo = baseRepo.BaseRepo
}
// Assign headRepo so it can be used below.
ci.HeadRepo = baseRepo.BaseRepo
}
} else {
if compareReq.HeadOwner == ctx.Repo.Owner.Name && compareReq.HeadRepoName == ctx.Repo.Repository.Name {