Skip to content

Commit 139f55a

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Use repo object format name instead of detecting from git repository (go-gitea#29702) Improve CSV rendering (go-gitea#29638) Remove jQuery AJAX from the comment edit history (go-gitea#29703) fix: rendering internal file links in org (go-gitea#29669) Fix broken webhooks (go-gitea#29690) Suppress error from monaco-editor (go-gitea#29684)
2 parents d0615dd + 3c6fc25 commit 139f55a

File tree

11 files changed

+108
-56
lines changed

11 files changed

+108
-56
lines changed

modules/indexer/code/git.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,9 @@ func genesisChanges(ctx context.Context, repo *repo_model.Repository, revision s
9191
return nil, runErr
9292
}
9393

94+
objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName)
95+
9496
var err error
95-
objectFormat, err := git.GetObjectFormatOfRepo(ctx, repo.RepoPath())
96-
if err != nil {
97-
return nil, err
98-
}
9997
changes.Updates, err = parseGitLsTreeOutput(objectFormat, stdout)
10098
return &changes, err
10199
}
@@ -174,10 +172,8 @@ func nonGenesisChanges(ctx context.Context, repo *repo_model.Repository, revisio
174172
return nil, err
175173
}
176174

177-
objectFormat, err := git.GetObjectFormatOfRepo(ctx, repo.RepoPath())
178-
if err != nil {
179-
return nil, err
180-
}
175+
objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName)
176+
181177
changes.Updates, err = parseGitLsTreeOutput(objectFormat, lsTreeStdout)
182178
return &changes, err
183179
}

modules/markup/orgmode/orgmode.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,18 @@ func (r *Writer) resolveLink(kind, link string) string {
142142
// so we need to try to guess the link kind again here
143143
kind = org.RegularLink{URL: link}.Kind()
144144
}
145+
145146
base := r.Ctx.Links.Base
147+
if r.Ctx.IsWiki {
148+
base = r.Ctx.Links.WikiLink()
149+
} else if r.Ctx.Links.HasBranchInfo() {
150+
base = r.Ctx.Links.SrcLink()
151+
}
152+
146153
if kind == "image" || kind == "video" {
147154
base = r.Ctx.Links.ResolveMediaLink(r.Ctx.IsWiki)
148155
}
156+
149157
link = util.URLJoin(base, link)
150158
}
151159
return link

modules/markup/orgmode/orgmode_test.go

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,50 @@ const AppURL = "http://localhost:3000/"
1919
func TestRender_StandardLinks(t *testing.T) {
2020
setting.AppURL = AppURL
2121

22-
test := func(input, expected string) {
22+
test := func(input, expected string, isWiki bool) {
2323
buffer, err := RenderString(&markup.RenderContext{
2424
Ctx: git.DefaultContext,
2525
Links: markup.Links{
2626
Base: "/relative-path",
2727
BranchPath: "branch/main",
2828
},
29+
IsWiki: isWiki,
2930
}, input)
3031
assert.NoError(t, err)
3132
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
3233
}
3334

3435
test("[[https://google.com/]]",
35-
`<p><a href="https://google.com/">https://google.com/</a></p>`)
36+
`<p><a href="https://google.com/">https://google.com/</a></p>`, false)
3637
test("[[WikiPage][The WikiPage Desc]]",
37-
`<p><a href="/relative-path/WikiPage">The WikiPage Desc</a></p>`)
38+
`<p><a href="/relative-path/wiki/WikiPage">The WikiPage Desc</a></p>`, true)
3839
test("[[ImageLink.svg][The Image Desc]]",
39-
`<p><a href="/relative-path/media/branch/main/ImageLink.svg">The Image Desc</a></p>`)
40+
`<p><a href="/relative-path/media/branch/main/ImageLink.svg">The Image Desc</a></p>`, false)
41+
}
42+
43+
func TestRender_InternalLinks(t *testing.T) {
44+
setting.AppURL = AppURL
45+
46+
test := func(input, expected string) {
47+
buffer, err := RenderString(&markup.RenderContext{
48+
Ctx: git.DefaultContext,
49+
Links: markup.Links{
50+
Base: "/relative-path",
51+
BranchPath: "branch/main",
52+
},
53+
}, input)
54+
assert.NoError(t, err)
55+
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
56+
}
57+
58+
test("[[file:test.org][Test]]",
59+
`<p><a href="/relative-path/src/branch/main/test.org">Test</a></p>`)
60+
test("[[./test.org][Test]]",
61+
`<p><a href="/relative-path/src/branch/main/test.org">Test</a></p>`)
62+
test("[[test.org][Test]]",
63+
`<p><a href="/relative-path/src/branch/main/test.org">Test</a></p>`)
64+
test("[[path/to/test.org][Test]]",
65+
`<p><a href="/relative-path/src/branch/main/path/to/test.org">Test</a></p>`)
4066
}
4167

4268
func TestRender_Media(t *testing.T) {

routers/web/repo/branch.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,7 @@ func RestoreBranchPost(ctx *context.Context) {
148148
return
149149
}
150150

151-
objectFormat, err := git.GetObjectFormatOfRepo(ctx, ctx.Repo.Repository.RepoPath())
152-
if err != nil {
153-
log.Error("RestoreBranch: CreateBranch: %w", err)
154-
ctx.Flash.Error(ctx.Tr("repo.branch.restore_failed", deletedBranch.Name))
155-
return
156-
}
151+
objectFormat := git.ObjectFormatFromName(ctx.Repo.Repository.ObjectFormatName)
157152

158153
// Don't return error below this
159154
if err := repo_service.PushUpdate(

routers/web/repo/setting/webhook.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -657,12 +657,7 @@ func TestWebhook(ctx *context.Context) {
657657
commit := ctx.Repo.Commit
658658
if commit == nil {
659659
ghost := user_model.NewGhostUser()
660-
objectFormat, err := git.GetObjectFormatOfRepo(ctx, ctx.Repo.Repository.RepoPath())
661-
if err != nil {
662-
ctx.Flash.Error("GetObjectFormatOfRepo: " + err.Error())
663-
ctx.Status(http.StatusInternalServerError)
664-
return
665-
}
660+
objectFormat := git.ObjectFormatFromName(ctx.Repo.Repository.ObjectFormatName)
666661
commit = &git.Commit{
667662
ID: objectFormat.EmptyObjectID(),
668663
Author: ghost.NewGitSig(),

services/mirror/mirror_pull.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,10 +479,7 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool {
479479
log.Error("SyncMirrors [repo: %-v]: unable to GetRefCommitID [ref_name: %s]: %v", m.Repo, result.refName, err)
480480
continue
481481
}
482-
objectFormat, err := git.GetObjectFormatOfRepo(ctx, m.Repo.RepoPath())
483-
if err != nil {
484-
log.Error("SyncMirrors [repo: %-v]: unable to GetHashTypeOfRepo: %v", m.Repo, err)
485-
}
482+
objectFormat := git.ObjectFormatFromName(m.Repo.ObjectFormatName)
486483
notify_service.SyncPushCommits(ctx, m.Repo.MustOwner(ctx), m.Repo, &repo_module.PushUpdateOptions{
487484
RefFullName: result.refName,
488485
OldCommitID: objectFormat.EmptyObjectID().String(),

services/pull/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
337337
}
338338
if err == nil {
339339
for _, pr := range prs {
340-
objectFormat, _ := git.GetObjectFormatOfRepo(ctx, pr.BaseRepo.RepoPath())
340+
objectFormat := git.ObjectFormatFromName(pr.BaseRepo.ObjectFormatName)
341341
if newCommitID != "" && newCommitID != objectFormat.EmptyObjectID().String() {
342342
changed, err := checkIfPRContentChanged(ctx, pr, oldCommitID, newCommitID)
343343
if err != nil {

services/release/release.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,7 @@ func DeleteReleaseByID(ctx context.Context, repo *repo_model.Repository, rel *re
326326
}
327327

328328
refName := git.RefNameFromTag(rel.TagName)
329-
objectFormat, err := git.GetObjectFormatOfRepo(ctx, repo.RepoPath())
330-
if err != nil {
331-
return err
332-
}
329+
objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName)
333330
notify_service.PushCommits(
334331
ctx, doer, repo,
335332
&repository.PushUpdateOptions{

web_src/css/repo.css

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,7 @@
14201420

14211421
.repository .data-table tr {
14221422
border-top: 0;
1423+
background: none !important;
14231424
}
14241425

14251426
.repository .data-table td,
@@ -1432,6 +1433,21 @@
14321433
border: 1px solid var(--color-secondary);
14331434
}
14341435

1436+
/* the border css competes with .markup where all tables have outer border which would add a double
1437+
border here, remove only the outer borders from this table */
1438+
.repository .data-table tr:first-child :is(td,th) {
1439+
border-top: none !important;
1440+
}
1441+
.repository .data-table tr:last-child :is(td,th) {
1442+
border-bottom: none !important;
1443+
}
1444+
.repository .data-table tr :is(td,th):first-child {
1445+
border-left: none !important;
1446+
}
1447+
.repository .data-table tr :is(td,th):last-child {
1448+
border-right: none !important;
1449+
}
1450+
14351451
.repository .data-table td {
14361452
white-space: pre-line;
14371453
}
@@ -1469,7 +1485,7 @@
14691485
min-width: 50px;
14701486
font-family: monospace;
14711487
line-height: 20px;
1472-
color: var(--color-secondary-dark-2);
1488+
color: var(--color-text-light-1);
14731489
white-space: nowrap;
14741490
vertical-align: top;
14751491
cursor: pointer;

web_src/js/bootstrap.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@
66
// This file must be imported before any lazy-loading is being attempted.
77
__webpack_public_path__ = `${window.config?.assetUrlPrefix ?? '/assets'}/`;
88

9+
const filteredErrors = new Set([
10+
'getModifierState is not a function', // https://github.com/microsoft/monaco-editor/issues/4325
11+
]);
12+
913
export function showGlobalErrorMessage(msg) {
1014
const pageContent = document.querySelector('.page-content');
1115
if (!pageContent) return;
1216

17+
for (const filteredError of filteredErrors) {
18+
if (msg.includes(filteredError)) return;
19+
}
20+
1321
// compact the message to a data attribute to avoid too many duplicated messages
1422
const msgCompact = msg.replace(/\W/g, '').trim();
1523
let msgDiv = pageContent.querySelector(`.js-global-error[data-global-error-msg-compact="${msgCompact}"]`);

web_src/js/features/repo-issue-content.js

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import $ from 'jquery';
22
import {svg} from '../svg.js';
33
import {showErrorToast} from '../modules/toast.js';
4+
import {GET, POST} from '../modules/fetch.js';
45

5-
const {appSubUrl, csrfToken} = window.config;
6+
const {appSubUrl} = window.config;
67
let i18nTextEdited;
78
let i18nTextOptions;
89
let i18nTextDeleteFromHistory;
@@ -32,19 +33,27 @@ function showContentHistoryDetail(issueBaseUrl, commentId, historyId, itemTitleH
3233
$dialog.find('.dialog-header-options').dropdown({
3334
showOnFocus: false,
3435
allowReselection: true,
35-
onChange(_value, _text, $item) {
36+
async onChange(_value, _text, $item) {
3637
const optionItem = $item.data('option-item');
3738
if (optionItem === 'delete') {
3839
if (window.confirm(i18nTextDeleteFromHistoryConfirm)) {
39-
$.post(`${issueBaseUrl}/content-history/soft-delete?comment_id=${commentId}&history_id=${historyId}`, {
40-
_csrf: csrfToken,
41-
}).done((resp) => {
40+
try {
41+
const params = new URLSearchParams();
42+
params.append('comment_id', commentId);
43+
params.append('history_id', historyId);
44+
45+
const response = await POST(`${issueBaseUrl}/content-history/soft-delete?${params.toString()}`);
46+
const resp = await response.json();
47+
4248
if (resp.ok) {
4349
$dialog.modal('hide');
4450
} else {
4551
showErrorToast(resp.message);
4652
}
47-
});
53+
} catch (error) {
54+
console.error('Error:', error);
55+
showErrorToast('An error occurred while deleting the history.');
56+
}
4857
}
4958
} else { // required by eslint
5059
showErrorToast(`unknown option item: ${optionItem}`);
@@ -55,19 +64,24 @@ function showContentHistoryDetail(issueBaseUrl, commentId, historyId, itemTitleH
5564
}
5665
});
5766
$dialog.modal({
58-
onShow() {
59-
$.ajax({
60-
url: `${issueBaseUrl}/content-history/detail?comment_id=${commentId}&history_id=${historyId}`,
61-
data: {
62-
_csrf: csrfToken,
63-
},
64-
}).done((resp) => {
67+
async onShow() {
68+
try {
69+
const params = new URLSearchParams();
70+
params.append('comment_id', commentId);
71+
params.append('history_id', historyId);
72+
73+
const url = `${issueBaseUrl}/content-history/detail?${params.toString()}`;
74+
const response = await GET(url);
75+
const resp = await response.json();
76+
6577
$dialog.find('.comment-diff-data').removeClass('is-loading').html(resp.diffHtml);
6678
// there is only one option "item[data-option-item=delete]", so the dropdown can be entirely shown/hidden.
6779
if (resp.canSoftDelete) {
6880
$dialog.find('.dialog-header-options').removeClass('gt-hidden');
6981
}
70-
});
82+
} catch (error) {
83+
console.error('Error:', error);
84+
}
7185
},
7286
onHidden() {
7387
$dialog.remove();
@@ -104,7 +118,7 @@ function showContentHistoryMenu(issueBaseUrl, $item, commentId) {
104118
});
105119
}
106120

107-
export function initRepoIssueContentHistory() {
121+
export async function initRepoIssueContentHistory() {
108122
const issueIndex = $('#issueIndex').val();
109123
if (!issueIndex) return;
110124

@@ -115,12 +129,10 @@ export function initRepoIssueContentHistory() {
115129
const repoLink = $('#repolink').val();
116130
const issueBaseUrl = `${appSubUrl}/${repoLink}/issues/${issueIndex}`;
117131

118-
$.ajax({
119-
url: `${issueBaseUrl}/content-history/overview`,
120-
data: {
121-
_csrf: csrfToken,
122-
},
123-
}).done((resp) => {
132+
try {
133+
const response = await GET(`${issueBaseUrl}/content-history/overview`);
134+
const resp = await response.json();
135+
124136
i18nTextEdited = resp.i18n.textEdited;
125137
i18nTextDeleteFromHistory = resp.i18n.textDeleteFromHistory;
126138
i18nTextDeleteFromHistoryConfirm = resp.i18n.textDeleteFromHistoryConfirm;
@@ -134,5 +146,7 @@ export function initRepoIssueContentHistory() {
134146
const $itemComment = $(`#issuecomment-${commentId}`);
135147
showContentHistoryMenu(issueBaseUrl, $itemComment, commentId);
136148
}
137-
});
149+
} catch (error) {
150+
console.error('Error:', error);
151+
}
138152
}

0 commit comments

Comments
 (0)