diff --git a/pyproject.toml b/pyproject.toml index 2be95b5..abeeb79 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,12 +17,12 @@ namespaces = true # ----------------------------------------- Project Metadata ------------------------------------- # [project] -version = "0.0.0.dev46" +version = "0.0.0.dev47" name = "PyLinks" dependencies = [ "requests >= 2.31.0, < 3", - "ExceptionMan == 0.0.0.dev33", - "MDit == 0.0.0.dev33", + "ExceptionMan == 0.0.0.dev34", + "MDit == 0.0.0.dev34", ] requires-python = ">=3.10" diff --git a/requirements.txt b/requirements.txt index 0fdb074..f92146f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ requests >= 2.31.0, < 3 -ExceptionMan == 0.0.0.dev33 -MDit == 0.0.0.dev33 \ No newline at end of file +ExceptionMan == 0.0.0.dev34 +MDit == 0.0.0.dev34 \ No newline at end of file diff --git a/src/pylinks/api/github.py b/src/pylinks/api/github.py index 05eec92..ad535e2 100644 --- a/src/pylinks/api/github.py +++ b/src/pylinks/api/github.py @@ -166,6 +166,16 @@ def _rest_query( endpoint=endpoint ) + def _graphql_query( + self, + payload: str, + extra_headers: dict | None = None, + ) -> dict: + return self._github.graphql_query( + query=f'repository(name: "{self._name}", owner: "{self._username}") {{{payload}}}', + extra_headers=extra_headers, + )["repository"] + @property def username(self) -> str: return self._username @@ -412,13 +422,9 @@ def discussion_categories(self) -> list[dict[str, str]]: - [GitHub Docs](https://docs.github.com/en/graphql/guides/using-the-graphql-api-for-discussions) - """ - payload = "{discussionCategories(first: 100) {edges {node {name, slug, id}}}}" - query = f'repository(name: "{self._name}", owner: "{self._username}") {payload}' - data = self._github.graphql_query(query) - discussions = [ - entry["node"] - for entry in data["repository"]["discussionCategories"]["edges"] - ] + payload = "discussionCategories(first: 100) {edges {node {name, slug, id}}}" + data = self._graphql_query(payload) + discussions = [entry["node"] for entry in data["discussionCategories"]["edges"]] return discussions def issue(self, number: int) -> dict: @@ -610,7 +616,12 @@ def pull(self, number: int) -> dict: """ return self._rest_query(f"pulls/{number}") - def pull_commits(self, number: int) -> list[dict]: + def pull_commits( + self, + number: int, + count: int = 0, + sort: Literal["first", "last"] = "last", + ) -> list[dict]: """ Get a list of commits for a pull request. @@ -629,6 +640,9 @@ def pull_commits(self, number: int) -> list[dict]: ---------- - [GitHub API Docs](https://docs.github.com/en/rest/pulls/commits?apiVersion=2022-11-28#list-commits-on-a-pull-request) """ + payload = f"pullRequest(number: {number})" + commits = "{{commits()" + commits = [] page = 1 while True: @@ -639,6 +653,8 @@ def pull_commits(self, number: int) -> list[dict]: break return commits + + def pull_create( self, head: str, @@ -1683,9 +1699,8 @@ def branch_protection_rules(self) -> list[dict]: ---------- - [GitHub API Docs](https://docs.github.com/en/graphql/reference/objects#branchprotectionruleconnection) """ - payload = "{branchProtectionRules(first: 100) {nodes {id, pattern}}}" - query = f'repository(name: "{self._name}", owner: "{self._username}") {payload}' - data = self._github.graphql_query(query) + payload = "branchProtectionRules(first: 100) {nodes {id, pattern}}" + data = self._graphql_query(payload) return data["repository"]["branchProtectionRules"]["nodes"] def branch_protection_rule_create(