tangled
alpha
login
or
join now
bad-example.com
/
hacktober-bot
6
fork
atom
announcing good-first-issue tags added on @tangled.sh (not affiliated with tangled!)
6
fork
atom
overview
issues
1
pulls
pipelines
get repo handle to render links to issues page
bad-example.com
5 months ago
ac157708
881bcfde
+48
1 changed file
expand all
collapse all
unified
split
src
main.rs
+48
src/main.rs
···
21
21
language::Language,
22
22
collection::Collection,
23
23
value::Data,
24
24
+
string::AtUri,
24
25
},
25
26
};
26
27
use std::time::Duration;
···
120
121
Ok(record_map)
121
122
}
122
123
124
124
+
async fn get_handle(client: &reqwest::Client, identifier: &str) -> Result<Option<String>> {
125
125
+
let mut url: Url = "https://slingshot.microcosm.blue".parse()?;
126
126
+
url.set_path("/xrpc/com.bad-example.identity.resolveMiniDoc");
127
127
+
url.query_pairs_mut().append_pair("identifier", identifier);
128
128
+
let handle = client
129
129
+
.get(url)
130
130
+
.send()
131
131
+
.await?
132
132
+
.error_for_status()?
133
133
+
.json::<serde_json::Value>()
134
134
+
.await?
135
135
+
.as_object()
136
136
+
.ok_or("minidoc response was not a json object")?
137
137
+
.get("handle")
138
138
+
.ok_or("minidoc response obj did not have 'handle' key")?
139
139
+
.as_str()
140
140
+
.ok_or("minidoc handle was not a string")?
141
141
+
.to_string();
142
142
+
if handle == "handle.invalid" {
143
143
+
Ok(None)
144
144
+
} else {
145
145
+
Ok(Some(handle))
146
146
+
}
147
147
+
}
148
148
+
123
149
#[tokio::main]
124
150
async fn main() -> Result<()> {
125
151
env_logger::init();
···
238
264
continue;
239
265
};
240
266
267
267
+
let Ok(repo_uri) = AtUri::new(repo) else {
268
268
+
eprintln!("failed to parse repo to aturi for {subject}");
269
269
+
continue;
270
270
+
};
271
271
+
241
272
let repo_record = match get_record(&req_client, repo).await {
242
273
Ok(m) => m,
243
274
Err(e) => {
···
249
280
eprintln!("failed to get name for repo for {subject}");
250
281
continue;
251
282
};
283
283
+
284
284
+
let repo_handle = match get_handle(&req_client, repo_uri.authority().as_str()).await {
285
285
+
Ok(Some(h)) => h,
286
286
+
Ok(None) => {
287
287
+
eprintln!("invalid handle from identifier in {repo_uri} for {subject}");
288
288
+
continue;
289
289
+
}
290
290
+
Err(e) => {
291
291
+
eprintln!("failed to get repo handle from identifier: {e} for {subject}");
292
292
+
continue;
293
293
+
}
294
294
+
};
295
295
+
296
296
+
let issues_url = format!("https://tangled.org/@{repo_handle}/{name}/issues");
297
297
+
println!("hi: {issues_url}");
298
298
+
299
299
+
// let message = format!(r#""#);
252
300
253
301
eprintln!("got {subject} {title:?} for {name}");
254
302
}