mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-02 04:29:02 +02:00
Merge branch 'main' into ssh-mirror-migrations
This commit is contained in:
@@ -181,10 +181,11 @@ func (u *User) UnmarshalJSON(data []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Repository https://github.com/npm/registry/blob/master/docs/REGISTRY-API.md#version
|
||||
// Repository https://docs.npmjs.com/cli/v11/configuring-npm/package-json#repository
|
||||
type Repository struct {
|
||||
Type string `json:"type"`
|
||||
URL string `json:"url"`
|
||||
Type string `json:"type"`
|
||||
URL string `json:"url"`
|
||||
Directory string `json:"directory,omitempty"`
|
||||
}
|
||||
|
||||
// PackageAttachment https://github.com/npm/registry/blob/master/docs/REGISTRY-API.md#package
|
||||
|
||||
@@ -28,8 +28,9 @@ func TestParsePackage(t *testing.T) {
|
||||
data := "H4sIAAAAAAAA/ytITM5OTE/VL4DQelnF+XkMVAYGBgZmJiYK2MRBwNDcSIHB2NTMwNDQzMwAqA7IMDUxA9LUdgg2UFpcklgEdAql5kD8ogCnhwio5lJQUMpLzE1VslJQcihOzi9I1S9JLS7RhSYIJR2QgrLUouLM/DyQGkM9Az1D3YIiqExKanFyUWZBCVQ2BKhVwQVJDKwosbQkI78IJO/tZ+LsbRykxFXLNdA+HwWjYBSMgpENACgAbtAACAAA"
|
||||
integrity := "sha512-yA4FJsVhetynGfOC1jFf79BuS+jrHbm0fhh+aHzCQkOaOBXKf9oBnC4a6DnLLnEsHQDRLYd00cwj8sCXpC+wIg=="
|
||||
repository := Repository{
|
||||
Type: "gitea",
|
||||
URL: "http://localhost:3000/gitea/test.git",
|
||||
Type: "gitea",
|
||||
URL: "http://localhost:3000/gitea/test.git",
|
||||
Directory: "packages/test-package",
|
||||
}
|
||||
|
||||
t.Run("InvalidUpload", func(t *testing.T) {
|
||||
@@ -298,6 +299,7 @@ func TestParsePackage(t *testing.T) {
|
||||
assert.Equal(t, "1.2.0", p.Metadata.Dependencies["package"])
|
||||
assert.Equal(t, repository.Type, p.Metadata.Repository.Type)
|
||||
assert.Equal(t, repository.URL, p.Metadata.Repository.URL)
|
||||
assert.Equal(t, repository.Directory, p.Metadata.Repository.Directory)
|
||||
})
|
||||
|
||||
t.Run("ValidLicenseMap", func(t *testing.T) {
|
||||
|
||||
@@ -434,6 +434,10 @@ type ChangesPayload struct {
|
||||
type PullRequestPayload struct {
|
||||
// The action performed on the pull request
|
||||
Action HookIssueAction `json:"action"`
|
||||
// The SHA of the most recent commit on the PR head branch before the push
|
||||
Before string `json:"before,omitempty"`
|
||||
// The SHA of the most recent commit on the PR head branch after the push
|
||||
After string `json:"after,omitempty"`
|
||||
// The index number of the pull request
|
||||
Index int64 `json:"number"`
|
||||
// Changes made to the pull request (for edit actions)
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package structs
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestPullRequestPayloadSynchronizeBeforeAfter(t *testing.T) {
|
||||
payload := &PullRequestPayload{
|
||||
Action: HookIssueSynchronized,
|
||||
Before: "1111111111111111111111111111111111111111",
|
||||
After: "2222222222222222222222222222222222222222",
|
||||
Index: 12,
|
||||
}
|
||||
|
||||
data, err := json.Marshal(payload)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.JSONEq(t, `{
|
||||
"action": "synchronized",
|
||||
"before": "1111111111111111111111111111111111111111",
|
||||
"after": "2222222222222222222222222222222222222222",
|
||||
"number": 12,
|
||||
"commit_id": "",
|
||||
"pull_request": null,
|
||||
"repository": null,
|
||||
"requested_reviewer": null,
|
||||
"review": null,
|
||||
"sender": null
|
||||
}`, string(data))
|
||||
}
|
||||
|
||||
func TestPullRequestPayloadNonSynchronizeOmitsBeforeAfter(t *testing.T) {
|
||||
payload := &PullRequestPayload{
|
||||
Action: HookIssueOpened,
|
||||
Index: 12,
|
||||
}
|
||||
|
||||
data, err := json.Marshal(payload)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.JSONEq(t, `{
|
||||
"action": "opened",
|
||||
"number": 12,
|
||||
"commit_id": "",
|
||||
"pull_request": null,
|
||||
"repository": null,
|
||||
"requested_reviewer": null,
|
||||
"review": null,
|
||||
"sender": null
|
||||
}`, string(data))
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/modules/charset"
|
||||
"code.gitea.io/gitea/modules/emoji"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/htmlutil"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/markup"
|
||||
@@ -223,6 +224,25 @@ func (ut *RenderUtils) MarkdownToHtml(input string) template.HTML { //nolint:rev
|
||||
return output
|
||||
}
|
||||
|
||||
// RenderPackageMarkdown renders package page Markdown so relative links resolve against the
|
||||
// linked repository's default branch instead of the site root, falling back to plain rendering
|
||||
// when there is no linked repository. pkgTreePath optionally roots links in a subdirectory
|
||||
// (e.g. npm's repository.directory for monorepo packages).
|
||||
func (ut *RenderUtils) RenderPackageMarkdown(input string, linkedRepo *repo.Repository, pkgTreePath ...string) template.HTML {
|
||||
if linkedRepo == nil {
|
||||
return `<div class="markup markdown">` + ut.MarkdownToHtml(input) + `</div>`
|
||||
}
|
||||
rctx := renderhelper.NewRenderContextRepoFile(ut.ctx, linkedRepo, renderhelper.RepoFileOptions{
|
||||
CurrentRefSubURL: git.RefNameFromBranch(linkedRepo.DefaultBranch).RefWebLinkPath(),
|
||||
CurrentTreePath: util.OptionalArg(pkgTreePath),
|
||||
})
|
||||
output, err := markdown.RenderString(rctx, input)
|
||||
if err != nil {
|
||||
log.Error("RenderString: %v", err)
|
||||
}
|
||||
return `<div class="markup markdown">` + output + `</div>`
|
||||
}
|
||||
|
||||
func (ut *RenderUtils) RenderLabels(labels []*issues_model.Label, repoLink string, issue *issues_model.Issue) template.HTML {
|
||||
isPullRequest := issue != nil && issue.IsPull
|
||||
baseLink := fmt.Sprintf("%s/%s", repoLink, util.Iif(isPullRequest, "pulls", "issues"))
|
||||
|
||||
@@ -194,6 +194,38 @@ space</p>
|
||||
assert.Equal(t, expected, string(newTestRenderUtils(t).MarkdownToHtml(testInput())))
|
||||
}
|
||||
|
||||
func TestRenderPackageMarkdown(t *testing.T) {
|
||||
defer test.MockVariableValue(&markup.RenderBehaviorForTesting.DisableAdditionalAttributes, true)()
|
||||
mockRepo := &repo.Repository{
|
||||
ID: 1, OwnerName: "user13", Name: "repo11", DefaultBranch: "main",
|
||||
Owner: &user_model.User{ID: 13, Name: "user13"},
|
||||
Units: []*repo.RepoUnit{},
|
||||
}
|
||||
ut := newTestRenderUtils(t)
|
||||
|
||||
t.Run("LinkedRepoWithDirectory", func(t *testing.T) {
|
||||
rendered := ut.RenderPackageMarkdown("[docs](docs/getting-started.md)\n", mockRepo, "pkg-subdir")
|
||||
expected := `<div class="markup markdown"><p><a href="/user13/repo11/src/branch/main/pkg-subdir/docs/getting-started.md" rel="nofollow">docs</a>
|
||||
<a href="/user13/repo11/src/branch/main/pkg-subdir/logo.png" target="_blank" rel="nofollow noopener"><img src="/user13/repo11/media/branch/main/pkg-subdir/logo.png" alt="logo"/></a></p>
|
||||
</div>`
|
||||
assert.Equal(t, expected, strings.TrimSpace(string(rendered)))
|
||||
})
|
||||
|
||||
t.Run("LinkedRepoWithEmptyDirectory", func(t *testing.T) {
|
||||
rendered := ut.RenderPackageMarkdown("[docs](docs/getting-started.md)", mockRepo, "")
|
||||
expected := `<div class="markup markdown"><p><a href="/user13/repo11/src/branch/main/docs/getting-started.md" rel="nofollow">docs</a></p>
|
||||
</div>`
|
||||
assert.Equal(t, expected, strings.TrimSpace(string(rendered)))
|
||||
})
|
||||
|
||||
t.Run("UnlinkedRepo", func(t *testing.T) {
|
||||
rendered := ut.RenderPackageMarkdown("[docs](docs/getting-started.md)", nil, "pkg-subdir")
|
||||
expected := `<div class="markup markdown"><p><a href="/docs/getting-started.md" rel="nofollow">docs</a></p>
|
||||
</div>`
|
||||
assert.Equal(t, expected, strings.TrimSpace(string(rendered)))
|
||||
})
|
||||
}
|
||||
|
||||
func TestRenderLabels(t *testing.T) {
|
||||
ut := newTestRenderUtils(t)
|
||||
label := &issues.Label{ID: 123, Name: "label-name", Color: "label-color"}
|
||||
|
||||
Reference in New Issue
Block a user