Repository: mozilla/bugbug

Issue:
Make the commit classifier script apply the Phabricator patch as its first step
Most failures happen when applying patches, so that should be the first step (right after cloning). This way, we don't waste time doing other things if the patch fails to apply.


Discussion:
@marco-c Kindly review my PR
Reopening as #1388 is being backed-out (#1419).
I would like to fix this issue @marco-c Assign me!
Hello @imskr, feel free to work on it, but please read the contributing rules: issues are not assigned until there is a PR linked to it.
Hello @marco-c .
I have sent a PR for this issue.
I am facing a problem for the TaskGroup checks, "bugbug link" task has failed while rest of them has passed.
Can you tell me how to resolve this problem?

Logs : https://community-tc.services.mozilla.com/tasks/MsFDby5-QRSxkFM04ed4Tg/runs/0/logs/https%3A%2F%2Fcommunity-tc.services.mozilla.com%2Fapi%2Fqueue%2Fv1%2Ftask%2FMsFDby5-QRSxkFM04ed4Tg%2Fruns%2F0%2Fartifacts%2Fpublic%2Flogs%2Flive.log
Let's discuss in the PR itself about issues with it.
Is this linked pull request made on Oct 2022 still active or can I give it a try? 
> Is this linked pull request made on Oct 2022 still active or can I give it a try?

It is closed now. You can try.
Ok sir, I will give it a try 

Resolving patch:
diff --git a/scripts/commit_classifier.py b/scripts/commit_classifier.py
--- a/scripts/commit_classifier.py
+++ b/scripts/commit_classifier.py
@@ -135,6 +135,8 @@ def __init__(
         method_defect_predictor_dir: str,
         use_single_process: bool,
         skip_feature_importance: bool,
+        phabricator_deployment: Optional[str] = None,
+        diff_id: Optional[int] = None,
     ):
         self.model_name = model_name
         self.repo_dir = repo_dir
@@ -148,6 +150,14 @@ def __init__(
                 "hg::https://hg.mozilla.org/mozilla-central", git_repo_dir
             )
 
+        self.revision = None
+        if diff_id is not None:
+            assert phabricator_deployment is not None
+            with hglib.open(self.repo_dir) as hg:
+                self.apply_phab(hg, phabricator_deployment, diff_id)
+
+                self.revision = hg.log(revrange="not public()")[0].node.decode("utf-8")
+
         self.method_defect_predictor_dir = method_defect_predictor_dir
         if method_defect_predictor_dir:
             self.clone_git_repo(
@@ -582,25 +592,13 @@ def feature_sort_key(f):
     def classify(
         self,
         revision: Optional[str] = None,
-        phabricator_deployment: Optional[str] = None,
-        diff_id: Optional[int] = None,
         runnable_jobs_path: Optional[str] = None,
     ) -> None:
-        if revision is not None:
-            assert phabricator_deployment is None
-            assert diff_id is None
-
-        if diff_id is not None:
-            assert phabricator_deployment is not None
-            assert revision is None
-
         self.update_commit_db()
 
-        if phabricator_deployment is not None and diff_id is not None:
-            with hglib.open(self.repo_dir) as hg:
-                self.apply_phab(hg, phabricator_deployment, diff_id)
-
-                revision = hg.log(revrange="not public()")[0].node.decode("utf-8")
+        if self.revision is not None:
+            assert revision is None
+            revision = self.revision
 
             commits = repository.download_commits(
                 self.repo_dir,
@@ -848,6 +846,14 @@ def main() -> None:
 
     args = parser.parse_args()
 
+    if args.revision is not None:
+        assert args.phabricator_deployment is None
+        assert args.diff_id is None
+
+    if args.diff_id is not None:
+        assert args.phabricator_deployment is not None
+        assert args.revision is None
+
     classifier = CommitClassifier(
         args.model,
         args.repo_dir,
@@ -855,10 +861,10 @@ def main() -> None:
         args.method_defect_predictor_dir,
         args.use_single_process,
         args.skip_feature_importance,
+        args.phabricator_deployment,
+        args.diff_id,
     )
-    classifier.classify(
-        args.revision, args.phabricator_deployment, args.diff_id, args.runnable_jobs
-    )
+    classifier.classify(args.revision, args.runnable_jobs)
 
 
 if __name__ == "__main__":


Test patch: