Schneider
5 years ago
5 changed files with 72 additions and 5 deletions
-
16Cargo.lock
-
2Cargo.toml
-
9src/app.rs
-
3src/main.rs
-
47src/template.rs
@ -0,0 +1,47 @@ |
|||||
|
//! This module contains structs for working with the github templates
|
||||
|
|
||||
|
use serde::{Deserialize, Serialize};
|
||||
|
|
||||
|
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
|
#[serde(rename_all = "camelCase")]
|
||||
|
pub struct Template {
|
||||
|
pub name: String,
|
||||
|
pub path: String,
|
||||
|
pub sha: String,
|
||||
|
pub size: i64,
|
||||
|
pub url: String,
|
||||
|
#[serde(rename = "html_url")]
|
||||
|
pub html_url: String,
|
||||
|
#[serde(rename = "git_url")]
|
||||
|
pub git_url: String,
|
||||
|
#[serde(rename = "download_url")]
|
||||
|
pub download_url: Option<String>,
|
||||
|
#[serde(rename = "type")]
|
||||
|
pub type_field: String,
|
||||
|
#[serde(rename = "_links")]
|
||||
|
pub links: Links,
|
||||
|
}
|
||||
|
|
||||
|
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
|
#[serde(rename_all = "camelCase")]
|
||||
|
pub struct Links {
|
||||
|
#[serde(rename = "self")]
|
||||
|
pub self_field: String,
|
||||
|
pub git: String,
|
||||
|
pub html: String,
|
||||
|
}
|
||||
|
|
||||
|
impl Template {
|
||||
|
/// Checks if this template file is a gitignore template file
|
||||
|
pub fn is_gitignore_template(&self) -> bool { self.name.ends_with(".gitignore") }
|
||||
|
|
||||
|
/// Returns the name of the file without the .gitignore ending
|
||||
|
///
|
||||
|
/// if `!self.is_gitignore_template()` the whole `self.name` is returned
|
||||
|
pub fn pretty_name(&self) -> &str {
|
||||
|
if let Some(dot_index) = self.name.rfind(".") {
|
||||
|
return &self.name[0..dot_index];
|
||||
|
}
|
||||
|
return self.name.as_str();
|
||||
|
}
|
||||
|
}
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue