forked from forgejo/forgejo
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
|
||||
// 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 {
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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.TrustStatus = "trusted"
|
||||
}
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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.TrustStatus = "untrusted"
|
||||
}
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
// Check we actually have a GPG SigningKey
|
||||
var err error
|
||||
if verification.SigningKey != nil {
|
||||
var isMember bool
|
||||
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.
|
||||
func (code *OAuth2AuthorizationCode) GenerateRedirectURI(state string) (redirect *url.URL, err error) {
|
||||
if redirect, err = url.Parse(code.RedirectURI); err != nil {
|
||||
return
|
||||
func (code *OAuth2AuthorizationCode) GenerateRedirectURI(state string) (*url.URL, error) {
|
||||
redirect, err := url.Parse(code.RedirectURI)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
q := redirect.Query()
|
||||
if state != "" {
|
||||
|
|
|
@ -16,10 +16,10 @@ type Watch struct {
|
|||
Mode RepoWatchMode `xorm:"SMALLINT NOT NULL DEFAULT 1"`
|
||||
}
|
||||
|
||||
func AddModeColumnToWatch(x *xorm.Engine) (err error) {
|
||||
if err = x.Sync2(new(Watch)); err != nil {
|
||||
return
|
||||
func AddModeColumnToWatch(x *xorm.Engine) error {
|
||||
if err := x.Sync2(new(Watch)); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = x.Exec("UPDATE `watch` SET `mode` = 1")
|
||||
_, err := x.Exec("UPDATE `watch` SET `mode` = 1")
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -23,25 +23,25 @@ func RecalculateStars(x *xorm.Engine) (err error) {
|
|||
|
||||
for start := 0; ; start += batchSize {
|
||||
users := make([]User, 0, batchSize)
|
||||
if err = sess.Limit(batchSize, start).Where("type = ?", 0).Cols("id").Find(&users); err != nil {
|
||||
return
|
||||
if err := sess.Limit(batchSize, start).Where("type = ?", 0).Cols("id").Find(&users); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(users) == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
if err = sess.Begin(); err != nil {
|
||||
return
|
||||
if err := sess.Begin(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
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 {
|
||||
return
|
||||
if _, err := sess.Exec("UPDATE `user` SET num_stars=(SELECT COUNT(*) FROM `star` WHERE uid=?) WHERE id=?", user.ID, user.ID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err = sess.Commit(); err != nil {
|
||||
return
|
||||
if err := sess.Commit(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,25 +44,25 @@ func DeleteMigrationCredentials(x *xorm.Engine) (err error) {
|
|||
|
||||
for start := 0; ; start += batchSize {
|
||||
tasks := make([]*Task, 0, batchSize)
|
||||
if err = sess.Limit(batchSize, start).Where(cond, 0).Find(&tasks); err != nil {
|
||||
return
|
||||
if err := sess.Limit(batchSize, start).Where(cond, 0).Find(&tasks); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(tasks) == 0 {
|
||||
break
|
||||
}
|
||||
if err = sess.Begin(); err != nil {
|
||||
return
|
||||
if err := sess.Begin(); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, t := range tasks {
|
||||
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 {
|
||||
return
|
||||
if _, err := sess.ID(t.ID).Cols("payload_content").Update(t); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err = sess.Commit(); err != nil {
|
||||
return
|
||||
if err := sess.Commit(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return err
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func AddPrimaryEmail2EmailAddress(x *xorm.Engine) (err error) {
|
||||
func AddPrimaryEmail2EmailAddress(x *xorm.Engine) error {
|
||||
type User struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
Email string `xorm:"NOT NULL"`
|
||||
|
@ -26,12 +26,12 @@ func AddPrimaryEmail2EmailAddress(x *xorm.Engine) (err error) {
|
|||
}
|
||||
|
||||
// Add lower_email and is_primary columns
|
||||
if err = x.Table("email_address").Sync2(new(EmailAddress1)); err != nil {
|
||||
return
|
||||
if err := x.Table("email_address").Sync2(new(EmailAddress1)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err = x.Exec("UPDATE email_address SET lower_email=LOWER(email), is_primary=?", false); err != nil {
|
||||
return
|
||||
if _, err := x.Exec("UPDATE email_address SET lower_email=LOWER(email), is_primary=?", false); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
type EmailAddress struct {
|
||||
|
@ -44,8 +44,8 @@ func AddPrimaryEmail2EmailAddress(x *xorm.Engine) (err error) {
|
|||
}
|
||||
|
||||
// change lower_email as unique
|
||||
if err = x.Sync2(new(EmailAddress)); err != nil {
|
||||
return
|
||||
if err := x.Sync2(new(EmailAddress)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
sess := x.NewSession()
|
||||
|
@ -55,34 +55,33 @@ func AddPrimaryEmail2EmailAddress(x *xorm.Engine) (err error) {
|
|||
|
||||
for start := 0; ; start += batchSize {
|
||||
users := make([]*User, 0, batchSize)
|
||||
if err = sess.Limit(batchSize, start).Find(&users); err != nil {
|
||||
return
|
||||
if err := sess.Limit(batchSize, start).Find(&users); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(users) == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
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 {
|
||||
return
|
||||
return err
|
||||
}
|
||||
if !exist {
|
||||
if _, err = sess.Insert(&EmailAddress{
|
||||
if _, err := sess.Insert(&EmailAddress{
|
||||
UID: user.ID,
|
||||
Email: user.Email,
|
||||
LowerEmail: strings.ToLower(user.Email),
|
||||
IsActivated: user.IsActive,
|
||||
IsPrimary: true,
|
||||
}); err != nil {
|
||||
return
|
||||
return err
|
||||
}
|
||||
} 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,
|
||||
}); err != nil {
|
||||
return
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue