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
|
@ -90,7 +90,7 @@ func IsUserHiddenCommentTypeGroupChecked(group string, hiddenCommentTypes *big.I
|
|||
commentTypes, ok := hiddenCommentTypeGroups[group]
|
||||
if !ok {
|
||||
log.Critical("the group map for hidden comment types is out of sync, unknown group: %v", group)
|
||||
return
|
||||
return false
|
||||
}
|
||||
if hiddenCommentTypes == nil {
|
||||
return false
|
||||
|
|
|
@ -779,7 +779,7 @@ func skipToNextDiffHead(input *bufio.Reader) (line string, err error) {
|
|||
for {
|
||||
lineBytes, isFragment, err = input.ReadLine()
|
||||
if err != nil {
|
||||
return
|
||||
return "", err
|
||||
}
|
||||
if wasFragment {
|
||||
wasFragment = isFragment
|
||||
|
@ -795,7 +795,7 @@ func skipToNextDiffHead(input *bufio.Reader) (line string, err error) {
|
|||
var tail string
|
||||
tail, err = input.ReadString('\n')
|
||||
if err != nil {
|
||||
return
|
||||
return "", err
|
||||
}
|
||||
line += tail
|
||||
}
|
||||
|
@ -821,22 +821,21 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio
|
|||
_, isFragment, err = input.ReadLine()
|
||||
if err != nil {
|
||||
// Now by the definition of ReadLine this cannot be io.EOF
|
||||
err = fmt.Errorf("unable to ReadLine: %w", err)
|
||||
return
|
||||
return nil, false, fmt.Errorf("unable to ReadLine: %w", err)
|
||||
}
|
||||
}
|
||||
sb.Reset()
|
||||
lineBytes, isFragment, err = input.ReadLine()
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
return
|
||||
return lineBytes, isFragment, err
|
||||
}
|
||||
err = fmt.Errorf("unable to ReadLine: %w", err)
|
||||
return
|
||||
return nil, false, err
|
||||
}
|
||||
if lineBytes[0] == 'd' {
|
||||
// End of hunks
|
||||
return
|
||||
return lineBytes, isFragment, err
|
||||
}
|
||||
|
||||
switch lineBytes[0] {
|
||||
|
@ -853,8 +852,7 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio
|
|||
lineBytes, isFragment, err = input.ReadLine()
|
||||
if err != nil {
|
||||
// Now by the definition of ReadLine this cannot be io.EOF
|
||||
err = fmt.Errorf("unable to ReadLine: %w", err)
|
||||
return
|
||||
return nil, false, fmt.Errorf("unable to ReadLine: %w", err)
|
||||
}
|
||||
_, _ = 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
|
||||
if !bytes.Equal(lineBytes, []byte("\\ No newline at end of file")) {
|
||||
err = fmt.Errorf("unexpected line in hunk: %s", string(lineBytes))
|
||||
return
|
||||
return nil, false, fmt.Errorf("unexpected line in hunk: %s", string(lineBytes))
|
||||
}
|
||||
// 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
|
||||
|
@ -953,8 +950,7 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio
|
|||
curSection.Lines = append(curSection.Lines, diffLine)
|
||||
default:
|
||||
// This is unexpected
|
||||
err = fmt.Errorf("unexpected line in hunk: %s", string(lineBytes))
|
||||
return
|
||||
return nil, false, fmt.Errorf("unexpected line in hunk: %s", string(lineBytes))
|
||||
}
|
||||
|
||||
line := string(lineBytes)
|
||||
|
@ -965,8 +961,7 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio
|
|||
lineBytes, isFragment, err = input.ReadLine()
|
||||
if err != nil {
|
||||
// Now by the definition of ReadLine this cannot be io.EOF
|
||||
err = fmt.Errorf("unable to ReadLine: %w", err)
|
||||
return
|
||||
return lineBytes, isFragment, fmt.Errorf("unable to ReadLine: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
removed, comment, err = issues_model.ToggleIssueAssignee(ctx, issue, doer, assigneeID)
|
||||
if err != nil {
|
||||
return
|
||||
return false, nil, err
|
||||
}
|
||||
|
||||
assignee, err1 := user_model.GetUserByID(ctx, assigneeID)
|
||||
if err1 != nil {
|
||||
err = err1
|
||||
return
|
||||
assignee, err := user_model.GetUserByID(ctx, assigneeID)
|
||||
if err != nil {
|
||||
return false, nil, err
|
||||
}
|
||||
|
||||
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 {
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if comment == nil || !isAdd {
|
||||
return
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// notify all user in this team
|
||||
if err = comment.LoadIssue(ctx); err != nil {
|
||||
return
|
||||
if err := comment.LoadIssue(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
members, err := organization.GetTeamMembers(ctx, &organization.SearchMembersOptions{
|
||||
TeamID: reviewer.ID,
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
|
||||
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.
|
||||
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
|
||||
issue.Title = title
|
||||
|
||||
if err = issues_model.ChangeIssueTitle(ctx, issue, doer, oldTitle); err != nil {
|
||||
return
|
||||
if err := issues_model.ChangeIssueTitle(ctx, issue, doer, oldTitle); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if issue.IsPull && issues_model.HasWorkInProgressPrefix(oldTitle) && !issues_model.HasWorkInProgressPrefix(title) {
|
||||
if err = issues_model.PullRequestCodeOwnersReview(ctx, issue, issue.PullRequest); err != nil {
|
||||
return
|
||||
if err := issues_model.PullRequestCodeOwnersReview(ctx, issue, issue.PullRequest); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,9 +12,9 @@ import (
|
|||
)
|
||||
|
||||
// ClearLabels clears all of an issue's labels
|
||||
func ClearLabels(issue *issues_model.Issue, doer *user_model.User) (err error) {
|
||||
if err = issues_model.ClearIssueLabels(issue, doer); err != nil {
|
||||
return
|
||||
func ClearLabels(issue *issues_model.Issue, doer *user_model.User) error {
|
||||
if err := issues_model.ClearIssueLabels(issue, doer); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
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) {
|
||||
review, err := issues_model.GetReviewByID(ctx, reviewID)
|
||||
if err != nil {
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
|
||||
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
|
||||
if err = review.LoadAttributes(ctx); err != nil {
|
||||
if err := review.LoadAttributes(ctx); err != nil {
|
||||
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")
|
||||
}
|
||||
|
||||
if err = issues_model.DismissReview(review, isDismiss); err != nil {
|
||||
return
|
||||
if err := issues_model.DismissReview(review, isDismiss); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if dismissPriors {
|
||||
|
@ -361,11 +361,11 @@ func DismissReview(ctx context.Context, reviewID, repoID int64, message string,
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
if err = review.Issue.LoadPullRequest(ctx); err != nil {
|
||||
return
|
||||
if err := review.Issue.LoadPullRequest(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = review.Issue.LoadAttributes(ctx); err != nil {
|
||||
return
|
||||
if err := review.Issue.LoadAttributes(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
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,
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
|
||||
comment.Review = review
|
||||
|
@ -386,5 +386,5 @@ func DismissReview(ctx context.Context, reviewID, repoID int64, message string,
|
|||
|
||||
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.
|
||||
func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *repo_model.Release,
|
||||
addAttachmentUUIDs, delAttachmentUUIDs []string, editAttachments map[string]string,
|
||||
) (err error) {
|
||||
) error {
|
||||
if rel.ID == 0 {
|
||||
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 {
|
||||
return
|
||||
if err := committer.Commit(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, uuid := range delAttachmentUUIDs {
|
||||
|
@ -280,14 +280,14 @@ func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *repo_mod
|
|||
|
||||
if !isCreated {
|
||||
notification.NotifyUpdateRelease(gitRepo.Ctx, doer, rel)
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
if !rel.IsDraft {
|
||||
notification.NotifyNewRelease(gitRepo.Ctx, rel)
|
||||
}
|
||||
|
||||
return err
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteReleaseByID deletes a release and corresponding Git tag by given ID.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue