Browse Source

Query specific commit, not master

The master branch has usually not yet been updated when we receive the bors
webhook, so we were ignoring commits. Before clippy subtree, we were presumably
only getting the next commit with a ~4-5 hour delay (when the next bors success
message was printed).
Mark Rousskov 5 years ago
parent
commit
5993b99d41
3 changed files with 40 additions and 26 deletions
  1. 1 1
      Cargo.toml
  2. 19 1
      src/github.rs
  3. 20 24
      src/handlers/rustc_commits.rs

+ 1 - 1
Cargo.toml

@@ -22,7 +22,7 @@ rust_team_data = { git = "https://github.com/rust-lang/team" }
 glob = "0.3.0"
 toml = "0.5.1"
 hyper = "0.13"
-tokio = { version = "0.2", features = ["macros"] }
+tokio = { version = "0.2", features = ["macros", "time"] }
 futures = { version = "0.3", default-features = false, features = ["std"] }
 uuid = { version = "0.8", features = ["v4"] }
 url = "2.1.0"

+ 19 - 1
src/github.rs

@@ -64,7 +64,11 @@ impl User {
         let is_pri_member = map
             .get("wg-prioritization")
             .map_or(false, |w| w.members.iter().any(|g| g.github == self.login));
-        Ok(map["all"].members.iter().any(|g| g.github == self.login) || is_triager || is_pri_member)
+        Ok(
+            map["all"].members.iter().any(|g| g.github == self.login)
+                || is_triager
+                || is_pri_member,
+        )
     }
 
     // Returns the ID of the given user, if the user is in the `all` team.
@@ -637,6 +641,20 @@ impl GithubClient {
         self.client.put(url).configure(self)
     }
 
+    pub async fn rust_commit(&self, sha: &str) -> Option<GithubCommit> {
+        let req = self.get(&format!(
+            "https://api.github.com/repos/rust-lang/rust/commits/{}",
+            sha
+        ));
+        match self.json(req).await {
+            Ok(r) => Some(r),
+            Err(e) => {
+                log::error!("Failed to query commit {:?}: {:?}", sha, e);
+                None
+            }
+        }
+    }
+
     /// This does not retrieve all of them, only the last several.
     pub async fn bors_commits(&self) -> Vec<GithubCommit> {
         let req = self.get("https://api.github.com/repos/rust-lang/rust/commits?author=bors");

+ 20 - 24
src/handlers/rustc_commits.rs

@@ -73,31 +73,27 @@ pub async fn handle(ctx: &Context, event: &Event) -> anyhow::Result<()> {
     // FIXME: ideally we would pull in all the commits here, but unfortunately
     // in rust-lang/rust's case there's bors-authored commits that aren't
     // actually from rust-lang/rust as they were merged into the clippy repo.
-    //
-    // For now we just ignore everything returned by this query other than the
-    // commit we *know* to be good (the one from the bors comment) but
-    // eventually we will want to be smarter here.
-    let resp = ctx.github.bors_commits().await;
-
-    for mut gc in resp.into_iter() {
-        // Only insert the just pushed commit
-        if gc.sha != sha {
-            continue;
+    let mut gc = match ctx.github.rust_commit(&sha).await {
+        Some(c) => c,
+        None => {
+            log::error!("Could not find bors-reported sha: {:?}", sha);
+            return Ok(());
         }
-        let res = rustc_commits::record_commit(
-            &ctx.db,
-            rustc_commits::Commit {
-                sha: gc.sha,
-                parent_sha: gc.parents.remove(0).sha,
-                time: gc.commit.author.date,
-            },
-        )
-        .await;
-        match res {
-            Ok(()) => {}
-            Err(e) => {
-                log::error!("Failed to record commit {:?}", e);
-            }
+    };
+
+    let res = rustc_commits::record_commit(
+        &ctx.db,
+        rustc_commits::Commit {
+            sha: gc.sha,
+            parent_sha: gc.parents.remove(0).sha,
+            time: gc.commit.author.date,
+        },
+    )
+    .await;
+    match res {
+        Ok(()) => {}
+        Err(e) => {
+            log::error!("Failed to record commit {:?}", e);
         }
     }