Explorar o código

Treat assign command as `r?` on PRs

The only disallowed command is "release"
Mark Rousskov %!s(int64=5) %!d(string=hai) anos
pai
achega
e772bd9120
Modificáronse 2 ficheiros con 38 adicións e 0 borrados
  1. 10 0
      src/github.rs
  2. 28 0
      src/handlers/assign.rs

+ 10 - 0
src/github.rs

@@ -100,6 +100,11 @@ impl Label {
     }
 }
 
+#[derive(Debug, serde::Deserialize)]
+pub struct PullRequestDetails {
+    // none for now
+}
+
 #[derive(Debug, serde::Deserialize)]
 pub struct Issue {
     pub number: u64,
@@ -109,6 +114,7 @@ pub struct Issue {
     user: User,
     labels: Vec<Label>,
     assignees: Vec<User>,
+    pull_request: Option<PullRequestDetails>,
     // API URL
     repository_url: String,
     comments_url: String,
@@ -177,6 +183,10 @@ impl Issue {
         format!("{}#{}", self.repository(), self.number)
     }
 
+    pub fn is_pr(&self) -> bool {
+        self.pull_request.is_some()
+    }
+
     pub async fn get_comment(&self, client: &GithubClient, id: usize) -> Result<Comment, Error> {
         let comment_url = format!("{}/issues/comments/{}", self.repository_url, id);
         let comment = client.json(client.get(&comment_url)).await?;

+ 28 - 0
src/handlers/assign.rs

@@ -83,6 +83,34 @@ async fn handle_input(ctx: &Context, event: &Event, cmd: AssignCommand) -> Resul
         true
     };
 
+    if event.issue().unwrap().is_pr() {
+        let username = match &cmd {
+            AssignCommand::Own => event.user().login.clone(),
+            AssignCommand::User { username } => username.clone(),
+            AssignCommand::Release => {
+                log::trace!(
+                    "ignoring release on PR {:?}, must always have assignee",
+                    event.issue().unwrap().global_id()
+                );
+                return Ok(());
+            }
+        };
+        if let Err(err) = event
+            .issue()
+            .unwrap()
+            .set_assignee(&ctx.github, &username)
+            .await
+        {
+            log::warn!(
+                "failed to set assignee of PR {} to {}: {:?}",
+                event.issue().unwrap().global_id(),
+                username,
+                err
+            );
+        }
+        return Ok(());
+    }
+
     let e = EditIssueBody::new(&event.issue().unwrap(), "ASSIGN");
 
     let to_assign = match cmd {