mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-25 09:54:46 +02:00
Merge remote-tracking branch 'upstream/main' into limit-repo-size
This commit is contained in:
@@ -21,35 +21,60 @@ func CreateCommitStatus(ctx context.Context, job *actions_model.ActionRunJob) er
|
||||
}
|
||||
|
||||
run := job.Run
|
||||
if run.Event != webhook_module.HookEventPush {
|
||||
var (
|
||||
sha string
|
||||
creatorID int64
|
||||
)
|
||||
|
||||
switch run.Event {
|
||||
case webhook_module.HookEventPush:
|
||||
payload, err := run.GetPushEventPayload()
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetPushEventPayload: %w", err)
|
||||
}
|
||||
|
||||
// Since the payload comes from json data, we should check if it's broken, or it will cause panic
|
||||
switch {
|
||||
case payload.Repo == nil:
|
||||
return fmt.Errorf("repo is missing in event payload")
|
||||
case payload.Pusher == nil:
|
||||
return fmt.Errorf("pusher is missing in event payload")
|
||||
case payload.HeadCommit == nil:
|
||||
return fmt.Errorf("head commit is missing in event payload")
|
||||
}
|
||||
|
||||
sha = payload.HeadCommit.ID
|
||||
creatorID = payload.Pusher.ID
|
||||
case webhook_module.HookEventPullRequest:
|
||||
payload, err := run.GetPullRequestEventPayload()
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetPullRequestEventPayload: %w", err)
|
||||
}
|
||||
|
||||
switch {
|
||||
case payload.PullRequest == nil:
|
||||
return fmt.Errorf("pull request is missing in event payload")
|
||||
case payload.PullRequest.Head == nil:
|
||||
return fmt.Errorf("head of pull request is missing in event payload")
|
||||
case payload.PullRequest.Head.Repository == nil:
|
||||
return fmt.Errorf("head repository of pull request is missing in event payload")
|
||||
case payload.PullRequest.Head.Repository.Owner == nil:
|
||||
return fmt.Errorf("owner of head repository of pull request is missing in evnt payload")
|
||||
}
|
||||
|
||||
sha = payload.PullRequest.Head.Sha
|
||||
creatorID = payload.PullRequest.Head.Repository.Owner.ID
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
|
||||
payload, err := run.GetPushEventPayload()
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetPushEventPayload: %w", err)
|
||||
}
|
||||
|
||||
// Since the payload comes from json data, we should check if it's broken, or it will cause panic
|
||||
switch {
|
||||
case payload.Repo == nil:
|
||||
return fmt.Errorf("repo is missing in event payload")
|
||||
case payload.Pusher == nil:
|
||||
return fmt.Errorf("pusher is missing in event payload")
|
||||
case payload.HeadCommit == nil:
|
||||
return fmt.Errorf("head commit is missing in event payload")
|
||||
}
|
||||
|
||||
creator, err := user_model.GetUserByID(ctx, payload.Pusher.ID)
|
||||
repo := run.Repo
|
||||
ctxname := job.Name
|
||||
state := toCommitStatus(job.Status)
|
||||
creator, err := user_model.GetUserByID(ctx, creatorID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetUserByID: %w", err)
|
||||
}
|
||||
|
||||
repo := run.Repo
|
||||
sha := payload.HeadCommit.ID
|
||||
ctxname := job.Name
|
||||
state := toCommitStatus(job.Status)
|
||||
|
||||
if statuses, _, err := git_model.GetLatestCommitStatus(ctx, repo.ID, sha, db.ListOptions{}); err == nil {
|
||||
for _, v := range statuses {
|
||||
if v.Context == ctxname {
|
||||
@@ -65,14 +90,14 @@ func CreateCommitStatus(ctx context.Context, job *actions_model.ActionRunJob) er
|
||||
|
||||
if err := git_model.NewCommitStatus(ctx, git_model.NewCommitStatusOptions{
|
||||
Repo: repo,
|
||||
SHA: payload.HeadCommit.ID,
|
||||
SHA: sha,
|
||||
Creator: creator,
|
||||
CommitStatus: &git_model.CommitStatus{
|
||||
SHA: sha,
|
||||
TargetURL: run.Link(),
|
||||
Description: "",
|
||||
Context: ctxname,
|
||||
CreatorID: payload.Pusher.ID,
|
||||
CreatorID: creatorID,
|
||||
State: state,
|
||||
},
|
||||
}); err != nil {
|
||||
|
||||
@@ -226,8 +226,8 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
|
||||
}
|
||||
|
||||
// UserNameChanged handle user name change for agit flow pull
|
||||
func UserNameChanged(user *user_model.User, newName string) error {
|
||||
pulls, err := issues_model.GetAllUnmergedAgitPullRequestByPoster(user.ID)
|
||||
func UserNameChanged(ctx context.Context, user *user_model.User, newName string) error {
|
||||
pulls, err := issues_model.GetAllUnmergedAgitPullRequestByPoster(ctx, user.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -38,6 +38,17 @@ func ToEmail(email *user_model.EmailAddress) *api.Email {
|
||||
}
|
||||
}
|
||||
|
||||
// ToEmail convert models.EmailAddress to api.Email
|
||||
func ToEmailSearch(email *user_model.SearchEmailResult) *api.Email {
|
||||
return &api.Email{
|
||||
Email: email.Email,
|
||||
Verified: email.IsActivated,
|
||||
Primary: email.IsPrimary,
|
||||
UserID: email.UID,
|
||||
UserName: email.Name,
|
||||
}
|
||||
}
|
||||
|
||||
// ToBranch convert a git.Commit and git.Branch to an api.Branch
|
||||
func ToBranch(ctx context.Context, repo *repo_model.Repository, b *git.Branch, c *git.Commit, bp *git_model.ProtectedBranch, user *user_model.User, isRepoAdmin bool) (*api.Branch, error) {
|
||||
if bp == nil {
|
||||
|
||||
@@ -100,6 +100,21 @@ func innerToRepo(ctx context.Context, repo *repo_model.Repository, mode perm.Acc
|
||||
hasProjects = true
|
||||
}
|
||||
|
||||
hasReleases := false
|
||||
if _, err := repo.GetUnit(ctx, unit_model.TypeReleases); err == nil {
|
||||
hasReleases = true
|
||||
}
|
||||
|
||||
hasPackages := false
|
||||
if _, err := repo.GetUnit(ctx, unit_model.TypePackages); err == nil {
|
||||
hasPackages = true
|
||||
}
|
||||
|
||||
hasActions := false
|
||||
if _, err := repo.GetUnit(ctx, unit_model.TypeActions); err == nil {
|
||||
hasActions = true
|
||||
}
|
||||
|
||||
if err := repo.LoadOwner(ctx); err != nil {
|
||||
return nil
|
||||
}
|
||||
@@ -174,6 +189,9 @@ func innerToRepo(ctx context.Context, repo *repo_model.Repository, mode perm.Acc
|
||||
InternalTracker: internalTracker,
|
||||
HasWiki: hasWiki,
|
||||
HasProjects: hasProjects,
|
||||
HasReleases: hasReleases,
|
||||
HasPackages: hasPackages,
|
||||
HasActions: hasActions,
|
||||
ExternalWiki: externalWiki,
|
||||
HasPullRequests: hasPullRequests,
|
||||
IgnoreWhitespaceConflicts: ignoreWhitespaceConflicts,
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
type PackageCleanupRuleForm struct {
|
||||
ID int64
|
||||
Enabled bool
|
||||
Type string `binding:"Required;In(cargo,chef,composer,conan,conda,container,generic,helm,maven,npm,nuget,pub,pypi,rubygems,vagrant)"`
|
||||
Type string `binding:"Required;In(cargo,chef,composer,conan,conda,container,generic,helm,maven,npm,nuget,pub,pypi,rubygems,swift,vagrant)"`
|
||||
KeepCount int `binding:"In(0,1,5,10,25,50,100)"`
|
||||
KeepPattern string `binding:"RegexPattern"`
|
||||
RemoveDays int `binding:"In(0,7,14,30,60,90,180)"`
|
||||
|
||||
@@ -865,8 +865,8 @@ func (g *GiteaLocalUploader) CreateReviews(reviews ...*base.Review) error {
|
||||
_, _, line, _ = git.ParseDiffHunkString(comment.DiffHunk)
|
||||
}
|
||||
|
||||
// SECURITY: The TreePath must be cleaned!
|
||||
comment.TreePath = util.CleanPath(comment.TreePath)
|
||||
// SECURITY: The TreePath must be cleaned! use relative path
|
||||
comment.TreePath = util.PathJoinRel(comment.TreePath)
|
||||
|
||||
var patch string
|
||||
reader, writer := io.Pipe()
|
||||
|
||||
@@ -8,8 +8,6 @@ import (
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
packages_model "code.gitea.io/gitea/models/packages"
|
||||
packages_module "code.gitea.io/gitea/modules/packages"
|
||||
@@ -33,7 +31,7 @@ type BlobUploader struct {
|
||||
}
|
||||
|
||||
func buildFilePath(id string) string {
|
||||
return filepath.Join(setting.Packages.ChunkedUploadPath, util.CleanPath(strings.ReplaceAll(id, "\\", "/")))
|
||||
return util.FilePathJoinAbs(setting.Packages.ChunkedUploadPath, id)
|
||||
}
|
||||
|
||||
// NewBlobUploader creates a new blob uploader for the given id
|
||||
|
||||
@@ -361,6 +361,8 @@ func CheckSizeQuotaExceeded(ctx context.Context, doer, owner *user_model.User, p
|
||||
typeSpecificSize = setting.Packages.LimitSizePyPI
|
||||
case packages_model.TypeRubyGems:
|
||||
typeSpecificSize = setting.Packages.LimitSizeRubyGems
|
||||
case packages_model.TypeSwift:
|
||||
typeSpecificSize = setting.Packages.LimitSizeSwift
|
||||
case packages_model.TypeVagrant:
|
||||
typeSpecificSize = setting.Packages.LimitSizeVagrant
|
||||
}
|
||||
|
||||
@@ -274,9 +274,12 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
|
||||
continue
|
||||
}
|
||||
|
||||
// If the PR is closed, someone still push some commits to the PR,
|
||||
// 1. We will insert comments of commits, but hidden until the PR is reopened.
|
||||
// 2. We won't send any notification.
|
||||
AddToTaskQueue(pr)
|
||||
comment, err := CreatePushPullComment(ctx, doer, pr, oldCommitID, newCommitID)
|
||||
if err == nil && comment != nil {
|
||||
if err == nil && comment != nil && !pr.Issue.IsClosed {
|
||||
notification.NotifyPullRequestPushCommits(ctx, doer, pr, comment)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,7 +214,9 @@ func GetContents(ctx context.Context, repo *repo_model.Repository, treePath, ref
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
contentsResponse.SubmoduleGitURL = &submodule.URL
|
||||
if submodule != nil && submodule.URL != "" {
|
||||
contentsResponse.SubmoduleGitURL = &submodule.URL
|
||||
}
|
||||
}
|
||||
// Handle links
|
||||
if entry.IsRegular() || entry.IsLink() {
|
||||
|
||||
@@ -129,7 +129,7 @@ func GetAuthorAndCommitterUsers(author, committer *IdentityOptions, doer *user_m
|
||||
// CleanUploadFileName Trims a filename and returns empty string if it is a .git directory
|
||||
func CleanUploadFileName(name string) string {
|
||||
// Rebase the filename
|
||||
name = strings.Trim(util.CleanPath(name), "/")
|
||||
name = util.PathJoinRel(name)
|
||||
// Git disallows any filenames to have a .git directory in them.
|
||||
for _, part := range strings.Split(name, "/") {
|
||||
if strings.ToLower(part) == ".git" {
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
// Copyright 2023 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/services/agit"
|
||||
container_service "code.gitea.io/gitea/services/packages/container"
|
||||
)
|
||||
|
||||
func renameUser(ctx context.Context, u *user_model.User, newUserName string) error {
|
||||
if u.IsOrganization() {
|
||||
return fmt.Errorf("cannot rename organization")
|
||||
}
|
||||
|
||||
if err := user_model.ChangeUserName(ctx, u, newUserName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := agit.UserNameChanged(ctx, u, newUserName); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := container_service.UpdateRepositoryNames(ctx, u, newUserName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
u.Name = newUserName
|
||||
u.LowerName = strings.ToLower(newUserName)
|
||||
if err := user_model.UpdateUser(ctx, u, false); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Trace("User name changed: %s -> %s", u.Name, newUserName)
|
||||
return nil
|
||||
}
|
||||
@@ -27,6 +27,22 @@ import (
|
||||
"code.gitea.io/gitea/services/packages"
|
||||
)
|
||||
|
||||
// RenameUser renames a user
|
||||
func RenameUser(ctx context.Context, u *user_model.User, newUserName string) error {
|
||||
ctx, committer, err := db.TxContext(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer committer.Close()
|
||||
if err := renameUser(ctx, u, newUserName); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := committer.Commit(); err != nil {
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// DeleteUser completely and permanently deletes everything of a user,
|
||||
// but issues/comments/pulls will be kept and shown as someone has been deleted,
|
||||
// unless the user is younger than USER_DELETE_WITH_COMMENTS_MAX_DAYS.
|
||||
|
||||
Reference in New Issue
Block a user