diff options
author | Tobias Henkel <tobias.henkel@bmw.de> | 2019-06-14 22:17:05 +0200 |
---|---|---|
committer | Tobias Henkel <tobias.henkel@bmw.de> | 2019-06-17 22:39:35 +0200 |
commit | a3e4e839741051e9d561c7a9996f5f12504043f8 (patch) | |
tree | ffc39761008081f5f16959ce7c4a4e9e05d71ba6 /tests/fakegithub.py | |
parent | 4a053ab53adf2deb5b2cb66db4c947b21ad127b8 (diff) | |
download | zuul-a3e4e839741051e9d561c7a9996f5f12504043f8.tar.gz |
Switch getPullBySha to using the search api
We currently cache the sha to pull request mapping locally in order to
be able to map status events to pull requests. This cache is not
effective in some cases. For instance on merge a pull request changes
its sha so it's not known by the cache. Some projects like ansible run
post merge jobs on a pr which in turn emit status events for the now
unknown sha's. This invalidates the cache and we need to sweep through
all pull requests of the project to find the correct one. This can
better be solved by using the search api.
However the search api is more restricted and allows 30 requests per
minute per installation. Based on local testing it's hard but not
impossible to reach the limit so we need to handle it
gracefully. Luckily we get all information we need to handle it when
we reached the rate limit.
Change-Id: Idb6c64caa9f948111a58135754174d898ca1528c
Diffstat (limited to 'tests/fakegithub.py')
-rw-r--r-- | tests/fakegithub.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/tests/fakegithub.py b/tests/fakegithub.py index f278e4940..ef0478f75 100644 --- a/tests/fakegithub.py +++ b/tests/fakegithub.py @@ -283,6 +283,10 @@ class FakeIssue(object): def pull_request(self): return FakePull(self._fake_pull_request) + @property + def number(self): + return self._fake_pull_request.number + class FakeFile(object): def __init__(self, filename): @@ -449,6 +453,14 @@ class FakeGithubClient(object): def tokenize(s): return re.findall(r'[\w]+', s) + def query_is_sha(s): + return re.match(r'[a-z0-9]{40}', s) + + if query_is_sha(query): + return (FakeIssueSearchResult(FakeIssue(pr)) + for pr in self._data.pull_requests.values() + if pr.head_sha == query) + parts = tokenize(query) terms = set() results = [] @@ -471,4 +483,4 @@ class FakeGithubClient(object): issue = FakeIssue(pr) results.append(FakeIssueSearchResult(issue)) - return results + return iter(results) |