瀏覽代碼

generate all relevant information for FCPDecorator

chaz-kiker 3 年之前
父節點
當前提交
73f11c5f0a
共有 4 個文件被更改,包括 975 次插入97 次删除
  1. 830 0
      SomeFile.txt
  2. 21 32
      src/actions.rs
  3. 64 64
      src/github.rs
  4. 60 1
      src/rfcbot.rs

文件差異過大導致無法顯示
+ 830 - 0
SomeFile.txt


+ 21 - 32
src/actions.rs

@@ -75,7 +75,6 @@ impl<'a> Action for Step<'a> {
 
         let mut context = Context::new();
         let mut results = HashMap::new();
-        let mut results_fcp = HashMap::new();
 
         for Query { repos, queries } in &self.actions {
             for repo in repos {
@@ -86,36 +85,6 @@ impl<'a> Action for Step<'a> {
                 for QueryMap { name, kind, query } in queries {
                     let issues = query.query(&repository, &gh).await;
 
-                    if let Some(issues_fcp) = issues.query_fcp(&repository, &gh).await {
-                        match issues_fcp {
-                            Ok(issues_fcp_decorators) => match kind {
-                                QueryKind::List => {
-                                    results_fcp
-                                        .entry(*name)
-                                        .or_insert(Vec::new())
-                                        .extend(issues_fcp_decorators);
-                                }
-                                QueryKind::Count => {
-                                    let count = issues_fcp_decorators.len();
-                                    let result = if let Some(value) = context.get(*name) {
-                                        value.as_u64().unwrap() + count as u64
-                                    } else {
-                                        count as u64
-                                    };
-
-                                    context.insert(*name, &result);
-                                }
-                            },
-                            Err(err) => {
-                                eprintln!("ERROR: {}", err);
-                                err.chain()
-                                    .skip(1)
-                                    .for_each(|cause| eprintln!("because: {}", cause));
-                                std::process::exit(1);
-                            }
-                        }
-                    }
-
                     match issues {
                         Ok(issues_decorator) => match kind {
                             QueryKind::List => {
@@ -149,7 +118,27 @@ impl<'a> Action for Step<'a> {
 
         for (name, issues) in &results {
             if name == &"proposed_fcp" {
-                println!("result (name, issues): ({}, {:#?})", &name, &issues);
+                let fcp_map = crate::rfcbot::get_all_fcps().await.unwrap();
+                println!("fcp_map: {:#?}", fcp_map);
+                let mut fcp_results = Vec::new();
+                for issue_decorator in issues.into_iter() {
+                    println!("issue_decorator: {:#?}", &issue_decorator);
+                    println!("issue_decorator.html_url: {:#?}", &issue_decorator.html_url);
+                    let key = format!(
+                        "rust-lang/{}:{}:{}",
+                        issue_decorator.repo_name.clone(),
+                        issue_decorator.number.clone(),
+                        issue_decorator.title.clone(),
+                    );
+                    if let Some(fcp) = fcp_map.get(&key) {
+                        let fcp_detail =
+                            crate::rfcbot::FCPDecorator::from_issue_fcp(&fcp, &issue_decorator);
+
+                        fcp_results.push(fcp_detail);
+                    }
+                }
+                context.insert(*name, &fcp_results);
+            } else {
                 context.insert(*name, issues);
             }
         }

+ 64 - 64
src/github.rs

@@ -1086,62 +1086,62 @@ impl<'q> IssuesQuery for Query<'q> {
     }
 }
 
-// impl<'q> FCPQuery for Query<'q>
-// where
-//     Query<'q>: IssuesQuery,
-#[async_trait]
-impl<'q> FCPQuery for IssuesQuery {
-    async fn query_fcp<'a>(
-        &'a self,
-        repo: &'a Repository,
-        client: &'a GithubClient,
-    ) -> anyhow::Result<Vec<crate::rfcbot::FCPDecorator>> {
-        let url = Url::parse(&"https://rfcbot.rs/api/all")?;
-        let res = reqwest::get(url)
-            .await?
-            .json::<Vec<crate::rfcbot::FullFCP>>()
-            .await?;
-
-        let mut map: HashMap<String, crate::rfcbot::FullFCP> = HashMap::new();
-        for full_fcp in res.into_iter() {
-            map.insert(
-                format!(
-                    "https://github.com/{}/{}",
-                    full_fcp.issue.repository.clone(),
-                    full_fcp.issue.number.clone()
-                ),
-                full_fcp,
-            );
-        }
-
-        let decorators = self.query(&repo, &client).await?;
-
-        let fcp_decorators: Vec<_> = decorators
-            .iter()
-            .filter_map(|issue_decorator| {
-                if let Some(full_fcp) = map.get(&issue_decorator.html_url) {
-                    Some(crate::rfcbot::FCPDecorator {
-                        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(),
-
-                        bot_tracking_comment: full_fcp.fcp.fk_bot_tracking_comment.to_string(),
-                        bot_tracking_comment_content: full_fcp.status_comment.body.clone(),
-                        initiating_comment: full_fcp.fcp.fk_initiating_comment.to_string(),
-                        initiating_comment_content: String::new(),
-                    })
-                } else {
-                    None
-                }
-            })
-            .collect();
-        Ok(fcp_decorators)
-    }
-}
+// // impl<'q> FCPQuery for Query<'q>
+// // where
+// //     Query<'q>: IssuesQuery,
+// #[async_trait]
+// impl<'q> FCPQuery for IssuesQuery {
+//     async fn query_fcp<'a>(
+//         &'a self,
+//         repo: &'a Repository,
+//         client: &'a GithubClient,
+//     ) -> anyhow::Result<Vec<crate::rfcbot::FCPDecorator>> {
+//         let url = Url::parse(&"https://rfcbot.rs/api/all")?;
+//         let res = reqwest::get(url)
+//             .await?
+//             .json::<Vec<crate::rfcbot::FullFCP>>()
+//             .await?;
+
+//         let mut map: HashMap<String, crate::rfcbot::FullFCP> = HashMap::new();
+//         for full_fcp in res.into_iter() {
+//             map.insert(
+//                 format!(
+//                     "https://github.com/{}/{}",
+//                     full_fcp.issue.repository.clone(),
+//                     full_fcp.issue.number.clone()
+//                 ),
+//                 full_fcp,
+//             );
+//         }
+
+//         let decorators = self.query(&repo, &client).await?;
+
+//         let fcp_decorators: Vec<_> = decorators
+//             .iter()
+//             .filter_map(|issue_decorator| {
+//                 if let Some(full_fcp) = map.get(&issue_decorator.html_url) {
+//                     Some(crate::rfcbot::FCPDecorator {
+//                         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(),
+
+//                         bot_tracking_comment: full_fcp.fcp.fk_bot_tracking_comment.to_string(),
+//                         bot_tracking_comment_content: full_fcp.status_comment.body.clone(),
+//                         initiating_comment: full_fcp.fcp.fk_initiating_comment.to_string(),
+//                         initiating_comment_content: String::new(),
+//                     })
+//                 } else {
+//                     None
+//                 }
+//             })
+//             .collect();
+//         Ok(fcp_decorators)
+//     }
+// }
 
 #[derive(Debug, serde::Deserialize)]
 #[serde(rename_all = "snake_case")]
@@ -1435,14 +1435,14 @@ pub trait IssuesQuery {
         client: &'a GithubClient,
     ) -> anyhow::Result<Vec<crate::actions::IssueDecorator>>;
 }
-#[async_trait]
-pub trait FCPQuery {
-    async fn query_fcp<'a>(
-        &'a self,
-        repo: &'a Repository,
-        client: &'a GithubClient,
-    ) -> anyhow::Result<Vec<crate::rfcbot::FCPDecorator>>;
-}
+// #[async_trait]
+// pub trait FCPQuery {
+//     async fn query_fcp<'a>(
+//         &'a self,
+//         repo: &'a Repository,
+//         client: &'a GithubClient,
+//     ) -> anyhow::Result<Vec<crate::rfcbot::FCPDecorator>>;
+// }
 
 #[cfg(test)]
 mod tests {

+ 60 - 1
src/rfcbot.rs

@@ -1,5 +1,6 @@
 use reqwest::Url;
 use serde::{Deserialize, Serialize};
+use std::collections::HashMap;
 
 #[derive(Serialize, Deserialize, Debug)]
 pub struct FCP {
@@ -28,7 +29,7 @@ pub struct FCPIssue {
     pub number: u32,
     pub fk_milestone: Option<String>,
     pub fk_user: u32,
-    pub fk_assignee: Option<String>,
+    pub fk_assignee: Option<u32>,
     pub open: bool,
     pub is_pull_request: bool,
     pub title: String,
@@ -71,7 +72,65 @@ pub struct FCPDecorator {
     pub updated_at: String,
 
     pub bot_tracking_comment: String,
+    pub bot_tracking_comment_html_url: String,
     pub bot_tracking_comment_content: String,
     pub initiating_comment: String,
+    pub initiating_comment_html_url: String,
     pub initiating_comment_content: String,
 }
+
+impl FCPDecorator {
+    pub fn from_issue_fcp(
+        full_fcp: &FullFCP,
+        issue_decorator: &crate::actions::IssueDecorator,
+    ) -> Self {
+        Self {
+            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(),
+
+            bot_tracking_comment: full_fcp.fcp.fk_bot_tracking_comment.to_string(),
+            bot_tracking_comment_html_url: format!(
+                "{}#issuecomment-{}",
+                issue_decorator.html_url, full_fcp.fcp.fk_bot_tracking_comment
+            ),
+            bot_tracking_comment_content: String::new(), // TODO: get from GitHub
+            initiating_comment: full_fcp.fcp.fk_initiating_comment.to_string(),
+            initiating_comment_html_url: format!(
+                "{}#issuecomment-{}",
+                issue_decorator.html_url, full_fcp.fcp.fk_initiating_comment
+            ),
+            initiating_comment_content: full_fcp.status_comment.body.clone(),
+        }
+    }
+}
+
+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?;
+    println!("res: {:#?}", res);
+
+    let mut map: HashMap<String, FullFCP> = HashMap::new();
+    for full_fcp in res.into_iter() {
+        map.insert(
+            // format!(
+            //     "https://github.com/{}/pulls/{}",
+            //     full_fcp.issue.repository.clone(),
+            //     full_fcp.issue.number.clone()
+            // ),
+            format!(
+                "{}:{}:{}",
+                full_fcp.issue.repository.clone(),
+                full_fcp.issue.number.clone(),
+                full_fcp.issue.title.clone(),
+            ),
+            full_fcp,
+        );
+    }
+
+    Ok(map)
+}

部分文件因文件數量過多而無法顯示