예제 #1
0
 def clear_user_permission_cache_for_org(
         cls, user: github_types.GitHubAccount) -> None:
     with utils.get_redis_for_cache() as redis:  # type: ignore
         for key in redis.scan_iter(
                 f"{cls.USERS_PERMISSION_CACHE_KEY_PREFIX}{cls.USERS_PERMISSION_CACHE_KEY_DELIMITER}{user['id']}{cls.USERS_PERMISSION_CACHE_KEY_DELIMITER}*"
         ):
             redis.delete(key)
예제 #2
0
 def clear_user_permission_cache_for_repo(
     cls,
     owner: github_types.GitHubAccount,
     repo: github_types.GitHubRepository,
 ) -> None:
     with utils.get_redis_for_cache() as redis:  # type: ignore
         redis.delete(cls._users_permission_cache_key_for_repo(owner, repo))
예제 #3
0
 def _save_cached_last_summary_head_sha(self, sha):
     # NOTE(sileht): We store it only for 1 month, if we lose it it's not a big deal, as it's just
     # to avoid race conditions when too many synchronize events occur in a short period of time
     with utils.get_redis_for_cache() as redis:
         redis.set(
             self.redis_last_summary_head_sha_key(self.pull),
             sha,
             ex=SUMMARY_SHA_EXPIRATION,
         )
예제 #4
0
 def get_cached_last_summary_head_sha_from_pull(
     cls,
     pull: dict,
 ) -> str:
     with utils.get_redis_for_cache() as redis:  # type: ignore
         # FIXME(jd): remove in January 2021
         # Look for old format
         ################
         owner = pull["base"]["repo"]["owner"]["id"]
         repo = pull["base"]["repo"]["id"]
         pull_number = pull["number"]
         for k in redis.keys(f"summary-sha~*~{owner}~{repo}~{pull_number}"):
             return redis.get(k)
         # ENDOF FIXME(jd)
         return redis.get(cls.redis_last_summary_head_sha_key(pull))
예제 #5
0
    def has_write_permission(self, user: github_types.GitHubAccount) -> bool:
        with utils.get_redis_for_cache() as redis:  # type: ignore
            key = self._users_permission_cache_key
            permission = redis.hget(key, user["id"])
            if permission is None:
                permission = self.client.item(
                    f"{self.base_url}/collaborators/{user['login']}/permission"
                )["permission"]
                with redis.pipeline() as pipe:
                    pipe.hset(key, user["id"], permission)
                    pipe.expire(key, self.USER_PERMISSION_EXPIRATION)
                    pipe.execute()

        return permission in (
            "admin",
            "maintain",
            "write",
        )
예제 #6
0
 def clear_cached_last_summary_head_sha(self):
     with utils.get_redis_for_cache() as redis:
         redis.delete(self.redis_last_summary_head_sha_key(self.pull))
예제 #7
0
 def clear_cached_last_summary_head_sha(self) -> None:
     with utils.get_redis_for_cache(
     ) as redis:  # type: ignore[attr-defined]
         redis.delete(self.redis_last_summary_head_sha_key(self.pull))