1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
use activitystreams_vocabulary::create_object;
create_object! {
/// Represents a named set of changes that are being proposed for applying to a specific [Repository](crate::Repository).
///
/// # Example
///
/// ```rust
/// use activityforge::{Patch, context};
/// use activitystreams_vocabulary::{Iri, MimeType};
///
/// # fn main() {
/// let id =
/// Iri::try_from("https://dev.example/aviva/game-of-life/pulls/825/versions/1/patches/1").unwrap();
/// let attributed_to = Iri::try_from("https://forge.example/luke").unwrap();
/// let context =
/// Iri::try_from("https://dev.example/aviva/game-of-life/pulls/825/versions/1").unwrap();
/// let media_type = MimeType::ApplicationGitPatch;
/// let content = "From c9ae5f4ff4a330b6e1196ceb7db1665bd4c1...";
///
/// let json_str = format!(
/// r#"{{
/// "@context": [
/// "https://www.w3.org/ns/activitystreams",
/// "https://forgefed.org/ns"
/// ],
/// "type": "Patch",
/// "id": "{id}",
/// "attributedTo": "{attributed_to}",
/// "content": "{content}",
/// "context": "{context}",
/// "mediaType": "{media_type}"
/// }}"#
/// );
///
/// let context_property = context::forgefed_context();
///
/// let patch = Patch::new()
/// .with_context_property(context_property)
/// .with_id(id)
/// .with_content(content)
/// .with_context(context)
/// .with_attributed_to(attributed_to)
/// .with_media_type(media_type);
///
/// assert_eq!(serde_json::to_string_pretty(&patch).unwrap(), json_str);
/// assert_eq!(
/// serde_json::from_str::<Patch>(json_str.as_str()).unwrap(),
/// patch
/// );
/// # }
/// ```
Patch: crate::ObjectType::Patch {}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::context;
use activitystreams_vocabulary::{Iri, MimeType};
#[test]
fn test_patch() {
let id =
Iri::try_from("https://dev.example/aviva/game-of-life/pulls/825/versions/1/patches/1")
.unwrap();
let attributed_to = Iri::try_from("https://forge.example/luke").unwrap();
let context =
Iri::try_from("https://dev.example/aviva/game-of-life/pulls/825/versions/1").unwrap();
let media_type = MimeType::ApplicationGitPatch;
let content = "From c9ae5f4ff4a330b6e1196ceb7db1665bd4c1...";
let json_str = format!(
r#"{{
"@context": [
"https://www.w3.org/ns/activitystreams",
"https://forgefed.org/ns"
],
"type": "Patch",
"id": "{id}",
"attributedTo": "{attributed_to}",
"content": "{content}",
"context": "{context}",
"mediaType": "{media_type}"
}}"#
);
let context_property = context::forgefed_context();
let patch = Patch::new()
.with_context_property(context_property)
.with_id(id)
.with_content(content)
.with_context(context)
.with_attributed_to(attributed_to)
.with_media_type(media_type);
assert_eq!(serde_json::to_string_pretty(&patch).unwrap(), json_str);
assert_eq!(
serde_json::from_str::<Patch>(json_str.as_str()).unwrap(),
patch
);
}
}