From 9b991f2947e923673bf1917ede7e38b71a39afcb Mon Sep 17 00:00:00 2001 From: HoshinoRei <81515470+HoshinoRei@users.noreply.github.com> Date: Sun, 22 Oct 2023 19:37:56 +0800 Subject: [PATCH 0001/1071] Fix an indentation in the Chinese documentation of Act Runner (#27730) In the [English document](https://docs.gitea.com/1.21/usage/actions/act-runner#configuring-cache-when-starting-a-runner-using-docker-image), there is indentation here, but there is no indentation in the Chinese document. --- docs/content/usage/actions/act-runner.zh-cn.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/content/usage/actions/act-runner.zh-cn.md b/docs/content/usage/actions/act-runner.zh-cn.md index f1404bf0b4..11b69960f7 100644 --- a/docs/content/usage/actions/act-runner.zh-cn.md +++ b/docs/content/usage/actions/act-runner.zh-cn.md @@ -208,12 +208,12 @@ services: ```yaml cache: -enabled: true -dir: "" -# 使用步骤 1. 获取的 LAN IP -host: "192.168.8.17" -# 使用步骤 2. 获取的端口号 -port: 8088 + enabled: true + dir: "" + # 使用步骤 1. 获取的 LAN IP + host: "192.168.8.17" + # 使用步骤 2. 获取的端口号 + port: 8088 ``` - 4.启动容器时, 将 Cache 端口映射至主机。 From 16cfa1784402856c7477fefe942d552b49908112 Mon Sep 17 00:00:00 2001 From: Denys Konovalov Date: Sun, 22 Oct 2023 13:59:31 +0200 Subject: [PATCH 0002/1071] fix issues in translation file (#27699) - use correct comment sign for INI (`;`) - remove duplicated `repo.branch.search` key - remove duplicated spaces & similar --- options/locale/locale_en-US.ini | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 84c457e9e8..d34d10566e 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -355,7 +355,6 @@ code_last_indexed_at = Last indexed %s relevant_repositories_tooltip = Repositories that are forks or that have no topic, no icon, and no description are hidden. relevant_repositories = Only relevant repositories are being shown, show unfiltered results. - [auth] create_new_account = Register Account register_helper_msg = Already have an account? Sign in now! @@ -858,7 +857,7 @@ oauth2_client_secret_hint = The secret will not be shown again after you leave o oauth2_application_edit = Edit oauth2_application_create_description = OAuth2 applications gives your third-party application access to user accounts on this instance. oauth2_application_remove_description = Removing an OAuth2 application will prevent it from accessing authorized user accounts on this instance. Continue? -oauth2_application_locked = Gitea pre-registers some OAuth2 applications on startup if enabled in config. To prevent unexpected bahavior, these can neither be edited nor removed. Please refer to the OAuth2 documentation for more information. +oauth2_application_locked = Gitea pre-registers some OAuth2 applications on startup if enabled in config. To prevent unexpected behavior, these can neither be edited nor removed. Please refer to the OAuth2 documentation for more information. authorized_oauth2_applications = Authorized OAuth2 Applications authorized_oauth2_applications_description = You have granted access to your personal Gitea account to these third party applications. Please revoke access for applications you no longer need. @@ -926,7 +925,7 @@ visibility.private = Private visibility.private_tooltip = Visible only to members of organizations you have joined [repo] -new_repo_helper = A repository contains all project files, including revision history. Already hosting one elsewhere? Migrate repository. +new_repo_helper = A repository contains all project files, including revision history. Already hosting one elsewhere? Migrate repository. owner = Owner owner_helper = Some organizations may not show up in the dropdown due to a maximum repository count limit. repo_name = Repository Name @@ -1023,9 +1022,9 @@ tree_path_not_found_branch = Path %[1]s doesn't exist in branch %[2]s tree_path_not_found_tag = Path %[1]s doesn't exist in tag %[2]s transfer.accept = Accept Transfer -transfer.accept_desc = Transfer to "%s" +transfer.accept_desc = Transfer to "%s" transfer.reject = Reject Transfer -transfer.reject_desc = Cancel transfer to "%s" +transfer.reject_desc = Cancel transfer to "%s" transfer.no_permission_to_accept = You do not have permission to accept this transfer. transfer.no_permission_to_reject = You do not have permission to reject this transfer. @@ -1159,7 +1158,7 @@ releases = Releases tag = Tag released_this = released this tagged_this = tagged this -file.title = %s at %s +file.title = %s at %s file_raw = Raw file_history = History file_view_source = View Source @@ -2507,7 +2506,6 @@ release.releases_for = Releases for %s release.tags_for = Tags for %s branch.name = Branch Name -branch.search = Search branches branch.already_exists = A branch named "%s" already exists. branch.delete_head = Delete branch.delete = Delete Branch "%s" @@ -3174,8 +3172,8 @@ monitor.start = Start Time monitor.execute_time = Execution Time monitor.last_execution_result = Result monitor.process.cancel = Cancel process -monitor.process.cancel_desc = Cancelling a process may cause data loss -monitor.process.cancel_notices = Cancel: %s? +monitor.process.cancel_desc = Cancelling a process may cause data loss +monitor.process.cancel_notices = Cancel: %s? monitor.process.children = Children monitor.queues = Queues @@ -3239,7 +3237,7 @@ mirror_sync_create = synced new reference %[3]s to %[3]s from mirror approve_pull_request = `approved %[3]s#%[2]s` reject_pull_request = `suggested changes for %[3]s#%[2]s` -publish_release = `released "%[4]s" at %[3]s` +publish_release = `released "%[4]s" at %[3]s` review_dismissed = `dismissed review from %[4]s for %[3]s#%[2]s` review_dismissed_reason = Reason: create_branch = created branch %[3]s in %[4]s @@ -3565,7 +3563,7 @@ type-3.display_name = Organization Project [git.filemode] changed_filemode = %[1]s → %[2]s -# Ordered by git filemode value, ascending. E.g. directory has "040000", normal file has "100644", … +; Ordered by git filemode value, ascending. E.g. directory has "040000", normal file has "100644", … directory = Directory normal_file = Normal file executable_file = Executable file From e3afe4a248ac3a961f332e2ba221bedafa3dfb7e Mon Sep 17 00:00:00 2001 From: tomholford <16504501+tomholford@users.noreply.github.com> Date: Sun, 22 Oct 2023 05:34:16 -0700 Subject: [PATCH 0003/1071] teams: new View button (#27685) Per the discussion on #22054, the flow for adding a new team member to an org is not intuitive for new Gitea users. The ideal solution would be to add a new button on the Org > Members index view (see the screenshot mockup in the issue description). However, this would require a refactor of the UX for the flow. The current flow has an implicit context of which team within the org the new member is being added to ('Owners' by default). From the Members index, there is no implicit context; the flow would have to add a picker for which team the new member should be added to. So, as a stopgap, this change simply adds a button to the Teams index page that performs the same action as clicking on the title of the team (a behavior that is currently too obscure as indicated in the comments on the issue). This should reduce support burden and serve as a decent temporary measure until the Add Member flow is refactored. --------- Co-authored-by: tomholford --- options/locale/locale_en-US.ini | 1 + templates/org/team/teams.tmpl | 1 + 2 files changed, 2 insertions(+) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index d34d10566e..b0c21816ae 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -91,6 +91,7 @@ remove = Remove remove_all = Remove All remove_label_str = Remove item "%s" edit = Edit +view = View enabled = Enabled disabled = Disabled diff --git a/templates/org/team/teams.tmpl b/templates/org/team/teams.tmpl index 6b16da9d11..9723294fd6 100644 --- a/templates/org/team/teams.tmpl +++ b/templates/org/team/teams.tmpl @@ -16,6 +16,7 @@
{{.Name}}
+ {{ctx.Locale.Tr "view"}} {{if .IsMember ctx $.SignedUser.ID}}
{{range .LanguageStats}} -
+
{{end}}
{{end}} diff --git a/web_src/js/modules/tippy.js b/web_src/js/modules/tippy.js index 4eed0aa4bb..ec7ee2141f 100644 --- a/web_src/js/modules/tippy.js +++ b/web_src/js/modules/tippy.js @@ -1,4 +1,4 @@ -import tippy from 'tippy.js'; +import tippy, {followCursor} from 'tippy.js'; const visibleInstances = new Set(); @@ -35,6 +35,7 @@ export function createTippy(target, opts = {}) { arrow: ``, role: 'menu', // HTML role attribute, only tooltips should use "tooltip" theme: other.role || 'menu', // CSS theme, we support either "tooltip" or "menu" + plugins: [followCursor], ...other, }); @@ -78,6 +79,7 @@ function attachTooltip(target, content = null) { theme: 'tooltip', hideOnClick, placement: target.getAttribute('data-tooltip-placement') || 'top-start', + followCursor: target.getAttribute('data-tooltip-follow-cursor') || false, ...(target.getAttribute('data-tooltip-interactive') === 'true' ? {interactive: true, aria: {content: 'describedby', expanded: false}} : {}), }; From f3956fcb28e665ee7f2773f4ae14842405bb2462 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sun, 22 Oct 2023 22:12:27 +0800 Subject: [PATCH 0005/1071] Fix incorrect ctx usage in defer function (#27740) --- services/task/migrate.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/services/task/migrate.go b/services/task/migrate.go index 475fa7a61b..9cef77a6c8 100644 --- a/services/task/migrate.go +++ b/services/task/migrate.go @@ -42,13 +42,11 @@ func handleCreateError(owner *user_model.User, err error) error { } func runMigrateTask(ctx context.Context, t *admin_model.Task) (err error) { - defer func() { + defer func(ctx context.Context) { if e := recover(); e != nil { err = fmt.Errorf("PANIC whilst trying to do migrate task: %v", e) log.Critical("PANIC during runMigrateTask[%d] by DoerID[%d] to RepoID[%d] for OwnerID[%d]: %v\nStacktrace: %v", t.ID, t.DoerID, t.RepoID, t.OwnerID, e, log.Stack(2)) } - // fixme: Because ctx is canceled here, so the db.DefaultContext is needed. - ctx := db.DefaultContext if err == nil { err = admin_model.FinishMigrateTask(ctx, t) if err == nil { @@ -69,7 +67,7 @@ func runMigrateTask(ctx context.Context, t *admin_model.Task) (err error) { } // then, do not delete the repository, otherwise the users won't be able to see the last error - }() + }(graceful.GetManager().ShutdownContext()) // even if the parent ctx is canceled, this defer-function still needs to update the task record in database if err = t.LoadRepo(ctx); err != nil { return err From 61d94b247ab0c9289cd04253fed78283300e8c5e Mon Sep 17 00:00:00 2001 From: Nanguan Lin <70063547+lng2020@users.noreply.github.com> Date: Mon, 23 Oct 2023 20:34:17 +0800 Subject: [PATCH 0006/1071] Fix `link-action` redirect network error (#27734) image --------- Co-authored-by: 6543 <6543@obermui.de> --- routers/web/repo/milestone.go | 7 ++++--- routers/web/repo/projects.go | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/routers/web/repo/milestone.go b/routers/web/repo/milestone.go index 4db02fce9e..0e6f630747 100644 --- a/routers/web/repo/milestone.go +++ b/routers/web/repo/milestone.go @@ -231,14 +231,15 @@ func EditMilestonePost(ctx *context.Context) { // ChangeMilestoneStatus response for change a milestone's status func ChangeMilestoneStatus(ctx *context.Context) { - toClose := false + var toClose bool switch ctx.Params(":action") { case "open": toClose = false case "close": toClose = true default: - ctx.Redirect(ctx.Repo.RepoLink + "/milestones") + ctx.JSONRedirect(ctx.Repo.RepoLink + "/milestones") + return } id := ctx.ParamsInt64(":id") @@ -250,7 +251,7 @@ func ChangeMilestoneStatus(ctx *context.Context) { } return } - ctx.Redirect(ctx.Repo.RepoLink + "/milestones?state=" + url.QueryEscape(ctx.Params(":action"))) + ctx.JSONRedirect(ctx.Repo.RepoLink + "/milestones?state=" + url.QueryEscape(ctx.Params(":action"))) } // DeleteMilestone delete a milestone diff --git a/routers/web/repo/projects.go b/routers/web/repo/projects.go index ada398fdc8..6417024f8b 100644 --- a/routers/web/repo/projects.go +++ b/routers/web/repo/projects.go @@ -161,14 +161,15 @@ func NewProjectPost(ctx *context.Context) { // ChangeProjectStatus updates the status of a project between "open" and "close" func ChangeProjectStatus(ctx *context.Context) { - toClose := false + var toClose bool switch ctx.Params(":action") { case "open": toClose = false case "close": toClose = true default: - ctx.Redirect(ctx.Repo.RepoLink + "/projects") + ctx.JSONRedirect(ctx.Repo.RepoLink + "/projects") + return } id := ctx.ParamsInt64(":id") @@ -180,7 +181,7 @@ func ChangeProjectStatus(ctx *context.Context) { } return } - ctx.Redirect(ctx.Repo.RepoLink + "/projects?state=" + url.QueryEscape(ctx.Params(":action"))) + ctx.JSONRedirect(ctx.Repo.RepoLink + "/projects?state=" + url.QueryEscape(ctx.Params(":action"))) } // DeleteProject delete a project From 51d1dc22ff94b561b1a3c00f8eb8ac04a4ee2674 Mon Sep 17 00:00:00 2001 From: Nanguan Lin <70063547+lng2020@users.noreply.github.com> Date: Mon, 23 Oct 2023 20:40:33 +0800 Subject: [PATCH 0007/1071] Fix duplicate project board when hitting `enter` key (#27746) When hitting the `enter` key to create a new project column, the request is sent twice because the `submit` event and `key up` event are both triggered. Probably a better solution is to rewrite these parts of the code to avoid using native jQuery but reuse the `form-fetch-action` class. But it's beyond my ability. --- web_src/js/features/repo-projects.js | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/web_src/js/features/repo-projects.js b/web_src/js/features/repo-projects.js index f12d4f234f..5a2a7e72ef 100644 --- a/web_src/js/features/repo-projects.js +++ b/web_src/js/features/repo-projects.js @@ -193,20 +193,6 @@ export function initRepoProject() { const url = $(this).data('url'); createNewColumn(url, columnTitle, projectColorInput); }); - - $('.new-project-column').on('input keyup', (e) => { - const columnTitle = $('#new_project_column'); - const projectColorInput = $('#new_project_column_color_picker'); - if (!columnTitle.val()) { - $('#new_project_column_submit').addClass('disabled'); - return; - } - $('#new_project_column_submit').removeClass('disabled'); - if (e.key === 'Enter') { - const url = $(this).data('url'); - createNewColumn(url, columnTitle, projectColorInput); - } - }); } function setLabelColor(label, color) { From 6352114a77cb67e8797f2c8552328f684092c42d Mon Sep 17 00:00:00 2001 From: Earl Warren <109468362+earl-warren@users.noreply.github.com> Date: Tue, 24 Oct 2023 01:02:00 +0200 Subject: [PATCH 0008/1071] Fix label render containing invalid HTML (#27752) - The label HTML contained a quote that wasn't being closed. Refs: https://codeberg.org/forgejo/forgejo/pulls/1651 (cherry picked from commit e2bc2c9a1fff482c49dbeb3a51e4e1c698bf506c) Co-authored-by: Gusted --- modules/templates/util_render.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/templates/util_render.go b/modules/templates/util_render.go index ed6eae326a..84c3a1587a 100644 --- a/modules/templates/util_render.go +++ b/modules/templates/util_render.go @@ -179,7 +179,7 @@ func RenderLabel(ctx context.Context, label *issues_model.Label) template.HTML { s := fmt.Sprintf(""+ "
%s
"+ - "
%s
"+ + "
%s
"+ "
", description, textColor, scopeColor, scopeText, From def907de7b3cda899846d55f99b0da2640a5274b Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Tue, 24 Oct 2023 10:00:06 +0800 Subject: [PATCH 0009/1071] Fix incorrect "tab" parameter for repo search sub-template (#27755) ![image](https://github.com/go-gitea/gitea/assets/2114189/c546824e-4824-4f4d-bd33-e558c6ddf0ef) ![image](https://github.com/go-gitea/gitea/assets/2114189/713eb72c-22fb-412b-a867-9cccbf7548ec) --- templates/explore/repo_search.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/explore/repo_search.tmpl b/templates/explore/repo_search.tmpl index 31b00d29e3..136d3f8e81 100644 --- a/templates/explore/repo_search.tmpl +++ b/templates/explore/repo_search.tmpl @@ -6,8 +6,8 @@ {{template "shared/searchinput" dict "Value" .Keyword "AutoFocus" true}} {{if .PageIsExploreRepositories}} - {{else}} - + {{else if .TabName}} + {{end}}
From ce83609ff636f4c09d91ac53bee75a350bb571d6 Mon Sep 17 00:00:00 2001 From: silverwind Date: Tue, 24 Oct 2023 04:54:59 +0200 Subject: [PATCH 0010/1071] Upgrade to golangci-lint@v1.55.0 (#27756) https://github.com/golangci/golangci-lint/releases/tag/v1.55.0 --- Makefile | 2 +- models/actions/task.go | 2 +- models/activities/action.go | 3 +- models/issues/review.go | 3 +- modules/activitypub/user_settings.go | 7 +- modules/git/submodule.go | 3 +- modules/lfs/transferadapter_test.go | 5 +- modules/markup/html_test.go | 130 +++++++++++------------ modules/markup/markdown/markdown_test.go | 36 +++---- modules/templates/htmlrenderer.go | 3 +- modules/util/path.go | 3 +- routers/api/v1/repo/pull.go | 3 +- routers/web/repo/cherry_pick.go | 5 +- routers/web/repo/issue_dependency.go | 5 +- routers/web/repo/patch.go | 5 +- services/mailer/mailer.go | 3 +- services/repository/files/temp_repo.go | 3 +- tests/integration/integration_test.go | 3 +- 18 files changed, 105 insertions(+), 119 deletions(-) diff --git a/Makefile b/Makefile index 8e03a71b8d..c38e88a8e0 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ XGO_VERSION := go-1.21.x AIR_PACKAGE ?= github.com/cosmtrek/air@v1.44.0 EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/cmd/editorconfig-checker@2.7.0 GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@v0.5.0 -GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.1 +GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.0 GXZ_PACKAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.11 MISSPELL_PACKAGE ?= github.com/client9/misspell/cmd/misspell@v0.3.4 SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@v0.30.5 diff --git a/models/actions/task.go b/models/actions/task.go index 69f52cf084..db0031b3b8 100644 --- a/models/actions/task.go +++ b/models/actions/task.go @@ -279,7 +279,7 @@ func CreateTaskForRunner(ctx context.Context, runner *ActionRunner) (*ActionTask return nil, false, fmt.Errorf("parse workflow of job %d: %w", job.ID, err) } else if len(gots) != 1 { return nil, false, fmt.Errorf("workflow of job %d: not single workflow", job.ID) - } else { + } else { //nolint:revive _, workflowJob = gots[0].Job() } diff --git a/models/activities/action.go b/models/activities/action.go index 1bfd62438b..15bd9a52ac 100644 --- a/models/activities/action.go +++ b/models/activities/action.go @@ -713,9 +713,8 @@ func DeleteIssueActions(ctx context.Context, repoID, issueID, issueIndex int64) break } else if _, err = db.GetEngine(ctx).In("comment_id", commentIDs).Delete(&Action{}); err != nil { return err - } else { - lastCommentID = commentIDs[len(commentIDs)-1] } + lastCommentID = commentIDs[len(commentIDs)-1] } _, err := e.Where("repo_id = ?", repoID). diff --git a/models/issues/review.go b/models/issues/review.go index 8b64ba8048..1cb5379b2f 100644 --- a/models/issues/review.go +++ b/models/issues/review.go @@ -213,9 +213,8 @@ func GetReviewByID(ctx context.Context, id int64) (*Review, error) { return nil, err } else if !has { return nil, ErrReviewNotExist{ID: id} - } else { - return review, nil } + return review, nil } // CreateReviewOptions represent the options to create a review. Type, Issue and Reviewer are required. diff --git a/modules/activitypub/user_settings.go b/modules/activitypub/user_settings.go index d196a3806e..7f939af352 100644 --- a/modules/activitypub/user_settings.go +++ b/modules/activitypub/user_settings.go @@ -29,11 +29,10 @@ func GetKeyPair(ctx context.Context, user *user_model.User) (pub, priv string, e return pub, priv, err } return pub, priv, err - } else { - priv = settings[user_model.UserActivityPubPrivPem].SettingValue - pub = settings[user_model.UserActivityPubPubPem].SettingValue - return pub, priv, err } + priv = settings[user_model.UserActivityPubPrivPem].SettingValue + pub = settings[user_model.UserActivityPubPubPem].SettingValue + return pub, priv, err } // GetPublicKey function returns a user's public key diff --git a/modules/git/submodule.go b/modules/git/submodule.go index 3afaa334db..37813ea4c7 100644 --- a/modules/git/submodule.go +++ b/modules/git/submodule.go @@ -101,9 +101,8 @@ func getRefURL(refURL, urlPrefix, repoFullName, sshDomain string) string { return ref.Scheme + "://" + ref.Host + ref.Path } else if urlPrefixHostname == refHostname || refHostname == sshDomain { return urlPrefix + path.Clean(path.Join("/", ref.Path)) - } else { - return "http://" + refHostname + ref.Path } + return "http://" + refHostname + ref.Path } } diff --git a/modules/lfs/transferadapter_test.go b/modules/lfs/transferadapter_test.go index f86d2c54be..6023cd07d3 100644 --- a/modules/lfs/transferadapter_test.go +++ b/modules/lfs/transferadapter_test.go @@ -62,10 +62,9 @@ func TestBasicTransferAdapter(t *testing.T) { json.NewEncoder(payload).Encode(er) return &http.Response{StatusCode: http.StatusNotFound, Body: io.NopCloser(payload)} - } else { - t.Errorf("Unknown test case: %s", url) - return nil } + t.Errorf("Unknown test case: %s", url) + return nil } hc := &http.Client{Transport: RoundTripFunc(roundTripHandler)} diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go index 9156bc6331..21bfc8314a 100644 --- a/modules/markup/html_test.go +++ b/modules/markup/html_test.go @@ -14,7 +14,7 @@ import ( "code.gitea.io/gitea/modules/emoji" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" - . "code.gitea.io/gitea/modules/markup" + "code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/markup/markdown" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" @@ -37,12 +37,12 @@ func TestMain(m *testing.M) { } func TestRender_Commits(t *testing.T) { - setting.AppURL = TestAppURL + setting.AppURL = markup.TestAppURL test := func(input, expected string) { - buffer, err := RenderString(&RenderContext{ + buffer, err := markup.RenderString(&markup.RenderContext{ Ctx: git.DefaultContext, RelativePath: ".md", - URLPrefix: TestRepoURL, + URLPrefix: markup.TestRepoURL, Metas: localMetas, }, input) assert.NoError(t, err) @@ -50,7 +50,7 @@ func TestRender_Commits(t *testing.T) { } sha := "65f1bf27bc3bf70f64657658635e66094edbcb4d" - repo := TestRepoURL + repo := markup.TestRepoURL commit := util.URLJoin(repo, "commit", sha) tree := util.URLJoin(repo, "tree", sha, "src") @@ -87,10 +87,10 @@ func TestRender_Commits(t *testing.T) { } func TestRender_CrossReferences(t *testing.T) { - setting.AppURL = TestAppURL + setting.AppURL = markup.TestAppURL test := func(input, expected string) { - buffer, err := RenderString(&RenderContext{ + buffer, err := markup.RenderString(&markup.RenderContext{ Ctx: git.DefaultContext, RelativePath: "a.md", URLPrefix: setting.AppSubURL, @@ -102,43 +102,43 @@ func TestRender_CrossReferences(t *testing.T) { test( "gogits/gogs#12345", - `

gogits/gogs#12345

`) + `

gogits/gogs#12345

`) test( "go-gitea/gitea#12345", - `

go-gitea/gitea#12345

`) + `

go-gitea/gitea#12345

`) test( "/home/gitea/go-gitea/gitea#12345", `

/home/gitea/go-gitea/gitea#12345

`) test( - util.URLJoin(TestAppURL, "gogitea", "gitea", "issues", "12345"), - `

gogitea/gitea#12345

`) + util.URLJoin(markup.TestAppURL, "gogitea", "gitea", "issues", "12345"), + `

gogitea/gitea#12345

`) test( - util.URLJoin(TestAppURL, "go-gitea", "gitea", "issues", "12345"), - `

go-gitea/gitea#12345

`) + util.URLJoin(markup.TestAppURL, "go-gitea", "gitea", "issues", "12345"), + `

go-gitea/gitea#12345

`) test( - util.URLJoin(TestAppURL, "gogitea", "some-repo-name", "issues", "12345"), - `

gogitea/some-repo-name#12345

`) + util.URLJoin(markup.TestAppURL, "gogitea", "some-repo-name", "issues", "12345"), + `

gogitea/some-repo-name#12345

`) } func TestMisc_IsSameDomain(t *testing.T) { - setting.AppURL = TestAppURL + setting.AppURL = markup.TestAppURL sha := "b6dd6210eaebc915fd5be5579c58cce4da2e2579" - commit := util.URLJoin(TestRepoURL, "commit", sha) + commit := util.URLJoin(markup.TestRepoURL, "commit", sha) - assert.True(t, IsSameDomain(commit)) - assert.False(t, IsSameDomain("http://google.com/ncr")) - assert.False(t, IsSameDomain("favicon.ico")) + assert.True(t, markup.IsSameDomain(commit)) + assert.False(t, markup.IsSameDomain("http://google.com/ncr")) + assert.False(t, markup.IsSameDomain("favicon.ico")) } func TestRender_links(t *testing.T) { - setting.AppURL = TestAppURL + setting.AppURL = markup.TestAppURL test := func(input, expected string) { - buffer, err := RenderString(&RenderContext{ + buffer, err := markup.RenderString(&markup.RenderContext{ Ctx: git.DefaultContext, RelativePath: "a.md", - URLPrefix: TestRepoURL, + URLPrefix: markup.TestRepoURL, }, input) assert.NoError(t, err) assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) @@ -147,8 +147,8 @@ func TestRender_links(t *testing.T) { defaultCustom := setting.Markdown.CustomURLSchemes setting.Markdown.CustomURLSchemes = []string{"ftp", "magnet"} - InitializeSanitizer() - CustomLinkURLSchemes(setting.Markdown.CustomURLSchemes) + markup.InitializeSanitizer() + markup.CustomLinkURLSchemes(setting.Markdown.CustomURLSchemes) test( "https://www.example.com", @@ -227,18 +227,18 @@ func TestRender_links(t *testing.T) { // Restore previous settings setting.Markdown.CustomURLSchemes = defaultCustom - InitializeSanitizer() - CustomLinkURLSchemes(setting.Markdown.CustomURLSchemes) + markup.InitializeSanitizer() + markup.CustomLinkURLSchemes(setting.Markdown.CustomURLSchemes) } func TestRender_email(t *testing.T) { - setting.AppURL = TestAppURL + setting.AppURL = markup.TestAppURL test := func(input, expected string) { - res, err := RenderString(&RenderContext{ + res, err := markup.RenderString(&markup.RenderContext{ Ctx: git.DefaultContext, RelativePath: "a.md", - URLPrefix: TestRepoURL, + URLPrefix: markup.TestRepoURL, }, input) assert.NoError(t, err) assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(res)) @@ -289,15 +289,15 @@ func TestRender_email(t *testing.T) { } func TestRender_emoji(t *testing.T) { - setting.AppURL = TestAppURL - setting.StaticURLPrefix = TestAppURL + setting.AppURL = markup.TestAppURL + setting.StaticURLPrefix = markup.TestAppURL test := func(input, expected string) { expected = strings.ReplaceAll(expected, "&", "&") - buffer, err := RenderString(&RenderContext{ + buffer, err := markup.RenderString(&markup.RenderContext{ Ctx: git.DefaultContext, RelativePath: "a.md", - URLPrefix: TestRepoURL, + URLPrefix: markup.TestRepoURL, }, input) assert.NoError(t, err) assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) @@ -354,19 +354,19 @@ func TestRender_emoji(t *testing.T) { } func TestRender_ShortLinks(t *testing.T) { - setting.AppURL = TestAppURL - tree := util.URLJoin(TestRepoURL, "src", "master") + setting.AppURL = markup.TestAppURL + tree := util.URLJoin(markup.TestRepoURL, "src", "master") test := func(input, expected, expectedWiki string) { - buffer, err := markdown.RenderString(&RenderContext{ + buffer, err := markdown.RenderString(&markup.RenderContext{ Ctx: git.DefaultContext, URLPrefix: tree, }, input) assert.NoError(t, err) assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) - buffer, err = markdown.RenderString(&RenderContext{ + buffer, err = markdown.RenderString(&markup.RenderContext{ Ctx: git.DefaultContext, - URLPrefix: TestRepoURL, + URLPrefix: markup.TestRepoURL, Metas: localMetas, IsWiki: true, }, input) @@ -374,7 +374,7 @@ func TestRender_ShortLinks(t *testing.T) { assert.Equal(t, strings.TrimSpace(expectedWiki), strings.TrimSpace(buffer)) } - rawtree := util.URLJoin(TestRepoURL, "raw", "master") + rawtree := util.URLJoin(markup.TestRepoURL, "raw", "master") url := util.URLJoin(tree, "Link") otherURL := util.URLJoin(tree, "Other-Link") encodedURL := util.URLJoin(tree, "Link%3F") @@ -382,13 +382,13 @@ func TestRender_ShortLinks(t *testing.T) { otherImgurl := util.URLJoin(rawtree, "Link+Other.jpg") encodedImgurl := util.URLJoin(rawtree, "Link+%23.jpg") notencodedImgurl := util.URLJoin(rawtree, "some", "path", "Link+#.jpg") - urlWiki := util.URLJoin(TestRepoURL, "wiki", "Link") - otherURLWiki := util.URLJoin(TestRepoURL, "wiki", "Other-Link") - encodedURLWiki := util.URLJoin(TestRepoURL, "wiki", "Link%3F") - imgurlWiki := util.URLJoin(TestRepoURL, "wiki", "raw", "Link.jpg") - otherImgurlWiki := util.URLJoin(TestRepoURL, "wiki", "raw", "Link+Other.jpg") - encodedImgurlWiki := util.URLJoin(TestRepoURL, "wiki", "raw", "Link+%23.jpg") - notencodedImgurlWiki := util.URLJoin(TestRepoURL, "wiki", "raw", "some", "path", "Link+#.jpg") + urlWiki := util.URLJoin(markup.TestRepoURL, "wiki", "Link") + otherURLWiki := util.URLJoin(markup.TestRepoURL, "wiki", "Other-Link") + encodedURLWiki := util.URLJoin(markup.TestRepoURL, "wiki", "Link%3F") + imgurlWiki := util.URLJoin(markup.TestRepoURL, "wiki", "raw", "Link.jpg") + otherImgurlWiki := util.URLJoin(markup.TestRepoURL, "wiki", "raw", "Link+Other.jpg") + encodedImgurlWiki := util.URLJoin(markup.TestRepoURL, "wiki", "raw", "Link+%23.jpg") + notencodedImgurlWiki := util.URLJoin(markup.TestRepoURL, "wiki", "raw", "some", "path", "Link+#.jpg") favicon := "http://google.com/favicon.ico" test( @@ -462,20 +462,20 @@ func TestRender_ShortLinks(t *testing.T) { } func TestRender_RelativeImages(t *testing.T) { - setting.AppURL = TestAppURL - tree := util.URLJoin(TestRepoURL, "src", "master") + setting.AppURL = markup.TestAppURL + tree := util.URLJoin(markup.TestRepoURL, "src", "master") test := func(input, expected, expectedWiki string) { - buffer, err := markdown.RenderString(&RenderContext{ + buffer, err := markdown.RenderString(&markup.RenderContext{ Ctx: git.DefaultContext, URLPrefix: tree, Metas: localMetas, }, input) assert.NoError(t, err) assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) - buffer, err = markdown.RenderString(&RenderContext{ + buffer, err = markdown.RenderString(&markup.RenderContext{ Ctx: git.DefaultContext, - URLPrefix: TestRepoURL, + URLPrefix: markup.TestRepoURL, Metas: localMetas, IsWiki: true, }, input) @@ -483,8 +483,8 @@ func TestRender_RelativeImages(t *testing.T) { assert.Equal(t, strings.TrimSpace(expectedWiki), strings.TrimSpace(buffer)) } - rawwiki := util.URLJoin(TestRepoURL, "wiki", "raw") - mediatree := util.URLJoin(TestRepoURL, "media", "master") + rawwiki := util.URLJoin(markup.TestRepoURL, "wiki", "raw") + mediatree := util.URLJoin(markup.TestRepoURL, "media", "master") test( ``, @@ -498,7 +498,7 @@ func TestRender_RelativeImages(t *testing.T) { } func Test_ParseClusterFuzz(t *testing.T) { - setting.AppURL = TestAppURL + setting.AppURL = markup.TestAppURL localMetas := map[string]string{ "user": "go-gitea", @@ -508,7 +508,7 @@ func Test_ParseClusterFuzz(t *testing.T) { data := "
` var res strings.Builder - err := PostProcess(&RenderContext{ + err := markup.PostProcess(&markup.RenderContext{ Ctx: git.DefaultContext, URLPrefix: "https://example.com", Metas: localMetas, @@ -593,7 +593,7 @@ func BenchmarkEmojiPostprocess(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { var res strings.Builder - err := PostProcess(&RenderContext{ + err := markup.PostProcess(&markup.RenderContext{ Ctx: git.DefaultContext, URLPrefix: "https://example.com", Metas: localMetas, @@ -604,7 +604,7 @@ func BenchmarkEmojiPostprocess(b *testing.B) { func TestFuzz(t *testing.T) { s := "t/l/issues/8#/../../a" - renderContext := RenderContext{ + renderContext := markup.RenderContext{ Ctx: git.DefaultContext, URLPrefix: "https://example.com/go-gitea/gitea", Metas: map[string]string{ @@ -613,7 +613,7 @@ func TestFuzz(t *testing.T) { }, } - err := PostProcess(&renderContext, strings.NewReader(s), io.Discard) + err := markup.PostProcess(&renderContext, strings.NewReader(s), io.Discard) assert.NoError(t, err) } @@ -622,7 +622,7 @@ func TestIssue18471(t *testing.T) { data := `http://domain/org/repo/compare/783b039...da951ce` var res strings.Builder - err := PostProcess(&RenderContext{ + err := markup.PostProcess(&markup.RenderContext{ Ctx: git.DefaultContext, URLPrefix: "https://example.com", Metas: localMetas, diff --git a/modules/markup/markdown/markdown_test.go b/modules/markup/markdown/markdown_test.go index f2322b2554..8f855f1b13 100644 --- a/modules/markup/markdown/markdown_test.go +++ b/modules/markup/markdown/markdown_test.go @@ -13,7 +13,7 @@ import ( "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/markup" - . "code.gitea.io/gitea/modules/markup/markdown" + "code.gitea.io/gitea/modules/markup/markdown" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" @@ -51,14 +51,14 @@ func TestRender_StandardLinks(t *testing.T) { setting.AppSubURL = AppSubURL test := func(input, expected, expectedWiki string) { - buffer, err := RenderString(&markup.RenderContext{ + buffer, err := markdown.RenderString(&markup.RenderContext{ Ctx: git.DefaultContext, URLPrefix: setting.AppSubURL, }, input) assert.NoError(t, err) assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) - buffer, err = RenderString(&markup.RenderContext{ + buffer, err = markdown.RenderString(&markup.RenderContext{ Ctx: git.DefaultContext, URLPrefix: setting.AppSubURL, IsWiki: true, @@ -82,7 +82,7 @@ func TestRender_Images(t *testing.T) { setting.AppSubURL = AppSubURL test := func(input, expected string) { - buffer, err := RenderString(&markup.RenderContext{ + buffer, err := markdown.RenderString(&markup.RenderContext{ Ctx: git.DefaultContext, URLPrefix: setting.AppSubURL, }, input) @@ -289,7 +289,7 @@ func TestTotal_RenderWiki(t *testing.T) { answers := testAnswers(util.URLJoin(AppSubURL, "wiki/"), util.URLJoin(AppSubURL, "wiki", "raw/")) for i := 0; i < len(sameCases); i++ { - line, err := RenderString(&markup.RenderContext{ + line, err := markdown.RenderString(&markup.RenderContext{ Ctx: git.DefaultContext, URLPrefix: AppSubURL, Metas: localMetas, @@ -313,7 +313,7 @@ func TestTotal_RenderWiki(t *testing.T) { } for i := 0; i < len(testCases); i += 2 { - line, err := RenderString(&markup.RenderContext{ + line, err := markdown.RenderString(&markup.RenderContext{ Ctx: git.DefaultContext, URLPrefix: AppSubURL, IsWiki: true, @@ -330,7 +330,7 @@ func TestTotal_RenderString(t *testing.T) { answers := testAnswers(util.URLJoin(AppSubURL, "src", "master/"), util.URLJoin(AppSubURL, "raw", "master/")) for i := 0; i < len(sameCases); i++ { - line, err := RenderString(&markup.RenderContext{ + line, err := markdown.RenderString(&markup.RenderContext{ Ctx: git.DefaultContext, URLPrefix: util.URLJoin(AppSubURL, "src", "master/"), Metas: localMetas, @@ -342,7 +342,7 @@ func TestTotal_RenderString(t *testing.T) { testCases := []string{} for i := 0; i < len(testCases); i += 2 { - line, err := RenderString(&markup.RenderContext{ + line, err := markdown.RenderString(&markup.RenderContext{ Ctx: git.DefaultContext, URLPrefix: AppSubURL, }, testCases[i]) @@ -353,17 +353,17 @@ func TestTotal_RenderString(t *testing.T) { func TestRender_RenderParagraphs(t *testing.T) { test := func(t *testing.T, str string, cnt int) { - res, err := RenderRawString(&markup.RenderContext{Ctx: git.DefaultContext}, str) + res, err := markdown.RenderRawString(&markup.RenderContext{Ctx: git.DefaultContext}, str) assert.NoError(t, err) assert.Equal(t, cnt, strings.Count(res, "image1
image2

` - res, err := RenderRawString(&markup.RenderContext{Ctx: git.DefaultContext}, testcase) + res, err := markdown.RenderRawString(&markup.RenderContext{Ctx: git.DefaultContext}, testcase) assert.NoError(t, err) assert.Equal(t, expected, res) } @@ -412,7 +412,7 @@ func TestRenderEmojiInLinks_Issue12331(t *testing.T) { testcase := `[Link with emoji :moon: in text](https://gitea.io)` expected := `

Link with emoji 🌔 in text

` - res, err := RenderString(&markup.RenderContext{Ctx: git.DefaultContext}, testcase) + res, err := markdown.RenderString(&markup.RenderContext{Ctx: git.DefaultContext}, testcase) assert.NoError(t, err) assert.Equal(t, expected, res) } @@ -446,7 +446,7 @@ func TestColorPreview(t *testing.T) { } for _, test := range positiveTests { - res, err := RenderString(&markup.RenderContext{Ctx: git.DefaultContext}, test.testcase) + res, err := markdown.RenderString(&markup.RenderContext{Ctx: git.DefaultContext}, test.testcase) assert.NoError(t, err, "Unexpected error in testcase: %q", test.testcase) assert.Equal(t, test.expected, res, "Unexpected result in testcase %q", test.testcase) @@ -466,7 +466,7 @@ func TestColorPreview(t *testing.T) { } for _, test := range negativeTests { - res, err := RenderString(&markup.RenderContext{Ctx: git.DefaultContext}, test) + res, err := markdown.RenderString(&markup.RenderContext{Ctx: git.DefaultContext}, test) assert.NoError(t, err, "Unexpected error in testcase: %q", test) assert.NotContains(t, res, ` Date: Tue, 24 Oct 2023 05:26:38 +0200 Subject: [PATCH 0011/1071] Do not force creation of _cargo-index repo on publish (#27266) Hello there, Cargo Index over HTTP is now prefered over git for package updates: we should not force users who do not need the GIT repo to have the repo created/updated on each publish (it can still be created in the packages settings). The current behavior when publishing is to check if the repo exist and create it on the fly if not, then update it's content. Cargo HTTP Index does not rely on the repo itself so this will be useless for everyone not using the git protocol for cargo registry. This PR only disable the creation on the fly of the repo when publishing a crate. This is linked to #26844 (error 500 when trying to publish a crate if user is missing write access to the repo) because it's now optional. --------- Co-authored-by: KN4CK3R --- routers/api/packages/cargo/cargo.go | 4 ++-- services/packages/cargo/index.go | 12 +++++++++--- services/packages/cleanup/cleanup.go | 4 ++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/routers/api/packages/cargo/cargo.go b/routers/api/packages/cargo/cargo.go index 225b6b5ade..8f1e965c9a 100644 --- a/routers/api/packages/cargo/cargo.go +++ b/routers/api/packages/cargo/cargo.go @@ -250,7 +250,7 @@ func UploadPackage(ctx *context.Context) { return } - if err := cargo_service.AddOrUpdatePackageIndex(ctx, ctx.Doer, ctx.Package.Owner, pv.PackageID); err != nil { + if err := cargo_service.UpdatePackageIndexIfExists(ctx, ctx.Doer, ctx.Package.Owner, pv.PackageID); err != nil { if err := packages_service.DeletePackageVersionAndReferences(ctx, pv); err != nil { log.Error("Rollback creation of package version: %v", err) } @@ -301,7 +301,7 @@ func yankPackage(ctx *context.Context, yank bool) { return } - if err := cargo_service.AddOrUpdatePackageIndex(ctx, ctx.Doer, ctx.Package.Owner, pv.PackageID); err != nil { + if err := cargo_service.UpdatePackageIndexIfExists(ctx, ctx.Doer, ctx.Package.Owner, pv.PackageID); err != nil { apiError(ctx, http.StatusInternalServerError, err) return } diff --git a/services/packages/cargo/index.go b/services/packages/cargo/index.go index 0561f168e1..8164ffb01c 100644 --- a/services/packages/cargo/index.go +++ b/services/packages/cargo/index.go @@ -106,10 +106,16 @@ func RebuildIndex(ctx context.Context, doer, owner *user_model.User) error { ) } -func AddOrUpdatePackageIndex(ctx context.Context, doer, owner *user_model.User, packageID int64) error { - repo, err := getOrCreateIndexRepository(ctx, doer, owner) +func UpdatePackageIndexIfExists(ctx context.Context, doer, owner *user_model.User, packageID int64) error { + // We do not want to force the creation of the repo here + // cargo http index does not rely on the repo itself, + // so if the repo does not exist, we just do nothing. + repo, err := repo_model.GetRepositoryByOwnerAndName(ctx, owner.Name, IndexRepositoryName) if err != nil { - return err + if errors.Is(err, util.ErrNotExist) { + return nil + } + return fmt.Errorf("GetRepositoryByOwnerAndName: %w", err) } p, err := packages_model.GetPackageByID(ctx, packageID) diff --git a/services/packages/cleanup/cleanup.go b/services/packages/cleanup/cleanup.go index 77bcfb1942..9bdd9d6aad 100644 --- a/services/packages/cleanup/cleanup.go +++ b/services/packages/cleanup/cleanup.go @@ -110,8 +110,8 @@ func ExecuteCleanupRules(outerCtx context.Context) error { if err != nil { return fmt.Errorf("GetUserByID failed: %w", err) } - if err := cargo_service.AddOrUpdatePackageIndex(ctx, owner, owner, p.ID); err != nil { - return fmt.Errorf("CleanupRule [%d]: cargo.AddOrUpdatePackageIndex failed: %w", pcr.ID, err) + if err := cargo_service.UpdatePackageIndexIfExists(ctx, owner, owner, p.ID); err != nil { + return fmt.Errorf("CleanupRule [%d]: cargo.UpdatePackageIndexIfExists failed: %w", pcr.ID, err) } } } From fba4ee7efcd0baead1611c0885468c15916cc7e1 Mon Sep 17 00:00:00 2001 From: silverwind Date: Wed, 25 Oct 2023 00:47:17 +0200 Subject: [PATCH 0012/1071] Add gap between diff boxes (#27776) Before (almost no gap between files): Screenshot 2023-10-24 at 19 43 32 After (with 8px gap): Screenshot 2023-10-24 at 19 43 22 --- web_src/css/repo.css | 3 +++ 1 file changed, 3 insertions(+) diff --git a/web_src/css/repo.css b/web_src/css/repo.css index c3e230f8e1..7d76dd8b3f 100644 --- a/web_src/css/repo.css +++ b/web_src/css/repo.css @@ -2734,6 +2734,9 @@ tbody.commit-list { #diff-file-boxes { flex: 1; max-width: 100%; + display: flex; + flex-direction: column; + gap: 8px; } #diff-file-tree { From 572f0963edc71239634ee782a3c69213479f34ba Mon Sep 17 00:00:00 2001 From: silverwind Date: Wed, 25 Oct 2023 05:09:18 +0200 Subject: [PATCH 0013/1071] Only show diff file tree when more than one file changed (#27775) When 0 or 1 files changed in a diff, we don't need to show a file tree. This behaviour matches GitHub. Single-file diff after this change, note absence of button: image Co-authored-by: Giteabot --- templates/repo/diff/box.tmpl | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/templates/repo/diff/box.tmpl b/templates/repo/diff/box.tmpl index 289ed90d3f..c037c3b365 100644 --- a/templates/repo/diff/box.tmpl +++ b/templates/repo/diff/box.tmpl @@ -1,7 +1,8 @@ +{{$showFileTree := (and (not .DiffNotAvailable) (gt .Diff.NumFiles 1))}}
- {{if not .DiffNotAvailable}} + {{if $showFileTree}} {{CountFmt .NumWatches}} @@ -74,7 +75,11 @@ {{$.CsrfTokenHtml}} {{end}} -
-
+
+ {{if $.PullMirror}}
{{ctx.Locale.Tr "repo.mirror_from"}} {{$.PullMirror.RemoteAddress}}
{{end}} + {{if .IsFork}}
{{ctx.Locale.Tr "repo.forked_from"}} {{.BaseRepo.FullName}}
{{end}} + {{if .IsGenerated}}
{{ctx.Locale.Tr "repo.generated_from"}} {{(.TemplateRepo ctx).FullName}}
{{end}} + {{end}} -
+