Title: [287978] trunk/Tools
Revision
287978
Author
[email protected]
Date
2022-01-13 07:22:22 -0800 (Thu, 13 Jan 2022)

Log Message

[EWS] Load contributors from stand-alone class
https://bugs.webkit.org/show_bug.cgi?id=235161
<rdar://problem/87491516>

Reviewed by Aakash Jain.

* Tools/CISupport/ews-build/steps.py:
(Contributors): Moved from ValidateCommiterAndReviewer.
(ValidateCommiterAndReviewer.load_contributors_from_disk): Moved to Contributors.
(ValidateCommiterAndReviewer.load_contributors_from_github): Ditto.
(ValidateCommiterAndReviewer.load_contributors): Ditto.
* Tools/CISupport/ews-build/steps_unittest.py:

Canonical link: https://commits.webkit.org/246007@main

Modified Paths

Diff

Modified: trunk/Tools/CISupport/ews-build/steps.py (287977 => 287978)


--- trunk/Tools/CISupport/ews-build/steps.py	2022-01-13 14:41:12 UTC (rev 287977)
+++ trunk/Tools/CISupport/ews-build/steps.py	2022-01-13 15:22:22 UTC (rev 287978)
@@ -89,6 +89,60 @@
         return '{}pull/{}'.format(repository_url, pr_number)
 
 
+class Contributors(object):
+    url = ''
+    contributors = {}
+
+    @classmethod
+    def load_from_disk(cls):
+        cwd = os.path.abspath(os.path.dirname(__file__))
+        repo_root = os.path.dirname(os.path.dirname(os.path.dirname(cwd)))
+        contributors_path = os.path.join(repo_root, 'metadata/contributors.json')
+        try:
+            with open(contributors_path, 'rb') as contributors_json:
+                return json.load(contributors_json), None
+        except Exception as e:
+            return {}, 'Failed to load {}\n'.format(contributors_path)
+
+    @classmethod
+    def load_from_github(cls):
+        try:
+            response = requests.get(cls.url, timeout=60)
+            if response.status_code != 200:
+                return {}, 'Failed to access {} with status code: {}\n'.format(cls.url, response.status_code)
+            return response.json(), None
+        except Exception as e:
+            return {}, 'Failed to access {url}\n'.format(url=""
+
+    @classmethod
+    def load(cls):
+        errors = []
+        contributors_json, error = cls.load_from_github()
+        if error:
+            errors.append(error)
+
+        if not contributors_json:
+            contributors_json, error = cls.load_from_disk()
+            if error:
+                errors.append(error)
+
+        contributors = {}
+        for value in contributors_json:
+            name = value.get('name')
+            emails = value.get('emails')
+            github_username = value.get('github')
+            if name and emails:
+                bugzilla_email = emails[0].lower()  # We're requiring that the first email is the primary bugzilla email
+                contributors[bugzilla_email] = {'name': name, 'status': value.get('status')}
+            if github_username and name and emails:
+                contributors[github_username] = dict(
+                    name=name,
+                    status=value.get('status'),
+                    email=emails[0],
+                )
+        return contributors, errors
+
+
 class ConfigureBuild(buildstep.BuildStep):
     name = 'configure-build'
     description = ['configuring build']
@@ -958,45 +1012,11 @@
 class ValidateCommiterAndReviewer(buildstep.BuildStep):
     name = 'validate-commiter-and-reviewer'
     descriptionDone = ['Validated commiter and reviewer']
-    url = ''
-    contributors = {}
 
-    def load_contributors_from_disk(self):
-        cwd = os.path.abspath(os.path.dirname(__file__))
-        repo_root = os.path.dirname(os.path.dirname(os.path.dirname(cwd)))
-        contributors_path = os.path.join(repo_root, 'metadata/contributors.json')
-        try:
-            with open(contributors_path, 'rb') as contributors_json:
-                return json.load(contributors_json)
-        except Exception as e:
-            self._addToLog('stdio', 'Failed to load {}\n'.format(contributors_path))
-            return {}
+    def __init__(self, *args, **kwargs):
+        super(ValidateCommiterAndReviewer, self).__init__(*args, **kwargs)
+        self.contributors = {}
 
-    def load_contributors_from_github(self):
-        try:
-            response = requests.get(self.url, timeout=60)
-            if response.status_code != 200:
-                self._addToLog('stdio', 'Failed to access {} with status code: {}\n'.format(self.url, response.status_code))
-                return {}
-            return response.json()
-        except Exception as e:
-            self._addToLog('stdio', 'Failed to access {url}\n'.format(url=""
-            return {}
-
-    def load_contributors(self):
-        contributors_json = self.load_contributors_from_github()
-        if not contributors_json:
-            contributors_json = self.load_contributors_from_disk()
-
-        contributors = {}
-        for value in contributors_json:
-            name = value.get('name')
-            emails = value.get('emails')
-            if name and emails:
-                bugzilla_email = emails[0].lower()  # We're requiring that the first email is the primary bugzilla email
-                contributors[bugzilla_email] = {'name': name, 'status': value.get('status')}
-        return contributors
-
     @defer.inlineCallbacks
     def _addToLog(self, logName, message):
         try:
@@ -1012,7 +1032,7 @@
 
     def fail_build(self, email, status):
         reason = '{} does not have {} permissions'.format(email, status)
-        comment = '{} does not have {} permissions according to {}.'.format(email, status, self.url)
+        comment = '{} does not have {} permissions according to {}.'.format(email, status, Contributors.url)
         comment += '\n\nRejecting attachment {} from commit queue.'.format(self.getProperty('patch_id', ''))
         self.setProperty('bugzilla_comment_text', comment)
 
@@ -1037,7 +1057,11 @@
         return contributor.get('name')
 
     def start(self):
-        self.contributors = self.load_contributors()
+        self.contributors, errors = Contributors.load()
+        for error in errors:
+            print(error)
+            self._addToLog('stdio', error)
+
         if not self.contributors:
             self.finished(FAILURE)
             self.descriptionDone = 'Failed to get contributors information'

Modified: trunk/Tools/CISupport/ews-build/steps_unittest.py (287977 => 287978)


--- trunk/Tools/CISupport/ews-build/steps_unittest.py	2022-01-13 14:41:12 UTC (rev 287977)
+++ trunk/Tools/CISupport/ews-build/steps_unittest.py	2022-01-13 15:22:22 UTC (rev 287978)
@@ -44,7 +44,7 @@
                    AnalyzeLayoutTestsResults, ApplyPatch, ApplyWatchList, ArchiveBuiltProduct, ArchiveTestResults,
                    CheckOutSource, CheckOutSpecificRevision, CheckPatchRelevance, CheckPatchStatusOnEWSQueues, CheckStyle,
                    CleanBuild, CleanUpGitIndexLock, CleanGitRepo, CleanWorkingDirectory, CompileJSC, CompileJSCWithoutPatch,
-                   CompileWebKit, CompileWebKitWithoutPatch, ConfigureBuild, CreateLocalGITCommit,
+                   CompileWebKit, CompileWebKitWithoutPatch, ConfigureBuild, ConfigureBuild, Contributors, CreateLocalGITCommit,
                    DownloadBuiltProduct, DownloadBuiltProductFromMaster, EWS_BUILD_HOSTNAME, ExtractBuiltProduct, ExtractTestResults,
                    FetchBranches, FindModifiedChangeLogs, FindModifiedLayoutTests, GitResetHard,
                    InstallBuiltProduct, InstallGtkDependencies, InstallWpeDependencies,
@@ -4585,10 +4585,10 @@
     def setUp(self):
         self.longMessage = True
 
-        def mock_load_contributors(cls, *args, **kwargs):
+        def mock_load_contributors(*args, **kwargs):
             return {'[email protected]': {'name': 'Aakash Jain', 'status': 'reviewer'},
-                    '[email protected]': {'name': 'WebKit Committer', 'status': 'committer'}}
-        ValidateCommiterAndReviewer.load_contributors = mock_load_contributors
+                    '[email protected]': {'name': 'WebKit Committer', 'status': 'committer'}}, []
+        Contributors.load = mock_load_contributors
         return self.setUpBuildStep()
 
     def tearDown(self):
@@ -4616,7 +4616,7 @@
         self.setupStep(ValidateCommiterAndReviewer())
         self.setProperty('patch_id', '1234')
         self.setProperty('patch_committer', '[email protected]')
-        ValidateCommiterAndReviewer.load_contributors = lambda x: {}
+        Contributors.load = lambda: ({}, [])
         self.expectHidden(False)
         self.expectOutcome(result=FAILURE, state_string='Failed to get contributors information')
         return self.runStep()
@@ -4639,8 +4639,7 @@
         return self.runStep()
 
     def test_load_contributors_from_disk(self):
-        ValidateCommiterAndReviewer._addToLog = lambda cls, logtype, log: sys.stdout.write(log)
-        contributors = filter(lambda element: element.get('name') == 'Aakash Jain', ValidateCommiterAndReviewer().load_contributors_from_disk())
+        contributors = filter(lambda element: element.get('name') == 'Aakash Jain', Contributors().load_from_disk()[0])
         self.assertEqual(list(contributors)[0]['emails'][0], '[email protected]')
 
 

Modified: trunk/Tools/ChangeLog (287977 => 287978)


--- trunk/Tools/ChangeLog	2022-01-13 14:41:12 UTC (rev 287977)
+++ trunk/Tools/ChangeLog	2022-01-13 15:22:22 UTC (rev 287978)
@@ -1,3 +1,18 @@
+2022-01-12  Jonathan Bedard  <[email protected]>
+
+        [EWS] Load contributors from stand-alone class
+        https://bugs.webkit.org/show_bug.cgi?id=235161
+        <rdar://problem/87491516>
+
+        Reviewed by Aakash Jain.
+
+        * CISupport/ews-build/steps.py:
+        (Contributors): Moved from ValidateCommiterAndReviewer.
+        (ValidateCommiterAndReviewer.load_contributors_from_disk): Moved to Contributors.
+        (ValidateCommiterAndReviewer.load_contributors_from_github): Ditto.
+        (ValidateCommiterAndReviewer.load_contributors): Ditto.
+        * CISupport/ews-build/steps_unittest.py:
+
 2022-01-12  Ryan Haddad  <[email protected]>
 
         Unreviewed, reverting r287944.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to