MCPcopy Create free account
hub / github.com/emwalker/digraph / make_link

Method make_link

backend/src/git/link.rs:336–377  ·  view source on GitHub ↗
(
        &self,
        mutation: &Mutation,
        link_id: &ExternalId,
        url: &RepoUrl,
    )

Source from the content-addressed store, hash-verified

334 }
335
336 fn make_link(
337 &self,
338 mutation: &Mutation,
339 link_id: &ExternalId,
340 url: &RepoUrl,
341 ) -> Result<(RepoLink, Option<String>)> {
342 if mutation.exists(self.repo_id, link_id)? {
343 if let Some(link) = mutation.fetch_link(self.repo_id, link_id) {
344 let title = link.metadata.title().to_owned();
345 return Ok((link, Some(title)));
346 }
347 }
348
349 let title = if let Some(title) = &self.title {
350 title.clone()
351 } else {
352 match self.fetcher.fetch(url) {
353 Ok(response) => response.title().unwrap_or_else(|| "Missing title".into()),
354 Err(_) => "Failed to fetch title".into(),
355 }
356 };
357
358 let mut parent_topics = BTreeSet::new();
359 if let Some(id) = &self.add_parent_topic_id {
360 parent_topics.insert(ParentTopic { id: id.to_owned() });
361 }
362
363 let link = RepoLink {
364 api_version: API_VERSION.into(),
365 parent_topics,
366 metadata: RepoLinkMetadata {
367 added: chrono::Utc::now(),
368 id: link_id.to_owned(),
369 details: Some(RepoLinkDetails {
370 title,
371 url: url.normalized.to_owned(),
372 }),
373 },
374 };
375
376 Ok((link, None))
377 }
378}

Callers 1

callMethod · 0.80

Calls 5

existsMethod · 0.80
insertMethod · 0.80
fetch_linkMethod · 0.45
titleMethod · 0.45
fetchMethod · 0.45

Tested by

no test coverage detected