Changeset 287978 in webkit
- Timestamp:
- Jan 13, 2022, 7:22:22 AM (5 years ago)
- Location:
- trunk/Tools
- Files:
-
- 3 edited
-
CISupport/ews-build/steps.py (modified) (4 diffs)
-
CISupport/ews-build/steps_unittest.py (modified) (4 diffs)
-
ChangeLog (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/CISupport/ews-build/steps.py
r287949 r287978 90 90 91 91 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 name=name, 140 status=value.get('status'), 141 email=emails[0], 142 ) 143 return contributors, errors 144 145 92 146 class ConfigureBuild(buildstep.BuildStep): 93 147 name = 'configure-build' … … 959 1013 name = 'validate-commiter-and-reviewer' 960 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 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 = {} 999 1019 1000 1020 @defer.inlineCallbacks … … 1013 1033 def fail_build(self, email, status): 1014 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 1036 comment += '\n\nRejecting attachment {} from commit queue.'.format(self.getProperty('patch_id', '')) 1017 1037 self.setProperty('bugzilla_comment_text', comment) … … 1038 1058 1039 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 1065 if not self.contributors: 1042 1066 self.finished(FAILURE) -
trunk/Tools/CISupport/ews-build/steps_unittest.py
r287857 r287978 45 45 CheckOutSource, CheckOutSpecificRevision, CheckPatchRelevance, CheckPatchStatusOnEWSQueues, CheckStyle, 46 46 CleanBuild, CleanUpGitIndexLock, CleanGitRepo, CleanWorkingDirectory, CompileJSC, CompileJSCWithoutPatch, 47 CompileWebKit, CompileWebKitWithoutPatch, ConfigureBuild, C reateLocalGITCommit,47 CompileWebKit, CompileWebKitWithoutPatch, ConfigureBuild, ConfigureBuild, Contributors, CreateLocalGITCommit, 48 48 DownloadBuiltProduct, DownloadBuiltProductFromMaster, EWS_BUILD_HOSTNAME, ExtractBuiltProduct, ExtractTestResults, 49 49 FetchBranches, FindModifiedChangeLogs, FindModifiedLayoutTests, GitResetHard, … … 4586 4586 self.longMessage = True 4587 4587 4588 def mock_load_contributors( cls,*args, **kwargs):4588 def mock_load_contributors(*args, **kwargs): 4589 4589 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_contributors4590 'committer@webkit.org': {'name': 'WebKit Committer', 'status': 'committer'}}, [] 4591 Contributors.load = mock_load_contributors 4592 4592 return self.setUpBuildStep() 4593 4593 … … 4617 4617 self.setProperty('patch_id', '1234') 4618 4618 self.setProperty('patch_committer', 'abc@webkit.org') 4619 ValidateCommiterAndReviewer.load_contributors = lambda x: {}4619 Contributors.load = lambda: ({}, []) 4620 4620 self.expectHidden(False) 4621 4621 self.expectOutcome(result=FAILURE, state_string='Failed to get contributors information') … … 4640 4640 4641 4641 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]) 4644 4643 self.assertEqual(list(contributors)[0]['emails'][0], 'aakash_jain@apple.com') 4645 4644 -
trunk/Tools/ChangeLog
r287964 r287978 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 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 1 16 2022-01-12 Ryan Haddad <ryanhaddad@apple.com> 2 17
Note:
See TracChangeset
for help on using the changeset viewer.