don't
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(lexicon): add sh.tangled.git.refUpdate to lexicon

Signed-off-by: tjh <did:plc:65gha4t3avpfpzmvpbwovss7>

+113
+1
crates/lexicon/src/sh/tangled.rs
··· 3 3 //! 4 4 pub mod actor; 5 5 pub mod feed; 6 + pub mod git; 6 7 pub mod graph; 7 8 pub mod knot; 8 9 pub mod repo;
+112
crates/lexicon/src/sh/tangled/git.rs
··· 1 + use std::borrow::Cow; 2 + 3 + use atproto::Did; 4 + use serde::{Deserialize, Serialize}; 5 + 6 + /// `sh.tangled.git.refUpdate` record 7 + /// 8 + /// See: <https://tangled.org/tangled.org/core/blob/master/lexicons/git/refUpdate.json> 9 + #[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] 10 + #[serde(rename_all = "camelCase")] 11 + pub struct RefUpdate<'a> { 12 + /// Ref being updated. 13 + #[serde(borrow)] 14 + pub r#ref: Cow<'a, str>, 15 + 16 + /// DID of the user that push this ref. 17 + pub committer_did: Cow<'a, Did>, 18 + 19 + /// DID of the owner of the repo. 20 + pub repo_did: Cow<'a, Did>, 21 + 22 + /// Name of the repo. 23 + pub repo_name: Cow<'a, str>, 24 + 25 + /// Old SHA of this ref. 26 + pub old_sha: Cow<'a, str>, 27 + 28 + /// New SHA of this ref. 29 + pub new_sha: Cow<'a, str>, 30 + 31 + pub meta: Meta<'a>, 32 + } 33 + 34 + #[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] 35 + #[serde(rename_all = "camelCase")] 36 + pub struct Meta<'a> { 37 + pub is_default_ref: bool, 38 + 39 + #[serde(borrow)] 40 + pub lang_breakdown: LanguageBreakdown<'a>, 41 + 42 + pub commit_count: CommitCountBreakdown<'a>, 43 + } 44 + 45 + #[derive(Debug, Default, PartialEq, Eq, Deserialize, Serialize)] 46 + #[serde(rename_all = "camelCase")] 47 + pub struct LanguageBreakdown<'a> { 48 + #[serde(borrow, default, skip_serializing_if = "Vec::is_empty")] 49 + pub inputs: Vec<Language<'a>>, 50 + } 51 + 52 + #[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] 53 + #[serde(rename_all = "camelCase")] 54 + pub struct Language<'a> { 55 + #[serde(borrow)] 56 + pub lang: Cow<'a, str>, 57 + pub size: u64, 58 + } 59 + 60 + #[derive(Debug, Default, PartialEq, Eq, Deserialize, Serialize)] 61 + #[serde(rename_all = "camelCase")] 62 + pub struct CommitCountBreakdown<'a> { 63 + #[serde(borrow, default, skip_serializing_if = "Vec::is_empty")] 64 + pub by_email: Vec<CommitCount<'a>>, 65 + } 66 + 67 + #[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] 68 + #[serde(rename_all = "camelCase")] 69 + pub struct CommitCount<'a> { 70 + #[serde(borrow)] 71 + pub email: Cow<'a, str>, 72 + pub count: u64, 73 + } 74 + 75 + #[cfg(test)] 76 + mod tests { 77 + use super::RefUpdate; 78 + 79 + #[test] 80 + fn can_deserialize() { 81 + const SAMPLE: &str = r#" 82 + { 83 + "$type": "", 84 + "committerDid": "did:plc:65gha4t3avpfpzmvpbwovss7", 85 + "meta": { 86 + "commitCount": { 87 + "byEmail": [ 88 + { 89 + "count": 1, 90 + "email": "x@tjh.dev" 91 + } 92 + ] 93 + }, 94 + "isDefaultRef": true, 95 + "langBreakdown": {} 96 + }, 97 + "newSha": "74771f21d2d409e7014af3206839fda30a429311", 98 + "oldSha": "0000000000000000000000000000000000000000", 99 + "ref": "refs/heads/main", 100 + "repoDid": "did:plc:65gha4t3avpfpzmvpbwovss7", 101 + "repoName": "lol" 102 + } 103 + 104 + "#; 105 + 106 + let update: RefUpdate = serde_json::from_str(SAMPLE).unwrap(); 107 + assert_eq!( 108 + update.committer_did.as_str(), 109 + "did:plc:65gha4t3avpfpzmvpbwovss7" 110 + ); 111 + } 112 + }