Skip to content

Commit 79018d0

Browse files
authored
Merge pull request #8945 from Turbo87/links-api
Expose `versions.links` column on the API
2 parents 7b5c61a + ec6bb54 commit 79018d0

18 files changed

+165
-0
lines changed

src/tests/krate/publish/links.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use crate::builders::PublishBuilder;
2+
use crate::util::insta::{self, assert_json_snapshot};
3+
use crate::util::{RequestHelper, TestApp};
4+
use http::StatusCode;
5+
6+
#[tokio::test(flavor = "multi_thread")]
7+
async fn test_crate_with_links_field() {
8+
let (app, anon, _, token) = TestApp::full().with_token();
9+
10+
let manifest = r#"
11+
[package]
12+
name = "foo"
13+
version = "1.0.0"
14+
description = "foo?!"
15+
license = "MIT"
16+
links = "git2"
17+
"#;
18+
19+
let pb = PublishBuilder::new("foo", "1.0.0").custom_manifest(manifest);
20+
let response = token.publish_crate(pb).await;
21+
assert_json_snapshot!(response.json(), {
22+
".crate.created_at" => "[datetime]",
23+
".crate.updated_at" => "[datetime]",
24+
});
25+
assert_eq!(response.status(), StatusCode::OK);
26+
27+
let response = anon.get::<()>("/api/v1/crates/foo/1.0.0").await;
28+
assert_json_snapshot!(response.json(), {
29+
".version.id" => insta::any_id_redaction(),
30+
".version.created_at" => "[datetime]",
31+
".version.updated_at" => "[datetime]",
32+
".version.audit_actions[].time" => "[datetime]",
33+
".version.published_by.id" => insta::any_id_redaction(),
34+
});
35+
assert_eq!(response.status(), StatusCode::OK);
36+
37+
let crates = app.crates_from_index_head("foo");
38+
assert_json_snapshot!(crates);
39+
}

src/tests/krate/publish/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ mod features;
99
mod git;
1010
mod inheritance;
1111
mod keywords;
12+
mod links;
1213
mod manifest;
1314
mod max_size;
1415
mod rate_limit;
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
source: src/tests/krate/publish/links.rs
3+
expression: response.json()
4+
---
5+
{
6+
"version": {
7+
"audit_actions": [
8+
{
9+
"action": "publish",
10+
"time": "[datetime]",
11+
"user": {
12+
"avatar": null,
13+
"id": 1,
14+
"login": "foo",
15+
"name": null,
16+
"url": "https://github.com/foo"
17+
}
18+
}
19+
],
20+
"bin_names": [],
21+
"checksum": "5631ca06d228e58274bbd8d6a3e81f7138a9e227a84bd63ecedb78afbc8144ea",
22+
"crate": "foo",
23+
"crate_size": 162,
24+
"created_at": "[datetime]",
25+
"dl_path": "/api/v1/crates/foo/1.0.0/download",
26+
"downloads": 0,
27+
"features": {},
28+
"has_lib": false,
29+
"id": "[id]",
30+
"lib_links": "git2",
31+
"license": "MIT",
32+
"links": {
33+
"authors": "/api/v1/crates/foo/1.0.0/authors",
34+
"dependencies": "/api/v1/crates/foo/1.0.0/dependencies",
35+
"version_downloads": "/api/v1/crates/foo/1.0.0/downloads"
36+
},
37+
"num": "1.0.0",
38+
"published_by": {
39+
"avatar": null,
40+
"id": "[id]",
41+
"login": "foo",
42+
"name": null,
43+
"url": "https://github.com/foo"
44+
},
45+
"readme_path": "/api/v1/crates/foo/1.0.0/readme",
46+
"rust_version": null,
47+
"updated_at": "[datetime]",
48+
"yanked": false
49+
}
50+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
source: src/tests/krate/publish/links.rs
3+
expression: crates
4+
---
5+
[
6+
{
7+
"name": "foo",
8+
"vers": "1.0.0",
9+
"deps": [],
10+
"cksum": "5631ca06d228e58274bbd8d6a3e81f7138a9e227a84bd63ecedb78afbc8144ea",
11+
"features": {},
12+
"yanked": false,
13+
"links": "git2"
14+
}
15+
]
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
source: src/tests/krate/publish/links.rs
3+
expression: response.json()
4+
---
5+
{
6+
"crate": {
7+
"badges": null,
8+
"categories": null,
9+
"created_at": "[datetime]",
10+
"description": "foo?!",
11+
"documentation": null,
12+
"downloads": 0,
13+
"exact_match": false,
14+
"homepage": null,
15+
"id": "foo",
16+
"keywords": null,
17+
"links": {
18+
"owner_team": "/api/v1/crates/foo/owner_team",
19+
"owner_user": "/api/v1/crates/foo/owner_user",
20+
"owners": "/api/v1/crates/foo/owners",
21+
"reverse_dependencies": "/api/v1/crates/foo/reverse_dependencies",
22+
"version_downloads": "/api/v1/crates/foo/downloads",
23+
"versions": "/api/v1/crates/foo/versions"
24+
},
25+
"max_stable_version": "1.0.0",
26+
"max_version": "1.0.0",
27+
"name": "foo",
28+
"newest_version": "1.0.0",
29+
"recent_downloads": null,
30+
"repository": null,
31+
"updated_at": "[datetime]",
32+
"versions": null
33+
},
34+
"warnings": {
35+
"invalid_badges": [],
36+
"invalid_categories": [],
37+
"other": []
38+
}
39+
}

src/tests/krate/publish/snapshots/all__krate__publish__manifest__boolean_readme-2.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ expression: response.json()
2727
"features": {},
2828
"has_lib": false,
2929
"id": "[id]",
30+
"lib_links": null,
3031
"license": "MIT",
3132
"links": {
3233
"authors": "/api/v1/crates/foo/1.0.0/authors",

src/tests/krate/publish/snapshots/all__krate__publish__manifest__lib_and_bin_crate-2.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ expression: response.json()
3030
"features": {},
3131
"has_lib": true,
3232
"id": "[id]",
33+
"lib_links": null,
3334
"license": "MIT",
3435
"links": {
3536
"authors": "/api/v1/crates/foo/1.0.0/authors",

src/tests/routes/crates/snapshots/all__routes__crates__read__show.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ expression: response.json()
5959
"features": {},
6060
"has_lib": null,
6161
"id": 1,
62+
"lib_links": null,
6263
"license": null,
6364
"links": {
6465
"authors": "/api/v1/crates/foo_show/1.0.0/authors",
@@ -84,6 +85,7 @@ expression: response.json()
8485
"features": {},
8586
"has_lib": null,
8687
"id": 3,
88+
"lib_links": null,
8789
"license": null,
8890
"links": {
8991
"authors": "/api/v1/crates/foo_show/0.5.1/authors",
@@ -115,6 +117,7 @@ expression: response.json()
115117
"features": {},
116118
"has_lib": null,
117119
"id": 2,
120+
"lib_links": null,
118121
"license": null,
119122
"links": {
120123
"authors": "/api/v1/crates/foo_show/0.5.0/authors",

src/tests/routes/crates/snapshots/all__routes__crates__reverse_dependencies__prerelease_versions_not_included_in_reverse_dependencies.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ expression: response.json()
3333
"features": {},
3434
"has_lib": null,
3535
"id": 3,
36+
"lib_links": null,
3637
"license": null,
3738
"links": {
3839
"authors": "/api/v1/crates/c3/1.0.0/authors",

src/tests/routes/crates/snapshots/all__routes__crates__reverse_dependencies__reverse_dependencies.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ expression: response.json()
3333
"features": {},
3434
"has_lib": null,
3535
"id": 3,
36+
"lib_links": null,
3637
"license": null,
3738
"links": {
3839
"authors": "/api/v1/crates/c2/1.1.0/authors",

src/tests/routes/crates/snapshots/all__routes__crates__reverse_dependencies__reverse_dependencies_includes_published_by_user_when_present.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ expression: response.json()
4545
"features": {},
4646
"has_lib": null,
4747
"id": 3,
48+
"lib_links": null,
4849
"license": null,
4950
"links": {
5051
"authors": "/api/v1/crates/c3/3.0.0/authors",
@@ -76,6 +77,7 @@ expression: response.json()
7677
"features": {},
7778
"has_lib": null,
7879
"id": 2,
80+
"lib_links": null,
7981
"license": null,
8082
"links": {
8183
"authors": "/api/v1/crates/c2/2.0.0/authors",

src/tests/routes/crates/snapshots/all__routes__crates__reverse_dependencies__reverse_dependencies_query_supports_u64_version_number_parts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ expression: response.json()
3333
"features": {},
3434
"has_lib": null,
3535
"id": 2,
36+
"lib_links": null,
3637
"license": null,
3738
"links": {
3839
"authors": "/api/v1/crates/c2/1.0.18446744073709551615/authors",

src/tests/routes/crates/snapshots/all__routes__crates__reverse_dependencies__reverse_dependencies_when_old_version_doesnt_depend_but_new_does.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ expression: response.json()
3333
"features": {},
3434
"has_lib": null,
3535
"id": 3,
36+
"lib_links": null,
3637
"license": null,
3738
"links": {
3839
"authors": "/api/v1/crates/c2/2.0.0/authors",

src/tests/routes/crates/snapshots/all__routes__crates__reverse_dependencies__yanked_versions_not_included_in_reverse_dependencies.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ expression: response.json()
3333
"features": {},
3434
"has_lib": null,
3535
"id": 3,
36+
"lib_links": null,
3637
"license": null,
3738
"links": {
3839
"authors": "/api/v1/crates/c2/2.0.0/authors",

src/tests/routes/crates/versions/snapshots/all__routes__crates__versions__list__versions.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ expression: response.json()
1616
"features": {},
1717
"has_lib": null,
1818
"id": 2,
19+
"lib_links": null,
1920
"license": null,
2021
"links": {
2122
"authors": "/api/v1/crates/foo_versions/1.0.0/authors",
@@ -41,6 +42,7 @@ expression: response.json()
4142
"features": {},
4243
"has_lib": null,
4344
"id": 1,
45+
"lib_links": null,
4446
"license": null,
4547
"links": {
4648
"authors": "/api/v1/crates/foo_versions/0.5.1/authors",
@@ -72,6 +74,7 @@ expression: response.json()
7274
"features": {},
7375
"has_lib": null,
7476
"id": 3,
77+
"lib_links": null,
7578
"license": null,
7679
"links": {
7780
"authors": "/api/v1/crates/foo_versions/0.5.0/authors",

src/tests/routes/crates/versions/snapshots/all__routes__crates__versions__read__show_by_crate_name_and_semver_no_published_by.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ expression: json
1515
"features": {},
1616
"has_lib": null,
1717
"id": "[id]",
18+
"lib_links": null,
1819
"license": null,
1920
"links": {
2021
"authors": "/api/v1/crates/foo_vers_show_no_pb/1.0.0/authors",

src/tests/routes/crates/versions/snapshots/all__routes__crates__versions__read__show_by_crate_name_and_version.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ expression: json
1515
"features": {},
1616
"has_lib": null,
1717
"id": "[id]",
18+
"lib_links": null,
1819
"license": null,
1920
"links": {
2021
"authors": "/api/v1/crates/foo_vers_show/2.0.0/authors",

src/views.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,7 @@ pub struct EncodableVersion {
558558
pub downloads: i32,
559559
pub features: serde_json::Value,
560560
pub yanked: bool,
561+
pub lib_links: Option<String>,
561562
// NOTE: Used by shields.io, altering `license` requires a PR with shields.io
562563
pub license: Option<String>,
563564
pub links: EncodableVersionLinks,
@@ -585,6 +586,7 @@ impl EncodableVersion {
585586
downloads,
586587
features,
587588
yanked,
589+
links: lib_links,
588590
license,
589591
crate_size,
590592
checksum,
@@ -611,6 +613,7 @@ impl EncodableVersion {
611613
downloads,
612614
features,
613615
yanked,
616+
lib_links,
614617
license,
615618
links,
616619
crate_size,
@@ -734,6 +737,7 @@ mod tests {
734737
features: serde_json::from_str("{}").unwrap(),
735738
yanked: false,
736739
license: None,
740+
lib_links: None,
737741
links: EncodableVersionLinks {
738742
dependencies: "".to_string(),
739743
version_downloads: "".to_string(),

0 commit comments

Comments
 (0)