diff --git a/modules/indexer/code/git.go b/modules/indexer/code/git.go index 76cd78e11e6bf..f105d032eba12 100644 --- a/modules/indexer/code/git.go +++ b/modules/indexer/code/git.go @@ -91,11 +91,9 @@ func genesisChanges(ctx context.Context, repo *repo_model.Repository, revision s return nil, runErr } + objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName) + var err error - objectFormat, err := git.GetObjectFormatOfRepo(ctx, repo.RepoPath()) - if err != nil { - return nil, err - } changes.Updates, err = parseGitLsTreeOutput(objectFormat, stdout) return &changes, err } @@ -174,10 +172,8 @@ func nonGenesisChanges(ctx context.Context, repo *repo_model.Repository, revisio return nil, err } - objectFormat, err := git.GetObjectFormatOfRepo(ctx, repo.RepoPath()) - if err != nil { - return nil, err - } + objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName) + changes.Updates, err = parseGitLsTreeOutput(objectFormat, lsTreeStdout) return &changes, err } diff --git a/modules/markup/orgmode/orgmode.go b/modules/markup/orgmode/orgmode.go index 7f253ae5f12c1..25f8d15ef4739 100644 --- a/modules/markup/orgmode/orgmode.go +++ b/modules/markup/orgmode/orgmode.go @@ -142,10 +142,18 @@ func (r *Writer) resolveLink(kind, link string) string { // so we need to try to guess the link kind again here kind = org.RegularLink{URL: link}.Kind() } + base := r.Ctx.Links.Base + if r.Ctx.IsWiki { + base = r.Ctx.Links.WikiLink() + } else if r.Ctx.Links.HasBranchInfo() { + base = r.Ctx.Links.SrcLink() + } + if kind == "image" || kind == "video" { base = r.Ctx.Links.ResolveMediaLink(r.Ctx.IsWiki) } + link = util.URLJoin(base, link) } return link diff --git a/modules/markup/orgmode/orgmode_test.go b/modules/markup/orgmode/orgmode_test.go index 95f53c9cc9ff5..75b60ed81f004 100644 --- a/modules/markup/orgmode/orgmode_test.go +++ b/modules/markup/orgmode/orgmode_test.go @@ -19,24 +19,50 @@ const AppURL = "http://localhost:3000/" func TestRender_StandardLinks(t *testing.T) { setting.AppURL = AppURL - test := func(input, expected string) { + test := func(input, expected string, isWiki bool) { buffer, err := RenderString(&markup.RenderContext{ Ctx: git.DefaultContext, Links: markup.Links{ Base: "/relative-path", BranchPath: "branch/main", }, + IsWiki: isWiki, }, input) assert.NoError(t, err) assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) } test("[[https://google.com/]]", - `
`) + ``, false) test("[[WikiPage][The WikiPage Desc]]", - ``) + ``, true) test("[[ImageLink.svg][The Image Desc]]", - ``) + ``, false) +} + +func TestRender_InternalLinks(t *testing.T) { + setting.AppURL = AppURL + + test := func(input, expected string) { + buffer, err := RenderString(&markup.RenderContext{ + Ctx: git.DefaultContext, + Links: markup.Links{ + Base: "/relative-path", + BranchPath: "branch/main", + }, + }, input) + assert.NoError(t, err) + assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) + } + + test("[[file:test.org][Test]]", + ``) + test("[[./test.org][Test]]", + ``) + test("[[test.org][Test]]", + ``) + test("[[path/to/test.org][Test]]", + ``) } func TestRender_Media(t *testing.T) { diff --git a/routers/web/repo/branch.go b/routers/web/repo/branch.go index ae51f0596b2de..f879a98786637 100644 --- a/routers/web/repo/branch.go +++ b/routers/web/repo/branch.go @@ -148,12 +148,7 @@ func RestoreBranchPost(ctx *context.Context) { return } - objectFormat, err := git.GetObjectFormatOfRepo(ctx, ctx.Repo.Repository.RepoPath()) - if err != nil { - log.Error("RestoreBranch: CreateBranch: %w", err) - ctx.Flash.Error(ctx.Tr("repo.branch.restore_failed", deletedBranch.Name)) - return - } + objectFormat := git.ObjectFormatFromName(ctx.Repo.Repository.ObjectFormatName) // Don't return error below this if err := repo_service.PushUpdate( diff --git a/routers/web/repo/setting/webhook.go b/routers/web/repo/setting/webhook.go index db0e3d7ab5de0..d4a2d066d09a4 100644 --- a/routers/web/repo/setting/webhook.go +++ b/routers/web/repo/setting/webhook.go @@ -657,12 +657,7 @@ func TestWebhook(ctx *context.Context) { commit := ctx.Repo.Commit if commit == nil { ghost := user_model.NewGhostUser() - objectFormat, err := git.GetObjectFormatOfRepo(ctx, ctx.Repo.Repository.RepoPath()) - if err != nil { - ctx.Flash.Error("GetObjectFormatOfRepo: " + err.Error()) - ctx.Status(http.StatusInternalServerError) - return - } + objectFormat := git.ObjectFormatFromName(ctx.Repo.Repository.ObjectFormatName) commit = &git.Commit{ ID: objectFormat.EmptyObjectID(), Author: ghost.NewGitSig(), diff --git a/services/mirror/mirror_pull.go b/services/mirror/mirror_pull.go index de4a58f27b787..2a38d4ba55d3a 100644 --- a/services/mirror/mirror_pull.go +++ b/services/mirror/mirror_pull.go @@ -479,10 +479,7 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool { log.Error("SyncMirrors [repo: %-v]: unable to GetRefCommitID [ref_name: %s]: %v", m.Repo, result.refName, err) continue } - objectFormat, err := git.GetObjectFormatOfRepo(ctx, m.Repo.RepoPath()) - if err != nil { - log.Error("SyncMirrors [repo: %-v]: unable to GetHashTypeOfRepo: %v", m.Repo, err) - } + objectFormat := git.ObjectFormatFromName(m.Repo.ObjectFormatName) notify_service.SyncPushCommits(ctx, m.Repo.MustOwner(ctx), m.Repo, &repo_module.PushUpdateOptions{ RefFullName: result.refName, OldCommitID: objectFormat.EmptyObjectID().String(), diff --git a/services/pull/pull.go b/services/pull/pull.go index be3d25d20a03c..9133a72acf748 100644 --- a/services/pull/pull.go +++ b/services/pull/pull.go @@ -337,7 +337,7 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string, } if err == nil { for _, pr := range prs { - objectFormat, _ := git.GetObjectFormatOfRepo(ctx, pr.BaseRepo.RepoPath()) + objectFormat := git.ObjectFormatFromName(pr.BaseRepo.ObjectFormatName) if newCommitID != "" && newCommitID != objectFormat.EmptyObjectID().String() { changed, err := checkIfPRContentChanged(ctx, pr, oldCommitID, newCommitID) if err != nil { diff --git a/services/release/release.go b/services/release/release.go index a359e5078e63a..ba5fd1dd986eb 100644 --- a/services/release/release.go +++ b/services/release/release.go @@ -326,10 +326,7 @@ func DeleteReleaseByID(ctx context.Context, repo *repo_model.Repository, rel *re } refName := git.RefNameFromTag(rel.TagName) - objectFormat, err := git.GetObjectFormatOfRepo(ctx, repo.RepoPath()) - if err != nil { - return err - } + objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName) notify_service.PushCommits( ctx, doer, repo, &repository.PushUpdateOptions{ diff --git a/web_src/css/repo.css b/web_src/css/repo.css index d60fb4db21a2f..03d9664331fda 100644 --- a/web_src/css/repo.css +++ b/web_src/css/repo.css @@ -1420,6 +1420,7 @@ .repository .data-table tr { border-top: 0; + background: none !important; } .repository .data-table td, @@ -1432,6 +1433,21 @@ border: 1px solid var(--color-secondary); } +/* the border css competes with .markup where all tables have outer border which would add a double + border here, remove only the outer borders from this table */ +.repository .data-table tr:first-child :is(td,th) { + border-top: none !important; +} +.repository .data-table tr:last-child :is(td,th) { + border-bottom: none !important; +} +.repository .data-table tr :is(td,th):first-child { + border-left: none !important; +} +.repository .data-table tr :is(td,th):last-child { + border-right: none !important; +} + .repository .data-table td { white-space: pre-line; } @@ -1469,7 +1485,7 @@ min-width: 50px; font-family: monospace; line-height: 20px; - color: var(--color-secondary-dark-2); + color: var(--color-text-light-1); white-space: nowrap; vertical-align: top; cursor: pointer; diff --git a/web_src/js/bootstrap.js b/web_src/js/bootstrap.js index c0047b0ac2418..698d17fa3675b 100644 --- a/web_src/js/bootstrap.js +++ b/web_src/js/bootstrap.js @@ -6,10 +6,18 @@ // This file must be imported before any lazy-loading is being attempted. __webpack_public_path__ = `${window.config?.assetUrlPrefix ?? '/assets'}/`; +const filteredErrors = new Set([ + 'getModifierState is not a function', // https://github.com/microsoft/monaco-editor/issues/4325 +]); + export function showGlobalErrorMessage(msg) { const pageContent = document.querySelector('.page-content'); if (!pageContent) return; + for (const filteredError of filteredErrors) { + if (msg.includes(filteredError)) return; + } + // compact the message to a data attribute to avoid too many duplicated messages const msgCompact = msg.replace(/\W/g, '').trim(); let msgDiv = pageContent.querySelector(`.js-global-error[data-global-error-msg-compact="${msgCompact}"]`); diff --git a/web_src/js/features/repo-issue-content.js b/web_src/js/features/repo-issue-content.js index fa35ae0a26078..f520d0ec8b487 100644 --- a/web_src/js/features/repo-issue-content.js +++ b/web_src/js/features/repo-issue-content.js @@ -1,8 +1,9 @@ import $ from 'jquery'; import {svg} from '../svg.js'; import {showErrorToast} from '../modules/toast.js'; +import {GET, POST} from '../modules/fetch.js'; -const {appSubUrl, csrfToken} = window.config; +const {appSubUrl} = window.config; let i18nTextEdited; let i18nTextOptions; let i18nTextDeleteFromHistory; @@ -32,19 +33,27 @@ function showContentHistoryDetail(issueBaseUrl, commentId, historyId, itemTitleH $dialog.find('.dialog-header-options').dropdown({ showOnFocus: false, allowReselection: true, - onChange(_value, _text, $item) { + async onChange(_value, _text, $item) { const optionItem = $item.data('option-item'); if (optionItem === 'delete') { if (window.confirm(i18nTextDeleteFromHistoryConfirm)) { - $.post(`${issueBaseUrl}/content-history/soft-delete?comment_id=${commentId}&history_id=${historyId}`, { - _csrf: csrfToken, - }).done((resp) => { + try { + const params = new URLSearchParams(); + params.append('comment_id', commentId); + params.append('history_id', historyId); + + const response = await POST(`${issueBaseUrl}/content-history/soft-delete?${params.toString()}`); + const resp = await response.json(); + if (resp.ok) { $dialog.modal('hide'); } else { showErrorToast(resp.message); } - }); + } catch (error) { + console.error('Error:', error); + showErrorToast('An error occurred while deleting the history.'); + } } } else { // required by eslint showErrorToast(`unknown option item: ${optionItem}`); @@ -55,19 +64,24 @@ function showContentHistoryDetail(issueBaseUrl, commentId, historyId, itemTitleH } }); $dialog.modal({ - onShow() { - $.ajax({ - url: `${issueBaseUrl}/content-history/detail?comment_id=${commentId}&history_id=${historyId}`, - data: { - _csrf: csrfToken, - }, - }).done((resp) => { + async onShow() { + try { + const params = new URLSearchParams(); + params.append('comment_id', commentId); + params.append('history_id', historyId); + + const url = `${issueBaseUrl}/content-history/detail?${params.toString()}`; + const response = await GET(url); + const resp = await response.json(); + $dialog.find('.comment-diff-data').removeClass('is-loading').html(resp.diffHtml); // there is only one option "item[data-option-item=delete]", so the dropdown can be entirely shown/hidden. if (resp.canSoftDelete) { $dialog.find('.dialog-header-options').removeClass('gt-hidden'); } - }); + } catch (error) { + console.error('Error:', error); + } }, onHidden() { $dialog.remove(); @@ -104,7 +118,7 @@ function showContentHistoryMenu(issueBaseUrl, $item, commentId) { }); } -export function initRepoIssueContentHistory() { +export async function initRepoIssueContentHistory() { const issueIndex = $('#issueIndex').val(); if (!issueIndex) return; @@ -115,12 +129,10 @@ export function initRepoIssueContentHistory() { const repoLink = $('#repolink').val(); const issueBaseUrl = `${appSubUrl}/${repoLink}/issues/${issueIndex}`; - $.ajax({ - url: `${issueBaseUrl}/content-history/overview`, - data: { - _csrf: csrfToken, - }, - }).done((resp) => { + try { + const response = await GET(`${issueBaseUrl}/content-history/overview`); + const resp = await response.json(); + i18nTextEdited = resp.i18n.textEdited; i18nTextDeleteFromHistory = resp.i18n.textDeleteFromHistory; i18nTextDeleteFromHistoryConfirm = resp.i18n.textDeleteFromHistoryConfirm; @@ -134,5 +146,7 @@ export function initRepoIssueContentHistory() { const $itemComment = $(`#issuecomment-${commentId}`); showContentHistoryMenu(issueBaseUrl, $itemComment, commentId); } - }); + } catch (error) { + console.error('Error:', error); + } }