瀏覽代碼

Refactor major change issue events

This continues the work in c21d8fe50b42462ee625c3ef4ec44aefdaf30070,
specifically with an aim at resolving #666.
Mark Rousskov 4 年之前
父節點
當前提交
89f435587a
共有 1 個文件被更改,包括 20 次插入25 次删除
  1. 20 25
      src/handlers/major_change.rs

+ 20 - 25
src/handlers/major_change.rs

@@ -1,6 +1,6 @@
 use crate::{
     config::MajorChangeConfig,
-    github::{self, Event},
+    github::{self, Event, IssuesAction},
     handlers::{Context, Handler},
     interactions::ErrorComment,
 };
@@ -37,34 +37,29 @@ impl Handler for MajorChangeHandler {
 
         match event {
             Event::Issue(e) => {
-                if e.action != github::IssuesAction::Opened
-                    && e.action != github::IssuesAction::Reopened
-                    && e.action != github::IssuesAction::Labeled
+                // If we were labeled with accepted, then issue that event
+                if e.action == IssuesAction::Labeled
+                    && e.label.map_or(false, |l| l.name == "major-change-accepted")
                 {
-                    return Ok(None);
+                    return Ok(Some(Invocation::AcceptedProposal));
                 }
 
-                if e.issue.labels().iter().any(|l| l.name == "major-change") {
-                    if e.issue
-                        .labels()
-                        .iter()
-                        .any(|l| l.name == "major-change-accepted")
-                    {
-                        return Ok(Some(Invocation::AcceptedProposal));
-                    } else {
-                        // Opening an issue with a label assigned triggers both
-                        // "Opened" and "labeled" events.
-                        if e.action == github::IssuesAction::Opened
-                            || e.action == github::IssuesAction::Reopened
-                        {
-                            return Ok(Some(Invocation::NewProposal));
-                        } else {
-                            // Nothing to do, issue was labeled, but not marked
-                            // as accepted
-                            return Ok(None);
-                        }
-                    }
+                // Opening an issue with a label assigned triggers both
+                // "Opened" and "Labeled" events.
+                //
+                // We want to treat reopened issues as new proposals but if the
+                // issues is freshly opened, we only want to trigger once;
+                // currently we do so on the label event.
+                if (e.action == IssuesAction::Reopened
+                    && e.issue.labels().iter().any(|l| l.name == "major-change"))
+                    || (e.action == IssuesAction::Labeled
+                        && e.label.map_or(false, |l| l.name == "major-change"))
+                {
+                    return Ok(Some(Invocation::NewProposal));
                 }
+
+                // All other issue events are ignored
+                return Ok(None);
             }
             Event::IssueComment(e) => {
                 if e.action != github::IssueCommentAction::Created {