11import asyncio
22import logging
33import re
4+ from collections import Counter
45
56import requests
67from django .conf import settings
@@ -200,6 +201,10 @@ def get_patch(self, pull_number: int) -> str:
200201 headers = {"Accept" : "application/vnd.github.patch" },
201202 )
202203
204+ def get_pull_request_commits (self , pull_number : int ) -> dict :
205+ """Get all commits from specific pull request from the repo."""
206+ return self ._repo_get (f"pulls/{ pull_number } /commits" )
207+
203208 def open_pull_request (self , pull_number : int ) -> dict :
204209 """Open the given pull request."""
205210 return self ._post (
@@ -278,6 +283,21 @@ def __init__(self, client: GitHubAPIClient, data: dict):
278283 self .user_html_url = data ["user" ]["html_url" ]
279284 self .user_login = data ["user" ]["login" ]
280285
286+ def _select_commit_author (
287+ self , commits : list [dict ]
288+ ) -> tuple [str | None , str | None ]:
289+ """Select the most common author in commits."""
290+ # This method is ported from lando.api.legacy.revisions.select_diff_author.
291+ commits = [commit ["commit" ] for commit in commits ]
292+ if not commits :
293+ return None , None
294+
295+ # Below is copied verbatim from the legacy method.
296+ authors = [c .get ("author" , {}) for c in commits ]
297+ authors = Counter ((a .get ("name" ), a .get ("email" )) for a in authors )
298+ authors = authors .most_common (1 )
299+ return authors [0 ][0 ] if authors else (None , None )
300+
281301 @property
282302 def diff (self ) -> str :
283303 return self .client .get_diff (self .number )
@@ -286,6 +306,14 @@ def diff(self) -> str:
286306 def patch (self ) -> str :
287307 return self .client .get_patch (self .number )
288308
309+ @property
310+ def commits (self ) -> str :
311+ return self .client .get_pull_request_commits (self .number )
312+
313+ @property
314+ def author (self ) -> str :
315+ return self ._select_commit_author (self .commits )
316+
289317 def serialize (self ) -> dict [str , str ]:
290318 """Return a dictionary with various pull request data."""
291319 return {
0 commit comments