user.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing,
  12. # software distributed under the License is distributed on an
  13. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. # KIND, either express or implied. See the License for the
  15. # specific language governing permissions and limitations
  16. # under the License.
  17. """Github utils for user."""
  18. from typing import Dict, List, Set
  19. class User:
  20. """Get users according specific pull requests list.
  21. :param prs: pull requests list.
  22. """
  23. def __init__(self, prs: List[Dict]):
  24. self.prs = prs
  25. def contribution_num(self) -> Dict:
  26. """Get unique contributor with name and commit number."""
  27. res = dict()
  28. for pr in self.prs:
  29. user_id = pr["user"]["login"]
  30. res[user_id] = res.setdefault(user_id, 0) + 1
  31. return res
  32. def contributors(self) -> Set[str]:
  33. """Get unique contributor with name."""
  34. cn = self.contribution_num()
  35. return {contributor for contributor in cn}