mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-25 08:59:31 -05:00
Less naked returns (#25713)
just a step towards #25655 and some related refactoring
This commit is contained in:
parent
b1eb1676aa
commit
8995046110
32 changed files with 254 additions and 239 deletions
|
@ -455,9 +455,9 @@ func hashAndVerifyForKeyID(sig *packet.Signature, payload string, committer *use
|
||||||
|
|
||||||
// CalculateTrustStatus will calculate the TrustStatus for a commit verification within a repository
|
// CalculateTrustStatus will calculate the TrustStatus for a commit verification within a repository
|
||||||
// There are several trust models in Gitea
|
// There are several trust models in Gitea
|
||||||
func CalculateTrustStatus(verification *CommitVerification, repoTrustModel repo_model.TrustModelType, isOwnerMemberCollaborator func(*user_model.User) (bool, error), keyMap *map[string]bool) (err error) {
|
func CalculateTrustStatus(verification *CommitVerification, repoTrustModel repo_model.TrustModelType, isOwnerMemberCollaborator func(*user_model.User) (bool, error), keyMap *map[string]bool) error {
|
||||||
if !verification.Verified {
|
if !verification.Verified {
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// In the Committer trust model a signature is trusted if it matches the committer
|
// In the Committer trust model a signature is trusted if it matches the committer
|
||||||
|
@ -475,7 +475,7 @@ func CalculateTrustStatus(verification *CommitVerification, repoTrustModel repo_
|
||||||
verification.SigningUser.Email == verification.CommittingUser.Email) {
|
verification.SigningUser.Email == verification.CommittingUser.Email) {
|
||||||
verification.TrustStatus = "trusted"
|
verification.TrustStatus = "trusted"
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now we drop to the more nuanced trust models...
|
// Now we drop to the more nuanced trust models...
|
||||||
|
@ -490,10 +490,11 @@ func CalculateTrustStatus(verification *CommitVerification, repoTrustModel repo_
|
||||||
verification.SigningUser.Email != verification.CommittingUser.Email) {
|
verification.SigningUser.Email != verification.CommittingUser.Email) {
|
||||||
verification.TrustStatus = "untrusted"
|
verification.TrustStatus = "untrusted"
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check we actually have a GPG SigningKey
|
// Check we actually have a GPG SigningKey
|
||||||
|
var err error
|
||||||
if verification.SigningKey != nil {
|
if verification.SigningKey != nil {
|
||||||
var isMember bool
|
var isMember bool
|
||||||
if keyMap != nil {
|
if keyMap != nil {
|
||||||
|
|
|
@ -306,9 +306,10 @@ func (code *OAuth2AuthorizationCode) TableName() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenerateRedirectURI generates a redirect URI for a successful authorization request. State will be used if not empty.
|
// GenerateRedirectURI generates a redirect URI for a successful authorization request. State will be used if not empty.
|
||||||
func (code *OAuth2AuthorizationCode) GenerateRedirectURI(state string) (redirect *url.URL, err error) {
|
func (code *OAuth2AuthorizationCode) GenerateRedirectURI(state string) (*url.URL, error) {
|
||||||
if redirect, err = url.Parse(code.RedirectURI); err != nil {
|
redirect, err := url.Parse(code.RedirectURI)
|
||||||
return
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
q := redirect.Query()
|
q := redirect.Query()
|
||||||
if state != "" {
|
if state != "" {
|
||||||
|
|
|
@ -16,10 +16,10 @@ type Watch struct {
|
||||||
Mode RepoWatchMode `xorm:"SMALLINT NOT NULL DEFAULT 1"`
|
Mode RepoWatchMode `xorm:"SMALLINT NOT NULL DEFAULT 1"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddModeColumnToWatch(x *xorm.Engine) (err error) {
|
func AddModeColumnToWatch(x *xorm.Engine) error {
|
||||||
if err = x.Sync2(new(Watch)); err != nil {
|
if err := x.Sync2(new(Watch)); err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
_, err = x.Exec("UPDATE `watch` SET `mode` = 1")
|
_, err := x.Exec("UPDATE `watch` SET `mode` = 1")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,25 +23,25 @@ func RecalculateStars(x *xorm.Engine) (err error) {
|
||||||
|
|
||||||
for start := 0; ; start += batchSize {
|
for start := 0; ; start += batchSize {
|
||||||
users := make([]User, 0, batchSize)
|
users := make([]User, 0, batchSize)
|
||||||
if err = sess.Limit(batchSize, start).Where("type = ?", 0).Cols("id").Find(&users); err != nil {
|
if err := sess.Limit(batchSize, start).Where("type = ?", 0).Cols("id").Find(&users); err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
if len(users) == 0 {
|
if len(users) == 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = sess.Begin(); err != nil {
|
if err := sess.Begin(); err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, user := range users {
|
for _, user := range users {
|
||||||
if _, err = sess.Exec("UPDATE `user` SET num_stars=(SELECT COUNT(*) FROM `star` WHERE uid=?) WHERE id=?", user.ID, user.ID); err != nil {
|
if _, err := sess.Exec("UPDATE `user` SET num_stars=(SELECT COUNT(*) FROM `star` WHERE uid=?) WHERE id=?", user.ID, user.ID); err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = sess.Commit(); err != nil {
|
if err := sess.Commit(); err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,25 +44,25 @@ func DeleteMigrationCredentials(x *xorm.Engine) (err error) {
|
||||||
|
|
||||||
for start := 0; ; start += batchSize {
|
for start := 0; ; start += batchSize {
|
||||||
tasks := make([]*Task, 0, batchSize)
|
tasks := make([]*Task, 0, batchSize)
|
||||||
if err = sess.Limit(batchSize, start).Where(cond, 0).Find(&tasks); err != nil {
|
if err := sess.Limit(batchSize, start).Where(cond, 0).Find(&tasks); err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
if len(tasks) == 0 {
|
if len(tasks) == 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if err = sess.Begin(); err != nil {
|
if err := sess.Begin(); err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
for _, t := range tasks {
|
for _, t := range tasks {
|
||||||
if t.PayloadContent, err = removeCredentials(t.PayloadContent); err != nil {
|
if t.PayloadContent, err = removeCredentials(t.PayloadContent); err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
if _, err = sess.ID(t.ID).Cols("payload_content").Update(t); err != nil {
|
if _, err := sess.ID(t.ID).Cols("payload_content").Update(t); err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err = sess.Commit(); err != nil {
|
if err := sess.Commit(); err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"xorm.io/xorm"
|
"xorm.io/xorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
func AddPrimaryEmail2EmailAddress(x *xorm.Engine) (err error) {
|
func AddPrimaryEmail2EmailAddress(x *xorm.Engine) error {
|
||||||
type User struct {
|
type User struct {
|
||||||
ID int64 `xorm:"pk autoincr"`
|
ID int64 `xorm:"pk autoincr"`
|
||||||
Email string `xorm:"NOT NULL"`
|
Email string `xorm:"NOT NULL"`
|
||||||
|
@ -26,12 +26,12 @@ func AddPrimaryEmail2EmailAddress(x *xorm.Engine) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add lower_email and is_primary columns
|
// Add lower_email and is_primary columns
|
||||||
if err = x.Table("email_address").Sync2(new(EmailAddress1)); err != nil {
|
if err := x.Table("email_address").Sync2(new(EmailAddress1)); err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err = x.Exec("UPDATE email_address SET lower_email=LOWER(email), is_primary=?", false); err != nil {
|
if _, err := x.Exec("UPDATE email_address SET lower_email=LOWER(email), is_primary=?", false); err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
type EmailAddress struct {
|
type EmailAddress struct {
|
||||||
|
@ -44,8 +44,8 @@ func AddPrimaryEmail2EmailAddress(x *xorm.Engine) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// change lower_email as unique
|
// change lower_email as unique
|
||||||
if err = x.Sync2(new(EmailAddress)); err != nil {
|
if err := x.Sync2(new(EmailAddress)); err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
sess := x.NewSession()
|
sess := x.NewSession()
|
||||||
|
@ -55,34 +55,33 @@ func AddPrimaryEmail2EmailAddress(x *xorm.Engine) (err error) {
|
||||||
|
|
||||||
for start := 0; ; start += batchSize {
|
for start := 0; ; start += batchSize {
|
||||||
users := make([]*User, 0, batchSize)
|
users := make([]*User, 0, batchSize)
|
||||||
if err = sess.Limit(batchSize, start).Find(&users); err != nil {
|
if err := sess.Limit(batchSize, start).Find(&users); err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
if len(users) == 0 {
|
if len(users) == 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, user := range users {
|
for _, user := range users {
|
||||||
var exist bool
|
exist, err := sess.Where("email=?", user.Email).Table("email_address").Exist()
|
||||||
exist, err = sess.Where("email=?", user.Email).Table("email_address").Exist()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
if !exist {
|
if !exist {
|
||||||
if _, err = sess.Insert(&EmailAddress{
|
if _, err := sess.Insert(&EmailAddress{
|
||||||
UID: user.ID,
|
UID: user.ID,
|
||||||
Email: user.Email,
|
Email: user.Email,
|
||||||
LowerEmail: strings.ToLower(user.Email),
|
LowerEmail: strings.ToLower(user.Email),
|
||||||
IsActivated: user.IsActive,
|
IsActivated: user.IsActive,
|
||||||
IsPrimary: true,
|
IsPrimary: true,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if _, err = sess.Where("email=?", user.Email).Cols("is_primary").Update(&EmailAddress{
|
if _, err := sess.Where("email=?", user.Email).Cols("is_primary").Update(&EmailAddress{
|
||||||
IsPrimary: true,
|
IsPrimary: true,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -422,10 +422,10 @@ func RepoIDAssignment() func(ctx *Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// RepoAssignment returns a middleware to handle repository assignment
|
// RepoAssignment returns a middleware to handle repository assignment
|
||||||
func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
|
func RepoAssignment(ctx *Context) context.CancelFunc {
|
||||||
if _, repoAssignmentOnce := ctx.Data["repoAssignmentExecuted"]; repoAssignmentOnce {
|
if _, repoAssignmentOnce := ctx.Data["repoAssignmentExecuted"]; repoAssignmentOnce {
|
||||||
log.Trace("RepoAssignment was exec already, skipping second call ...")
|
log.Trace("RepoAssignment was exec already, skipping second call ...")
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
ctx.Data["repoAssignmentExecuted"] = true
|
ctx.Data["repoAssignmentExecuted"] = true
|
||||||
|
|
||||||
|
@ -453,7 +453,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
|
||||||
// https://github.com/golang/go/issues/19760
|
// https://github.com/golang/go/issues/19760
|
||||||
if ctx.FormString("go-get") == "1" {
|
if ctx.FormString("go-get") == "1" {
|
||||||
EarlyResponseForGoGetMeta(ctx)
|
EarlyResponseForGoGetMeta(ctx)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if redirectUserID, err := user_model.LookupUserRedirect(userName); err == nil {
|
if redirectUserID, err := user_model.LookupUserRedirect(userName); err == nil {
|
||||||
|
@ -466,7 +466,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
|
||||||
} else {
|
} else {
|
||||||
ctx.ServerError("GetUserByName", err)
|
ctx.ServerError("GetUserByName", err)
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx.Repo.Owner = owner
|
ctx.Repo.Owner = owner
|
||||||
|
@ -490,7 +490,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
|
||||||
redirectPath += "?" + ctx.Req.URL.RawQuery
|
redirectPath += "?" + ctx.Req.URL.RawQuery
|
||||||
}
|
}
|
||||||
ctx.Redirect(path.Join(setting.AppSubURL, redirectPath))
|
ctx.Redirect(path.Join(setting.AppSubURL, redirectPath))
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get repository.
|
// Get repository.
|
||||||
|
@ -503,7 +503,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
|
||||||
} else if repo_model.IsErrRedirectNotExist(err) {
|
} else if repo_model.IsErrRedirectNotExist(err) {
|
||||||
if ctx.FormString("go-get") == "1" {
|
if ctx.FormString("go-get") == "1" {
|
||||||
EarlyResponseForGoGetMeta(ctx)
|
EarlyResponseForGoGetMeta(ctx)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
ctx.NotFound("GetRepositoryByName", nil)
|
ctx.NotFound("GetRepositoryByName", nil)
|
||||||
} else {
|
} else {
|
||||||
|
@ -512,13 +512,13 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
|
||||||
} else {
|
} else {
|
||||||
ctx.ServerError("GetRepositoryByName", err)
|
ctx.ServerError("GetRepositoryByName", err)
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
repo.Owner = owner
|
repo.Owner = owner
|
||||||
|
|
||||||
repoAssignment(ctx, repo)
|
repoAssignment(ctx, repo)
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Repo.RepoLink = repo.Link()
|
ctx.Repo.RepoLink = repo.Link()
|
||||||
|
@ -542,12 +542,12 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetReleaseCountByRepoID", err)
|
ctx.ServerError("GetReleaseCountByRepoID", err)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
ctx.Data["NumReleases"], err = repo_model.GetReleaseCountByRepoID(ctx, ctx.Repo.Repository.ID, repo_model.FindReleasesOptions{})
|
ctx.Data["NumReleases"], err = repo_model.GetReleaseCountByRepoID(ctx, ctx.Repo.Repository.ID, repo_model.FindReleasesOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetReleaseCountByRepoID", err)
|
ctx.ServerError("GetReleaseCountByRepoID", err)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Data["Title"] = owner.Name + "/" + repo.Name
|
ctx.Data["Title"] = owner.Name + "/" + repo.Name
|
||||||
|
@ -563,14 +563,14 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
|
||||||
canSignedUserFork, err := repo_module.CanUserForkRepo(ctx.Doer, ctx.Repo.Repository)
|
canSignedUserFork, err := repo_module.CanUserForkRepo(ctx.Doer, ctx.Repo.Repository)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("CanUserForkRepo", err)
|
ctx.ServerError("CanUserForkRepo", err)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
ctx.Data["CanSignedUserFork"] = canSignedUserFork
|
ctx.Data["CanSignedUserFork"] = canSignedUserFork
|
||||||
|
|
||||||
userAndOrgForks, err := repo_model.GetForksByUserAndOrgs(ctx, ctx.Doer, ctx.Repo.Repository)
|
userAndOrgForks, err := repo_model.GetForksByUserAndOrgs(ctx, ctx.Doer, ctx.Repo.Repository)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetForksByUserAndOrgs", err)
|
ctx.ServerError("GetForksByUserAndOrgs", err)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
ctx.Data["UserAndOrgForks"] = userAndOrgForks
|
ctx.Data["UserAndOrgForks"] = userAndOrgForks
|
||||||
|
|
||||||
|
@ -604,14 +604,14 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
|
||||||
if repo.IsFork {
|
if repo.IsFork {
|
||||||
RetrieveBaseRepo(ctx, repo)
|
RetrieveBaseRepo(ctx, repo)
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if repo.IsGenerated() {
|
if repo.IsGenerated() {
|
||||||
RetrieveTemplateRepo(ctx, repo)
|
RetrieveTemplateRepo(ctx, repo)
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -623,7 +623,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
|
||||||
if !isHomeOrSettings {
|
if !isHomeOrSettings {
|
||||||
ctx.Redirect(ctx.Repo.RepoLink)
|
ctx.Redirect(ctx.Repo.RepoLink)
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
gitRepo, err := git.OpenRepository(ctx, repo_model.RepoPath(userName, repoName))
|
gitRepo, err := git.OpenRepository(ctx, repo_model.RepoPath(userName, repoName))
|
||||||
|
@ -636,10 +636,10 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
|
||||||
if !isHomeOrSettings {
|
if !isHomeOrSettings {
|
||||||
ctx.Redirect(ctx.Repo.RepoLink)
|
ctx.Redirect(ctx.Repo.RepoLink)
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
ctx.ServerError("RepoAssignment Invalid repo "+repo_model.RepoPath(userName, repoName), err)
|
ctx.ServerError("RepoAssignment Invalid repo "+repo_model.RepoPath(userName, repoName), err)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
if ctx.Repo.GitRepo != nil {
|
if ctx.Repo.GitRepo != nil {
|
||||||
ctx.Repo.GitRepo.Close()
|
ctx.Repo.GitRepo.Close()
|
||||||
|
@ -647,7 +647,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
|
||||||
ctx.Repo.GitRepo = gitRepo
|
ctx.Repo.GitRepo = gitRepo
|
||||||
|
|
||||||
// We opened it, we should close it
|
// We opened it, we should close it
|
||||||
cancel = func() {
|
cancel := func() {
|
||||||
// If it's been set to nil then assume someone else has closed it.
|
// If it's been set to nil then assume someone else has closed it.
|
||||||
if ctx.Repo.GitRepo != nil {
|
if ctx.Repo.GitRepo != nil {
|
||||||
ctx.Repo.GitRepo.Close()
|
ctx.Repo.GitRepo.Close()
|
||||||
|
@ -657,13 +657,13 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
|
||||||
// Stop at this point when the repo is empty.
|
// Stop at this point when the repo is empty.
|
||||||
if ctx.Repo.Repository.IsEmpty {
|
if ctx.Repo.Repository.IsEmpty {
|
||||||
ctx.Data["BranchName"] = ctx.Repo.Repository.DefaultBranch
|
ctx.Data["BranchName"] = ctx.Repo.Repository.DefaultBranch
|
||||||
return
|
return cancel
|
||||||
}
|
}
|
||||||
|
|
||||||
tags, err := repo_model.GetTagNamesByRepoID(ctx, ctx.Repo.Repository.ID)
|
tags, err := repo_model.GetTagNamesByRepoID(ctx, ctx.Repo.Repository.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetTagNamesByRepoID", err)
|
ctx.ServerError("GetTagNamesByRepoID", err)
|
||||||
return
|
return cancel
|
||||||
}
|
}
|
||||||
ctx.Data["Tags"] = tags
|
ctx.Data["Tags"] = tags
|
||||||
|
|
||||||
|
@ -677,7 +677,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
|
||||||
branchesTotal, err := git_model.CountBranches(ctx, branchOpts)
|
branchesTotal, err := git_model.CountBranches(ctx, branchOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("CountBranches", err)
|
ctx.ServerError("CountBranches", err)
|
||||||
return
|
return cancel
|
||||||
}
|
}
|
||||||
|
|
||||||
// non empty repo should have at least 1 branch, so this repository's branches haven't been synced yet
|
// non empty repo should have at least 1 branch, so this repository's branches haven't been synced yet
|
||||||
|
@ -685,7 +685,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
|
||||||
branchesTotal, err = repo_module.SyncRepoBranches(ctx, ctx.Repo.Repository.ID, 0)
|
branchesTotal, err = repo_module.SyncRepoBranches(ctx, ctx.Repo.Repository.ID, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("SyncRepoBranches", err)
|
ctx.ServerError("SyncRepoBranches", err)
|
||||||
return
|
return cancel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -694,7 +694,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
|
||||||
brs, err := git_model.FindBranchNames(ctx, branchOpts)
|
brs, err := git_model.FindBranchNames(ctx, branchOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetBranches", err)
|
ctx.ServerError("GetBranches", err)
|
||||||
return
|
return cancel
|
||||||
}
|
}
|
||||||
// always put default branch on the top
|
// always put default branch on the top
|
||||||
ctx.Data["Branches"] = append(branchOpts.ExcludeBranchNames, brs...)
|
ctx.Data["Branches"] = append(branchOpts.ExcludeBranchNames, brs...)
|
||||||
|
@ -741,12 +741,12 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
|
||||||
repoTransfer, err := models.GetPendingRepositoryTransfer(ctx, ctx.Repo.Repository)
|
repoTransfer, err := models.GetPendingRepositoryTransfer(ctx, ctx.Repo.Repository)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetPendingRepositoryTransfer", err)
|
ctx.ServerError("GetPendingRepositoryTransfer", err)
|
||||||
return
|
return cancel
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := repoTransfer.LoadAttributes(ctx); err != nil {
|
if err := repoTransfer.LoadAttributes(ctx); err != nil {
|
||||||
ctx.ServerError("LoadRecipient", err)
|
ctx.ServerError("LoadRecipient", err)
|
||||||
return
|
return cancel
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Data["RepoTransfer"] = repoTransfer
|
ctx.Data["RepoTransfer"] = repoTransfer
|
||||||
|
@ -894,7 +894,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
|
||||||
ctx.Repo.IsViewBranch = true
|
ctx.Repo.IsViewBranch = true
|
||||||
ctx.Repo.BranchName = ctx.Repo.Repository.DefaultBranch
|
ctx.Repo.BranchName = ctx.Repo.Repository.DefaultBranch
|
||||||
ctx.Data["TreePath"] = ""
|
ctx.Data["TreePath"] = ""
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -907,7 +907,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
|
||||||
ctx.Repo.GitRepo, err = git.OpenRepository(ctx, repoPath)
|
ctx.Repo.GitRepo, err = git.OpenRepository(ctx, repoPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("RepoRef Invalid repo "+repoPath, err)
|
ctx.ServerError("RepoRef Invalid repo "+repoPath, err)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
// We opened it, we should close it
|
// We opened it, we should close it
|
||||||
cancel = func() {
|
cancel = func() {
|
||||||
|
@ -944,7 +944,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
|
||||||
ctx.Repo.Repository.MarkAsBrokenEmpty()
|
ctx.Repo.Repository.MarkAsBrokenEmpty()
|
||||||
} else {
|
} else {
|
||||||
ctx.ServerError("GetBranchCommit", err)
|
ctx.ServerError("GetBranchCommit", err)
|
||||||
return
|
return cancel
|
||||||
}
|
}
|
||||||
ctx.Repo.IsViewBranch = true
|
ctx.Repo.IsViewBranch = true
|
||||||
} else {
|
} else {
|
||||||
|
@ -956,7 +956,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
|
||||||
ctx.Flash.Info(ctx.Tr("repo.branch.renamed", refName, renamedBranchName))
|
ctx.Flash.Info(ctx.Tr("repo.branch.renamed", refName, renamedBranchName))
|
||||||
link := setting.AppSubURL + strings.Replace(ctx.Req.URL.EscapedPath(), util.PathEscapeSegments(refName), util.PathEscapeSegments(renamedBranchName), 1)
|
link := setting.AppSubURL + strings.Replace(ctx.Req.URL.EscapedPath(), util.PathEscapeSegments(refName), util.PathEscapeSegments(renamedBranchName), 1)
|
||||||
ctx.Redirect(link)
|
ctx.Redirect(link)
|
||||||
return
|
return cancel
|
||||||
}
|
}
|
||||||
|
|
||||||
if refType.RefTypeIncludesBranches() && ctx.Repo.GitRepo.IsBranchExist(refName) {
|
if refType.RefTypeIncludesBranches() && ctx.Repo.GitRepo.IsBranchExist(refName) {
|
||||||
|
@ -966,7 +966,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
|
||||||
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(refName)
|
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(refName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetBranchCommit", err)
|
ctx.ServerError("GetBranchCommit", err)
|
||||||
return
|
return cancel
|
||||||
}
|
}
|
||||||
ctx.Repo.CommitID = ctx.Repo.Commit.ID.String()
|
ctx.Repo.CommitID = ctx.Repo.Commit.ID.String()
|
||||||
|
|
||||||
|
@ -978,10 +978,10 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if git.IsErrNotExist(err) {
|
if git.IsErrNotExist(err) {
|
||||||
ctx.NotFound("GetTagCommit", err)
|
ctx.NotFound("GetTagCommit", err)
|
||||||
return
|
return cancel
|
||||||
}
|
}
|
||||||
ctx.ServerError("GetTagCommit", err)
|
ctx.ServerError("GetTagCommit", err)
|
||||||
return
|
return cancel
|
||||||
}
|
}
|
||||||
ctx.Repo.CommitID = ctx.Repo.Commit.ID.String()
|
ctx.Repo.CommitID = ctx.Repo.Commit.ID.String()
|
||||||
} else if len(refName) >= 7 && len(refName) <= git.SHAFullLength {
|
} else if len(refName) >= 7 && len(refName) <= git.SHAFullLength {
|
||||||
|
@ -991,7 +991,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
|
||||||
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetCommit(refName)
|
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetCommit(refName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.NotFound("GetCommit", err)
|
ctx.NotFound("GetCommit", err)
|
||||||
return
|
return cancel
|
||||||
}
|
}
|
||||||
// If short commit ID add canonical link header
|
// If short commit ID add canonical link header
|
||||||
if len(refName) < git.SHAFullLength {
|
if len(refName) < git.SHAFullLength {
|
||||||
|
@ -1000,10 +1000,10 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if len(ignoreNotExistErr) > 0 && ignoreNotExistErr[0] {
|
if len(ignoreNotExistErr) > 0 && ignoreNotExistErr[0] {
|
||||||
return
|
return cancel
|
||||||
}
|
}
|
||||||
ctx.NotFound("RepoRef invalid repo", fmt.Errorf("branch or tag not exist: %s", refName))
|
ctx.NotFound("RepoRef invalid repo", fmt.Errorf("branch or tag not exist: %s", refName))
|
||||||
return
|
return cancel
|
||||||
}
|
}
|
||||||
|
|
||||||
if refType == RepoRefLegacy {
|
if refType == RepoRefLegacy {
|
||||||
|
@ -1015,7 +1015,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
|
||||||
util.PathEscapeSegments(prefix),
|
util.PathEscapeSegments(prefix),
|
||||||
ctx.Repo.BranchNameSubURL(),
|
ctx.Repo.BranchNameSubURL(),
|
||||||
util.PathEscapeSegments(ctx.Repo.TreePath)))
|
util.PathEscapeSegments(ctx.Repo.TreePath)))
|
||||||
return
|
return cancel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1033,7 +1033,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
|
||||||
ctx.Repo.CommitsCount, err = ctx.Repo.GetCommitsCount()
|
ctx.Repo.CommitsCount, err = ctx.Repo.GetCommitsCount()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetCommitsCount", err)
|
ctx.ServerError("GetCommitsCount", err)
|
||||||
return
|
return cancel
|
||||||
}
|
}
|
||||||
ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount
|
ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount
|
||||||
ctx.Repo.GitRepo.LastCommitCache = git.NewLastCommitCache(ctx.Repo.CommitsCount, ctx.Repo.Repository.FullName(), ctx.Repo.GitRepo, cache.GetCache())
|
ctx.Repo.GitRepo.LastCommitCache = git.NewLastCommitCache(ctx.Repo.CommitsCount, ctx.Repo.Repository.FullName(), ctx.Repo.GitRepo, cache.GetCache())
|
||||||
|
|
|
@ -6,6 +6,7 @@ package doctor
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
|
@ -40,12 +41,12 @@ func parseBool16961(bs []byte) (bool, error) {
|
||||||
func fixUnitConfig16961(bs []byte, cfg *repo_model.UnitConfig) (fixed bool, err error) {
|
func fixUnitConfig16961(bs []byte, cfg *repo_model.UnitConfig) (fixed bool, err error) {
|
||||||
err = json.UnmarshalHandleDoubleEncode(bs, &cfg)
|
err = json.UnmarshalHandleDoubleEncode(bs, &cfg)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle #16961
|
// Handle #16961
|
||||||
if string(bs) != "&{}" && len(bs) != 0 {
|
if string(bs) != "&{}" && len(bs) != 0 {
|
||||||
return
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return true, nil
|
return true, nil
|
||||||
|
@ -54,14 +55,14 @@ func fixUnitConfig16961(bs []byte, cfg *repo_model.UnitConfig) (fixed bool, err
|
||||||
func fixExternalWikiConfig16961(bs []byte, cfg *repo_model.ExternalWikiConfig) (fixed bool, err error) {
|
func fixExternalWikiConfig16961(bs []byte, cfg *repo_model.ExternalWikiConfig) (fixed bool, err error) {
|
||||||
err = json.UnmarshalHandleDoubleEncode(bs, &cfg)
|
err = json.UnmarshalHandleDoubleEncode(bs, &cfg)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(bs) < 3 {
|
if len(bs) < 3 {
|
||||||
return
|
return false, err
|
||||||
}
|
}
|
||||||
if bs[0] != '&' || bs[1] != '{' || bs[len(bs)-1] != '}' {
|
if bs[0] != '&' || bs[1] != '{' || bs[len(bs)-1] != '}' {
|
||||||
return
|
return false, err
|
||||||
}
|
}
|
||||||
cfg.ExternalWikiURL = string(bs[2 : len(bs)-1])
|
cfg.ExternalWikiURL = string(bs[2 : len(bs)-1])
|
||||||
return true, nil
|
return true, nil
|
||||||
|
@ -70,20 +71,20 @@ func fixExternalWikiConfig16961(bs []byte, cfg *repo_model.ExternalWikiConfig) (
|
||||||
func fixExternalTrackerConfig16961(bs []byte, cfg *repo_model.ExternalTrackerConfig) (fixed bool, err error) {
|
func fixExternalTrackerConfig16961(bs []byte, cfg *repo_model.ExternalTrackerConfig) (fixed bool, err error) {
|
||||||
err = json.UnmarshalHandleDoubleEncode(bs, &cfg)
|
err = json.UnmarshalHandleDoubleEncode(bs, &cfg)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return
|
return false, nil
|
||||||
}
|
}
|
||||||
// Handle #16961
|
// Handle #16961
|
||||||
if len(bs) < 3 {
|
if len(bs) < 3 {
|
||||||
return
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if bs[0] != '&' || bs[1] != '{' || bs[len(bs)-1] != '}' {
|
if bs[0] != '&' || bs[1] != '{' || bs[len(bs)-1] != '}' {
|
||||||
return
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
parts := bytes.Split(bs[2:len(bs)-1], []byte{' '})
|
parts := bytes.Split(bs[2:len(bs)-1], []byte{' '})
|
||||||
if len(parts) != 3 {
|
if len(parts) != 3 {
|
||||||
return
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.ExternalTrackerURL = string(bytes.Join(parts[:len(parts)-2], []byte{' '}))
|
cfg.ExternalTrackerURL = string(bytes.Join(parts[:len(parts)-2], []byte{' '}))
|
||||||
|
@ -95,16 +96,16 @@ func fixExternalTrackerConfig16961(bs []byte, cfg *repo_model.ExternalTrackerCon
|
||||||
func fixPullRequestsConfig16961(bs []byte, cfg *repo_model.PullRequestsConfig) (fixed bool, err error) {
|
func fixPullRequestsConfig16961(bs []byte, cfg *repo_model.PullRequestsConfig) (fixed bool, err error) {
|
||||||
err = json.UnmarshalHandleDoubleEncode(bs, &cfg)
|
err = json.UnmarshalHandleDoubleEncode(bs, &cfg)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle #16961
|
// Handle #16961
|
||||||
if len(bs) < 3 {
|
if len(bs) < 3 {
|
||||||
return
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if bs[0] != '&' || bs[1] != '{' || bs[len(bs)-1] != '}' {
|
if bs[0] != '&' || bs[1] != '{' || bs[len(bs)-1] != '}' {
|
||||||
return
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// PullRequestsConfig was the following in 1.14
|
// PullRequestsConfig was the following in 1.14
|
||||||
|
@ -123,37 +124,37 @@ func fixPullRequestsConfig16961(bs []byte, cfg *repo_model.PullRequestsConfig) (
|
||||||
// DefaultMergeStyle MergeStyle
|
// DefaultMergeStyle MergeStyle
|
||||||
parts := bytes.Split(bs[2:len(bs)-1], []byte{' '})
|
parts := bytes.Split(bs[2:len(bs)-1], []byte{' '})
|
||||||
if len(parts) < 7 {
|
if len(parts) < 7 {
|
||||||
return
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var parseErr error
|
var parseErr error
|
||||||
cfg.IgnoreWhitespaceConflicts, parseErr = parseBool16961(parts[0])
|
cfg.IgnoreWhitespaceConflicts, parseErr = parseBool16961(parts[0])
|
||||||
if parseErr != nil {
|
if parseErr != nil {
|
||||||
return
|
return false, errors.Join(err, parseErr)
|
||||||
}
|
}
|
||||||
cfg.AllowMerge, parseErr = parseBool16961(parts[1])
|
cfg.AllowMerge, parseErr = parseBool16961(parts[1])
|
||||||
if parseErr != nil {
|
if parseErr != nil {
|
||||||
return
|
return false, errors.Join(err, parseErr)
|
||||||
}
|
}
|
||||||
cfg.AllowRebase, parseErr = parseBool16961(parts[2])
|
cfg.AllowRebase, parseErr = parseBool16961(parts[2])
|
||||||
if parseErr != nil {
|
if parseErr != nil {
|
||||||
return
|
return false, errors.Join(err, parseErr)
|
||||||
}
|
}
|
||||||
cfg.AllowRebaseMerge, parseErr = parseBool16961(parts[3])
|
cfg.AllowRebaseMerge, parseErr = parseBool16961(parts[3])
|
||||||
if parseErr != nil {
|
if parseErr != nil {
|
||||||
return
|
return false, errors.Join(err, parseErr)
|
||||||
}
|
}
|
||||||
cfg.AllowSquash, parseErr = parseBool16961(parts[4])
|
cfg.AllowSquash, parseErr = parseBool16961(parts[4])
|
||||||
if parseErr != nil {
|
if parseErr != nil {
|
||||||
return
|
return false, errors.Join(err, parseErr)
|
||||||
}
|
}
|
||||||
cfg.AllowManualMerge, parseErr = parseBool16961(parts[5])
|
cfg.AllowManualMerge, parseErr = parseBool16961(parts[5])
|
||||||
if parseErr != nil {
|
if parseErr != nil {
|
||||||
return
|
return false, errors.Join(err, parseErr)
|
||||||
}
|
}
|
||||||
cfg.AutodetectManualMerge, parseErr = parseBool16961(parts[6])
|
cfg.AutodetectManualMerge, parseErr = parseBool16961(parts[6])
|
||||||
if parseErr != nil {
|
if parseErr != nil {
|
||||||
return
|
return false, errors.Join(err, parseErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1.14 unit
|
// 1.14 unit
|
||||||
|
@ -162,12 +163,12 @@ func fixPullRequestsConfig16961(bs []byte, cfg *repo_model.PullRequestsConfig) (
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(parts) < 9 {
|
if len(parts) < 9 {
|
||||||
return
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.DefaultDeleteBranchAfterMerge, parseErr = parseBool16961(parts[7])
|
cfg.DefaultDeleteBranchAfterMerge, parseErr = parseBool16961(parts[7])
|
||||||
if parseErr != nil {
|
if parseErr != nil {
|
||||||
return
|
return false, errors.Join(err, parseErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.DefaultMergeStyle = repo_model.MergeStyle(string(bytes.Join(parts[8:], []byte{' '})))
|
cfg.DefaultMergeStyle = repo_model.MergeStyle(string(bytes.Join(parts[8:], []byte{' '})))
|
||||||
|
@ -177,34 +178,34 @@ func fixPullRequestsConfig16961(bs []byte, cfg *repo_model.PullRequestsConfig) (
|
||||||
func fixIssuesConfig16961(bs []byte, cfg *repo_model.IssuesConfig) (fixed bool, err error) {
|
func fixIssuesConfig16961(bs []byte, cfg *repo_model.IssuesConfig) (fixed bool, err error) {
|
||||||
err = json.UnmarshalHandleDoubleEncode(bs, &cfg)
|
err = json.UnmarshalHandleDoubleEncode(bs, &cfg)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle #16961
|
// Handle #16961
|
||||||
if len(bs) < 3 {
|
if len(bs) < 3 {
|
||||||
return
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if bs[0] != '&' || bs[1] != '{' || bs[len(bs)-1] != '}' {
|
if bs[0] != '&' || bs[1] != '{' || bs[len(bs)-1] != '}' {
|
||||||
return
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
parts := bytes.Split(bs[2:len(bs)-1], []byte{' '})
|
parts := bytes.Split(bs[2:len(bs)-1], []byte{' '})
|
||||||
if len(parts) != 3 {
|
if len(parts) != 3 {
|
||||||
return
|
return false, err
|
||||||
}
|
}
|
||||||
var parseErr error
|
var parseErr error
|
||||||
cfg.EnableTimetracker, parseErr = parseBool16961(parts[0])
|
cfg.EnableTimetracker, parseErr = parseBool16961(parts[0])
|
||||||
if parseErr != nil {
|
if parseErr != nil {
|
||||||
return
|
return false, errors.Join(err, parseErr)
|
||||||
}
|
}
|
||||||
cfg.AllowOnlyContributorsToTrackTime, parseErr = parseBool16961(parts[1])
|
cfg.AllowOnlyContributorsToTrackTime, parseErr = parseBool16961(parts[1])
|
||||||
if parseErr != nil {
|
if parseErr != nil {
|
||||||
return
|
return false, errors.Join(err, parseErr)
|
||||||
}
|
}
|
||||||
cfg.EnableDependencies, parseErr = parseBool16961(parts[2])
|
cfg.EnableDependencies, parseErr = parseBool16961(parts[2])
|
||||||
if parseErr != nil {
|
if parseErr != nil {
|
||||||
return
|
return false, errors.Join(err, parseErr)
|
||||||
}
|
}
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ import (
|
||||||
|
|
||||||
func wrapNewlines(w io.Writer, prefix, value []byte) (sum int64, err error) {
|
func wrapNewlines(w io.Writer, prefix, value []byte) (sum int64, err error) {
|
||||||
if len(value) == 0 {
|
if len(value) == 0 {
|
||||||
return
|
return 0, nil
|
||||||
}
|
}
|
||||||
var n int
|
var n int
|
||||||
last := 0
|
last := 0
|
||||||
|
@ -23,24 +23,24 @@ func wrapNewlines(w io.Writer, prefix, value []byte) (sum int64, err error) {
|
||||||
n, err = w.Write(prefix)
|
n, err = w.Write(prefix)
|
||||||
sum += int64(n)
|
sum += int64(n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return sum, err
|
||||||
}
|
}
|
||||||
n, err = w.Write(value[last : last+j+1])
|
n, err = w.Write(value[last : last+j+1])
|
||||||
sum += int64(n)
|
sum += int64(n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return sum, err
|
||||||
}
|
}
|
||||||
last += j + 1
|
last += j + 1
|
||||||
}
|
}
|
||||||
n, err = w.Write(prefix)
|
n, err = w.Write(prefix)
|
||||||
sum += int64(n)
|
sum += int64(n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return sum, err
|
||||||
}
|
}
|
||||||
n, err = w.Write(value[last:])
|
n, err = w.Write(value[last:])
|
||||||
sum += int64(n)
|
sum += int64(n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return sum, err
|
||||||
}
|
}
|
||||||
n, err = w.Write([]byte("\n"))
|
n, err = w.Write([]byte("\n"))
|
||||||
sum += int64(n)
|
sum += int64(n)
|
||||||
|
|
|
@ -70,11 +70,11 @@ func checkIfNoneMatchIsValid(req *http.Request, etag string) bool {
|
||||||
|
|
||||||
// HandleGenericETagTimeCache handles ETag-based caching with Last-Modified caching for a HTTP request.
|
// HandleGenericETagTimeCache handles ETag-based caching with Last-Modified caching for a HTTP request.
|
||||||
// It returns true if the request was handled.
|
// It returns true if the request was handled.
|
||||||
func HandleGenericETagTimeCache(req *http.Request, w http.ResponseWriter, etag string, lastModified time.Time) (handled bool) {
|
func HandleGenericETagTimeCache(req *http.Request, w http.ResponseWriter, etag string, lastModified *time.Time) (handled bool) {
|
||||||
if len(etag) > 0 {
|
if len(etag) > 0 {
|
||||||
w.Header().Set("Etag", etag)
|
w.Header().Set("Etag", etag)
|
||||||
}
|
}
|
||||||
if !lastModified.IsZero() {
|
if lastModified != nil && !lastModified.IsZero() {
|
||||||
w.Header().Set("Last-Modified", lastModified.Format(http.TimeFormat))
|
w.Header().Set("Last-Modified", lastModified.Format(http.TimeFormat))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ func HandleGenericETagTimeCache(req *http.Request, w http.ResponseWriter, etag s
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !lastModified.IsZero() {
|
if lastModified != nil && !lastModified.IsZero() {
|
||||||
ifModifiedSince := req.Header.Get("If-Modified-Since")
|
ifModifiedSince := req.Header.Get("If-Modified-Since")
|
||||||
if ifModifiedSince != "" {
|
if ifModifiedSince != "" {
|
||||||
t, err := time.Parse(http.TimeFormat, ifModifiedSince)
|
t, err := time.Parse(http.TimeFormat, ifModifiedSince)
|
||||||
|
|
|
@ -206,7 +206,7 @@ func ServeContentByReader(r *http.Request, w http.ResponseWriter, filePath strin
|
||||||
_, _ = io.CopyN(w, reader, partialLength) // just like http.ServeContent, not necessary to handle the error
|
_, _ = io.CopyN(w, reader, partialLength) // just like http.ServeContent, not necessary to handle the error
|
||||||
}
|
}
|
||||||
|
|
||||||
func ServeContentByReadSeeker(r *http.Request, w http.ResponseWriter, filePath string, modTime time.Time, reader io.ReadSeeker) {
|
func ServeContentByReadSeeker(r *http.Request, w http.ResponseWriter, filePath string, modTime *time.Time, reader io.ReadSeeker) {
|
||||||
buf := make([]byte, mimeDetectionBufferLen)
|
buf := make([]byte, mimeDetectionBufferLen)
|
||||||
n, err := util.ReadAtMost(reader, buf)
|
n, err := util.ReadAtMost(reader, buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -221,5 +221,8 @@ func ServeContentByReadSeeker(r *http.Request, w http.ResponseWriter, filePath s
|
||||||
buf = buf[:n]
|
buf = buf[:n]
|
||||||
}
|
}
|
||||||
setServeHeadersByFile(r, w, filePath, buf)
|
setServeHeadersByFile(r, w, filePath, buf)
|
||||||
http.ServeContent(w, r, path.Base(filePath), modTime, reader)
|
if modTime == nil {
|
||||||
|
modTime = &time.Time{}
|
||||||
|
}
|
||||||
|
http.ServeContent(w, r, path.Base(filePath), *modTime, reader)
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
@ -78,7 +77,7 @@ func TestServeContentByReadSeeker(t *testing.T) {
|
||||||
defer seekReader.Close()
|
defer seekReader.Close()
|
||||||
|
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
ServeContentByReadSeeker(r, w, "test", time.Time{}, seekReader)
|
ServeContentByReadSeeker(r, w, "test", nil, seekReader)
|
||||||
assert.Equal(t, expectedStatusCode, w.Code)
|
assert.Equal(t, expectedStatusCode, w.Code)
|
||||||
if expectedStatusCode == http.StatusPartialContent || expectedStatusCode == http.StatusOK {
|
if expectedStatusCode == http.StatusPartialContent || expectedStatusCode == http.StatusOK {
|
||||||
assert.Equal(t, fmt.Sprint(len(expectedContent)), w.Header().Get("Content-Length"))
|
assert.Equal(t, fmt.Sprint(len(expectedContent)), w.Header().Get("Content-Length"))
|
||||||
|
|
|
@ -211,7 +211,7 @@ func (pm *Manager) nextPID() (start time.Time, pid IDType) {
|
||||||
pid = IDType(strconv.FormatInt(start.Unix(), 16))
|
pid = IDType(strconv.FormatInt(start.Unix(), 16))
|
||||||
|
|
||||||
if pm.next == 1 {
|
if pm.next == 1 {
|
||||||
return
|
return start, pid
|
||||||
}
|
}
|
||||||
pid = IDType(string(pid) + "-" + strconv.FormatInt(pm.next, 10))
|
pid = IDType(string(pid) + "-" + strconv.FormatInt(pm.next, 10))
|
||||||
return start, pid
|
return start, pid
|
||||||
|
|
|
@ -256,3 +256,8 @@ func ToFloat64(number any) (float64, error) {
|
||||||
}
|
}
|
||||||
return value, nil
|
return value, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToPointer returns the pointer of a copy of any given value
|
||||||
|
func ToPointer[T any](val T) *T {
|
||||||
|
return &val
|
||||||
|
}
|
||||||
|
|
|
@ -224,3 +224,12 @@ func TestToTitleCase(t *testing.T) {
|
||||||
assert.Equal(t, ToTitleCase(`foo bar baz`), `Foo Bar Baz`)
|
assert.Equal(t, ToTitleCase(`foo bar baz`), `Foo Bar Baz`)
|
||||||
assert.Equal(t, ToTitleCase(`FOO BAR BAZ`), `Foo Bar Baz`)
|
assert.Equal(t, ToTitleCase(`FOO BAR BAZ`), `Foo Bar Baz`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestToPointer(t *testing.T) {
|
||||||
|
assert.Equal(t, "abc", *ToPointer("abc"))
|
||||||
|
assert.Equal(t, 123, *ToPointer(123))
|
||||||
|
abc := "abc"
|
||||||
|
assert.False(t, &abc == ToPointer(abc))
|
||||||
|
val123 := 123
|
||||||
|
assert.False(t, &val123 == ToPointer(val123))
|
||||||
|
}
|
||||||
|
|
|
@ -219,7 +219,7 @@ func GetRawFileOrLFS(ctx *context.APIContext) {
|
||||||
common.ServeContentByReadSeeker(ctx.Base, ctx.Repo.TreePath, lastModified, lfsDataRc)
|
common.ServeContentByReadSeeker(ctx.Base, ctx.Repo.TreePath, lastModified, lfsDataRc)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getBlobForEntry(ctx *context.APIContext) (blob *git.Blob, entry *git.TreeEntry, lastModified time.Time) {
|
func getBlobForEntry(ctx *context.APIContext) (blob *git.Blob, entry *git.TreeEntry, lastModified *time.Time) {
|
||||||
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath)
|
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if git.IsErrNotExist(err) {
|
if git.IsErrNotExist(err) {
|
||||||
|
@ -227,23 +227,23 @@ func getBlobForEntry(ctx *context.APIContext) (blob *git.Blob, entry *git.TreeEn
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetTreeEntryByPath", err)
|
ctx.Error(http.StatusInternalServerError, "GetTreeEntryByPath", err)
|
||||||
}
|
}
|
||||||
return
|
return nil, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if entry.IsDir() || entry.IsSubModule() {
|
if entry.IsDir() || entry.IsSubModule() {
|
||||||
ctx.NotFound("getBlobForEntry", nil)
|
ctx.NotFound("getBlobForEntry", nil)
|
||||||
return
|
return nil, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
info, _, err := git.Entries([]*git.TreeEntry{entry}).GetCommitsInfo(ctx, ctx.Repo.Commit, path.Dir("/" + ctx.Repo.TreePath)[1:])
|
info, _, err := git.Entries([]*git.TreeEntry{entry}).GetCommitsInfo(ctx, ctx.Repo.Commit, path.Dir("/" + ctx.Repo.TreePath)[1:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetCommitsInfo", err)
|
ctx.Error(http.StatusInternalServerError, "GetCommitsInfo", err)
|
||||||
return
|
return nil, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(info) == 1 {
|
if len(info) == 1 {
|
||||||
// Not Modified
|
// Not Modified
|
||||||
lastModified = info[0].Commit.Committer.When
|
lastModified = &info[0].Commit.Committer.When
|
||||||
}
|
}
|
||||||
blob = entry.Blob()
|
blob = entry.Blob()
|
||||||
|
|
||||||
|
|
|
@ -298,26 +298,26 @@ func ClearIssueLabels(ctx *context.APIContext) {
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
func prepareForReplaceOrAdd(ctx *context.APIContext, form api.IssueLabelsOption) (issue *issues_model.Issue, labels []*issues_model.Label, err error) {
|
func prepareForReplaceOrAdd(ctx *context.APIContext, form api.IssueLabelsOption) (*issues_model.Issue, []*issues_model.Label, error) {
|
||||||
issue, err = issues_model.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
issue, err := issues_model.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrIssueNotExist(err) {
|
if issues_model.IsErrIssueNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.NotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
|
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
|
||||||
}
|
}
|
||||||
return
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
labels, err = issues_model.GetLabelsByIDs(form.Labels)
|
labels, err := issues_model.GetLabelsByIDs(form.Labels)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetLabelsByIDs", err)
|
ctx.Error(http.StatusInternalServerError, "GetLabelsByIDs", err)
|
||||||
return
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) {
|
if !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) {
|
||||||
ctx.Status(http.StatusForbidden)
|
ctx.Status(http.StatusForbidden)
|
||||||
return
|
return nil, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return issue, labels, err
|
return issue, labels, err
|
||||||
|
|
|
@ -15,7 +15,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// ServeBlob download a git.Blob
|
// ServeBlob download a git.Blob
|
||||||
func ServeBlob(ctx *context.Base, filePath string, blob *git.Blob, lastModified time.Time) error {
|
func ServeBlob(ctx *context.Base, filePath string, blob *git.Blob, lastModified *time.Time) error {
|
||||||
if httpcache.HandleGenericETagTimeCache(ctx.Req, ctx.Resp, `"`+blob.ID.String()+`"`, lastModified) {
|
if httpcache.HandleGenericETagTimeCache(ctx.Req, ctx.Resp, `"`+blob.ID.String()+`"`, lastModified) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,6 @@ func ServeContentByReader(ctx *context.Base, filePath string, size int64, reader
|
||||||
httplib.ServeContentByReader(ctx.Req, ctx.Resp, filePath, size, reader)
|
httplib.ServeContentByReader(ctx.Req, ctx.Resp, filePath, size, reader)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ServeContentByReadSeeker(ctx *context.Base, filePath string, modTime time.Time, reader io.ReadSeeker) {
|
func ServeContentByReadSeeker(ctx *context.Base, filePath string, modTime *time.Time, reader io.ReadSeeker) {
|
||||||
httplib.ServeContentByReadSeeker(ctx.Req, ctx.Resp, filePath, modTime, reader)
|
httplib.ServeContentByReadSeeker(ctx.Req, ctx.Resp, filePath, modTime, reader)
|
||||||
}
|
}
|
||||||
|
|
|
@ -497,23 +497,23 @@ func createUserInContext(ctx *context.Context, tpl base.TplName, form any, u *us
|
||||||
hasUser, err = user_model.GetUser(user)
|
hasUser, err = user_model.GetUser(user)
|
||||||
if !hasUser || err != nil {
|
if !hasUser || err != nil {
|
||||||
ctx.ServerError("UserLinkAccount", err)
|
ctx.ServerError("UserLinkAccount", err)
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: probably we should respect 'remember' user's choice...
|
// TODO: probably we should respect 'remember' user's choice...
|
||||||
linkAccount(ctx, user, *gothUser, true)
|
linkAccount(ctx, user, *gothUser, true)
|
||||||
return // user is already created here, all redirects are handled
|
return false // user is already created here, all redirects are handled
|
||||||
} else if setting.OAuth2Client.AccountLinking == setting.OAuth2AccountLinkingLogin {
|
} else if setting.OAuth2Client.AccountLinking == setting.OAuth2AccountLinkingLogin {
|
||||||
showLinkingLogin(ctx, *gothUser)
|
showLinkingLogin(ctx, *gothUser)
|
||||||
return // user will be created only after linking login
|
return false // user will be created only after linking login
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle error without template
|
// handle error without template
|
||||||
if len(tpl) == 0 {
|
if len(tpl) == 0 {
|
||||||
ctx.ServerError("CreateUser", err)
|
ctx.ServerError("CreateUser", err)
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle error with template
|
// handle error with template
|
||||||
|
@ -542,7 +542,7 @@ func createUserInContext(ctx *context.Context, tpl base.TplName, form any, u *us
|
||||||
default:
|
default:
|
||||||
ctx.ServerError("CreateUser", err)
|
ctx.ServerError("CreateUser", err)
|
||||||
}
|
}
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
log.Trace("Account created: %s", u.Name)
|
log.Trace("Account created: %s", u.Name)
|
||||||
return true
|
return true
|
||||||
|
@ -559,7 +559,7 @@ func handleUserCreated(ctx *context.Context, u *user_model.User, gothUser *goth.
|
||||||
u.SetLastLogin()
|
u.SetLastLogin()
|
||||||
if err := user_model.UpdateUserCols(ctx, u, "is_admin", "is_active", "last_login_unix"); err != nil {
|
if err := user_model.UpdateUserCols(ctx, u, "is_admin", "is_active", "last_login_unix"); err != nil {
|
||||||
ctx.ServerError("UpdateUser", err)
|
ctx.ServerError("UpdateUser", err)
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -577,7 +577,7 @@ func handleUserCreated(ctx *context.Context, u *user_model.User, gothUser *goth.
|
||||||
if setting.Service.RegisterManualConfirm {
|
if setting.Service.RegisterManualConfirm {
|
||||||
ctx.Data["ManualActivationOnly"] = true
|
ctx.Data["ManualActivationOnly"] = true
|
||||||
ctx.HTML(http.StatusOK, TplActivate)
|
ctx.HTML(http.StatusOK, TplActivate)
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
mailer.SendActivateAccountMail(ctx.Locale, u)
|
mailer.SendActivateAccountMail(ctx.Locale, u)
|
||||||
|
@ -592,7 +592,7 @@ func handleUserCreated(ctx *context.Context, u *user_model.User, gothUser *goth.
|
||||||
log.Error("Set cache(MailResendLimit) fail: %v", err)
|
log.Error("Set cache(MailResendLimit) fail: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -15,6 +15,7 @@ import (
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
"code.gitea.io/gitea/modules/storage"
|
"code.gitea.io/gitea/modules/storage"
|
||||||
"code.gitea.io/gitea/modules/upload"
|
"code.gitea.io/gitea/modules/upload"
|
||||||
|
"code.gitea.io/gitea/modules/util"
|
||||||
"code.gitea.io/gitea/routers/common"
|
"code.gitea.io/gitea/routers/common"
|
||||||
"code.gitea.io/gitea/services/attachment"
|
"code.gitea.io/gitea/services/attachment"
|
||||||
repo_service "code.gitea.io/gitea/services/repository"
|
repo_service "code.gitea.io/gitea/services/repository"
|
||||||
|
@ -148,7 +149,7 @@ func ServeAttachment(ctx *context.Context, uuid string) {
|
||||||
}
|
}
|
||||||
defer fr.Close()
|
defer fr.Close()
|
||||||
|
|
||||||
common.ServeContentByReadSeeker(ctx.Base, attach.Name, attach.CreatedUnix.AsTime(), fr)
|
common.ServeContentByReadSeeker(ctx.Base, attach.Name, util.ToPointer(attach.CreatedUnix.AsTime()), fr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAttachment serve attachments
|
// GetAttachment serve attachments
|
||||||
|
|
|
@ -20,7 +20,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// ServeBlobOrLFS download a git.Blob redirecting to LFS if necessary
|
// ServeBlobOrLFS download a git.Blob redirecting to LFS if necessary
|
||||||
func ServeBlobOrLFS(ctx *context.Context, blob *git.Blob, lastModified time.Time) error {
|
func ServeBlobOrLFS(ctx *context.Context, blob *git.Blob, lastModified *time.Time) error {
|
||||||
if httpcache.HandleGenericETagTimeCache(ctx.Req, ctx.Resp, `"`+blob.ID.String()+`"`, lastModified) {
|
if httpcache.HandleGenericETagTimeCache(ctx.Req, ctx.Resp, `"`+blob.ID.String()+`"`, lastModified) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ func ServeBlobOrLFS(ctx *context.Context, blob *git.Blob, lastModified time.Time
|
||||||
return common.ServeBlob(ctx.Base, ctx.Repo.TreePath, blob, lastModified)
|
return common.ServeBlob(ctx.Base, ctx.Repo.TreePath, blob, lastModified)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getBlobForEntry(ctx *context.Context) (blob *git.Blob, lastModified time.Time) {
|
func getBlobForEntry(ctx *context.Context) (blob *git.Blob, lastModified *time.Time) {
|
||||||
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath)
|
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if git.IsErrNotExist(err) {
|
if git.IsErrNotExist(err) {
|
||||||
|
@ -90,23 +90,23 @@ func getBlobForEntry(ctx *context.Context) (blob *git.Blob, lastModified time.Ti
|
||||||
} else {
|
} else {
|
||||||
ctx.ServerError("GetTreeEntryByPath", err)
|
ctx.ServerError("GetTreeEntryByPath", err)
|
||||||
}
|
}
|
||||||
return
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if entry.IsDir() || entry.IsSubModule() {
|
if entry.IsDir() || entry.IsSubModule() {
|
||||||
ctx.NotFound("getBlobForEntry", nil)
|
ctx.NotFound("getBlobForEntry", nil)
|
||||||
return
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
info, _, err := git.Entries([]*git.TreeEntry{entry}).GetCommitsInfo(ctx, ctx.Repo.Commit, path.Dir("/" + ctx.Repo.TreePath)[1:])
|
info, _, err := git.Entries([]*git.TreeEntry{entry}).GetCommitsInfo(ctx, ctx.Repo.Commit, path.Dir("/" + ctx.Repo.TreePath)[1:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetCommitsInfo", err)
|
ctx.ServerError("GetCommitsInfo", err)
|
||||||
return
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(info) == 1 {
|
if len(info) == 1 {
|
||||||
// Not Modified
|
// Not Modified
|
||||||
lastModified = info[0].Commit.Committer.When
|
lastModified = &info[0].Commit.Committer.When
|
||||||
}
|
}
|
||||||
blob = entry.Blob()
|
blob = entry.Blob()
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ func DownloadByID(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = common.ServeBlob(ctx.Base, ctx.Repo.TreePath, blob, time.Time{}); err != nil {
|
if err = common.ServeBlob(ctx.Base, ctx.Repo.TreePath, blob, nil); err != nil {
|
||||||
ctx.ServerError("ServeBlob", err)
|
ctx.ServerError("ServeBlob", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -164,7 +164,7 @@ func DownloadByIDOrLFS(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = ServeBlobOrLFS(ctx, blob, time.Time{}); err != nil {
|
if err = ServeBlobOrLFS(ctx, blob, nil); err != nil {
|
||||||
ctx.ServerError("ServeBlob", err)
|
ctx.ServerError("ServeBlob", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,13 +56,13 @@ func CorsHandler() func(next http.Handler) http.Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
// httpBase implementation git smart HTTP protocol
|
// httpBase implementation git smart HTTP protocol
|
||||||
func httpBase(ctx *context.Context) (h *serviceHandler) {
|
func httpBase(ctx *context.Context) *serviceHandler {
|
||||||
username := ctx.Params(":username")
|
username := ctx.Params(":username")
|
||||||
reponame := strings.TrimSuffix(ctx.Params(":reponame"), ".git")
|
reponame := strings.TrimSuffix(ctx.Params(":reponame"), ".git")
|
||||||
|
|
||||||
if ctx.FormString("go-get") == "1" {
|
if ctx.FormString("go-get") == "1" {
|
||||||
context.EarlyResponseForGoGetMeta(ctx)
|
context.EarlyResponseForGoGetMeta(ctx)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var isPull, receivePack bool
|
var isPull, receivePack bool
|
||||||
|
@ -101,7 +101,7 @@ func httpBase(ctx *context.Context) (h *serviceHandler) {
|
||||||
owner := ctx.ContextUser
|
owner := ctx.ContextUser
|
||||||
if !owner.IsOrganization() && !owner.IsActive {
|
if !owner.IsOrganization() && !owner.IsActive {
|
||||||
ctx.PlainText(http.StatusForbidden, "Repository cannot be accessed. You cannot push or open issues/pull-requests.")
|
ctx.PlainText(http.StatusForbidden, "Repository cannot be accessed. You cannot push or open issues/pull-requests.")
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
repoExist := true
|
repoExist := true
|
||||||
|
@ -110,19 +110,19 @@ func httpBase(ctx *context.Context) (h *serviceHandler) {
|
||||||
if repo_model.IsErrRepoNotExist(err) {
|
if repo_model.IsErrRepoNotExist(err) {
|
||||||
if redirectRepoID, err := repo_model.LookupRedirect(owner.ID, reponame); err == nil {
|
if redirectRepoID, err := repo_model.LookupRedirect(owner.ID, reponame); err == nil {
|
||||||
context.RedirectToRepo(ctx.Base, redirectRepoID)
|
context.RedirectToRepo(ctx.Base, redirectRepoID)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
repoExist = false
|
repoExist = false
|
||||||
} else {
|
} else {
|
||||||
ctx.ServerError("GetRepositoryByName", err)
|
ctx.ServerError("GetRepositoryByName", err)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't allow pushing if the repo is archived
|
// Don't allow pushing if the repo is archived
|
||||||
if repoExist && repo.IsArchived && !isPull {
|
if repoExist && repo.IsArchived && !isPull {
|
||||||
ctx.PlainText(http.StatusForbidden, "This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.")
|
ctx.PlainText(http.StatusForbidden, "This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.")
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only public pull don't need auth.
|
// Only public pull don't need auth.
|
||||||
|
@ -136,7 +136,7 @@ func httpBase(ctx *context.Context) (h *serviceHandler) {
|
||||||
if isPublicPull {
|
if isPublicPull {
|
||||||
if err := repo.LoadOwner(ctx); err != nil {
|
if err := repo.LoadOwner(ctx); err != nil {
|
||||||
ctx.ServerError("LoadOwner", err)
|
ctx.ServerError("LoadOwner", err)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
askAuth = askAuth || (repo.Owner.Visibility != structs.VisibleTypePublic)
|
askAuth = askAuth || (repo.Owner.Visibility != structs.VisibleTypePublic)
|
||||||
|
@ -149,12 +149,12 @@ func httpBase(ctx *context.Context) (h *serviceHandler) {
|
||||||
// TODO: support digit auth - which would be Authorization header with digit
|
// TODO: support digit auth - which would be Authorization header with digit
|
||||||
ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=\".\"")
|
ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=\".\"")
|
||||||
ctx.Error(http.StatusUnauthorized)
|
ctx.Error(http.StatusUnauthorized)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
context.CheckRepoScopedToken(ctx, repo, auth_model.GetScopeLevelFromAccessMode(accessMode))
|
context.CheckRepoScopedToken(ctx, repo, auth_model.GetScopeLevelFromAccessMode(accessMode))
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.IsBasicAuth && ctx.Data["IsApiToken"] != true && ctx.Data["IsActionsToken"] != true {
|
if ctx.IsBasicAuth && ctx.Data["IsApiToken"] != true && ctx.Data["IsActionsToken"] != true {
|
||||||
|
@ -162,16 +162,16 @@ func httpBase(ctx *context.Context) (h *serviceHandler) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// TODO: This response should be changed to "invalid credentials" for security reasons once the expectation behind it (creating an app token to authenticate) is properly documented
|
// TODO: This response should be changed to "invalid credentials" for security reasons once the expectation behind it (creating an app token to authenticate) is properly documented
|
||||||
ctx.PlainText(http.StatusUnauthorized, "Users with two-factor authentication enabled cannot perform HTTP/HTTPS operations via plain username and password. Please create and use a personal access token on the user settings page")
|
ctx.PlainText(http.StatusUnauthorized, "Users with two-factor authentication enabled cannot perform HTTP/HTTPS operations via plain username and password. Please create and use a personal access token on the user settings page")
|
||||||
return
|
return nil
|
||||||
} else if !auth_model.IsErrTwoFactorNotEnrolled(err) {
|
} else if !auth_model.IsErrTwoFactorNotEnrolled(err) {
|
||||||
ctx.ServerError("IsErrTwoFactorNotEnrolled", err)
|
ctx.ServerError("IsErrTwoFactorNotEnrolled", err)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.Doer.IsActive || ctx.Doer.ProhibitLogin {
|
if !ctx.Doer.IsActive || ctx.Doer.ProhibitLogin {
|
||||||
ctx.PlainText(http.StatusForbidden, "Your account is disabled.")
|
ctx.PlainText(http.StatusForbidden, "Your account is disabled.")
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
environ = []string{
|
environ = []string{
|
||||||
|
@ -193,23 +193,23 @@ func httpBase(ctx *context.Context) (h *serviceHandler) {
|
||||||
task, err := actions_model.GetTaskByID(ctx, taskID)
|
task, err := actions_model.GetTaskByID(ctx, taskID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetTaskByID", err)
|
ctx.ServerError("GetTaskByID", err)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
if task.RepoID != repo.ID {
|
if task.RepoID != repo.ID {
|
||||||
ctx.PlainText(http.StatusForbidden, "User permission denied")
|
ctx.PlainText(http.StatusForbidden, "User permission denied")
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if task.IsForkPullRequest {
|
if task.IsForkPullRequest {
|
||||||
if accessMode > perm.AccessModeRead {
|
if accessMode > perm.AccessModeRead {
|
||||||
ctx.PlainText(http.StatusForbidden, "User permission denied")
|
ctx.PlainText(http.StatusForbidden, "User permission denied")
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
environ = append(environ, fmt.Sprintf("%s=%d", repo_module.EnvActionPerm, perm.AccessModeRead))
|
environ = append(environ, fmt.Sprintf("%s=%d", repo_module.EnvActionPerm, perm.AccessModeRead))
|
||||||
} else {
|
} else {
|
||||||
if accessMode > perm.AccessModeWrite {
|
if accessMode > perm.AccessModeWrite {
|
||||||
ctx.PlainText(http.StatusForbidden, "User permission denied")
|
ctx.PlainText(http.StatusForbidden, "User permission denied")
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
environ = append(environ, fmt.Sprintf("%s=%d", repo_module.EnvActionPerm, perm.AccessModeWrite))
|
environ = append(environ, fmt.Sprintf("%s=%d", repo_module.EnvActionPerm, perm.AccessModeWrite))
|
||||||
}
|
}
|
||||||
|
@ -217,18 +217,18 @@ func httpBase(ctx *context.Context) (h *serviceHandler) {
|
||||||
p, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer)
|
p, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetUserRepoPermission", err)
|
ctx.ServerError("GetUserRepoPermission", err)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if !p.CanAccess(accessMode, unitType) {
|
if !p.CanAccess(accessMode, unitType) {
|
||||||
ctx.PlainText(http.StatusNotFound, "Repository not found")
|
ctx.PlainText(http.StatusNotFound, "Repository not found")
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !isPull && repo.IsMirror {
|
if !isPull && repo.IsMirror {
|
||||||
ctx.PlainText(http.StatusForbidden, "mirror repository is read-only")
|
ctx.PlainText(http.StatusForbidden, "mirror repository is read-only")
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,34 +246,34 @@ func httpBase(ctx *context.Context) (h *serviceHandler) {
|
||||||
if !repoExist {
|
if !repoExist {
|
||||||
if !receivePack {
|
if !receivePack {
|
||||||
ctx.PlainText(http.StatusNotFound, "Repository not found")
|
ctx.PlainText(http.StatusNotFound, "Repository not found")
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if isWiki { // you cannot send wiki operation before create the repository
|
if isWiki { // you cannot send wiki operation before create the repository
|
||||||
ctx.PlainText(http.StatusNotFound, "Repository not found")
|
ctx.PlainText(http.StatusNotFound, "Repository not found")
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if owner.IsOrganization() && !setting.Repository.EnablePushCreateOrg {
|
if owner.IsOrganization() && !setting.Repository.EnablePushCreateOrg {
|
||||||
ctx.PlainText(http.StatusForbidden, "Push to create is not enabled for organizations.")
|
ctx.PlainText(http.StatusForbidden, "Push to create is not enabled for organizations.")
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
if !owner.IsOrganization() && !setting.Repository.EnablePushCreateUser {
|
if !owner.IsOrganization() && !setting.Repository.EnablePushCreateUser {
|
||||||
ctx.PlainText(http.StatusForbidden, "Push to create is not enabled for users.")
|
ctx.PlainText(http.StatusForbidden, "Push to create is not enabled for users.")
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return dummy payload if GET receive-pack
|
// Return dummy payload if GET receive-pack
|
||||||
if ctx.Req.Method == http.MethodGet {
|
if ctx.Req.Method == http.MethodGet {
|
||||||
dummyInfoRefs(ctx)
|
dummyInfoRefs(ctx)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
repo, err = repo_service.PushCreateRepo(ctx, ctx.Doer, owner, reponame)
|
repo, err = repo_service.PushCreateRepo(ctx, ctx.Doer, owner, reponame)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("pushCreateRepo: %v", err)
|
log.Error("pushCreateRepo: %v", err)
|
||||||
ctx.Status(http.StatusNotFound)
|
ctx.Status(http.StatusNotFound)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,11 +282,11 @@ func httpBase(ctx *context.Context) (h *serviceHandler) {
|
||||||
if _, err := repo.GetUnit(ctx, unit.TypeWiki); err != nil {
|
if _, err := repo.GetUnit(ctx, unit.TypeWiki); err != nil {
|
||||||
if repo_model.IsErrUnitTypeNotExist(err) {
|
if repo_model.IsErrUnitTypeNotExist(err) {
|
||||||
ctx.PlainText(http.StatusForbidden, "repository wiki is disabled")
|
ctx.PlainText(http.StatusForbidden, "repository wiki is disabled")
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
log.Error("Failed to get the wiki unit in %-v Error: %v", repo, err)
|
log.Error("Failed to get the wiki unit in %-v Error: %v", repo, err)
|
||||||
ctx.ServerError("GetUnit(UnitTypeWiki) for "+repo.FullName(), err)
|
ctx.ServerError("GetUnit(UnitTypeWiki) for "+repo.FullName(), err)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1922,9 +1922,12 @@ func ViewIssue(ctx *context.Context) {
|
||||||
ctx.HTML(http.StatusOK, tplIssueView)
|
ctx.HTML(http.StatusOK, tplIssueView)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// checkBlockedByIssues return canRead and notPermitted
|
||||||
func checkBlockedByIssues(ctx *context.Context, blockers []*issues_model.DependencyInfo) (canRead, notPermitted []*issues_model.DependencyInfo) {
|
func checkBlockedByIssues(ctx *context.Context, blockers []*issues_model.DependencyInfo) (canRead, notPermitted []*issues_model.DependencyInfo) {
|
||||||
var lastRepoID int64
|
var (
|
||||||
var lastPerm access_model.Permission
|
lastRepoID int64
|
||||||
|
lastPerm access_model.Permission
|
||||||
|
)
|
||||||
for i, blocker := range blockers {
|
for i, blocker := range blockers {
|
||||||
// Get the permissions for this repository
|
// Get the permissions for this repository
|
||||||
perm := lastPerm
|
perm := lastPerm
|
||||||
|
@ -1936,7 +1939,7 @@ func checkBlockedByIssues(ctx *context.Context, blockers []*issues_model.Depende
|
||||||
perm, err = access_model.GetUserRepoPermission(ctx, &blocker.Repository, ctx.Doer)
|
perm, err = access_model.GetUserRepoPermission(ctx, &blocker.Repository, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetUserRepoPermission", err)
|
ctx.ServerError("GetUserRepoPermission", err)
|
||||||
return
|
return nil, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastRepoID = blocker.Repository.ID
|
lastRepoID = blocker.Repository.ID
|
||||||
|
|
|
@ -12,7 +12,6 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
git_model "code.gitea.io/gitea/models/git"
|
git_model "code.gitea.io/gitea/models/git"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
|
@ -671,7 +670,7 @@ func WikiRaw(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if entry != nil {
|
if entry != nil {
|
||||||
if err = common.ServeBlob(ctx.Base, ctx.Repo.TreePath, entry.Blob(), time.Time{}); err != nil {
|
if err = common.ServeBlob(ctx.Base, ctx.Repo.TreePath, entry.Blob(), nil); err != nil {
|
||||||
ctx.ServerError("ServeBlob", err)
|
ctx.ServerError("ServeBlob", err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
|
@ -1256,20 +1256,20 @@ func registerRoutes(m *web.Route) {
|
||||||
|
|
||||||
m.Group("/blob_excerpt", func() {
|
m.Group("/blob_excerpt", func() {
|
||||||
m.Get("/{sha}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.ExcerptBlob)
|
m.Get("/{sha}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.ExcerptBlob)
|
||||||
}, func(ctx *context.Context) (cancel gocontext.CancelFunc) {
|
}, func(ctx *context.Context) gocontext.CancelFunc {
|
||||||
if ctx.FormBool("wiki") {
|
if ctx.FormBool("wiki") {
|
||||||
ctx.Data["PageIsWiki"] = true
|
ctx.Data["PageIsWiki"] = true
|
||||||
repo.MustEnableWiki(ctx)
|
repo.MustEnableWiki(ctx)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
reqRepoCodeReader(ctx)
|
reqRepoCodeReader(ctx)
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
cancel = context.RepoRef()(ctx)
|
cancel := context.RepoRef()(ctx)
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return cancel
|
||||||
}
|
}
|
||||||
|
|
||||||
repo.MustBeNotEmpty(ctx)
|
repo.MustBeNotEmpty(ctx)
|
||||||
|
|
|
@ -90,7 +90,7 @@ func IsUserHiddenCommentTypeGroupChecked(group string, hiddenCommentTypes *big.I
|
||||||
commentTypes, ok := hiddenCommentTypeGroups[group]
|
commentTypes, ok := hiddenCommentTypeGroups[group]
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Critical("the group map for hidden comment types is out of sync, unknown group: %v", group)
|
log.Critical("the group map for hidden comment types is out of sync, unknown group: %v", group)
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
if hiddenCommentTypes == nil {
|
if hiddenCommentTypes == nil {
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -779,7 +779,7 @@ func skipToNextDiffHead(input *bufio.Reader) (line string, err error) {
|
||||||
for {
|
for {
|
||||||
lineBytes, isFragment, err = input.ReadLine()
|
lineBytes, isFragment, err = input.ReadLine()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return "", err
|
||||||
}
|
}
|
||||||
if wasFragment {
|
if wasFragment {
|
||||||
wasFragment = isFragment
|
wasFragment = isFragment
|
||||||
|
@ -795,7 +795,7 @@ func skipToNextDiffHead(input *bufio.Reader) (line string, err error) {
|
||||||
var tail string
|
var tail string
|
||||||
tail, err = input.ReadString('\n')
|
tail, err = input.ReadString('\n')
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return "", err
|
||||||
}
|
}
|
||||||
line += tail
|
line += tail
|
||||||
}
|
}
|
||||||
|
@ -821,22 +821,21 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio
|
||||||
_, isFragment, err = input.ReadLine()
|
_, isFragment, err = input.ReadLine()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Now by the definition of ReadLine this cannot be io.EOF
|
// Now by the definition of ReadLine this cannot be io.EOF
|
||||||
err = fmt.Errorf("unable to ReadLine: %w", err)
|
return nil, false, fmt.Errorf("unable to ReadLine: %w", err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sb.Reset()
|
sb.Reset()
|
||||||
lineBytes, isFragment, err = input.ReadLine()
|
lineBytes, isFragment, err = input.ReadLine()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
return
|
return lineBytes, isFragment, err
|
||||||
}
|
}
|
||||||
err = fmt.Errorf("unable to ReadLine: %w", err)
|
err = fmt.Errorf("unable to ReadLine: %w", err)
|
||||||
return
|
return nil, false, err
|
||||||
}
|
}
|
||||||
if lineBytes[0] == 'd' {
|
if lineBytes[0] == 'd' {
|
||||||
// End of hunks
|
// End of hunks
|
||||||
return
|
return lineBytes, isFragment, err
|
||||||
}
|
}
|
||||||
|
|
||||||
switch lineBytes[0] {
|
switch lineBytes[0] {
|
||||||
|
@ -853,8 +852,7 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio
|
||||||
lineBytes, isFragment, err = input.ReadLine()
|
lineBytes, isFragment, err = input.ReadLine()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Now by the definition of ReadLine this cannot be io.EOF
|
// Now by the definition of ReadLine this cannot be io.EOF
|
||||||
err = fmt.Errorf("unable to ReadLine: %w", err)
|
return nil, false, fmt.Errorf("unable to ReadLine: %w", err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
_, _ = sb.Write(lineBytes)
|
_, _ = sb.Write(lineBytes)
|
||||||
}
|
}
|
||||||
|
@ -884,8 +882,7 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio
|
||||||
}
|
}
|
||||||
// This is used only to indicate that the current file does not have a terminal newline
|
// This is used only to indicate that the current file does not have a terminal newline
|
||||||
if !bytes.Equal(lineBytes, []byte("\\ No newline at end of file")) {
|
if !bytes.Equal(lineBytes, []byte("\\ No newline at end of file")) {
|
||||||
err = fmt.Errorf("unexpected line in hunk: %s", string(lineBytes))
|
return nil, false, fmt.Errorf("unexpected line in hunk: %s", string(lineBytes))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
// Technically this should be the end the file!
|
// Technically this should be the end the file!
|
||||||
// FIXME: we should be putting a marker at the end of the file if there is no terminal new line
|
// FIXME: we should be putting a marker at the end of the file if there is no terminal new line
|
||||||
|
@ -953,8 +950,7 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio
|
||||||
curSection.Lines = append(curSection.Lines, diffLine)
|
curSection.Lines = append(curSection.Lines, diffLine)
|
||||||
default:
|
default:
|
||||||
// This is unexpected
|
// This is unexpected
|
||||||
err = fmt.Errorf("unexpected line in hunk: %s", string(lineBytes))
|
return nil, false, fmt.Errorf("unexpected line in hunk: %s", string(lineBytes))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
line := string(lineBytes)
|
line := string(lineBytes)
|
||||||
|
@ -965,8 +961,7 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio
|
||||||
lineBytes, isFragment, err = input.ReadLine()
|
lineBytes, isFragment, err = input.ReadLine()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Now by the definition of ReadLine this cannot be io.EOF
|
// Now by the definition of ReadLine this cannot be io.EOF
|
||||||
err = fmt.Errorf("unable to ReadLine: %w", err)
|
return lineBytes, isFragment, fmt.Errorf("unable to ReadLine: %w", err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,13 +46,12 @@ func DeleteNotPassedAssignee(ctx context.Context, issue *issues_model.Issue, doe
|
||||||
func ToggleAssignee(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, assigneeID int64) (removed bool, comment *issues_model.Comment, err error) {
|
func ToggleAssignee(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, assigneeID int64) (removed bool, comment *issues_model.Comment, err error) {
|
||||||
removed, comment, err = issues_model.ToggleIssueAssignee(ctx, issue, doer, assigneeID)
|
removed, comment, err = issues_model.ToggleIssueAssignee(ctx, issue, doer, assigneeID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return false, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
assignee, err1 := user_model.GetUserByID(ctx, assigneeID)
|
assignee, err := user_model.GetUserByID(ctx, assigneeID)
|
||||||
if err1 != nil {
|
if err != nil {
|
||||||
err = err1
|
return false, nil, err
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
notification.NotifyIssueChangeAssignee(ctx, doer, issue, assignee, removed, comment)
|
notification.NotifyIssueChangeAssignee(ctx, doer, issue, assignee, removed, comment)
|
||||||
|
@ -236,23 +235,23 @@ func TeamReviewRequest(ctx context.Context, issue *issues_model.Issue, doer *use
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if comment == nil || !isAdd {
|
if comment == nil || !isAdd {
|
||||||
return
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// notify all user in this team
|
// notify all user in this team
|
||||||
if err = comment.LoadIssue(ctx); err != nil {
|
if err := comment.LoadIssue(ctx); err != nil {
|
||||||
return
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
members, err := organization.GetTeamMembers(ctx, &organization.SearchMembersOptions{
|
members, err := organization.GetTeamMembers(ctx, &organization.SearchMembersOptions{
|
||||||
TeamID: reviewer.ID,
|
TeamID: reviewer.ID,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, member := range members {
|
for _, member := range members {
|
||||||
|
|
|
@ -49,17 +49,17 @@ func NewIssue(ctx context.Context, repo *repo_model.Repository, issue *issues_mo
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChangeTitle changes the title of this issue, as the given user.
|
// ChangeTitle changes the title of this issue, as the given user.
|
||||||
func ChangeTitle(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, title string) (err error) {
|
func ChangeTitle(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, title string) error {
|
||||||
oldTitle := issue.Title
|
oldTitle := issue.Title
|
||||||
issue.Title = title
|
issue.Title = title
|
||||||
|
|
||||||
if err = issues_model.ChangeIssueTitle(ctx, issue, doer, oldTitle); err != nil {
|
if err := issues_model.ChangeIssueTitle(ctx, issue, doer, oldTitle); err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if issue.IsPull && issues_model.HasWorkInProgressPrefix(oldTitle) && !issues_model.HasWorkInProgressPrefix(title) {
|
if issue.IsPull && issues_model.HasWorkInProgressPrefix(oldTitle) && !issues_model.HasWorkInProgressPrefix(title) {
|
||||||
if err = issues_model.PullRequestCodeOwnersReview(ctx, issue, issue.PullRequest); err != nil {
|
if err := issues_model.PullRequestCodeOwnersReview(ctx, issue, issue.PullRequest); err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,9 +12,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// ClearLabels clears all of an issue's labels
|
// ClearLabels clears all of an issue's labels
|
||||||
func ClearLabels(issue *issues_model.Issue, doer *user_model.User) (err error) {
|
func ClearLabels(issue *issues_model.Issue, doer *user_model.User) error {
|
||||||
if err = issues_model.ClearIssueLabels(issue, doer); err != nil {
|
if err := issues_model.ClearIssueLabels(issue, doer); err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
notification.NotifyIssueClearLabels(db.DefaultContext, doer, issue)
|
notification.NotifyIssueClearLabels(db.DefaultContext, doer, issue)
|
||||||
|
|
|
@ -320,7 +320,7 @@ func SubmitReview(ctx context.Context, doer *user_model.User, gitRepo *git.Repos
|
||||||
func DismissReview(ctx context.Context, reviewID, repoID int64, message string, doer *user_model.User, isDismiss, dismissPriors bool) (comment *issues_model.Comment, err error) {
|
func DismissReview(ctx context.Context, reviewID, repoID int64, message string, doer *user_model.User, isDismiss, dismissPriors bool) (comment *issues_model.Comment, err error) {
|
||||||
review, err := issues_model.GetReviewByID(ctx, reviewID)
|
review, err := issues_model.GetReviewByID(ctx, reviewID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if review.Type != issues_model.ReviewTypeApprove && review.Type != issues_model.ReviewTypeReject {
|
if review.Type != issues_model.ReviewTypeApprove && review.Type != issues_model.ReviewTypeReject {
|
||||||
|
@ -328,7 +328,7 @@ func DismissReview(ctx context.Context, reviewID, repoID int64, message string,
|
||||||
}
|
}
|
||||||
|
|
||||||
// load data for notify
|
// load data for notify
|
||||||
if err = review.LoadAttributes(ctx); err != nil {
|
if err := review.LoadAttributes(ctx); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -337,8 +337,8 @@ func DismissReview(ctx context.Context, reviewID, repoID int64, message string,
|
||||||
return nil, fmt.Errorf("reviews's repository is not the same as the one we expect")
|
return nil, fmt.Errorf("reviews's repository is not the same as the one we expect")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = issues_model.DismissReview(review, isDismiss); err != nil {
|
if err := issues_model.DismissReview(review, isDismiss); err != nil {
|
||||||
return
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if dismissPriors {
|
if dismissPriors {
|
||||||
|
@ -361,11 +361,11 @@ func DismissReview(ctx context.Context, reviewID, repoID int64, message string,
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = review.Issue.LoadPullRequest(ctx); err != nil {
|
if err := review.Issue.LoadPullRequest(ctx); err != nil {
|
||||||
return
|
return nil, err
|
||||||
}
|
}
|
||||||
if err = review.Issue.LoadAttributes(ctx); err != nil {
|
if err := review.Issue.LoadAttributes(ctx); err != nil {
|
||||||
return
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
comment, err = issue_service.CreateComment(ctx, &issues_model.CreateCommentOptions{
|
comment, err = issue_service.CreateComment(ctx, &issues_model.CreateCommentOptions{
|
||||||
|
@ -377,7 +377,7 @@ func DismissReview(ctx context.Context, reviewID, repoID int64, message string,
|
||||||
Repo: review.Issue.Repo,
|
Repo: review.Issue.Repo,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
comment.Review = review
|
comment.Review = review
|
||||||
|
@ -386,5 +386,5 @@ func DismissReview(ctx context.Context, reviewID, repoID int64, message string,
|
||||||
|
|
||||||
notification.NotifyPullReviewDismiss(ctx, doer, review, comment)
|
notification.NotifyPullReviewDismiss(ctx, doer, review, comment)
|
||||||
|
|
||||||
return comment, err
|
return comment, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -187,7 +187,7 @@ func CreateNewTag(ctx context.Context, doer *user_model.User, repo *repo_model.R
|
||||||
// editAttachments accept a map of attachment uuid to new attachment name which will be updated with attachments.
|
// editAttachments accept a map of attachment uuid to new attachment name which will be updated with attachments.
|
||||||
func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *repo_model.Release,
|
func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *repo_model.Release,
|
||||||
addAttachmentUUIDs, delAttachmentUUIDs []string, editAttachments map[string]string,
|
addAttachmentUUIDs, delAttachmentUUIDs []string, editAttachments map[string]string,
|
||||||
) (err error) {
|
) error {
|
||||||
if rel.ID == 0 {
|
if rel.ID == 0 {
|
||||||
return errors.New("UpdateRelease only accepts an exist release")
|
return errors.New("UpdateRelease only accepts an exist release")
|
||||||
}
|
}
|
||||||
|
@ -264,8 +264,8 @@ func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *repo_mod
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = committer.Commit(); err != nil {
|
if err := committer.Commit(); err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, uuid := range delAttachmentUUIDs {
|
for _, uuid := range delAttachmentUUIDs {
|
||||||
|
@ -280,14 +280,14 @@ func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *repo_mod
|
||||||
|
|
||||||
if !isCreated {
|
if !isCreated {
|
||||||
notification.NotifyUpdateRelease(gitRepo.Ctx, doer, rel)
|
notification.NotifyUpdateRelease(gitRepo.Ctx, doer, rel)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if !rel.IsDraft {
|
if !rel.IsDraft {
|
||||||
notification.NotifyNewRelease(gitRepo.Ctx, rel)
|
notification.NotifyNewRelease(gitRepo.Ctx, rel)
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteReleaseByID deletes a release and corresponding Git tag by given ID.
|
// DeleteReleaseByID deletes a release and corresponding Git tag by given ID.
|
||||||
|
|
Loading…
Reference in a new issue