diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml index 845dae7fc1..f783d58187 100644 --- a/models/fixtures/repository.yml +++ b/models/fixtures/repository.yml @@ -26,7 +26,7 @@ fork_id: 0 is_template: false template_id: 0 - size: 7320 + size: 7597 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false diff --git a/modules/migration/pullrequest.go b/modules/migration/pullrequest.go index 4e7500f0d6..1435991bd2 100644 --- a/modules/migration/pullrequest.go +++ b/modules/migration/pullrequest.go @@ -45,7 +45,7 @@ func (p *PullRequest) GetContext() DownloaderContext { return p.Context } // IsForkPullRequest returns true if the pull request from a forked repository but not the same repository func (p *PullRequest) IsForkPullRequest() bool { - return p.Head.RepoPath() != p.Base.RepoPath() + return p.Head.RepoFullName() != p.Base.RepoFullName() } // GetGitRefName returns pull request relative path to head @@ -62,8 +62,8 @@ type PullRequestBranch struct { OwnerName string `yaml:"owner_name"` } -// RepoPath returns pull request repo path -func (p PullRequestBranch) RepoPath() string { +// RepoFullName returns pull request repo full name +func (p PullRequestBranch) RepoFullName() string { return fmt.Sprintf("%s/%s", p.OwnerName, p.RepoName) } diff --git a/release-notes/5109.md b/release-notes/5109.md new file mode 100644 index 0000000000..b3aecd8100 --- /dev/null +++ b/release-notes/5109.md @@ -0,0 +1,2 @@ +fix: [commit](https://codeberg.org/forgejo/forgejo/commit/3ade4d9b2bfa6ae84a1ded932907a53060565575) Don't return 500 if mirror url contains special chars +fix: [commit](https://codeberg.org/forgejo/forgejo/commit/dda53569b1b70507469fc296881eec89606ab9c3) Fix agit automerge diff --git a/routers/web/auth/linkaccount.go b/routers/web/auth/linkaccount.go index f744a57a43..9b0141c14e 100644 --- a/routers/web/auth/linkaccount.go +++ b/routers/web/auth/linkaccount.go @@ -40,6 +40,7 @@ func LinkAccount(ctx *context.Context) { ctx.Data["HcaptchaSitekey"] = setting.Service.HcaptchaSitekey ctx.Data["McaptchaSitekey"] = setting.Service.McaptchaSitekey ctx.Data["McaptchaURL"] = setting.Service.McaptchaURL + ctx.Data["CfTurnstileSitekey"] = setting.Service.CfTurnstileSitekey ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration ctx.Data["AllowOnlyInternalRegistration"] = setting.Service.AllowOnlyInternalRegistration ctx.Data["ShowRegistrationButton"] = false @@ -128,6 +129,7 @@ func LinkAccountPostSignIn(ctx *context.Context) { ctx.Data["HcaptchaSitekey"] = setting.Service.HcaptchaSitekey ctx.Data["McaptchaSitekey"] = setting.Service.McaptchaSitekey ctx.Data["McaptchaURL"] = setting.Service.McaptchaURL + ctx.Data["CfTurnstileSitekey"] = setting.Service.CfTurnstileSitekey ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration ctx.Data["ShowRegistrationButton"] = false @@ -215,6 +217,7 @@ func LinkAccountPostRegister(ctx *context.Context) { ctx.Data["HcaptchaSitekey"] = setting.Service.HcaptchaSitekey ctx.Data["McaptchaSitekey"] = setting.Service.McaptchaSitekey ctx.Data["McaptchaURL"] = setting.Service.McaptchaURL + ctx.Data["CfTurnstileSitekey"] = setting.Service.CfTurnstileSitekey ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration ctx.Data["ShowRegistrationButton"] = false diff --git a/routers/web/auth/openid.go b/routers/web/auth/openid.go index 2143b8096a..83268faacb 100644 --- a/routers/web/auth/openid.go +++ b/routers/web/auth/openid.go @@ -307,6 +307,7 @@ func RegisterOpenID(ctx *context.Context) { ctx.Data["RecaptchaURL"] = setting.Service.RecaptchaURL ctx.Data["McaptchaSitekey"] = setting.Service.McaptchaSitekey ctx.Data["McaptchaURL"] = setting.Service.McaptchaURL + ctx.Data["CfTurnstileSitekey"] = setting.Service.CfTurnstileSitekey ctx.Data["OpenID"] = oid userName, _ := ctx.Session.Get("openid_determined_username").(string) if userName != "" { diff --git a/routers/web/repo/setting/setting.go b/routers/web/repo/setting/setting.go index 32e1d99e24..f6a372117f 100644 --- a/routers/web/repo/setting/setting.go +++ b/routers/web/repo/setting/setting.go @@ -481,7 +481,8 @@ func SettingsPost(ctx *context.Context) { } remoteAddress, err := util.SanitizeURL(address) if err != nil { - ctx.ServerError("SanitizeURL", err) + ctx.Data["Err_MirrorAddress"] = true + handleSettingRemoteAddrError(ctx, err, form) return } pullMirror.RemoteAddress = remoteAddress @@ -667,7 +668,8 @@ func SettingsPost(ctx *context.Context) { remoteAddress, err := util.SanitizeURL(address) if err != nil { - ctx.ServerError("SanitizeURL", err) + ctx.Data["Err_PushMirrorAddress"] = true + handleSettingRemoteAddrError(ctx, err, form) return } diff --git a/services/actions/notifier.go b/services/actions/notifier.go index 1166bbbfd2..e97afad990 100644 --- a/services/actions/notifier.go +++ b/services/actions/notifier.go @@ -396,7 +396,7 @@ func (n *actionsNotifier) ForkRepository(ctx context.Context, doer *user_model.U // Add to hook queue for created repo after session commit. if u.IsOrganization() { newNotifyInput(repo, doer, webhook_module.HookEventRepository). - WithRef(oldRepo.DefaultBranch). + WithRef(git.RefNameFromBranch(oldRepo.DefaultBranch).String()). WithPayload(&api.RepositoryPayload{ Action: api.HookRepoCreated, Repository: convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm_model.AccessModeOwner}), diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go index 86897d5cba..751b896162 100644 --- a/services/actions/notifier_helper.go +++ b/services/actions/notifier_helper.go @@ -69,7 +69,7 @@ type notifyInput struct { Event webhook_module.HookEventType // optional - Ref string + Ref git.RefName Payload api.Payloader PullRequest *issues_model.PullRequest } @@ -93,7 +93,7 @@ func (input *notifyInput) WithDoer(doer *user_model.User) *notifyInput { } func (input *notifyInput) WithRef(ref string) *notifyInput { - input.Ref = ref + input.Ref = git.RefName(ref) return input } @@ -105,7 +105,7 @@ func (input *notifyInput) WithPayload(payload api.Payloader) *notifyInput { func (input *notifyInput) WithPullRequest(pr *issues_model.PullRequest) *notifyInput { input.PullRequest = pr if input.Ref == "" { - input.Ref = pr.GetGitRefName() + input.Ref = git.RefName(pr.GetGitRefName()) } return input } @@ -148,20 +148,25 @@ func notify(ctx context.Context, input *notifyInput) error { defer gitRepo.Close() ref := input.Ref - if ref != input.Repo.DefaultBranch && actions_module.IsDefaultBranchWorkflow(input.Event) { + if ref.BranchName() != input.Repo.DefaultBranch && actions_module.IsDefaultBranchWorkflow(input.Event) { if ref != "" { log.Warn("Event %q should only trigger workflows on the default branch, but its ref is %q. Will fall back to the default branch", input.Event, ref) } - ref = input.Repo.DefaultBranch + ref = git.RefNameFromBranch(input.Repo.DefaultBranch) } if ref == "" { log.Warn("Ref of event %q is empty, will fall back to the default branch", input.Event) - ref = input.Repo.DefaultBranch + ref = git.RefNameFromBranch(input.Repo.DefaultBranch) + } + + commitID, err := gitRepo.GetRefCommitID(ref.String()) + if err != nil { + return fmt.Errorf("gitRepo.GetRefCommitID: %w", err) } // Get the commit object for the ref - commit, err := gitRepo.GetCommit(ref) + commit, err := gitRepo.GetCommit(commitID) if err != nil { return fmt.Errorf("gitRepo.GetCommit: %w", err) } @@ -177,7 +182,7 @@ func notify(ctx context.Context, input *notifyInput) error { var detectedWorkflows []*actions_module.DetectedWorkflow actionsConfig := input.Repo.MustGetUnit(ctx, unit_model.TypeActions).ActionsConfig() - shouldDetectSchedules := input.Event == webhook_module.HookEventPush && git.RefName(input.Ref).BranchName() == input.Repo.DefaultBranch + shouldDetectSchedules := input.Event == webhook_module.HookEventPush && input.Ref.BranchName() == input.Repo.DefaultBranch workflows, schedules, err := actions_module.DetectWorkflows(gitRepo, commit, input.Event, input.Payload, @@ -235,12 +240,12 @@ func notify(ctx context.Context, input *notifyInput) error { } if shouldDetectSchedules { - if err := handleSchedules(ctx, schedules, commit, input, ref); err != nil { + if err := handleSchedules(ctx, schedules, commit, input, ref.String()); err != nil { return err } } - return handleWorkflows(ctx, detectedWorkflows, commit, input, ref) + return handleWorkflows(ctx, detectedWorkflows, commit, input, ref.String()) } func SkipPullRequestEvent(ctx context.Context, event webhook_module.HookEventType, repoID int64, commitSHA string) bool { diff --git a/services/automerge/automerge.go b/services/automerge/automerge.go index 9729616033..a1ee204882 100644 --- a/services/automerge/automerge.go +++ b/services/automerge/automerge.go @@ -245,9 +245,21 @@ func handlePullRequestAutoMerge(pullID int64, sha string) { defer headGitRepo.Close() } - headBranchExist := headGitRepo.IsBranchExist(pr.HeadBranch) - if pr.HeadRepo == nil || !headBranchExist { - log.Warn("Head branch of auto merge %-v does not exist [HeadRepoID: %d, Branch: %s]", pr, pr.HeadRepoID, pr.HeadBranch) + switch pr.Flow { + case issues_model.PullRequestFlowGithub: + headBranchExist := headGitRepo.IsBranchExist(pr.HeadBranch) + if pr.HeadRepo == nil || !headBranchExist { + log.Warn("Head branch of auto merge %-v does not exist [HeadRepoID: %d, Branch: %s]", pr, pr.HeadRepoID, pr.HeadBranch) + return + } + case issues_model.PullRequestFlowAGit: + headBranchExist := git.IsReferenceExist(ctx, baseGitRepo.Path, pr.GetGitRefName()) + if !headBranchExist { + log.Warn("Head branch of auto merge %-v does not exist [HeadRepoID: %d, Branch(Agit): %s]", pr, pr.HeadRepoID, pr.HeadBranch) + return + } + default: + log.Error("wrong flow type %d", pr.Flow) return } diff --git a/templates/repo/branch/list.tmpl b/templates/repo/branch/list.tmpl index e2c7c6f186..f5bffb097e 100644 --- a/templates/repo/branch/list.tmpl +++ b/templates/repo/branch/list.tmpl @@ -20,9 +20,11 @@
{{svg "octicon-git-commit" 16 "tw-mr-1"}}{{ShortSha .DefaultBranchBranch.DBBranch.CommitID}} · · {{ctx.Locale.Tr "org.repo_updated" (TimeSince .DefaultBranchBranch.DBBranch.CommitTime.AsTime ctx.Locale)}} {{if .DefaultBranchBranch.DBBranch.Pusher}} {{template "shared/user/avatarlink" dict "user" .DefaultBranchBranch.DBBranch.Pusher}}{{template "shared/user/namelink" .DefaultBranchBranch.DBBranch.Pusher}}{{end}}
@@ -39,7 +41,7 @@ {{end}} {{if .EnableFeed}} - {{svg "octicon-rss"}} + {{svg "octicon-rss"}} {{end}} {{if not $.DisableDownloadSourceArchives}}{{ctx.Locale.Tr "repo.branch.deleted_by" .DBBranch.DeletedBy.Name}} {{TimeSinceUnix .DBBranch.DeletedUnix ctx.Locale}}
{{else}}{{svg "octicon-git-commit" 16 "tw-mr-1"}}{{ShortSha .DBBranch.CommitID}} · · {{ctx.Locale.Tr "org.repo_updated" (TimeSince .DBBranch.CommitTime.AsTime ctx.Locale)}} {{if .DBBranch.Pusher}} {{template "shared/user/avatarlink" dict "user" .DBBranch.Pusher}} {{template "shared/user/namelink" .DBBranch.Pusher}}{{end}}
@@ -158,7 +162,7 @@ {{end}} {{if $.EnableFeed}} - {{svg "octicon-rss"}} + {{svg "octicon-rss"}} {{end}} {{if and (not .DBBranch.IsDeleted) (not $.DisableDownloadSourceArchives)}}