-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from amlight/feat/create_issues
feat: added `repo_issue_create` and `org_repos_issue_create` concurrent funcs
- Loading branch information
Showing
6 changed files
with
162 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
import asyncio | ||
from typing import List | ||
|
||
import httpx | ||
|
||
from .base import base_url, headers | ||
from .repo_client import org_repos_by_attr | ||
|
||
|
||
async def repo_issue_create( | ||
owner: str, | ||
repo: str, | ||
title: str, | ||
body: str = "", | ||
assignees: List[str] = None, | ||
labels: List[str] = None, | ||
) -> dict: | ||
"""Create an issue in a repository.""" | ||
assignees = assignees if assignees else [] | ||
labels = labels if labels else [] | ||
url = f"{base_url()}/repos/{owner}/{repo}/issues" | ||
async with httpx.AsyncClient() as client: | ||
r = await client.post( | ||
url, | ||
headers=headers(), | ||
json={ | ||
"title": title, | ||
"body": body, | ||
"assignees": assignees, | ||
"labels": labels, | ||
}, | ||
) | ||
r.raise_for_status() | ||
rbody = r.json() | ||
return { | ||
"number": rbody.get("number"), | ||
"title": rbody.get("title"), | ||
"html_url": rbody.get("html_url"), | ||
} | ||
|
||
|
||
async def org_repos_issue_create( | ||
org: str, | ||
title: str, | ||
body: str = "", | ||
assignees: List[str] = None, | ||
labels: List[str] = None, | ||
included_repos: List[str] = None, | ||
): | ||
"""Create an issue in repos of an org.""" | ||
repos = await org_repos_by_attr(org, "name", included_repos) | ||
coros = [ | ||
repo_issue_create(org, repo, title, body, assignees, labels) for repo in repos | ||
] | ||
results = await asyncio.gather(*coros) | ||
return {repo: result for repo, result in zip(repos, results)} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
import respx | ||
from httpx import Response | ||
|
||
from ghs.base import base_url | ||
from ghs.issue_client import repo_issue_create | ||
|
||
|
||
async def test_repo_issue_create(respx_mock, repo_issue_data) -> None: | ||
with respx.mock(base_url=base_url()) as respx_mock: | ||
owner = "kytos-ng" | ||
repo = "kytos" | ||
respx_mock.post(f"/repos/{owner}/{repo}/issues").mock( | ||
return_value=Response(200, json=repo_issue_data) | ||
) | ||
response = await repo_issue_create(owner, repo, "some title") | ||
assert response["number"] == repo_issue_data["number"] | ||
assert response["title"] == repo_issue_data["title"] | ||
assert response["html_url"] == repo_issue_data["html_url"] |