validate-committer-lists 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. #!/usr/bin/env python
  2. # Copyright (c) 2009, Google Inc. All rights reserved.
  3. #
  4. # Redistribution and use in source and binary forms, with or without
  5. # modification, are permitted provided that the following conditions are
  6. # met:
  7. #
  8. # * Redistributions of source code must retain the above copyright
  9. # notice, this list of conditions and the following disclaimer.
  10. # * Redistributions in binary form must reproduce the above
  11. # copyright notice, this list of conditions and the following disclaimer
  12. # in the documentation and/or other materials provided with the
  13. # distribution.
  14. # * Neither the name of Google Inc. nor the names of its
  15. # contributors may be used to endorse or promote products derived from
  16. # this software without specific prior written permission.
  17. #
  18. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. #
  30. # Checks Python's known list of committers against lists.webkit.org and SVN history.
  31. import logging
  32. import os
  33. import subprocess
  34. import re
  35. import urllib2
  36. from datetime import date, datetime, timedelta
  37. from optparse import OptionParser
  38. from webkitpy.common.config.committers import CommitterList
  39. from webkitpy.common.checkout.scm import Git
  40. from webkitpy.common.net.bugzilla import Bugzilla
  41. # WebKit includes a built copy of BeautifulSoup in Scripts/webkitpy
  42. # so this import should always succeed.
  43. from webkitpy.thirdparty.BeautifulSoup import BeautifulSoup
  44. _log = logging.getLogger(__name__)
  45. def print_list_if_non_empty(title, list_to_print):
  46. if not list_to_print:
  47. return
  48. print # Newline before the list
  49. print title
  50. for item in list_to_print:
  51. print item
  52. class CommitterListFromMailingList(object):
  53. committers_list_url = "http://lists.webkit.org/mailman/roster/webkit-committers"
  54. reviewers_list_url = "http://lists.webkit.org/mailman/roster/webkit-reviewers"
  55. def _fetch_emails_from_page(self, url):
  56. page = urllib2.urlopen(url)
  57. soup = BeautifulSoup(page)
  58. emails = []
  59. # Grab the cells in the first column (which happens to be the bug ids).
  60. for email_item in soup('li'):
  61. email_link = email_item.find("a")
  62. email = email_link.string.replace(" at ", "@") # The email is obfuscated using " at " instead of "@".
  63. emails.append(email)
  64. return emails
  65. @staticmethod
  66. def _commiters_not_found_in_email_list(committers, emails):
  67. missing_from_mailing_list = []
  68. for committer in committers:
  69. for email in committer.emails:
  70. if email in emails:
  71. break
  72. else:
  73. missing_from_mailing_list.append(committer)
  74. return missing_from_mailing_list
  75. @staticmethod
  76. def _emails_not_found_in_committer_list(committers, emails):
  77. email_to_committer_map = {}
  78. for committer in committers:
  79. for email in committer.emails:
  80. email_to_committer_map[email] = committer
  81. return filter(lambda email: not email_to_committer_map.get(email), emails)
  82. def check_for_emails_missing_from_list(self, committer_list):
  83. committer_emails = self._fetch_emails_from_page(self.committers_list_url)
  84. list_name = "webkit-committers@lists.webkit.org"
  85. missing_from_mailing_list = self._commiters_not_found_in_email_list(committer_list.committers(), committer_emails)
  86. print_list_if_non_empty("Committers missing from %s:" % list_name, missing_from_mailing_list)
  87. users_missing_from_committers = self._emails_not_found_in_committer_list(committer_list.committers(), committer_emails)
  88. print_list_if_non_empty("Subcribers to %s missing from contributors.json:" % list_name, users_missing_from_committers)
  89. reviewer_emails = self._fetch_emails_from_page(self.reviewers_list_url)
  90. list_name = "webkit-reviewers@lists.webkit.org"
  91. missing_from_mailing_list = self._commiters_not_found_in_email_list(committer_list.reviewers(), reviewer_emails)
  92. print_list_if_non_empty("Reviewers missing from %s:" % list_name, missing_from_mailing_list)
  93. missing_from_reviewers = self._emails_not_found_in_committer_list(committer_list.reviewers(), reviewer_emails)
  94. print_list_if_non_empty("Subcribers to %s missing from reviewers in contributors.json:" % list_name, missing_from_reviewers)
  95. missing_from_committers = self._emails_not_found_in_committer_list(committer_list.committers(), reviewer_emails)
  96. print_list_if_non_empty("Subcribers to %s completely missing from contributors.json:" % list_name, missing_from_committers)
  97. class CommitterListFromGit(object):
  98. login_to_email_address = {
  99. 'aliceli1' : 'alice.liu@apple.com',
  100. 'bdash' : 'mrowe@apple.com',
  101. 'bdibello' : 'bdibello@apple.com', # Bruce DiBello, only 4 commits: r10023, r9548, r9538, r9535
  102. 'cblu' : 'cblu@apple.com',
  103. 'cpeterse' : 'cpetersen@apple.com',
  104. 'eseidel' : 'eric@webkit.org',
  105. 'gdennis' : 'gdennis@webkit.org',
  106. 'goldsmit' : 'goldsmit@apple.com', # Debbie Goldsmith, only one commit r8839
  107. 'gramps' : 'gramps@apple.com',
  108. 'honeycutt' : 'jhoneycutt@apple.com',
  109. 'jdevalk' : 'joost@webkit.org',
  110. 'jens' : 'jens@apple.com',
  111. 'justing' : 'justin.garcia@apple.com',
  112. 'kali' : 'kali@apple.com', # Christy Warren, did BIDI work, 5 commits: r8815, r8802, r8801, r8791, r8773, r8603
  113. 'kjk' : 'kkowalczyk@gmail.com',
  114. 'kmccullo' : 'kmccullough@apple.com',
  115. 'kocienda' : 'kocienda@apple.com',
  116. 'lamadio' : 'lamadio@apple.com', # Lou Amadio, only 2 commits: r17949 and r17783
  117. 'lars' : 'lars@kde.org',
  118. 'lweintraub' : 'lweintraub@apple.com',
  119. 'lypanov' : 'lypanov@kde.org',
  120. 'mhay' : 'mhay@apple.com', # Mike Hay, 3 commits: r3813, r2552, r2548
  121. 'ouch' : 'ouch@apple.com', # John Louch
  122. 'pyeh' : 'patti@apple.com', # Patti Yeh, did VoiceOver work in WebKit
  123. 'rjw' : 'rjw@apple.com',
  124. 'seangies' : 'seangies@apple.com', # Sean Gies?, only 5 commits: r16600, r16592, r16511, r16489, r16484
  125. 'sheridan' : 'sheridan@apple.com', # Shelly Sheridan
  126. 'thatcher' : 'timothy@apple.com',
  127. 'tomernic' : 'timo@apple.com',
  128. 'trey' : 'trey@usa.net',
  129. 'tristan' : 'tristan@apple.com',
  130. 'vicki' : 'vicki@apple.com',
  131. 'voas' : 'voas@apple.com', # Ed Voas, did some Carbon work in WebKit
  132. 'zack' : 'zack@kde.org',
  133. 'zimmermann' : 'zimmermann@webkit.org',
  134. }
  135. def __init__(self):
  136. self._last_commit_time_by_author_cache = {}
  137. def _fetch_authors_and_last_commit_time_from_git_log(self):
  138. last_commit_dates = {}
  139. git_log_args = ['git', 'log', '--reverse', '--pretty=format:%ae %at']
  140. process = subprocess.Popen(git_log_args, stdout=subprocess.PIPE)
  141. # eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc 1257090899
  142. line_regexp = re.compile("^(?P<author>.+)@\S+ (?P<timestamp>\d+)$")
  143. while True:
  144. output_line = process.stdout.readline()
  145. if output_line == '' and process.poll() != None:
  146. return last_commit_dates
  147. match_result = line_regexp.match(output_line)
  148. if not match_result:
  149. _log.error("Failed to match line: %s" % output_line)
  150. exit(1)
  151. last_commit_dates[match_result.group('author')] = float(match_result.group('timestamp'))
  152. def _fill_in_emails_for_old_logins(self):
  153. authors_missing_email = filter(lambda author: author.find('@') == -1, self._last_commit_time_by_author_cache)
  154. authors_with_email = filter(lambda author: author.find('@') != -1, self._last_commit_time_by_author_cache)
  155. prefixes_of_authors_with_email = map(lambda author: author.split('@')[0], authors_with_email)
  156. for author in authors_missing_email:
  157. # First check to see if we have a manual mapping from login to email.
  158. author_email = self.login_to_email_address.get(author)
  159. # Most old logins like 'darin' are now just 'darin@apple.com', so check for a prefix match if a manual mapping was not found.
  160. if not author_email and author in prefixes_of_authors_with_email:
  161. author_email_index = prefixes_of_authors_with_email.index(author)
  162. author_email = authors_with_email[author_email_index]
  163. if not author_email:
  164. # No known email mapping, likely not an active committer. We could log here.
  165. continue
  166. # _log.info("%s -> %s" % (author, author_email)) # For sanity checking.
  167. no_email_commit_time = self._last_commit_time_by_author_cache.get(author)
  168. email_commit_time = self._last_commit_time_by_author_cache.get(author_email)
  169. # We compare the timestamps for extra sanity even though we could assume commits before email address were used for login are always going to be older.
  170. if not email_commit_time or email_commit_time < no_email_commit_time:
  171. self._last_commit_time_by_author_cache[author_email] = no_email_commit_time
  172. del self._last_commit_time_by_author_cache[author]
  173. def _last_commit_by_author(self):
  174. if not self._last_commit_time_by_author_cache:
  175. self._last_commit_time_by_author_cache = self._fetch_authors_and_last_commit_time_from_git_log()
  176. self._fill_in_emails_for_old_logins()
  177. del self._last_commit_time_by_author_cache['(no author)'] # The initial svn import isn't very useful.
  178. return self._last_commit_time_by_author_cache
  179. @staticmethod
  180. def _print_three_column_row(widths, values):
  181. print "%s%s%s" % (values[0].ljust(widths[0]), values[1].ljust(widths[1]), values[2])
  182. def print_possibly_expired_committers(self, committer_list):
  183. authors_and_last_commits = self._last_commit_by_author().items()
  184. authors_and_last_commits.sort(lambda a,b: cmp(a[1], b[1]), reverse=True)
  185. committer_cuttof = date.today() - timedelta(days=365)
  186. column_widths = [13, 25]
  187. print
  188. print "Committers who have not committed within one year:"
  189. self._print_three_column_row(column_widths, ("Last Commit", "Committer Email", "Committer Record"))
  190. for (author, last_commit) in authors_and_last_commits:
  191. last_commit_date = date.fromtimestamp(last_commit)
  192. if committer_cuttof > last_commit_date:
  193. committer_record = committer_list.committer_by_email(author)
  194. self._print_three_column_row(column_widths, (str(last_commit_date), author, committer_record))
  195. def print_committers_missing_from_committer_list(self, committer_list):
  196. missing_from_contributors_json = []
  197. last_commit_time_by_author = self._last_commit_by_author()
  198. for author in last_commit_time_by_author:
  199. if not committer_list.committer_by_email(author):
  200. missing_from_contributors_json.append(author)
  201. never_committed = []
  202. for committer in committer_list.committers():
  203. for email in committer.emails:
  204. if last_commit_time_by_author.get(email):
  205. break
  206. else:
  207. never_committed.append(committer)
  208. print_list_if_non_empty("Historical committers missing from contributors.json:", missing_from_contributors_json)
  209. print_list_if_non_empty("Committers in contributors.json who have never committed:", never_committed)
  210. class CommitterListBugzillaChecker(object):
  211. def __init__(self):
  212. self._bugzilla = Bugzilla()
  213. def _has_invalid_bugzilla_email(self, committer):
  214. return not self._bugzilla.queries.fetch_logins_matching_substring(committer.bugzilla_email())
  215. def print_committers_with_invalid_bugzilla_emails(self, committer_list):
  216. print # Print a newline before we start hitting bugzilla (it logs about logging in).
  217. print "Checking committer emails against bugzilla (this will take a long time)"
  218. committers_with_invalid_bugzilla_email = filter(self._has_invalid_bugzilla_email, committer_list.committers())
  219. print_list_if_non_empty("Committers with invalid bugzilla email:", committers_with_invalid_bugzilla_email)
  220. def main():
  221. parser = OptionParser()
  222. parser.add_option("-b", "--check-bugzilla-emails", action="store_true", help="Check the bugzilla_email for each committer against bugs.webkit.org")
  223. (options, args) = parser.parse_args()
  224. committer_list = CommitterList()
  225. CommitterListFromMailingList().check_for_emails_missing_from_list(committer_list)
  226. if not Git.in_working_directory("."):
  227. print """\n\nWARNING: validate-committer-lists requires a git checkout.
  228. The following checks are disabled:
  229. - List of committers ordered by last commit
  230. - List of historical committers missing from contributors.json
  231. """
  232. return 1
  233. svn_committer_list = CommitterListFromGit()
  234. svn_committer_list.print_possibly_expired_committers(committer_list)
  235. svn_committer_list.print_committers_missing_from_committer_list(committer_list)
  236. if options.check_bugzilla_emails:
  237. CommitterListBugzillaChecker().print_committers_with_invalid_bugzilla_emails(committer_list)
  238. if __name__ == "__main__":
  239. main()