Skip to content

Commit 63a1a42

Browse files
authored
Merge branch 'main' into blender-fix-git-hook-pr-disabled
2 parents efc7f10 + 78e6b21 commit 63a1a42

File tree

7 files changed

+76
-58
lines changed

7 files changed

+76
-58
lines changed

modules/notification/ui/ui.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ func (ns *notificationService) NotifyIssueChangeStatus(ctx context.Context, doer
9797
_ = ns.issueQueue.Push(issueNotificationOpts{
9898
IssueID: issue.ID,
9999
NotificationAuthorID: doer.ID,
100+
CommentID: actionComment.ID,
100101
})
101102
}
102103

modules/util/io.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package util
55

66
import (
7+
"errors"
78
"io"
89
)
910

@@ -17,3 +18,24 @@ func ReadAtMost(r io.Reader, buf []byte) (n int, err error) {
1718
}
1819
return n, err
1920
}
21+
22+
// ErrNotEmpty is an error reported when there is a non-empty reader
23+
var ErrNotEmpty = errors.New("not-empty")
24+
25+
// IsEmptyReader reads a reader and ensures it is empty
26+
func IsEmptyReader(r io.Reader) (err error) {
27+
var buf [1]byte
28+
29+
for {
30+
n, err := r.Read(buf[:])
31+
if err != nil {
32+
if err == io.EOF {
33+
return nil
34+
}
35+
return err
36+
}
37+
if n > 0 {
38+
return ErrNotEmpty
39+
}
40+
}
41+
}

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ email_not_associate = The email address is not associated with any account.
322322
send_reset_mail = Send Account Recovery Email
323323
reset_password = Account Recovery
324324
invalid_code = Your confirmation code is invalid or has expired.
325+
invalid_password = Your password does not match the password that was used to create the account.
325326
reset_password_helper = Recover Account
326327
reset_password_wrong_user = You are signed in as %s, but the account recovery link is for %s
327328
password_too_short = Password length cannot be less than %d characters.

routers/web/auth/auth.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ func Activate(ctx *context.Context) {
633633
user := user_model.VerifyUserActiveCode(code)
634634
// if code is wrong
635635
if user == nil {
636-
ctx.Data["IsActivateFailed"] = true
636+
ctx.Data["IsCodeInvalid"] = true
637637
ctx.HTML(http.StatusOK, TplActivate)
638638
return
639639
}
@@ -660,7 +660,7 @@ func ActivatePost(ctx *context.Context) {
660660
user := user_model.VerifyUserActiveCode(code)
661661
// if code is wrong
662662
if user == nil {
663-
ctx.Data["IsActivateFailed"] = true
663+
ctx.Data["IsCodeInvalid"] = true
664664
ctx.HTML(http.StatusOK, TplActivate)
665665
return
666666
}
@@ -675,7 +675,7 @@ func ActivatePost(ctx *context.Context) {
675675
return
676676
}
677677
if !user.ValidatePassword(password) {
678-
ctx.Data["IsActivateFailed"] = true
678+
ctx.Data["IsPasswordInvalid"] = true
679679
ctx.HTML(http.StatusOK, TplActivate)
680680
return
681681
}

services/mailer/incoming/incoming_handler.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,17 @@ func (h *ReplyHandler) Handle(ctx context.Context, content *MailContent, doer *u
7171
return err
7272
}
7373

74-
if !perm.CanWriteIssuesOrPulls(issue.IsPull) || issue.IsLocked && !doer.IsAdmin {
74+
// Locked issues require write permissions
75+
if issue.IsLocked && !perm.CanWriteIssuesOrPulls(issue.IsPull) && !doer.IsAdmin {
7576
log.Debug("can't write issue or pull")
7677
return nil
7778
}
7879

80+
if !perm.CanReadIssuesOrPulls(issue.IsPull) {
81+
log.Debug("can't read issue or pull")
82+
return nil
83+
}
84+
7985
switch r := ref.(type) {
8086
case *issues_model.Issue:
8187
attachmentIDs := make([]string, 0, len(content.Attachments))

services/pull/pull.go

Lines changed: 39 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44
package pull
55

66
import (
7-
"bufio"
8-
"bytes"
97
"context"
108
"fmt"
119
"io"
10+
"os"
1211
"regexp"
1312
"strings"
14-
"time"
1513

1614
"code.gitea.io/gitea/models"
1715
"code.gitea.io/gitea/models/db"
@@ -29,6 +27,7 @@ import (
2927
repo_module "code.gitea.io/gitea/modules/repository"
3028
"code.gitea.io/gitea/modules/setting"
3129
"code.gitea.io/gitea/modules/sync"
30+
"code.gitea.io/gitea/modules/util"
3231
issue_service "code.gitea.io/gitea/services/issue"
3332
)
3433

@@ -351,69 +350,56 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
351350
// checkIfPRContentChanged checks if diff to target branch has changed by push
352351
// A commit can be considered to leave the PR untouched if the patch/diff with its merge base is unchanged
353352
func checkIfPRContentChanged(ctx context.Context, pr *issues_model.PullRequest, oldCommitID, newCommitID string) (hasChanged bool, err error) {
354-
if err = pr.LoadHeadRepo(ctx); err != nil {
355-
return false, fmt.Errorf("LoadHeadRepo: %w", err)
356-
} else if pr.HeadRepo == nil {
357-
// corrupt data assumed changed
358-
return true, nil
359-
}
360-
361-
if err = pr.LoadBaseRepo(ctx); err != nil {
362-
return false, fmt.Errorf("LoadBaseRepo: %w", err)
363-
}
364-
365-
headGitRepo, err := git.OpenRepository(ctx, pr.HeadRepo.RepoPath())
353+
tmpBasePath, err := createTemporaryRepo(ctx, pr)
366354
if err != nil {
367-
return false, fmt.Errorf("OpenRepository: %w", err)
368-
}
369-
defer headGitRepo.Close()
370-
371-
// Add a temporary remote.
372-
tmpRemote := "checkIfPRContentChanged-" + fmt.Sprint(time.Now().UnixNano())
373-
if err = headGitRepo.AddRemote(tmpRemote, pr.BaseRepo.RepoPath(), true); err != nil {
374-
return false, fmt.Errorf("AddRemote: %s/%s-%s: %w", pr.HeadRepo.OwnerName, pr.HeadRepo.Name, tmpRemote, err)
355+
log.Error("CreateTemporaryRepo: %v", err)
356+
return false, err
375357
}
376358
defer func() {
377-
if err := headGitRepo.RemoveRemote(tmpRemote); err != nil {
378-
log.Error("checkIfPRContentChanged: RemoveRemote: %s/%s-%s: %v", pr.HeadRepo.OwnerName, pr.HeadRepo.Name, tmpRemote, err)
359+
if err := repo_module.RemoveTemporaryPath(tmpBasePath); err != nil {
360+
log.Error("checkIfPRContentChanged: RemoveTemporaryPath: %s", err)
379361
}
380362
}()
381-
// To synchronize repo and get a base ref
382-
_, base, err := headGitRepo.GetMergeBase(tmpRemote, pr.BaseBranch, pr.HeadBranch)
363+
364+
tmpRepo, err := git.OpenRepository(ctx, tmpBasePath)
383365
if err != nil {
384-
return false, fmt.Errorf("GetMergeBase: %w", err)
366+
return false, fmt.Errorf("OpenRepository: %w", err)
385367
}
368+
defer tmpRepo.Close()
386369

387-
diffBefore := &bytes.Buffer{}
388-
diffAfter := &bytes.Buffer{}
389-
if err := headGitRepo.GetDiffFromMergeBase(base, oldCommitID, diffBefore); err != nil {
390-
// If old commit not found, assume changed.
391-
log.Debug("GetDiffFromMergeBase: %v", err)
392-
return true, nil
393-
}
394-
if err := headGitRepo.GetDiffFromMergeBase(base, newCommitID, diffAfter); err != nil {
395-
// New commit should be found
396-
return false, fmt.Errorf("GetDiffFromMergeBase: %w", err)
370+
// Find the merge-base
371+
_, base, err := tmpRepo.GetMergeBase("", "base", "tracking")
372+
if err != nil {
373+
return false, fmt.Errorf("GetMergeBase: %w", err)
397374
}
398375

399-
diffBeforeLines := bufio.NewScanner(diffBefore)
400-
diffAfterLines := bufio.NewScanner(diffAfter)
401-
402-
for diffBeforeLines.Scan() && diffAfterLines.Scan() {
403-
if strings.HasPrefix(diffBeforeLines.Text(), "index") && strings.HasPrefix(diffAfterLines.Text(), "index") {
404-
// file hashes can change without the diff changing
405-
continue
406-
} else if strings.HasPrefix(diffBeforeLines.Text(), "@@") && strings.HasPrefix(diffAfterLines.Text(), "@@") {
407-
// the location of the difference may change
408-
continue
409-
} else if !bytes.Equal(diffBeforeLines.Bytes(), diffAfterLines.Bytes()) {
376+
cmd := git.NewCommand(ctx, "diff", "--name-only", "-z").AddDynamicArguments(newCommitID, oldCommitID, base)
377+
stdoutReader, stdoutWriter, err := os.Pipe()
378+
if err != nil {
379+
return false, fmt.Errorf("unable to open pipe for to run diff: %w", err)
380+
}
381+
382+
if err := cmd.Run(&git.RunOpts{
383+
Dir: tmpBasePath,
384+
Stdout: stdoutWriter,
385+
PipelineFunc: func(ctx context.Context, cancel context.CancelFunc) error {
386+
_ = stdoutWriter.Close()
387+
defer func() {
388+
_ = stdoutReader.Close()
389+
}()
390+
return util.IsEmptyReader(stdoutReader)
391+
},
392+
}); err != nil {
393+
if err == util.ErrNotEmpty {
410394
return true, nil
411395
}
412-
}
413396

414-
if diffBeforeLines.Scan() || diffAfterLines.Scan() {
415-
// Diffs not of equal length
416-
return true, nil
397+
log.Error("Unable to run diff on %s %s %s in tempRepo for PR[%d]%s/%s...%s/%s: Error: %v",
398+
newCommitID, oldCommitID, base,
399+
pr.ID, pr.BaseRepo.FullName(), pr.BaseBranch, pr.HeadRepo.FullName(), pr.HeadBranch,
400+
err)
401+
402+
return false, fmt.Errorf("Unable to run git diff --name-only -z %s %s %s: %w", newCommitID, oldCommitID, base, err)
417403
}
418404

419405
return false, nil

templates/user/auth/activate.tmpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030
<input id="code" name="code" type="hidden" value="{{.Code}}">
3131
{{else if .IsSendRegisterMail}}
3232
<p>{{.locale.Tr "auth.confirmation_mail_sent_prompt" (.Email|Escape) .ActiveCodeLives | Str2html}}</p>
33-
{{else if .IsActivateFailed}}
33+
{{else if .IsCodeInvalid}}
3434
<p>{{.locale.Tr "auth.invalid_code"}}</p>
35+
{{else if .IsPasswordInvalid}}
36+
<p>{{.locale.Tr "auth.invalid_password"}}</p>
3537
{{else if .ManualActivationOnly}}
3638
<p class="center">{{.locale.Tr "auth.manual_activation_only"}}</p>
3739
{{else}}

0 commit comments

Comments
 (0)