mirror of
https://github.com/facebook/sapling.git
synced 2024-10-06 23:07:18 +03:00
732d512647
Summary:
Historically, we avoided running the Black autoformatter on our
fork of ghstack so that the code would be easier to diff with
upstream. Now that Black is run on upstream ghstack:
e5eca89cb3
we have no reason to exclude it from our linter.
Going forward, we should update the GitHub CI to run `black --check`
and report back so that contributors get this signal as well.
Reviewed By: zsol
Differential Revision: D42494629
fbshipit-source-id: 7f09ec46f687e56662f4f6ac477fd2fd077709d6
87 lines
2.5 KiB
Python
87 lines
2.5 KiB
Python
from abc import ABCMeta, abstractmethod
|
|
from typing import Any, Sequence
|
|
|
|
|
|
class GitHubEndpoint(metaclass=ABCMeta):
|
|
@abstractmethod
|
|
async def graphql(self, query: str, **kwargs: Any) -> Any:
|
|
"""Execute a GraphQL query asynchronously.
|
|
|
|
Args:
|
|
query: string GraphQL query to execute
|
|
**kwargs: values for variables in the graphql query
|
|
|
|
Returns: parsed JSON response
|
|
"""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def graphql_sync(self, query: str, **kwargs: Any) -> Any:
|
|
"""Execute a GraphQL query synchronously.
|
|
|
|
Args:
|
|
query: string GraphQL query to execute
|
|
**kwargs: values for variables in the graphql query
|
|
|
|
Returns: parsed JSON response
|
|
"""
|
|
pass
|
|
|
|
# This hook function should be invoked when a 'git push' to GitHub
|
|
# occurs. This is used by testing to simulate actions GitHub
|
|
# takes upon branch push, more conveniently than setting up
|
|
# a branch hook on the repository and receiving events from it.
|
|
# TODO: generalize to any repo
|
|
@abstractmethod
|
|
def push_hook(self, refName: Sequence[str]) -> None:
|
|
pass
|
|
|
|
def get(self, path: str, **kwargs: Any) -> Any:
|
|
"""
|
|
Send a GET request to endpoint 'path'.
|
|
|
|
Returns: parsed JSON response
|
|
"""
|
|
return self.rest("get", path, **kwargs)
|
|
|
|
def post(self, path: str, **kwargs: Any) -> Any:
|
|
"""
|
|
Send a POST request to endpoint 'path'.
|
|
|
|
Returns: parsed JSON response
|
|
"""
|
|
return self.rest("post", path, **kwargs)
|
|
|
|
def patch(self, path: str, **kwargs: Any) -> Any:
|
|
"""
|
|
Send a PATCH request to endpoint 'path'.
|
|
|
|
Returns: parsed JSON response
|
|
"""
|
|
return self.rest("patch", path, **kwargs)
|
|
|
|
@abstractmethod
|
|
def rest(self, method: str, path: str, **kwargs: Any) -> Any:
|
|
"""
|
|
Send a 'method' request to endpoint 'path'.
|
|
|
|
Args:
|
|
method: 'GET', 'POST', etc.
|
|
path: relative URL path to access on endpoint
|
|
**kwargs: dictionary of JSON payload to send
|
|
|
|
Returns: parsed JSON response
|
|
"""
|
|
pass
|
|
|
|
|
|
def get_github_endpoint(hostname: str) -> GitHubEndpoint:
|
|
"""Factory method to generate a GitHubEndpoint.
|
|
|
|
Currently, it only supports GitHubCLIEndpoint. We will add a fake
|
|
GitHubEndpoint for integration test later.
|
|
"""
|
|
from ghstack.github_cli_endpoint import GitHubCLIEndpoint
|
|
|
|
return GitHubCLIEndpoint(hostname)
|