extract_gist_data

Function extract_gist_data 

Source
pub fn extract_gist_data(
    location: &str,
    gist_config: &GistConfig,
) -> Result<(String, Option<String>, Option<String>)>
Expand description

Parses a Gist location string to extract its ID, and optional SHA and filename.

This function is highly flexible and can interpret several Gist location formats, including full URLs, shorthand notations, and special placeholder values.

§Placeholder Behavior

If the location string is a placeholder ("gist", or an empty/whitespace string), the function will attempt to use the id from the provided gist_config as a fallback. If gist_config is None in this case, it will return an error.

§Supported URL Formats

  • https://gist.github.com/{user}/{id}
  • https://gist.github.com/{user}/{id}/{sha}
  • https://gist.githubusercontent.com/{user}/{id}/raw
  • https://gist.githubusercontent.com/{user}/{id}/raw/{file}
  • https://gist.githubusercontent.com/{user}/{id}/raw/{sha}
  • https://gist.githubusercontent.com/{user}/{id}/raw/{sha}/{file}
  • https://api.github.com/gists/{id}
  • https://api.github.com/gists/{id}/{sha}

§Supported Shorthand Formats

  • {file} (with the id from the config)
  • {id}
  • {id}/{file}
  • {id}/{sha}
  • {id}/{sha}/{file}