瀏覽代碼

clean up code

chaz-kiker 3 年之前
父節點
當前提交
fb496d24cc
共有 3 個文件被更改,包括 2 次插入167 次删除
  1. 0 21
      src/actions.rs
  2. 2 18
      src/github.rs
  3. 0 128
      src/rfcbot.rs

+ 0 - 21
src/actions.rs

@@ -56,22 +56,6 @@ pub struct FCPDetails {
     pub initiating_comment_content: String,
 }
 
-#[derive(Serialize, Deserialize, Debug)]
-pub struct FCPDecorator {
-    pub number: u64,
-    pub title: String,
-    pub html_url: String,
-    pub repo_name: String,
-    pub labels: String,
-    pub assignees: String,
-    pub updated_at: String,
-
-    pub bot_tracking_comment_html_url: String,
-    pub bot_tracking_comment_content: String,
-    pub initiating_comment_html_url: String,
-    pub initiating_comment_content: String,
-}
-
 lazy_static! {
     pub static ref TEMPLATES: Tera = {
         match Tera::new("templates/*") {
@@ -143,11 +127,6 @@ impl<'a> Action for Step<'a> {
         }
 
         for (name, issues) in &results {
-            // if name == &"proposed_fcp" {
-
-            //     context.insert(*name, &fcp_results);
-            // } else {
-            // }
             context.insert(*name, issues);
         }
 

+ 2 - 18
src/github.rs

@@ -1065,16 +1065,10 @@ impl<'q> IssuesQuery for Query<'q> {
             .get_issues(&client, self)
             .await
             .with_context(|| "Unable to get issues.")?;
-
-        // let fcp_collection = crate::rfcbot::FCPCollectionBox {};
-        // fcp_collection.get_all_fcps().await?;
-
-        // let fcp_map = crate::rfcbot::get_all_fcps().await?;
-
         let issues_decorator: Vec<_> = issues
             .into_iter()
             .map(|issue| async move {
-                // TODO: seems like a *really* bad approach but not sure how to make it better
+                // TODO: this seems like a *really* bad approach, but I'm not sure how to make it better
                 let fcp_map = crate::rfcbot::get_all_fcps().await?;
                 let fcp_details = if include_fcp_details {
                     let repository_name = if let Some(repo) = issue.repository.get() {
@@ -1098,22 +1092,12 @@ impl<'q> IssuesQuery for Query<'q> {
                         let fk_initiating_comment = fcp.fcp.fk_initiating_comment;
                         let initiating_comment_html_url =
                             format!("{}#issuecomment-{}", issue.html_url, fk_initiating_comment,);
-                        // TODO: get from GitHub
-                        // let url = format!(
-                        //     "{}/repos/rust-lang/{}/issues/comments/{}",
-                        //     Repository::GITHUB_API_URL,
-                        //     repository_name,
-                        //     fk_initiating_comment
-                        // );
                         let init_comment = issue
-                            .get_comment(&client, fk_initiating_comment.try_into().unwrap())
+                            .get_comment(&client, fk_initiating_comment.try_into()?)
                             .await?;
-                        // let init_comment_content = init_comment.body;
-                        // client.json::<String>(client.get(&url)).await.unwrap();
                         let initiating_comment_content = quote_reply(&init_comment.body);
 
                         Some(crate::actions::FCPDetails {
-                            // additional properties from FullFCP (from rfcbot)
                             bot_tracking_comment_html_url,
                             bot_tracking_comment_content,
                             initiating_comment_html_url,

+ 0 - 128
src/rfcbot.rs

@@ -1,4 +1,3 @@
-use crate::actions::FCPDecorator;
 use reqwest::Url;
 use serde::{Deserialize, Serialize};
 use std::collections::HashMap;
@@ -62,133 +61,6 @@ pub struct FullFCP {
     pub status_comment: StatusComment,
 }
 
-fn quote_reply(markdown: &str) -> String {
-    if markdown.is_empty() {
-        String::from("*No content*")
-    } else {
-        format!("\n\t> {}", markdown.replace("\n", "\n\t> "))
-    }
-}
-
-// #[async_trait]
-// pub trait IssueToFCP {
-//     async fn from_issue_fcp<'a>(
-//         full_fcp: &FullFCP,
-//         issue_decorator: &crate::actions::IssueDecorator,
-//         client: &'a GithubClient,
-//     ) -> anyhow::Result<Self>;
-// }
-
-// #[async_trait]
-// impl<'q> IssueToFCP for FCPDecorator {
-//     async fn from_issue_fcp<'a>(
-//         full_fcp: &FullFCP,
-//         issue_decorator: &crate::actions::IssueDecorator,
-//         client: &'a GithubClient,
-//     ) -> anyhow::Result<Self> {
-//         let bot_tracking_comment_html_url = format!(
-//             "{}#issuecomment-{}",
-//             issue_decorator.html_url, full_fcp.fcp.fk_bot_tracking_comment
-//         );
-//         let bot_tracking_comment_content = quote_reply(&full_fcp.status_comment.body);
-//         let fk_initiating_comment = full_fcp.fcp.fk_initiating_comment;
-//         let initiating_comment_html_url = format!(
-//             "{}#issuecomment-{}",
-//             issue_decorator.html_url, fk_initiating_comment,
-//         );
-//         // TODO: get from GitHub
-//         let url = format!(
-//             "{}/issues/comments/{}",
-//             issue_decorator.html_url, fk_initiating_comment
-//         );
-//         let init_comment_content = client._send_req(client.get(&url)).await?.json().await?;
-//         let initiating_comment_content = quote_reply(&init_comment_content);
-
-//         Self {
-//             // shared properties with IssueDecorator
-//             number: issue_decorator.number.clone(),
-//             title: issue_decorator.title.clone(),
-//             html_url: issue_decorator.html_url.clone(),
-//             repo_name: issue_decorator.repo_name.clone(),
-//             labels: issue_decorator.labels.clone(),
-//             assignees: issue_decorator.assignees.clone(),
-//             updated_at: issue_decorator.updated_at.clone(),
-
-//             // additional properties from FullFCP (from rfcbot)
-//             bot_tracking_comment_html_url,
-//             bot_tracking_comment_content,
-//             initiating_comment_html_url,
-//             initiating_comment_content,
-//         }
-//     }
-// }
-
-impl FCPDecorator {
-    pub fn from_issue_fcp(
-        full_fcp: &FullFCP,
-        issue_decorator: &crate::actions::IssueDecorator,
-    ) -> Self {
-        let bot_tracking_comment_html_url = format!(
-            "{}#issuecomment-{}",
-            issue_decorator.html_url, full_fcp.fcp.fk_bot_tracking_comment
-        );
-        let bot_tracking_comment_content = quote_reply(&full_fcp.status_comment.body);
-        let initiating_comment_html_url = format!(
-            "{}#issuecomment-{}",
-            issue_decorator.html_url, full_fcp.fcp.fk_initiating_comment
-        );
-        // TODO: get from GitHub
-        let initiating_comment_content = quote_reply(&String::new());
-
-        Self {
-            // shared properties with IssueDecorator
-            number: issue_decorator.number.clone(),
-            title: issue_decorator.title.clone(),
-            html_url: issue_decorator.html_url.clone(),
-            repo_name: issue_decorator.repo_name.clone(),
-            labels: issue_decorator.labels.clone(),
-            assignees: issue_decorator.assignees.clone(),
-            updated_at: issue_decorator.updated_at.clone(),
-
-            // additional properties from FullFCP (from rfcbot)
-            bot_tracking_comment_html_url,
-            bot_tracking_comment_content,
-            initiating_comment_html_url,
-            initiating_comment_content,
-        }
-    }
-}
-
-// pub struct FCPCollection {
-//     pub fcps: Box<dyn HashMap<String, FullFCP> + Send + Sync>,
-// }
-
-// // pub trait FCPQuery {
-// //     pub fn get<'a>(&'a self) -> anyhow::Result<HashMap<String, FullFCP>>;
-// // }
-
-// impl FCPCollection {
-//     pub async fn get_all_fcps(&self) -> anyhow::Result<()> {
-//         let url = Url::parse(&"https://rfcbot.rs/api/all")?;
-//         let res = reqwest::get(url).await?.json::<Vec<FullFCP>>().await?;
-//         let mut map: HashMap<String, FullFCP> = HashMap::new();
-//         for full_fcp in res.into_iter() {
-//             map.insert(
-//                 format!(
-//                     "{}:{}:{}",
-//                     full_fcp.issue.repository.clone(),
-//                     full_fcp.issue.number.clone(),
-//                     full_fcp.issue.title.clone(),
-//                 ),
-//                 full_fcp,
-//             );
-//         }
-
-//         self.fcps = Box::new(map);
-//         Ok(())
-//     }
-// }
-
 pub async fn get_all_fcps() -> anyhow::Result<HashMap<String, FullFCP>> {
     let url = Url::parse(&"https://rfcbot.rs/api/all")?;
     let res = reqwest::get(url).await?.json::<Vec<FullFCP>>().await?;