-
Notifications
You must be signed in to change notification settings - Fork 227
WIP: watcher: add sqs sdk, add first draft for event payload structs #3349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
syphar
wants to merge
16
commits into
rust-lang:main
Choose a base branch
from
syphar:crates-io-sqs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9d1b50b
add aws-sdk-sqs
syphar fddeb9a
add shared subcrate for event types
syphar 87c4384
feat(events): add event envelope metadata
syphar b7403da
refactor(events): version event payload types
syphar e52cae8
refactor(events): use typed event timestamps
syphar 6b053a3
refactor(events): use chrono timestamps
syphar 0b7dd8d
wider deps
syphar 277ea22
fix(watcher): make version delete idempotent
syphar cb7453f
feat(watcher): add SQS config
syphar de207e5
refactor(watcher): parse SQS queue URL
syphar b311a59
chore(lockfile): record watcher url dep
syphar e84c343
refactor(events): drop schema version
syphar 1e374cf
renames
syphar bb4d845
some cleanup
syphar c0436b1
no rustls
syphar 26db891
Merge branch 'main' into crates-io-sqs
syphar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| [package] | ||
| name = "docs_rs_crates_io" | ||
| version = "0.1.0" | ||
| description = "types & logic for the direct integration between docs.rs & crates.io" | ||
|
|
||
| authors.workspace = true | ||
| license.workspace = true | ||
| repository.workspace = true | ||
| edition.workspace = true | ||
|
|
||
| [dependencies] | ||
| chrono = { version = "0.4", features = ["serde"] } | ||
| serde = { version = "1", features = ["derive"] } | ||
| semver = { version = "1", features = ["serde"] } | ||
|
|
||
| [dev-dependencies] | ||
| serde_json = "1.0" | ||
|
|
||
| [lints] | ||
| workspace = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,207 @@ | ||
| #![allow(clippy::disallowed_types)] | ||
|
|
||
| use chrono::{DateTime, Utc}; | ||
| use std::fmt; | ||
|
|
||
| /// A change that can happen to a crate on our index. | ||
| #[derive(Clone, serde::Serialize, serde::Deserialize, Eq, PartialEq, Debug)] | ||
| #[serde(tag = "type", content = "payload", rename_all = "snake_case")] | ||
| pub enum IndexChangeV1 { | ||
| /// A crate version was added. | ||
| Added(CrateVersion), | ||
| /// A crate version was unyanked. | ||
| Unyanked(CrateVersion), | ||
| /// A crate version was yanked. | ||
| Yanked(CrateVersion), | ||
| /// The name of the crate whose file was deleted, which implies all versions were deleted as well. | ||
| CrateDeleted { name: String }, | ||
| /// A crate version was deleted. | ||
| VersionDeleted(CrateVersion), | ||
| } | ||
|
|
||
| impl fmt::Display for IndexChangeV1 { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| write!( | ||
| f, | ||
| "{}", | ||
| match *self { | ||
| IndexChangeV1::Added(_) => "added", | ||
| IndexChangeV1::Yanked(_) => "yanked", | ||
| IndexChangeV1::CrateDeleted { .. } => "crate deleted", | ||
| IndexChangeV1::VersionDeleted(_) => "version deleted", | ||
| IndexChangeV1::Unyanked(_) => "unyanked", | ||
| } | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| /// A conventional event envelope for our events between crates.io & docs.rs | ||
| #[derive(Clone, serde::Serialize, serde::Deserialize, Eq, PartialEq, Debug)] | ||
| pub struct Event<T> { | ||
| /// Unique event identifier for deduplication and tracing. | ||
| pub id: String, | ||
| /// Timestamp when the event occured | ||
| pub occurred_at: DateTime<Utc>, | ||
| /// The typed payload. | ||
| #[serde(flatten)] | ||
| pub change: T, | ||
| } | ||
|
|
||
| /// The first version of the public event wire format. | ||
| pub type IndexChangeEventV1 = Event<IndexChangeV1>; | ||
|
|
||
| /// Pack all information we know about a change made to a version of a crate. | ||
| #[derive(Clone, serde::Serialize, serde::Deserialize, Eq, PartialEq, Debug)] | ||
| pub struct CrateVersion { | ||
| /// The crate name, i.e. `clap`. | ||
| pub name: String, | ||
| /// is the release yanked? | ||
| pub yanked: bool, | ||
| /// The semantic version of the crate. | ||
| #[serde(rename = "vers")] | ||
| pub version: semver::Version, | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use serde_json::json; | ||
|
|
||
| fn crate_version() -> CrateVersion { | ||
| CrateVersion { | ||
| name: "clap".into(), | ||
| yanked: false, | ||
| version: semver::Version::new(4, 5, 0), | ||
| } | ||
| } | ||
|
|
||
| fn event(change: IndexChangeV1) -> IndexChangeEventV1 { | ||
| IndexChangeEventV1 { | ||
| id: "evt_123".into(), | ||
| occurred_at: DateTime::parse_from_rfc3339("2026-05-22T12:34:56Z") | ||
| .unwrap() | ||
| .with_timezone(&Utc), | ||
| change, | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn crate_version_serializes_with_vers_field() { | ||
| let event = crate_version(); | ||
|
|
||
| assert_eq!( | ||
| serde_json::to_value(&event).unwrap(), | ||
| json!({ | ||
| "name": "clap", | ||
| "yanked": false, | ||
| "vers": "4.5.0", | ||
| }) | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn change_serializes_with_expected_variant_shapes() { | ||
| let crate_version = crate_version(); | ||
|
|
||
| let cases = [ | ||
| ( | ||
| IndexChangeV1::Added(crate_version.clone()), | ||
| json!({ | ||
| "type": "added", | ||
| "payload": { | ||
| "name": "clap", | ||
| "yanked": false, | ||
| "vers": "4.5.0", | ||
| } | ||
| }), | ||
| ), | ||
| ( | ||
| IndexChangeV1::Unyanked(crate_version.clone()), | ||
| json!({ | ||
| "type": "unyanked", | ||
| "payload": { | ||
| "name": "clap", | ||
| "yanked": false, | ||
| "vers": "4.5.0", | ||
| } | ||
| }), | ||
| ), | ||
| ( | ||
| IndexChangeV1::Yanked(crate_version.clone()), | ||
| json!({ | ||
| "type": "yanked", | ||
| "payload": { | ||
| "name": "clap", | ||
| "yanked": false, | ||
| "vers": "4.5.0", | ||
| } | ||
| }), | ||
| ), | ||
| ( | ||
| IndexChangeV1::CrateDeleted { | ||
| name: "old-crate".into(), | ||
| }, | ||
| json!({ | ||
| "type": "crate_deleted", | ||
| "payload": { | ||
| "name": "old-crate" | ||
| } | ||
| }), | ||
| ), | ||
| ( | ||
| IndexChangeV1::VersionDeleted(crate_version), | ||
| json!({ | ||
| "type": "version_deleted", | ||
| "payload": { | ||
| "name": "clap", | ||
| "yanked": false, | ||
| "vers": "4.5.0", | ||
| } | ||
| }), | ||
| ), | ||
| ]; | ||
|
|
||
| for (event, expected) in cases { | ||
| assert_eq!(serde_json::to_value(&event).unwrap(), expected); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn event_serializes_with_minimum_metadata() { | ||
| let event = event(IndexChangeV1::CrateDeleted { | ||
| name: "old-crate".into(), | ||
| }); | ||
|
|
||
| assert_eq!( | ||
| serde_json::to_value(&event).unwrap(), | ||
| json!({ | ||
| "id": "evt_123", | ||
| "occurred_at": "2026-05-22T12:34:56Z", | ||
| "type": "crate_deleted", | ||
| "payload": { | ||
| "name": "old-crate" | ||
| } | ||
| }) | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn event_deserializes_rfc3339_occurred_at() { | ||
| let event: IndexChangeEventV1 = serde_json::from_value(json!({ | ||
| "id": "evt_123", | ||
| "occurred_at": "2026-05-22T12:34:56Z", | ||
| "type": "crate_deleted", | ||
| "payload": { | ||
| "name": "old-crate" | ||
| } | ||
| })) | ||
| .unwrap(); | ||
|
|
||
| assert_eq!( | ||
| event.occurred_at, | ||
| DateTime::parse_from_rfc3339("2026-05-22T12:34:56Z") | ||
| .unwrap() | ||
| .with_timezone(&Utc) | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| pub mod events; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note to myself:
this needs either
pubor accessorsView changes since the review