Răsfoiți Sursa

very broken, just playing around

chaz-kiker 3 ani în urmă
părinte
comite
bf26ff7b69
8 a modificat fișierele cu 213 adăugiri și 24 ștergeri
  1. 0 0
      SomeFile.txt
  2. 39 2
      src/actions.rs
  3. 12 18
      src/agenda.rs
  4. 69 3
      src/github.rs
  5. 1 0
      src/lib.rs
  6. 77 0
      src/rfcbot.rs
  7. 13 0
      templates/_issues_fcps.tt
  8. 2 1
      templates/lang_agenda.tt

+ 0 - 0
SomeFile.txt


+ 39 - 2
src/actions.rs

@@ -35,7 +35,7 @@ pub struct QueryMap<'a> {
     pub query: Box<dyn github::IssuesQuery + Send + Sync>,
 }
 
-#[derive(serde::Serialize)]
+#[derive(Debug, serde::Serialize)]
 pub struct IssueDecorator {
     pub number: u64,
     pub title: String,
@@ -75,6 +75,7 @@ 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 {
@@ -85,6 +86,36 @@ 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 => {
@@ -117,9 +148,15 @@ impl<'a> Action for Step<'a> {
         }
 
         for (name, issues) in &results {
-            context.insert(*name, issues);
+            if name == &"proposed_fcp" {
+                println!("result (name, issues): ({}, {:#?})", &name, &issues);
+                context.insert(*name, issues);
+            }
         }
 
+        println!("self.name: {}", self.name);
+        println!("context: {:#?}", context);
+
         TEMPLATES
             .render(&format!("{}.tt", self.name), &context)
             .unwrap()

+ 12 - 18
src/agenda.rs

@@ -606,23 +606,17 @@ pub fn lang_planning<'a>() -> Box<dyn Action> {
 pub fn compiler_backlog_bonanza<'a>() -> Box<dyn Action> {
     Box::new(Step {
         name: "compiler_backlog_bonanza",
-        actions: vec![
-            Query {
-                repos: vec![
-                    ("rust-lang", "rust"),
-                ],
-                queries: vec![
-                    QueryMap {
-                        name: "tracking_issues",
-                        kind: QueryKind::List,
-                        query: Box::new(github::Query {
-                            filters: vec![("state", "open")],
-                            include_labels: vec!["C-tracking-issue"],
-                            exclude_labels: vec!["T-libs-api", "T-libs", "T-lang", "T-rustdoc"],
-                        }),
-                    },
-                ],
-            },
-        ],
+        actions: vec![Query {
+            repos: vec![("rust-lang", "rust")],
+            queries: vec![QueryMap {
+                name: "tracking_issues",
+                kind: QueryKind::List,
+                query: Box::new(github::Query {
+                    filters: vec![("state", "open")],
+                    include_labels: vec!["C-tracking-issue"],
+                    exclude_labels: vec!["T-libs-api", "T-libs", "T-lang", "T-rustdoc"],
+                }),
+            }],
+        }],
     })
 }

+ 69 - 3
src/github.rs

@@ -7,8 +7,9 @@ use futures::{future::BoxFuture, FutureExt};
 use hyper::header::HeaderValue;
 use once_cell::sync::OnceCell;
 use reqwest::header::{AUTHORIZATION, USER_AGENT};
-use reqwest::{Client, Request, RequestBuilder, Response, StatusCode};
+use reqwest::{Client, Request, RequestBuilder, Response, StatusCode, Url};
 use std::{
+    collections::HashMap,
     fmt,
     time::{Duration, SystemTime},
 };
@@ -929,7 +930,7 @@ impl Repository {
             } else {
                 self.build_issues_url(&filters, include_labels, ordering)
             };
-    
+
             let result = client.get(&url);
             if use_search_api {
                 let result = client
@@ -939,7 +940,7 @@ impl Repository {
                 issues.extend(result.items);
                 if issues.len() < result.total_count {
                     ordering.page += 1;
-                    continue
+                    continue;
                 }
             } else {
                 // FIXME: paginate with non-search
@@ -1085,6 +1086,63 @@ 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)
+    }
+}
+
 #[derive(Debug, serde::Deserialize)]
 #[serde(rename_all = "snake_case")]
 pub enum CreateKind {
@@ -1377,6 +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>>;
+}
 
 #[cfg(test)]
 mod tests {

+ 1 - 0
src/lib.rs

@@ -19,6 +19,7 @@ pub mod handlers;
 pub mod interactions;
 pub mod notification_listing;
 pub mod payload;
+pub mod rfcbot;
 pub mod team;
 mod team_data;
 pub mod triage;

+ 77 - 0
src/rfcbot.rs

@@ -0,0 +1,77 @@
+use reqwest::Url;
+use serde::{Deserialize, Serialize};
+
+#[derive(Serialize, Deserialize, Debug)]
+pub struct FCP {
+    pub id: u32,
+    pub fk_issue: u32,
+    pub fk_initiator: u32,
+    pub fk_initiating_comment: u32,
+    pub disposition: Option<String>,
+    pub fk_bot_tracking_comment: u32,
+    pub fcp_start: Option<String>,
+    pub fcp_closed: bool,
+}
+#[derive(Serialize, Deserialize, Debug)]
+pub struct Reviewer {
+    pub id: u32,
+    pub login: String,
+}
+#[derive(Serialize, Deserialize, Debug)]
+pub struct Review {
+    pub reviewer: Reviewer,
+    pub approved: bool,
+}
+#[derive(Serialize, Deserialize, Debug)]
+pub struct FCPIssue {
+    pub id: u32,
+    pub number: u32,
+    pub fk_milestone: Option<String>,
+    pub fk_user: u32,
+    pub fk_assignee: Option<String>,
+    pub open: bool,
+    pub is_pull_request: bool,
+    pub title: String,
+    pub body: String,
+    pub locked: bool,
+    pub closed_at: Option<String>,
+    pub created_at: Option<String>,
+    pub updated_at: Option<String>,
+    pub labels: Vec<String>,
+    pub repository: String,
+}
+
+#[derive(Serialize, Deserialize, Debug)]
+pub struct StatusComment {
+    pub id: u64,
+    pub fk_issue: u32,
+    pub fk_user: u32,
+    pub body: String,
+    pub created_at: String,
+    pub updated_at: Option<String>,
+    pub repository: String,
+}
+
+#[derive(Serialize, Deserialize, Debug)]
+pub struct FullFCP {
+    pub fcp: FCP,
+    pub reviews: Vec<Review>,
+    pub issue: FCPIssue,
+    pub status_comment: StatusComment,
+}
+
+#[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: String,
+    pub bot_tracking_comment_content: String,
+    pub initiating_comment: String,
+    pub initiating_comment_content: String,
+}

+ 13 - 0
templates/_issues_fcps.tt

@@ -0,0 +1,13 @@
+{% import "_issue.tt" as issue %}
+
+{% macro render(issues, heading="###", empty="No issues this time.") %}
+{%- for issue in issues %}
+{{heading}} "{{issue.title}}" {{issue.repo_name}}#{{issue.number}}
+
+**Link:** {{issue.html_url}}
+{%else%}
+
+None.
+
+{%endfor%}
+{% endmacro %}

+ 2 - 1
templates/lang_agenda.tt

@@ -1,4 +1,5 @@
 {% import "_issues_heading.tt" as issues_heading %}
+{% import "_issues_fcps.tt" as issues_fcps %}
 {% import "_issues.tt" as issues %}
 ---
 title: Triage meeting DATE
@@ -47,7 +48,7 @@ tags: triage-meeting
 
 **Check your boxes!**
 
-{{-issues_heading::render(issues=proposed_fcp)}}
+{{-issues_fcps::render(issues=proposed_fcp)}}
 
 ## Active FCPs