use enum
This commit is contained in:
parent
3a5fafc6c0
commit
a76bdc867c
1 changed files with 27 additions and 5 deletions
|
@ -1,4 +1,5 @@
|
||||||
use ramhorns::Content;
|
use core::panic;
|
||||||
|
|
||||||
use reqwest::header::ACCEPT;
|
use reqwest::header::ACCEPT;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
@ -24,11 +25,28 @@ struct GithubPullRequest {
|
||||||
merged_at: Option<String>,
|
merged_at: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Content, Debug)]
|
#[derive(Clone, Copy)]
|
||||||
|
pub enum ProjectState {
|
||||||
|
Closed = 0,
|
||||||
|
Open = 1,
|
||||||
|
Merged = 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<u8> for ProjectState {
|
||||||
|
fn from(orig: u8) -> Self {
|
||||||
|
match orig {
|
||||||
|
0 => Self::Closed,
|
||||||
|
1 => Self::Open,
|
||||||
|
2 => Self::Merged,
|
||||||
|
_ => panic!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Project {
|
pub struct Project {
|
||||||
pub project: String,
|
pub project: String,
|
||||||
pub project_url: String,
|
pub project_url: String,
|
||||||
pub status: String,
|
pub status: ProjectState,
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub id: u32,
|
pub id: u32,
|
||||||
pub contrib_url: String,
|
pub contrib_url: String,
|
||||||
|
@ -54,9 +72,13 @@ pub async fn fetch_pr() -> Vec<Project> {
|
||||||
project: p.repository_url.split('/').last().unwrap().to_string(),
|
project: p.repository_url.split('/').last().unwrap().to_string(),
|
||||||
project_url: p.repository_url.clone(),
|
project_url: p.repository_url.clone(),
|
||||||
status: if p.pull_request.merged_at.is_none() {
|
status: if p.pull_request.merged_at.is_none() {
|
||||||
p.state.clone()
|
if p.state == "closed" {
|
||||||
|
ProjectState::Closed
|
||||||
} else {
|
} else {
|
||||||
"merged".to_string()
|
ProjectState::Open
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ProjectState::Merged
|
||||||
},
|
},
|
||||||
title: p.title.clone(),
|
title: p.title.clone(),
|
||||||
id: p.number,
|
id: p.number,
|
||||||
|
|
Loading…
Reference in a new issue