| Differences between
and this patch
- a/Tools/ChangeLog +15 lines
Lines 1-3 a/Tools/ChangeLog_sec1
1
2022-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 NOBODY (OOPS!).
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
1
2022-01-12  J Pascoe  <j_pascoe@apple.com>
16
2022-01-12  J Pascoe  <j_pascoe@apple.com>
2
17
3
        [WebAuthn] Fix freebie call without user gesture not being given
18
        [WebAuthn] Fix freebie call without user gesture not being given
- a/Tools/CISupport/ews-build/steps.py -40 / +64 lines
Lines 89-95 class GitHub(object): a/Tools/CISupport/ews-build/steps.py_sec1
89
        return '{}pull/{}'.format(repository_url, pr_number)
89
        return '{}pull/{}'.format(repository_url, pr_number)
90
90
91
91
92
class ConfigureBuild(buildstep.BuildStep):
92
class 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
                    printable='{} <{}>'.format(name, emails[0].lower()),
140
                    status=value.get('status'),
141
                    email=emails[0],
142
                )
143
        return contributors, errors
144
145
146
class ConfigureBuild(buildstep.BuildStep, GitHubMixin):
93
    name = 'configure-build'
147
    name = 'configure-build'
94
    description = ['configuring build']
148
    description = ['configuring build']
95
    descriptionDone = ['Configured build']
149
    descriptionDone = ['Configured build']
Lines 958-1001 class ValidatePatch(buildstep.BuildStep, BugzillaMixin): a/Tools/CISupport/ews-build/steps.py_sec2
958
class ValidateCommiterAndReviewer(buildstep.BuildStep):
1012
class ValidateCommiterAndReviewer(buildstep.BuildStep):
959
    name = 'validate-commiter-and-reviewer'
1013
    name = 'validate-commiter-and-reviewer'
960
    descriptionDone = ['Validated commiter and reviewer']
1014
    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
1015
986
    def load_contributors(self):
1016
    def __init__(self, *args, **kwargs):
987
        contributors_json = self.load_contributors_from_github()
1017
        super(ValidateCommiterAndReviewer, self).__init__(*args, **kwargs)
988
        if not contributors_json:
1018
        self.contributors = {}
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
999
1019
1000
    @defer.inlineCallbacks
1020
    @defer.inlineCallbacks
1001
    def _addToLog(self, logName, message):
1021
    def _addToLog(self, logName, message):
Lines 1012-1018 class ValidateCommiterAndReviewer(buildstep.BuildStep): a/Tools/CISupport/ews-build/steps.py_sec3
1012
1032
1013
    def fail_build(self, email, status):
1033
    def fail_build(self, email, status):
1014
        reason = '{} does not have {} permissions'.format(email, status)
1034
        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)
1016
        comment += '\n\nRejecting attachment {} from commit queue.'.format(self.getProperty('patch_id', ''))
1036
        comment += '\n\nRejecting attachment {} from commit queue.'.format(self.getProperty('patch_id', ''))
1017
        self.setProperty('bugzilla_comment_text', comment)
1037
        self.setProperty('bugzilla_comment_text', comment)
1018
1038
Lines 1037-1043 class ValidateCommiterAndReviewer(buildstep.BuildStep): a/Tools/CISupport/ews-build/steps.py_sec4
1037
        return contributor.get('name')
1057
        return contributor.get('name')
1038
1058
1039
    def start(self):
1059
    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
1041
        if not self.contributors:
1065
        if not self.contributors:
1042
            self.finished(FAILURE)
1066
            self.finished(FAILURE)
1043
            self.descriptionDone = 'Failed to get contributors information'
1067
            self.descriptionDone = 'Failed to get contributors information'
- a/Tools/CISupport/ews-build/steps_unittest.py -7 / +6 lines
Lines 44-50 from steps import (AnalyzeAPITestsResults, AnalyzeCompileWebKitResults, AnalyzeJ a/Tools/CISupport/ews-build/steps_unittest.py_sec1
44
                   AnalyzeLayoutTestsResults, ApplyPatch, ApplyWatchList, ArchiveBuiltProduct, ArchiveTestResults,
44
                   AnalyzeLayoutTestsResults, ApplyPatch, ApplyWatchList, ArchiveBuiltProduct, ArchiveTestResults,
45
                   CheckOutSource, CheckOutSpecificRevision, CheckPatchRelevance, CheckPatchStatusOnEWSQueues, CheckStyle,
45
                   CheckOutSource, CheckOutSpecificRevision, CheckPatchRelevance, CheckPatchStatusOnEWSQueues, CheckStyle,
46
                   CleanBuild, CleanUpGitIndexLock, CleanGitRepo, CleanWorkingDirectory, CompileJSC, CompileJSCWithoutPatch,
46
                   CleanBuild, CleanUpGitIndexLock, CleanGitRepo, CleanWorkingDirectory, CompileJSC, CompileJSCWithoutPatch,
47
                   CompileWebKit, CompileWebKitWithoutPatch, ConfigureBuild, CreateLocalGITCommit,
47
                   CompileWebKit, CompileWebKitWithoutPatch, ConfigureBuild, ConfigureBuild, Contributors, CreateLocalGITCommit,
48
                   DownloadBuiltProduct, DownloadBuiltProductFromMaster, EWS_BUILD_HOSTNAME, ExtractBuiltProduct, ExtractTestResults,
48
                   DownloadBuiltProduct, DownloadBuiltProductFromMaster, EWS_BUILD_HOSTNAME, ExtractBuiltProduct, ExtractTestResults,
49
                   FetchBranches, FindModifiedChangeLogs, FindModifiedLayoutTests, GitResetHard,
49
                   FetchBranches, FindModifiedChangeLogs, FindModifiedLayoutTests, GitResetHard,
50
                   InstallBuiltProduct, InstallGtkDependencies, InstallWpeDependencies,
50
                   InstallBuiltProduct, InstallGtkDependencies, InstallWpeDependencies,
Lines 4585-4594 class TestValidateCommiterAndReviewer(BuildStepMixinAdditions, unittest.TestCase a/Tools/CISupport/ews-build/steps_unittest.py_sec2
4585
    def setUp(self):
4585
    def setUp(self):
4586
        self.longMessage = True
4586
        self.longMessage = True
4587
4587
4588
        def mock_load_contributors(cls, *args, **kwargs):
4588
        def mock_load_contributors(*args, **kwargs):
4589
            return {'aakash_jain@apple.com': {'name': 'Aakash Jain', 'status': 'reviewer'},
4589
            return {'aakash_jain@apple.com': {'name': 'Aakash Jain', 'status': 'reviewer'},
4590
                    'committer@webkit.org': {'name': 'WebKit Committer', 'status': 'committer'}}
4590
                    'committer@webkit.org': {'name': 'WebKit Committer', 'status': 'committer'}}, []
4591
        ValidateCommiterAndReviewer.load_contributors = mock_load_contributors
4591
        Contributors.load = mock_load_contributors
4592
        return self.setUpBuildStep()
4592
        return self.setUpBuildStep()
4593
4593
4594
    def tearDown(self):
4594
    def tearDown(self):
Lines 4616-4622 class TestValidateCommiterAndReviewer(BuildStepMixinAdditions, unittest.TestCase a/Tools/CISupport/ews-build/steps_unittest.py_sec3
4616
        self.setupStep(ValidateCommiterAndReviewer())
4616
        self.setupStep(ValidateCommiterAndReviewer())
4617
        self.setProperty('patch_id', '1234')
4617
        self.setProperty('patch_id', '1234')
4618
        self.setProperty('patch_committer', 'abc@webkit.org')
4618
        self.setProperty('patch_committer', 'abc@webkit.org')
4619
        ValidateCommiterAndReviewer.load_contributors = lambda x: {}
4619
        Contributors.load = lambda: ({}, [])
4620
        self.expectHidden(False)
4620
        self.expectHidden(False)
4621
        self.expectOutcome(result=FAILURE, state_string='Failed to get contributors information')
4621
        self.expectOutcome(result=FAILURE, state_string='Failed to get contributors information')
4622
        return self.runStep()
4622
        return self.runStep()
Lines 4639-4646 class TestValidateCommiterAndReviewer(BuildStepMixinAdditions, unittest.TestCase a/Tools/CISupport/ews-build/steps_unittest.py_sec4
4639
        return self.runStep()
4639
        return self.runStep()
4640
4640
4641
    def test_load_contributors_from_disk(self):
4641
    def test_load_contributors_from_disk(self):
4642
        ValidateCommiterAndReviewer._addToLog = lambda cls, logtype, log: sys.stdout.write(log)
4642
        contributors = filter(lambda element: element.get('name') == 'Aakash Jain', Contributors().load_from_disk()[0])
4643
        contributors = filter(lambda element: element.get('name') == 'Aakash Jain', ValidateCommiterAndReviewer().load_contributors_from_disk())
4644
        self.assertEqual(list(contributors)[0]['emails'][0], 'aakash_jain@apple.com')
4643
        self.assertEqual(list(contributors)[0]['emails'][0], 'aakash_jain@apple.com')
4645
4644
4646
4645

Return to Bug 235161