Skip to content

Commit

Permalink
Merge remote-tracking branch 'giteaofficial/main'
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
zjjhot committed Mar 11, 2024
2 parents d0615dd + 3c6fc25 commit 139f55a
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 56 deletions.
12 changes: 4 additions & 8 deletions modules/indexer/code/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
8 changes: 8 additions & 0 deletions modules/markup/orgmode/orgmode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 30 additions & 4 deletions modules/markup/orgmode/orgmode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/]]",
`<p><a href="https://google.com/">https://google.com/</a></p>`)
`<p><a href="https://google.com/">https://google.com/</a></p>`, false)
test("[[WikiPage][The WikiPage Desc]]",
`<p><a href="/relative-path/WikiPage">The WikiPage Desc</a></p>`)
`<p><a href="/relative-path/wiki/WikiPage">The WikiPage Desc</a></p>`, true)
test("[[ImageLink.svg][The Image Desc]]",
`<p><a href="/relative-path/media/branch/main/ImageLink.svg">The Image Desc</a></p>`)
`<p><a href="/relative-path/media/branch/main/ImageLink.svg">The Image Desc</a></p>`, 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]]",
`<p><a href="/relative-path/src/branch/main/test.org">Test</a></p>`)
test("[[./test.org][Test]]",
`<p><a href="/relative-path/src/branch/main/test.org">Test</a></p>`)
test("[[test.org][Test]]",
`<p><a href="/relative-path/src/branch/main/test.org">Test</a></p>`)
test("[[path/to/test.org][Test]]",
`<p><a href="/relative-path/src/branch/main/path/to/test.org">Test</a></p>`)
}

func TestRender_Media(t *testing.T) {
Expand Down
7 changes: 1 addition & 6 deletions routers/web/repo/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 1 addition & 6 deletions routers/web/repo/setting/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
5 changes: 1 addition & 4 deletions services/mirror/mirror_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion services/pull/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 1 addition & 4 deletions services/release/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
18 changes: 17 additions & 1 deletion web_src/css/repo.css
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,7 @@

.repository .data-table tr {
border-top: 0;
background: none !important;
}

.repository .data-table td,
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions web_src/js/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}"]`);
Expand Down
58 changes: 36 additions & 22 deletions web_src/js/features/repo-issue-content.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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}`);
Expand All @@ -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();
Expand Down Expand Up @@ -104,7 +118,7 @@ function showContentHistoryMenu(issueBaseUrl, $item, commentId) {
});
}

export function initRepoIssueContentHistory() {
export async function initRepoIssueContentHistory() {
const issueIndex = $('#issueIndex').val();
if (!issueIndex) return;

Expand All @@ -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;
Expand All @@ -134,5 +146,7 @@ export function initRepoIssueContentHistory() {
const $itemComment = $(`#issuecomment-${commentId}`);
showContentHistoryMenu(issueBaseUrl, $itemComment, commentId);
}
});
} catch (error) {
console.error('Error:', error);
}
}

0 comments on commit 139f55a

Please sign in to comment.