⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 287978 in webkit


Ignore:
Timestamp:
Jan 13, 2022, 7:22:22 AM (5 years ago)
Author:
Jonathan Bedard
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

Location:
trunk/Tools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/CISupport/ews-build/steps.py

    r287949 r287978  
    9090
    9191
     92class Contributors(object):
     93    url = 'https://raw.githubusercontent.com/WebKit/WebKit/main/metadata/contributors.json'
     94    contributors = {}
     95
     96    @classmethod
     97    def load_from_disk(cls):
     98        cwd = os.path.abspath(os.path.dirname(__file__))
     99        repo_root = os.path.dirname(os.path.dirname(os.path.dirname(cwd)))
     100        contributors_path = os.path.join(repo_root, 'metadata/contributors.json')
     101        try:
     102            with open(contributors_path, 'rb') as contributors_json:
     103                return json.load(contributors_json), None
     104        except Exception as e:
     105            return {}, 'Failed to load {}\n'.format(contributors_path)
     106
     107    @classmethod
     108    def load_from_github(cls):
     109        try:
     110            response = requests.get(cls.url, timeout=60)
     111            if response.status_code != 200:
     112                return {}, 'Failed to access {} with status code: {}\n'.format(cls.url, response.status_code)
     113            return response.json(), None
     114        except Exception as e:
     115            return {}, 'Failed to access {url}\n'.format(url=cls.url)
     116
     117    @classmethod
     118    def load(cls):
     119        errors = []
     120        contributors_json, error = cls.load_from_github()
     121        if error:
     122            errors.append(error)
     123
     124        if not contributors_json:
     125            contributors_json, error = cls.load_from_disk()
     126            if error:
     127                errors.append(error)
     128
     129        contributors = {}
     130        for value in contributors_json:
     131            name = value.get('name')
     132            emails = value.get('emails')
     133            github_username = value.get('github')
     134            if name and emails:
     135                bugzilla_email = emails[0].lower()  # We're requiring that the first email is the primary bugzilla email
     136                contributors[bugzilla_email] = {'name': name, 'status': value.get('status')}
     137            if github_username and name and emails:
     138                contributors[github_username] = dict(
     139                    name=name,
     140                    status=value.get('status'),
     141                    email=emails[0],
     142                )
     143        return contributors, errors
     144
     145
    92146class ConfigureBuild(buildstep.BuildStep):
    93147    name = 'configure-build'
    … …  
    9591013    name = 'validate-commiter-and-reviewer'
    9601014    descriptionDone = ['Validated commiter and reviewer']
    961     url = 'https://raw.githubusercontent.com/WebKit/WebKit/main/metadata/contributors.json'
    962     contributors = {}
    963 
    964     def load_contributors_from_disk(self):
    965         cwd = os.path.abspath(os.path.dirname(__file__))
    966         repo_root = os.path.dirname(os.path.dirname(os.path.dirname(cwd)))
    967         contributors_path = os.path.join(repo_root, 'metadata/contributors.json')
    968         try:
    969             with open(contributors_path, 'rb') as contributors_json:
    970                 return json.load(contributors_json)
    971         except Exception as e:
    972             self._addToLog('stdio', 'Failed to load {}\n'.format(contributors_path))
    973             return {}
    974 
    975     def load_contributors_from_github(self):
    976         try:
    977             response = requests.get(self.url, timeout=60)
    978             if response.status_code != 200:
    979                 self._addToLog('stdio', 'Failed to access {} with status code: {}\n'.format(self.url, response.status_code))
    980                 return {}
    981             return response.json()
    982         except Exception as e:
    983             self._addToLog('stdio', 'Failed to access {url}\n'.format(url=self.url))
    984             return {}
    985 
    986     def load_contributors(self):
    987         contributors_json = self.load_contributors_from_github()
    988         if not contributors_json:
    989             contributors_json = self.load_contributors_from_disk()
    990 
    991         contributors = {}
    992         for value in contributors_json:
    993             name = value.get('name')
    994             emails = value.get('emails')
    995             if name and emails:
    996                 bugzilla_email = emails[0].lower()  # We're requiring that the first email is the primary bugzilla email
    997                 contributors[bugzilla_email] = {'name': name, 'status': value.get('status')}
    998         return contributors
     1015
     1016    def __init__(self, *args, **kwargs):
     1017        super(ValidateCommiterAndReviewer, self).__init__(*args, **kwargs)
     1018        self.contributors = {}
    9991019
    10001020    @defer.inlineCallbacks
    … …  
    10131033    def fail_build(self, email, status):
    10141034        reason = '{} does not have {} permissions'.format(email, status)
    1015         comment = '{} does not have {} permissions according to {}.'.format(email, status, self.url)
     1035        comment = '{} does not have {} permissions according to {}.'.format(email, status, Contributors.url)
    10161036        comment += '\n\nRejecting attachment {} from commit queue.'.format(self.getProperty('patch_id', ''))
    10171037        self.setProperty('bugzilla_comment_text', comment)
    … …  
    10381058
    10391059    def start(self):
    1040         self.contributors = self.load_contributors()
     1060        self.contributors, errors = Contributors.load()
     1061        for error in errors:
     1062            print(error)
     1063            self._addToLog('stdio', error)
     1064
    10411065        if not self.contributors:
    10421066            self.finished(FAILURE)
  • trunk/Tools/CISupport/ews-build/steps_unittest.py

    r287857 r287978  
    4545                   CheckOutSource, CheckOutSpecificRevision, CheckPatchRelevance, CheckPatchStatusOnEWSQueues, CheckStyle,
    4646                   CleanBuild, CleanUpGitIndexLock, CleanGitRepo, CleanWorkingDirectory, CompileJSC, CompileJSCWithoutPatch,
    47                    CompileWebKit, CompileWebKitWithoutPatch, ConfigureBuild, CreateLocalGITCommit,
     47                   CompileWebKit, CompileWebKitWithoutPatch, ConfigureBuild, ConfigureBuild, Contributors, CreateLocalGITCommit,
    4848                   DownloadBuiltProduct, DownloadBuiltProductFromMaster, EWS_BUILD_HOSTNAME, ExtractBuiltProduct, ExtractTestResults,
    4949                   FetchBranches, FindModifiedChangeLogs, FindModifiedLayoutTests, GitResetHard,
    … …  
    45864586        self.longMessage = True
    45874587
    4588         def mock_load_contributors(cls, *args, **kwargs):
     4588        def mock_load_contributors(*args, **kwargs):
    45894589            return {'aakash_jain@apple.com': {'name': 'Aakash Jain', 'status': 'reviewer'},
    4590                     'committer@webkit.org': {'name': 'WebKit Committer', 'status': 'committer'}}
    4591         ValidateCommiterAndReviewer.load_contributors = mock_load_contributors
     4590                    'committer@webkit.org': {'name': 'WebKit Committer', 'status': 'committer'}}, []
     4591        Contributors.load = mock_load_contributors
    45924592        return self.setUpBuildStep()
    45934593
    … …  
    46174617        self.setProperty('patch_id', '1234')
    46184618        self.setProperty('patch_committer', 'abc@webkit.org')
    4619         ValidateCommiterAndReviewer.load_contributors = lambda x: {}
     4619        Contributors.load = lambda: ({}, [])
    46204620        self.expectHidden(False)
    46214621        self.expectOutcome(result=FAILURE, state_string='Failed to get contributors information')
    … …  
    46404640
    46414641    def test_load_contributors_from_disk(self):
    4642         ValidateCommiterAndReviewer._addToLog = lambda cls, logtype, log: sys.stdout.write(log)
    4643         contributors = filter(lambda element: element.get('name') == 'Aakash Jain', ValidateCommiterAndReviewer().load_contributors_from_disk())
     4642        contributors = filter(lambda element: element.get('name') == 'Aakash Jain', Contributors().load_from_disk()[0])
    46444643        self.assertEqual(list(contributors)[0]['emails'][0], 'aakash_jain@apple.com')
    46454644
  • trunk/Tools/ChangeLog

    r287964 r287978  
     12022-01-12  Jonathan Bedard  <jbedard@apple.com>
     2
     3        [EWS] Load contributors from stand-alone class
     4        https://bugs.webkit.org/show_bug.cgi?id=235161
     5        <rdar://problem/87491516>
     6
     7        Reviewed by Aakash Jain.
     8
     9        * CISupport/ews-build/steps.py:
     10        (Contributors): Moved from ValidateCommiterAndReviewer.
     11        (ValidateCommiterAndReviewer.load_contributors_from_disk): Moved to Contributors.
     12        (ValidateCommiterAndReviewer.load_contributors_from_github): Ditto.
     13        (ValidateCommiterAndReviewer.load_contributors): Ditto.
     14        * CISupport/ews-build/steps_unittest.py:
     15
    1162022-01-12  Ryan Haddad  <ryanhaddad@apple.com>
    217
Note: See TracChangeset for help on using the changeset viewer.