tangled
alpha
login
or
join now
bad-example.com
/
hacktober-bot
announcing good-first-issue tags added on @tangled.sh (not affiliated with tangled!)
6
fork
atom
overview
issues
1
pulls
pipelines
get issue and repo from label add event
bad-example.com
4 months ago
881bcfde
6d8b2a1c
+56
-1
1 changed file
expand all
collapse all
unified
split
src
main.rs
+56
-1
src/main.rs
···
23
value::Data,
24
},
25
};
0
26
27
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
28
···
98
Ok(())
99
}
100
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
101
#[tokio::main]
102
async fn main() -> Result<()> {
103
env_logger::init();
···
134
let mut receiver = JetstreamConnector::new(jetstream_config)?
135
.connect_cursor(args.jetstream_cursor.map(Cursor::from_raw_u64))
136
.await?;
0
0
0
0
0
137
138
println!("receiving jetstream messages...");
139
loop {
···
195
continue;
196
};
197
198
-
eprintln!("got {subject} {o:?}");
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
199
}
200
201
// let u2: Url = "https://bad-example.com".parse()?;
···
23
value::Data,
24
},
25
};
26
+
use std::time::Duration;
27
28
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
29
···
99
Ok(())
100
}
101
102
+
async fn get_record(client: &reqwest::Client, at_uri: &str) -> Result<serde_json::Map<String, serde_json::Value>> {
103
+
let mut url: Url = "https://slingshot.microcosm.blue".parse()?;
104
+
url.set_path("/xrpc/com.bad-example.repo.getUriRecord");
105
+
url.query_pairs_mut().append_pair("at_uri", at_uri);
106
+
let record_map = client
107
+
.get(url)
108
+
.send()
109
+
.await?
110
+
.error_for_status()?
111
+
.json::<serde_json::Value>()
112
+
.await?
113
+
.as_object()
114
+
.ok_or("get_record response was not a json object")?
115
+
.get("value")
116
+
.ok_or("get_record response obj did not have 'value' key")?
117
+
.as_object()
118
+
.ok_or("get_record response.value was not an object")?
119
+
.clone();
120
+
Ok(record_map)
121
+
}
122
+
123
#[tokio::main]
124
async fn main() -> Result<()> {
125
env_logger::init();
···
156
let mut receiver = JetstreamConnector::new(jetstream_config)?
157
.connect_cursor(args.jetstream_cursor.map(Cursor::from_raw_u64))
158
.await?;
159
+
160
+
let req_client = reqwest::Client::builder()
161
+
.user_agent("hacktober_bot")
162
+
.timeout(Duration::from_secs(9))
163
+
.build()?;
164
165
println!("receiving jetstream messages...");
166
loop {
···
222
continue;
223
};
224
225
+
let issue_record = match get_record(&req_client, subject).await {
226
+
Ok(m) => m,
227
+
Err(e) => {
228
+
eprintln!("failed to get issue record: {e} for {subject}");
229
+
continue;
230
+
}
231
+
};
232
+
let Some(serde_json::Value::String(title)) = issue_record.get("title") else {
233
+
eprintln!("failed to get title from issue for {subject}");
234
+
continue;
235
+
};
236
+
let Some(serde_json::Value::String(repo)) = issue_record.get("repo") else {
237
+
eprintln!("failed to get repo from issue for {subject}");
238
+
continue;
239
+
};
240
+
241
+
let repo_record = match get_record(&req_client, repo).await {
242
+
Ok(m) => m,
243
+
Err(e) => {
244
+
eprintln!("failed to get repo record: {e} for {subject}");
245
+
continue;
246
+
}
247
+
};
248
+
let Some(serde_json::Value::String(name)) = repo_record.get("name") else {
249
+
eprintln!("failed to get name for repo for {subject}");
250
+
continue;
251
+
};
252
+
253
+
eprintln!("got {subject} {title:?} for {name}");
254
}
255
256
// let u2: Url = "https://bad-example.com".parse()?;