Skip to content

Commit 46addc1

Browse files
Zettat123KN4CK3R
andauthored
Return repository in npm package metadata endpoint (#23539)
Close #23444 Add `Repository` to npm package `Metadata` struct so the `repository` in `package.json` can be stored and be returned in the endpoint. Co-authored-by: KN4CK3R <[email protected]>
1 parent d0f4818 commit 46addc1

File tree

5 files changed

+18
-0
lines changed

5 files changed

+18
-0
lines changed

modules/packages/npm/creator.go

+1
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ func ParsePackage(r io.Reader) (*Package, error) {
223223
OptionalDependencies: meta.OptionalDependencies,
224224
Bin: meta.Bin,
225225
Readme: meta.Readme,
226+
Repository: meta.Repository,
226227
},
227228
}
228229

modules/packages/npm/creator_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ func TestParsePackage(t *testing.T) {
2626
packageDescription := "Test Description"
2727
data := "H4sIAAAAAAAA/ytITM5OTE/VL4DQelnF+XkMVAYGBgZmJiYK2MRBwNDcSIHB2NTMwNDQzMwAqA7IMDUxA9LUdgg2UFpcklgEdAql5kD8ogCnhwio5lJQUMpLzE1VslJQcihOzi9I1S9JLS7RhSYIJR2QgrLUouLM/DyQGkM9Az1D3YIiqExKanFyUWZBCVQ2BKhVwQVJDKwosbQkI78IJO/tZ+LsbRykxFXLNdA+HwWjYBSMgpENACgAbtAACAAA"
2828
integrity := "sha512-yA4FJsVhetynGfOC1jFf79BuS+jrHbm0fhh+aHzCQkOaOBXKf9oBnC4a6DnLLnEsHQDRLYd00cwj8sCXpC+wIg=="
29+
repository := Repository{
30+
Type: "gitea",
31+
URL: "http://localhost:3000/gitea/test.git",
32+
}
2933

3034
t.Run("InvalidUpload", func(t *testing.T) {
3135
p, err := ParsePackage(bytes.NewReader([]byte{0}))
@@ -242,6 +246,7 @@ func TestParsePackage(t *testing.T) {
242246
Dist: PackageDistribution{
243247
Integrity: integrity,
244248
},
249+
Repository: repository,
245250
},
246251
},
247252
},
@@ -272,5 +277,7 @@ func TestParsePackage(t *testing.T) {
272277
assert.Equal(t, "https://gitea.io/", p.Metadata.ProjectURL)
273278
assert.Contains(t, p.Metadata.Dependencies, "package")
274279
assert.Equal(t, "1.2.0", p.Metadata.Dependencies["package"])
280+
assert.Equal(t, repository.Type, p.Metadata.Repository.Type)
281+
assert.Equal(t, repository.URL, p.Metadata.Repository.URL)
275282
})
276283
}

modules/packages/npm/metadata.go

+1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ type Metadata struct {
2121
OptionalDependencies map[string]string `json:"optional_dependencies,omitempty"`
2222
Bin map[string]string `json:"bin,omitempty"`
2323
Readme string `json:"readme,omitempty"`
24+
Repository Repository `json:"repository,omitempty"`
2425
}

routers/api/packages/npm/api.go

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func createPackageMetadataResponse(registryURL string, pds []*packages_model.Pac
4545
Author: npm_module.User{Name: metadata.Author},
4646
License: metadata.License,
4747
Versions: versions,
48+
Repository: metadata.Repository,
4849
}
4950
}
5051

tests/integration/api_packages_npm_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ func TestPackageNpm(t *testing.T) {
3737
packageDescription := "Test Description"
3838
packageBinName := "cli"
3939
packageBinPath := "./cli.sh"
40+
repoType := "gitea"
41+
repoURL := "http://localhost:3000/gitea/test.git"
4042

4143
data := "H4sIAAAAAAAA/ytITM5OTE/VL4DQelnF+XkMVAYGBgZmJiYK2MRBwNDcSIHB2NTMwNDQzMwAqA7IMDUxA9LUdgg2UFpcklgEdAql5kD8ogCnhwio5lJQUMpLzE1VslJQcihOzi9I1S9JLS7RhSYIJR2QgrLUouLM/DyQGkM9Az1D3YIiqExKanFyUWZBCVQ2BKhVwQVJDKwosbQkI78IJO/tZ+LsbRykxFXLNdA+HwWjYBSMgpENACgAbtAACAAA"
4244

@@ -62,6 +64,10 @@ func TestPackageNpm(t *testing.T) {
6264
"dist": {
6365
"integrity": "sha512-yA4FJsVhetynGfOC1jFf79BuS+jrHbm0fhh+aHzCQkOaOBXKf9oBnC4a6DnLLnEsHQDRLYd00cwj8sCXpC+wIg==",
6466
"shasum": "aaa7eaf852a948b0aa05afeda35b1badca155d90"
67+
},
68+
"repository": {
69+
"type": "` + repoType + `",
70+
"url": "` + repoURL + `"
6571
}
6672
}
6773
},
@@ -169,6 +175,8 @@ func TestPackageNpm(t *testing.T) {
169175
assert.Equal(t, "sha512-yA4FJsVhetynGfOC1jFf79BuS+jrHbm0fhh+aHzCQkOaOBXKf9oBnC4a6DnLLnEsHQDRLYd00cwj8sCXpC+wIg==", pmv.Dist.Integrity)
170176
assert.Equal(t, "aaa7eaf852a948b0aa05afeda35b1badca155d90", pmv.Dist.Shasum)
171177
assert.Equal(t, fmt.Sprintf("%s%s/-/%s/%s", setting.AppURL, root[1:], packageVersion, filename), pmv.Dist.Tarball)
178+
assert.Equal(t, repoType, result.Repository.Type)
179+
assert.Equal(t, repoURL, result.Repository.URL)
172180
})
173181

174182
t.Run("AddTag", func(t *testing.T) {

0 commit comments

Comments
 (0)