Skip to content

Commit 52eb9cb

Browse files
committed
Expose versions.edition content on the API
1 parent 61f5a2f commit 52eb9cb

File tree

25 files changed

+169
-6
lines changed

25 files changed

+169
-6
lines changed

src/tests/krate/publish/edition.rs

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

src/tests/krate/publish/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ mod basics;
44
mod build_metadata;
55
mod categories;
66
mod dependencies;
7+
mod edition;
78
mod emails;
89
mod features;
910
mod git;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
source: src/tests/krate/publish/edition.rs
3+
expression: response.json()
4+
snapshot_kind: text
5+
---
6+
{
7+
"version": {
8+
"audit_actions": [
9+
{
10+
"action": "publish",
11+
"time": "[datetime]",
12+
"user": {
13+
"avatar": null,
14+
"id": "[id]",
15+
"login": "foo",
16+
"name": null,
17+
"url": "https://github.com/foo"
18+
}
19+
}
20+
],
21+
"bin_names": [],
22+
"checksum": "4805f4e5e01fc111fc0b2bfa5986931ef1b64504eca42b15b5ef8b98e45c9125",
23+
"crate": "foo",
24+
"crate_size": 169,
25+
"created_at": "[datetime]",
26+
"dl_path": "/api/v1/crates/foo/1.0.0/download",
27+
"downloads": 0,
28+
"edition": "2021",
29+
"features": {},
30+
"has_lib": false,
31+
"id": "[id]",
32+
"lib_links": null,
33+
"license": "MIT",
34+
"links": {
35+
"authors": "/api/v1/crates/foo/1.0.0/authors",
36+
"dependencies": "/api/v1/crates/foo/1.0.0/dependencies",
37+
"version_downloads": "/api/v1/crates/foo/1.0.0/downloads"
38+
},
39+
"num": "1.0.0",
40+
"published_by": {
41+
"avatar": null,
42+
"id": "[id]",
43+
"login": "foo",
44+
"name": null,
45+
"url": "https://github.com/foo"
46+
},
47+
"readme_path": "/api/v1/crates/foo/1.0.0/readme",
48+
"rust_version": "1.0",
49+
"updated_at": "[datetime]",
50+
"yank_message": null,
51+
"yanked": false
52+
}
53+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
source: src/tests/krate/publish/edition.rs
3+
expression: response.json()
4+
snapshot_kind: text
5+
---
6+
{
7+
"crate": {
8+
"badges": [],
9+
"categories": null,
10+
"created_at": "[datetime]",
11+
"default_version": "1.0.0",
12+
"description": "description",
13+
"documentation": null,
14+
"downloads": 0,
15+
"exact_match": false,
16+
"homepage": null,
17+
"id": "foo",
18+
"keywords": null,
19+
"links": {
20+
"owner_team": "/api/v1/crates/foo/owner_team",
21+
"owner_user": "/api/v1/crates/foo/owner_user",
22+
"owners": "/api/v1/crates/foo/owners",
23+
"reverse_dependencies": "/api/v1/crates/foo/reverse_dependencies",
24+
"version_downloads": "/api/v1/crates/foo/downloads",
25+
"versions": "/api/v1/crates/foo/versions"
26+
},
27+
"max_stable_version": "1.0.0",
28+
"max_version": "1.0.0",
29+
"name": "foo",
30+
"newest_version": "1.0.0",
31+
"recent_downloads": null,
32+
"repository": null,
33+
"updated_at": "[datetime]",
34+
"versions": null,
35+
"yanked": false
36+
},
37+
"warnings": {
38+
"invalid_badges": [],
39+
"invalid_categories": [],
40+
"other": []
41+
}
42+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ snapshot_kind: text
2525
"created_at": "[datetime]",
2626
"dl_path": "/api/v1/crates/foo/1.0.0/download",
2727
"downloads": 0,
28+
"edition": null,
2829
"features": {},
2930
"has_lib": false,
3031
"id": "[id]",

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ snapshot_kind: text
2525
"created_at": "[datetime]",
2626
"dl_path": "/api/v1/crates/foo/1.0.0/download",
2727
"downloads": 0,
28+
"edition": null,
2829
"features": {},
2930
"has_lib": false,
3031
"id": "[id]",

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ snapshot_kind: text
2828
"created_at": "[datetime]",
2929
"dl_path": "/api/v1/crates/foo/1.0.0/download",
3030
"downloads": 0,
31+
"edition": null,
3132
"features": {},
3233
"has_lib": true,
3334
"id": "[id]",

src/tests/krate/snapshots/crates_io__tests__krate__yanking__patch_version_yank_unyank-2.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ snapshot_kind: text
5858
"checksum": "ddfc395ab340f413ee1d1ed0afce51a7c9df1c99c551fed5aef76edd4abe4048",
5959
"rust_version": null,
6060
"has_lib": false,
61-
"bin_names": []
61+
"bin_names": [],
62+
"edition": null
6263
}
6364
}

src/tests/krate/snapshots/crates_io__tests__krate__yanking__patch_version_yank_unyank-3.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ snapshot_kind: text
6969
"checksum": "ddfc395ab340f413ee1d1ed0afce51a7c9df1c99c551fed5aef76edd4abe4048",
7070
"rust_version": null,
7171
"has_lib": false,
72-
"bin_names": []
72+
"bin_names": [],
73+
"edition": null
7374
}
7475
}

src/tests/krate/snapshots/crates_io__tests__krate__yanking__patch_version_yank_unyank-4.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ snapshot_kind: text
6969
"checksum": "ddfc395ab340f413ee1d1ed0afce51a7c9df1c99c551fed5aef76edd4abe4048",
7070
"rust_version": null,
7171
"has_lib": false,
72-
"bin_names": []
72+
"bin_names": [],
73+
"edition": null
7374
}
7475
}

src/tests/krate/snapshots/crates_io__tests__krate__yanking__patch_version_yank_unyank-5.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ snapshot_kind: text
8080
"checksum": "ddfc395ab340f413ee1d1ed0afce51a7c9df1c99c551fed5aef76edd4abe4048",
8181
"rust_version": null,
8282
"has_lib": false,
83-
"bin_names": []
83+
"bin_names": [],
84+
"edition": null
8485
}
8586
}

src/tests/krate/snapshots/crates_io__tests__krate__yanking__patch_version_yank_unyank-6.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ snapshot_kind: text
8080
"checksum": "ddfc395ab340f413ee1d1ed0afce51a7c9df1c99c551fed5aef76edd4abe4048",
8181
"rust_version": null,
8282
"has_lib": false,
83-
"bin_names": []
83+
"bin_names": [],
84+
"edition": null
8485
}
8586
}

src/tests/krate/snapshots/crates_io__tests__krate__yanking__patch_version_yank_unyank.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ snapshot_kind: text
5858
"checksum": "ddfc395ab340f413ee1d1ed0afce51a7c9df1c99c551fed5aef76edd4abe4048",
5959
"rust_version": null,
6060
"has_lib": false,
61-
"bin_names": []
61+
"bin_names": [],
62+
"edition": null
6263
}
6364
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ snapshot_kind: text
5959
"created_at": "[datetime]",
6060
"dl_path": "/api/v1/crates/foo_show/1.0.0/download",
6161
"downloads": 0,
62+
"edition": null,
6263
"features": {},
6364
"has_lib": null,
6465
"id": 1,
@@ -86,6 +87,7 @@ snapshot_kind: text
8687
"created_at": "[datetime]",
8788
"dl_path": "/api/v1/crates/foo_show/0.5.1/download",
8889
"downloads": 0,
90+
"edition": null,
8991
"features": {},
9092
"has_lib": null,
9193
"id": 3,
@@ -119,6 +121,7 @@ snapshot_kind: text
119121
"created_at": "[datetime]",
120122
"dl_path": "/api/v1/crates/foo_show/0.5.0/download",
121123
"downloads": 0,
124+
"edition": null,
122125
"features": {},
123126
"has_lib": null,
124127
"id": 2,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ snapshot_kind: text
5858
"created_at": "[datetime]",
5959
"dl_path": "/api/v1/crates/foo_show/1.0.0/download",
6060
"downloads": 0,
61+
"edition": null,
6162
"features": {},
6263
"has_lib": null,
6364
"id": 1,
@@ -91,6 +92,7 @@ snapshot_kind: text
9192
"created_at": "[datetime]",
9293
"dl_path": "/api/v1/crates/foo_show/0.5.0/download",
9394
"downloads": 0,
95+
"edition": null,
9496
"features": {},
9597
"has_lib": null,
9698
"id": 2,

src/tests/routes/crates/snapshots/crates_io__tests__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
@@ -31,6 +31,7 @@ snapshot_kind: text
3131
"created_at": "[datetime]",
3232
"dl_path": "/api/v1/crates/c3/1.0.0/download",
3333
"downloads": 0,
34+
"edition": null,
3435
"features": {},
3536
"has_lib": null,
3637
"id": 3,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ snapshot_kind: text
3131
"created_at": "[datetime]",
3232
"dl_path": "/api/v1/crates/c2/1.1.0/download",
3333
"downloads": 0,
34+
"edition": null,
3435
"features": {},
3536
"has_lib": null,
3637
"id": 3,

src/tests/routes/crates/snapshots/crates_io__tests__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
@@ -43,6 +43,7 @@ snapshot_kind: text
4343
"created_at": "[datetime]",
4444
"dl_path": "/api/v1/crates/c3/3.0.0/download",
4545
"downloads": 0,
46+
"edition": null,
4647
"features": {},
4748
"has_lib": null,
4849
"id": 3,
@@ -76,6 +77,7 @@ snapshot_kind: text
7677
"created_at": "[datetime]",
7778
"dl_path": "/api/v1/crates/c2/2.0.0/download",
7879
"downloads": 0,
80+
"edition": null,
7981
"features": {},
8082
"has_lib": null,
8183
"id": 2,

src/tests/routes/crates/snapshots/crates_io__tests__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
@@ -31,6 +31,7 @@ snapshot_kind: text
3131
"created_at": "[datetime]",
3232
"dl_path": "/api/v1/crates/c2/1.0.18446744073709551615/download",
3333
"downloads": 0,
34+
"edition": null,
3435
"features": {},
3536
"has_lib": null,
3637
"id": 2,

src/tests/routes/crates/snapshots/crates_io__tests__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
@@ -31,6 +31,7 @@ snapshot_kind: text
3131
"created_at": "[datetime]",
3232
"dl_path": "/api/v1/crates/c2/2.0.0/download",
3333
"downloads": 0,
34+
"edition": null,
3435
"features": {},
3536
"has_lib": null,
3637
"id": 3,

src/tests/routes/crates/snapshots/crates_io__tests__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
@@ -31,6 +31,7 @@ snapshot_kind: text
3131
"created_at": "[datetime]",
3232
"dl_path": "/api/v1/crates/c2/2.0.0/download",
3333
"downloads": 0,
34+
"edition": null,
3435
"features": {},
3536
"has_lib": null,
3637
"id": 3,

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ snapshot_kind: text
1414
"created_at": "[datetime]",
1515
"dl_path": "/api/v1/crates/foo_versions/1.0.0/download",
1616
"downloads": 0,
17+
"edition": null,
1718
"features": {},
1819
"has_lib": null,
1920
"id": 2,
@@ -41,6 +42,7 @@ snapshot_kind: text
4142
"created_at": "[datetime]",
4243
"dl_path": "/api/v1/crates/foo_versions/0.5.1/download",
4344
"downloads": 0,
45+
"edition": null,
4446
"features": {},
4547
"has_lib": null,
4648
"id": 1,
@@ -74,6 +76,7 @@ snapshot_kind: text
7476
"created_at": "[datetime]",
7577
"dl_path": "/api/v1/crates/foo_versions/0.5.0/download",
7678
"downloads": 0,
79+
"edition": null,
7780
"features": {},
7881
"has_lib": null,
7982
"id": 3,

src/tests/routes/crates/versions/snapshots/crates_io__tests__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
@@ -13,6 +13,7 @@ snapshot_kind: text
1313
"created_at": "[datetime]",
1414
"dl_path": "/api/v1/crates/foo_vers_show_no_pb/1.0.0/download",
1515
"downloads": 0,
16+
"edition": null,
1617
"features": {},
1718
"has_lib": null,
1819
"id": "[id]",

src/tests/routes/crates/versions/snapshots/crates_io__tests__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
@@ -13,6 +13,7 @@ snapshot_kind: text
1313
"created_at": "[datetime]",
1414
"dl_path": "/api/v1/crates/foo_vers_show/2.0.0/download",
1515
"downloads": 0,
16+
"edition": null,
1617
"features": {},
1718
"has_lib": null,
1819
"id": "[id]",

src/views.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ pub struct EncodableVersion {
586586
pub rust_version: Option<String>,
587587
pub has_lib: Option<bool>,
588588
pub bin_names: Option<Vec<Option<String>>>,
589+
pub edition: Option<String>,
589590
}
590591

591592
impl EncodableVersion {
@@ -611,6 +612,7 @@ impl EncodableVersion {
611612
rust_version,
612613
has_lib,
613614
bin_names,
615+
edition,
614616
..
615617
} = version;
616618

@@ -640,6 +642,7 @@ impl EncodableVersion {
640642
rust_version,
641643
has_lib,
642644
bin_names,
645+
edition,
643646
published_by: published_by.map(User::into),
644647
audit_actions: audit_actions
645648
.into_iter()
@@ -769,6 +772,7 @@ mod tests {
769772
has_lib: None,
770773
bin_names: None,
771774
published_by: None,
775+
edition: None,
772776
audit_actions: vec![EncodableAuditAction {
773777
action: "publish".to_string(),
774778
user: EncodablePublicUser {

0 commit comments

Comments
 (0)