Merge pull request '[v7.0/forgejo] templates: Be more forgiving about missing package metadata' (#3705) from bp-v7.0/forgejo-ac4d535 into v7.0/forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/3705
Reviewed-by: Gergely Nagy <algernon@noreply.codeberg.org>
This commit is contained in:
Earl Warren 2024-05-10 18:47:36 +00:00
commit ba1f73f550
3 changed files with 52 additions and 37 deletions

View file

@ -23,6 +23,7 @@
&lt;/snapshotRepository&gt; &lt;/snapshotRepository&gt;
&lt;/distributionManagement&gt;</code></pre></div> &lt;/distributionManagement&gt;</code></pre></div>
</div> </div>
{{if .PackageDescriptor.Metadata}}
<div class="field"> <div class="field">
<label>{{svg "octicon-code"}} {{ctx.Locale.Tr "packages.maven.install"}}</label> <label>{{svg "octicon-code"}} {{ctx.Locale.Tr "packages.maven.install"}}</label>
<div class="markup"><pre class="code-block"><code>&lt;dependency&gt; <div class="markup"><pre class="code-block"><code>&lt;dependency&gt;
@ -42,9 +43,11 @@
<div class="field"> <div class="field">
<label>{{ctx.Locale.Tr "packages.registry.documentation" "Maven" "https://forgejo.org/docs/latest/user/packages/maven/"}}</label> <label>{{ctx.Locale.Tr "packages.registry.documentation" "Maven" "https://forgejo.org/docs/latest/user/packages/maven/"}}</label>
</div> </div>
{{end}}
</div> </div>
</div> </div>
{{if .PackageDescriptor.Metadata}}
{{if .PackageDescriptor.Metadata.Description}} {{if .PackageDescriptor.Metadata.Description}}
<h4 class="ui top attached header">{{ctx.Locale.Tr "packages.about"}}</h4> <h4 class="ui top attached header">{{ctx.Locale.Tr "packages.about"}}</h4>
<div class="ui attached segment"> <div class="ui attached segment">
@ -68,4 +71,5 @@
</div> </div>
</div> </div>
{{end}} {{end}}
{{end}}
{{end}} {{end}}

View file

@ -1,4 +1,4 @@
{{if eq .PackageDescriptor.Package.Type "maven"}} {{if and (eq .PackageDescriptor.Package.Type "maven") .PackageDescriptor.Metadata}}
{{if .PackageDescriptor.Metadata.Name}}<div class="item">{{svg "octicon-note" 16 "tw-mr-2"}} {{.PackageDescriptor.Metadata.Name}}</div>{{end}} {{if .PackageDescriptor.Metadata.Name}}<div class="item">{{svg "octicon-note" 16 "tw-mr-2"}} {{.PackageDescriptor.Metadata.Name}}</div>{{end}}
{{if .PackageDescriptor.Metadata.ProjectURL}}<div class="item">{{svg "octicon-link-external" 16 "tw-mr-2"}} <a href="{{.PackageDescriptor.Metadata.ProjectURL}}" target="_blank" rel="noopener noreferrer me">{{ctx.Locale.Tr "packages.details.project_site"}}</a></div>{{end}} {{if .PackageDescriptor.Metadata.ProjectURL}}<div class="item">{{svg "octicon-link-external" 16 "tw-mr-2"}} <a href="{{.PackageDescriptor.Metadata.ProjectURL}}" target="_blank" rel="noopener noreferrer me">{{ctx.Locale.Tr "packages.details.project_site"}}</a></div>{{end}}
{{range .PackageDescriptor.Metadata.Licenses}}<div class="item" title="{{ctx.Locale.Tr "packages.details.license"}}">{{svg "octicon-law" 16 "tw-mr-2"}} {{.}}</div>{{end}} {{range .PackageDescriptor.Metadata.Licenses}}<div class="item" title="{{ctx.Locale.Tr "packages.details.license"}}">{{svg "octicon-law" 16 "tw-mr-2"}} {{.}}</div>{{end}}

View file

@ -241,4 +241,15 @@ func TestPackageMaven(t *testing.T) {
putFile(t, fmt.Sprintf("/%s/maven-metadata.xml", snapshotVersion), "test", http.StatusCreated) putFile(t, fmt.Sprintf("/%s/maven-metadata.xml", snapshotVersion), "test", http.StatusCreated)
putFile(t, fmt.Sprintf("/%s/maven-metadata.xml", snapshotVersion), "test-overwrite", http.StatusCreated) putFile(t, fmt.Sprintf("/%s/maven-metadata.xml", snapshotVersion), "test-overwrite", http.StatusCreated)
}) })
t.Run("Partial upload", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
partialVersion := packageVersion + "-PARTIAL"
putFile(t, fmt.Sprintf("/%s/%s", partialVersion, filename), "test", http.StatusCreated)
pkgUIURL := fmt.Sprintf("/%s/-/packages/maven/%s-%s/%s", user.Name, groupID, artifactID, partialVersion)
req := NewRequest(t, "GET", pkgUIURL)
resp := MakeRequest(t, req, http.StatusOK)
assert.NotContains(t, resp.Body.String(), "Internal server error")
})
} }