Skip to content

Commit

Permalink
Merge tag 'refs/tags/v1.21.10' into release/v1.21-tk
Browse files Browse the repository at this point in the history
v1.21.10
* BUGFIXES
  * Fix Add/Remove WIP on pull request title failure (go-gitea#29999) (go-gitea#30066)
  * Fix misuse of `TxContext` (go-gitea#30061) (go-gitea#30062)
  * Respect DEFAULT_ORG_MEMBER_VISIBLE setting when adding creator to org (go-gitea#30013) (go-gitea#30035)
  * Escape paths for find file correctly (go-gitea#30026) (go-gitea#30031)
  * Remove duplicate option in admin screen and now-unused translation keys (go-gitea#28492) (go-gitea#30024)
  * Fix manual merge form and 404 page templates (go-gitea#30000)

# gpg: Signature made Tue, Mar 26, 2024  7:48:36 AM
# gpg:                using EDDSA key 8722B61D72341082553B201CB8BE6D610E61C862
# gpg: Can't check signature: No public key
  • Loading branch information
TKaxv-7S committed Apr 10, 2024
2 parents 6ea0f04 + d6b0d0e commit 37da8c7
Show file tree
Hide file tree
Showing 71 changed files with 1,354 additions and 509 deletions.
43 changes: 43 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,49 @@ This changelog goes through all the changes that have been made in each release
without substantial changes to our git log; to see the highlights of what has
been added to each release, please refer to the [blog](https://blog.gitea.com).

## [1.21.10](https://github.com/go-gitea/gitea/releases/tag/1.21.10) - 2024-03-25

* BUGFIXES
* Fix Add/Remove WIP on pull request title failure (#29999) (#30066)
* Fix misuse of `TxContext` (#30061) (#30062)
* Respect DEFAULT_ORG_MEMBER_VISIBLE setting when adding creator to org (#30013) (#30035)
* Escape paths for find file correctly (#30026) (#30031)
* Remove duplicate option in admin screen and now-unused translation keys (#28492) (#30024)
* Fix manual merge form and 404 page templates (#30000)

## [1.21.9](https://github.com/go-gitea/gitea/releases/tag/1.21.9) - 2024-03-21

* PERFORMANCE
* Only do counting when count_only=true for repo dashboard (#29884) (#29905)
* Add cache for dashboard commit status (#29932)
* ENHANCEMENT
* Make runs-on support variable expression (#29468) (#29782)
* Show Actions post step when it's running (#29926) (#29928)
* BUGFIXES
* Fix PR creation via API between branches of the same repo with head field namespaced (#26986) (#29857)
* Fix and rewrite markup anchor processing (#29931) (#29946)
* Notify reviewers added via CODEOWNERS (#29842) (#29902)
* Fix template error when comment review doesn't exist (#29888) (#29889)
* Fix user id column case (#29863) (#29867)
* Make meilisearch do exact search for issues (#29740 & #29671) (#29846)
* Fix the `for` attribute not pointing to the ID of the color picker (#29813) (#29815)
* Fix codeowner detected diff base branch to mergebase (#29783) (#29807)
* Fix Safari spinner rendering (#29801) (#29802)
* Fix missing translation on milestones (#29785) (#29789)
* Fix user router possible panic (#29751) (#29786)
* Fix possible NPE in ToPullReviewList (#29759) (#29775)
* Fix the wrong default value of ENABLE_OPENID_SIGNIN on docs (#29925) (#29927)
* Solving the issue of UI disruption when the review is deleted without refreshing (#29951) (#29968)
* Fix loadOneBranch panic (#29938) (#29939)
* Fix invalid link of the commit status when ref is tagged (#29752) (#29908)
* Editor error message misleading due to re-used key. (#29859) (#29876)
* Fix double border and border-radius on empty action steps (#29845) (#29850)
* Use `Temporal.PlainDate` for absolute dates (#29804) (#29808)
* Fix incorrect package link method calls in templates (#29580) (#29764)
* Fix the bug that the user may log out if GetUserByID returns unknown error (#29962) (#29964)
* Performance improvements for pull request list page (#29900) (#29972)
* Fix bugs in rerunning jobs (#29983) (#29955)

## [1.21.8](https://github.com/go-gitea/gitea/releases/tag/1.21.8) - 2024-03-12

* SECURITY
Expand Down
2 changes: 1 addition & 1 deletion docs/content/administration/config-cheat-sheet.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ And the following unique queues:

## OpenID (`openid`)

- `ENABLE_OPENID_SIGNIN`: **false**: Allow authentication in via OpenID.
- `ENABLE_OPENID_SIGNIN`: **true**: Allow authentication in via OpenID.
- `ENABLE_OPENID_SIGNUP`: **! DISABLE\_REGISTRATION**: Allow registering via OpenID.
- `WHITELISTED_URIS`: **_empty_**: If non-empty, list of POSIX regex patterns matching
OpenID URI's to permit.
Expand Down
2 changes: 1 addition & 1 deletion docs/content/administration/config-cheat-sheet.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ Gitea 创建以下非唯一队列:

## OpenID (`openid`)

- `ENABLE_OPENID_SIGNIN`: **false**:允许通过OpenID进行身份验证。
- `ENABLE_OPENID_SIGNIN`: **true**:允许通过OpenID进行身份验证。
- `ENABLE_OPENID_SIGNUP`: **! DISABLE\_REGISTRATION**:允许通过OpenID进行注册。
- `WHITELISTED_URIS`: **_empty_**:如果非空,是一组匹配OpenID URI的POSIX正则表达式模式,用于允许访问。
- `BLACKLISTED_URIS`: **_empty_**:如果非空,是一组匹配OpenID URI的POSIX正则表达式模式,用于阻止访问。
Expand Down
29 changes: 29 additions & 0 deletions models/activities/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"

"xorm.io/builder"
"xorm.io/xorm"
Expand Down Expand Up @@ -821,3 +822,31 @@ func UpdateNotificationStatuses(ctx context.Context, user *user_model.User, curr
Update(n)
return err
}

// LoadIssuePullRequests loads all issues' pull requests if possible
func (nl NotificationList) LoadIssuePullRequests(ctx context.Context) error {
issues := make(map[int64]*issues_model.Issue, len(nl))
for _, notification := range nl {
if notification.Issue != nil && notification.Issue.IsPull && notification.Issue.PullRequest == nil {
issues[notification.Issue.ID] = notification.Issue
}
}

if len(issues) == 0 {
return nil
}

pulls, err := issues_model.GetPullRequestByIssueIDs(ctx, util.KeysOfMap(issues))
if err != nil {
return err
}

for _, pull := range pulls {
if issue := issues[pull.IssueID]; issue != nil {
issue.PullRequest = pull
issue.PullRequest.Issue = issue
}
}

return nil
}
10 changes: 10 additions & 0 deletions models/db/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ func (c *halfCommitter) Close() error {

// TxContext represents a transaction Context,
// it will reuse the existing transaction in the parent context or create a new one.
// Some tips to use:
//
// 1 It's always recommended to use `WithTx` in new code instead of `TxContext`, since `WithTx` will handle the transaction automatically.
// 2. To maintain the old code which uses `TxContext`:
// a. Always call `Close()` before returning regardless of whether `Commit()` has been called.
// b. Always call `Commit()` before returning if there are no errors, even if the code did not change any data.
// c. Remember the `Committer` will be a halfCommitter when a transaction is being reused.
// So calling `Commit()` will do nothing, but calling `Close()` without calling `Commit()` will rollback the transaction.
// And all operations submitted by the caller stack will be rollbacked as well, not only the operations in the current function.
// d. It doesn't mean rollback is forbidden, but always do it only when there is an error, and you do want to rollback.
func TxContext(parentCtx context.Context) (*Context, Committer, error) {
if sess, ok := inTransaction(parentCtx); ok {
return newContext(parentCtx, sess, true), &halfCommitter{committer: sess}, nil
Expand Down
8 changes: 8 additions & 0 deletions models/fixtures/comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,11 @@
content: "comment in private pository"
created_unix: 946684811
updated_unix: 946684811

-
id: 9
type: 22 # review
poster_id: 2
issue_id: 2 # in repo_id 1
review_id: 20
created_unix: 946684810
9 changes: 9 additions & 0 deletions models/fixtures/review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,12 @@
content: "review request for user15"
updated_unix: 946684835
created_unix: 946684835

-
id: 20
type: 22
reviewer_id: 1
issue_id: 2
content: "Review Comment"
updated_unix: 946684810
created_unix: 946684810
14 changes: 0 additions & 14 deletions models/issues/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,20 +200,6 @@ func (issue *Issue) IsTimetrackerEnabled(ctx context.Context) bool {
return issue.Repo.IsTimetrackerEnabled(ctx)
}

// GetPullRequest returns the issue pull request
func (issue *Issue) GetPullRequest() (pr *PullRequest, err error) {
if !issue.IsPull {
return nil, fmt.Errorf("Issue is not a pull request")
}

pr, err = GetPullRequestByIssueID(db.DefaultContext, issue.ID)
if err != nil {
return nil, err
}
pr.Issue = issue
return pr, err
}

// LoadPoster loads poster
func (issue *Issue) LoadPoster(ctx context.Context) (err error) {
if issue.Poster == nil && issue.PosterID != 0 {
Expand Down
3 changes: 3 additions & 0 deletions models/issues/issue_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,9 @@ func (issues IssueList) LoadPullRequests(ctx context.Context) error {

for _, issue := range issues {
issue.PullRequest = pullRequestMaps[issue.ID]
if issue.PullRequest != nil {
issue.PullRequest.Issue = issue
}
}
return nil
}
Expand Down
84 changes: 4 additions & 80 deletions models/issues/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,8 +706,8 @@ func (pr *PullRequest) UpdateColsIfNotMerged(ctx context.Context, cols ...string

// IsWorkInProgress determine if the Pull Request is a Work In Progress by its title
// Issue must be set before this method can be called.
func (pr *PullRequest) IsWorkInProgress() bool {
if err := pr.LoadIssue(db.DefaultContext); err != nil {
func (pr *PullRequest) IsWorkInProgress(ctx context.Context) bool {
if err := pr.LoadIssue(ctx); err != nil {
log.Error("LoadIssue: %v", err)
return false
}
Expand Down Expand Up @@ -810,14 +810,14 @@ func UpdateAllowEdits(ctx context.Context, pr *PullRequest) error {
}

// Mergeable returns if the pullrequest is mergeable.
func (pr *PullRequest) Mergeable() bool {
func (pr *PullRequest) Mergeable(ctx context.Context) bool {
// If a pull request isn't mergable if it's:
// - Being conflict checked.
// - Has a conflict.
// - Received a error while being conflict checked.
// - Is a work-in-progress pull request.
return pr.Status != PullRequestStatusChecking && pr.Status != PullRequestStatusConflict &&
pr.Status != PullRequestStatusError && !pr.IsWorkInProgress()
pr.Status != PullRequestStatusError && !pr.IsWorkInProgress(ctx)
}

// HasEnoughApprovals returns true if pr has enough granted approvals.
Expand Down Expand Up @@ -887,82 +887,6 @@ func MergeBlockedByOutdatedBranch(protectBranch *git_model.ProtectedBranch, pr *
return protectBranch.BlockOnOutdatedBranch && pr.CommitsBehind > 0
}

func PullRequestCodeOwnersReview(ctx context.Context, pull *Issue, pr *PullRequest) error {
files := []string{"CODEOWNERS", "docs/CODEOWNERS", ".gitea/CODEOWNERS"}

if pr.IsWorkInProgress() {
return nil
}

if err := pr.LoadBaseRepo(ctx); err != nil {
return err
}

repo, err := git.OpenRepository(ctx, pr.BaseRepo.RepoPath())
if err != nil {
return err
}
defer repo.Close()

branch, err := repo.GetDefaultBranch()
if err != nil {
return err
}

commit, err := repo.GetBranchCommit(branch)
if err != nil {
return err
}

var data string
for _, file := range files {
if blob, err := commit.GetBlobByPath(file); err == nil {
data, err = blob.GetBlobContent(setting.UI.MaxDisplayFileSize)
if err == nil {
break
}
}
}

rules, _ := GetCodeOwnersFromContent(ctx, data)
changedFiles, err := repo.GetFilesChangedBetween(git.BranchPrefix+pr.BaseBranch, pr.GetGitRefName())
if err != nil {
return err
}

uniqUsers := make(map[int64]*user_model.User)
uniqTeams := make(map[string]*org_model.Team)
for _, rule := range rules {
for _, f := range changedFiles {
if (rule.Rule.MatchString(f) && !rule.Negative) || (!rule.Rule.MatchString(f) && rule.Negative) {
for _, u := range rule.Users {
uniqUsers[u.ID] = u
}
for _, t := range rule.Teams {
uniqTeams[fmt.Sprintf("%d/%d", t.OrgID, t.ID)] = t
}
}
}
}

for _, u := range uniqUsers {
if u.ID != pull.Poster.ID {
if _, err := AddReviewRequest(ctx, pull, u, pull.Poster); err != nil {
log.Warn("Failed add assignee user: %s to PR review: %s#%d, error: %s", u.Name, pr.BaseRepo.Name, pr.ID, err)
return err
}
}
}
for _, t := range uniqTeams {
if _, err := AddTeamReviewRequest(ctx, pull, t, pull.Poster); err != nil {
log.Warn("Failed add assignee team: %s to PR review: %s#%d, error: %s", t.Name, pr.BaseRepo.Name, pr.ID, err)
return err
}
}

return nil
}

// GetCodeOwnersFromContent returns the code owners configuration
// Return empty slice if files missing
// Return warning messages on parsing errors
Expand Down
9 changes: 9 additions & 0 deletions models/issues/pull_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,12 @@ func HasMergedPullRequestInRepo(ctx context.Context, repoID, posterID int64) (bo
Limit(1).
Get(new(Issue))
}

// GetPullRequestByIssueIDs returns all pull requests by issue ids
func GetPullRequestByIssueIDs(ctx context.Context, issueIDs []int64) (PullRequestList, error) {
prs := make([]*PullRequest, 0, len(issueIDs))
return prs, db.GetEngine(ctx).
Where("issue_id > 0").
In("issue_id", issueIDs).
Find(&prs)
}
6 changes: 3 additions & 3 deletions models/issues/pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,13 @@ func TestPullRequest_IsWorkInProgress(t *testing.T) {
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2})
pr.LoadIssue(db.DefaultContext)

assert.False(t, pr.IsWorkInProgress())
assert.False(t, pr.IsWorkInProgress(db.DefaultContext))

pr.Issue.Title = "WIP: " + pr.Issue.Title
assert.True(t, pr.IsWorkInProgress())
assert.True(t, pr.IsWorkInProgress(db.DefaultContext))

pr.Issue.Title = "[wip]: " + pr.Issue.Title
assert.True(t, pr.IsWorkInProgress())
assert.True(t, pr.IsWorkInProgress(db.DefaultContext))
}

func TestPullRequest_GetWorkInProgressPrefixWorkInProgress(t *testing.T) {
Expand Down
11 changes: 5 additions & 6 deletions models/issues/review.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,11 @@ type CreateReviewOptions struct {

// IsOfficialReviewer check if at least one of the provided reviewers can make official reviews in issue (counts towards required approvals)
func IsOfficialReviewer(ctx context.Context, issue *Issue, reviewer *user_model.User) (bool, error) {
pr, err := GetPullRequestByIssueID(ctx, issue.ID)
if err != nil {
if err := issue.LoadPullRequest(ctx); err != nil {
return false, err
}

pr := issue.PullRequest
rule, err := git_model.GetFirstMatchProtectedBranchRule(ctx, pr.BaseRepoID, pr.BaseBranch)
if err != nil {
return false, err
Expand Down Expand Up @@ -272,11 +272,10 @@ func IsOfficialReviewer(ctx context.Context, issue *Issue, reviewer *user_model.

// IsOfficialReviewerTeam check if reviewer in this team can make official reviews in issue (counts towards required approvals)
func IsOfficialReviewerTeam(ctx context.Context, issue *Issue, team *organization.Team) (bool, error) {
pr, err := GetPullRequestByIssueID(ctx, issue.ID)
if err != nil {
if err := issue.LoadPullRequest(ctx); err != nil {
return false, err
}
pb, err := git_model.GetFirstMatchProtectedBranchRule(ctx, pr.BaseRepoID, pr.BaseBranch)
pb, err := git_model.GetFirstMatchProtectedBranchRule(ctx, issue.PullRequest.BaseRepoID, issue.PullRequest.BaseBranch)
if err != nil {
return false, err
}
Expand Down Expand Up @@ -622,7 +621,7 @@ func AddReviewRequest(ctx context.Context, issue *Issue, reviewer, doer *user_mo

// skip it when reviewer hase been request to review
if review != nil && review.Type == ReviewTypeRequest {
return nil, nil
return nil, committer.Commit() // still commit the transaction, or committer.Close() will rollback it, even if it's a reused transaction.
}

// if the reviewer is an official reviewer,
Expand Down
5 changes: 3 additions & 2 deletions models/organization/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,9 @@ func CreateOrganization(org *Organization, owner *user_model.User) (err error) {

// Add initial creator to organization and owner team.
if err = db.Insert(ctx, &OrgUser{
UID: owner.ID,
OrgID: org.ID,
UID: owner.ID,
OrgID: org.ID,
IsPublic: setting.Service.DefaultOrgMemberVisible,
}); err != nil {
return fmt.Errorf("insert org-user relation: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions models/user/email_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ func SearchEmails(ctx context.Context, opts *SearchEmailOptions) ([]*SearchEmail
cond = cond.And(builder.Eq{"email_address.is_activated": false})
}

count, err := db.GetEngine(ctx).Join("INNER", "`user`", "`user`.ID = email_address.uid").
count, err := db.GetEngine(ctx).Join("INNER", "`user`", "`user`.id = email_address.uid").
Where(cond).Count(new(EmailAddress))
if err != nil {
return nil, 0, fmt.Errorf("Count: %w", err)
Expand All @@ -507,7 +507,7 @@ func SearchEmails(ctx context.Context, opts *SearchEmailOptions) ([]*SearchEmail
emails := make([]*SearchEmailResult, 0, opts.PageSize)
err = db.GetEngine(ctx).Table("email_address").
Select("email_address.*, `user`.name, `user`.full_name").
Join("INNER", "`user`", "`user`.ID = email_address.uid").
Join("INNER", "`user`", "`user`.id = email_address.uid").
Where(cond).
OrderBy(orderby).
Limit(opts.PageSize, (opts.Page-1)*opts.PageSize).
Expand Down
Loading

0 comments on commit 37da8c7

Please sign in to comment.