diff --git a/app/example_data.py b/app/example_data.py new file mode 100644 index 0000000..9fe8271 --- /dev/null +++ b/app/example_data.py @@ -0,0 +1,335 @@ +new_commit = { + "ref": "refs/heads/bx-test", + "before": "7680dd143e0c4faa05c5dbea822b247226d27490", + "after": "209d4b058850f04ce1ce29ead1509a072078605f", + "compare_url": "https://git.svs-tech.pro/ksenia_mikhailova/test-webhook/compare/7680dd143e0c4faa05c5dbea822b247226d27490...209d4b058850f04ce1ce29ead1509a072078605f", + "commits": [ + { + "id": "209d4b058850f04ce1ce29ead1509a072078605f", + "message": "test\n", + "url": "https://git.svs-tech.pro/ksenia_mikhailova/test-webhook/commit/209d4b058850f04ce1ce29ead1509a072078605f", + "author": { + "name": "aarizona", + "email": "ar.ariz.arizona@gmail.com", + "username": "", + }, + "committer": { + "name": "aarizona", + "email": "ar.ariz.arizona@gmail.com", + "username": "", + }, + "verification": None, + "timestamp": "2024-05-02T11:56:57+03:00", + "added": [], + "removed": [], + "modified": ["app/main.py"], + } + ], + "total_commits": 1, + "head_commit": { + "id": "209d4b058850f04ce1ce29ead1509a072078605f", + "message": "test\n", + "url": "https://git.svs-tech.pro/ksenia_mikhailova/test-webhook/commit/209d4b058850f04ce1ce29ead1509a072078605f", + "author": { + "name": "aarizona", + "email": "ar.ariz.arizona@gmail.com", + "username": "", + }, + "committer": { + "name": "aarizona", + "email": "ar.ariz.arizona@gmail.com", + "username": "", + }, + "verification": None, + "timestamp": "2024-05-02T11:56:57+03:00", + "added": [], + "removed": [], + "modified": ["app/main.py"], + }, + "repository": { + "id": 16, + "owner": { + "id": 5, + "login": "ksenia_mikhailova", + "login_name": "", + "full_name": "", + "email": "k.mikhailova@svs-tech.pro", + "avatar_url": "https://git.svs-tech.pro/avatar/656964d6d4fe71056017525a6d035721", + "language": "", + "is_admin": False, + "last_login": "0001-01-01T00:00:00Z", + "created": "2024-03-26T09:48:12+03:00", + "restricted": False, + "active": False, + "prohibit_login": False, + "location": "", + "website": "", + "description": "", + "visibility": "public", + "followers_count": 0, + "following_count": 0, + "starred_repos_count": 0, + "username": "ksenia_mikhailova", + }, + "name": "test-webhook", + "full_name": "ksenia_mikhailova/test-webhook", + "description": "", + "empty": False, + "private": False, + "fork": False, + "template": False, + "parent": None, + "mirror": False, + "size": 23, + "language": "", + "languages_url": "https://git.svs-tech.pro/api/v1/repos/ksenia_mikhailova/test-webhook/languages", + "html_url": "https://git.svs-tech.pro/ksenia_mikhailova/test-webhook", + "url": "https://git.svs-tech.pro/api/v1/repos/ksenia_mikhailova/test-webhook", + "link": "", + "ssh_url": "git@git.svs-tech.pro:ksenia_mikhailova/test-webhook.git", + "clone_url": "https://git.svs-tech.pro/ksenia_mikhailova/test-webhook.git", + "original_url": "", + "website": "", + "stars_count": 0, + "forks_count": 0, + "watchers_count": 1, + "open_issues_count": 0, + "open_pr_counter": 0, + "release_counter": 0, + "default_branch": "main", + "archived": False, + "created_at": "2024-05-02T11:12:56+03:00", + "updated_at": "2024-05-02T11:54:13+03:00", + "archived_at": "1970-01-01T03:00:00+03:00", + "permissions": {"admin": True, "push": True, "pull": True}, + "has_issues": True, + "internal_tracker": { + "enable_time_tracker": True, + "allow_only_contributors_to_track_time": True, + "enable_issue_dependencies": True, + }, + "has_wiki": True, + "has_pull_requests": True, + "has_projects": True, + "has_releases": True, + "has_packages": True, + "has_actions": False, + "ignore_whitespace_conflicts": False, + "allow_merge_commits": True, + "allow_rebase": True, + "allow_rebase_explicit": True, + "allow_squash_merge": True, + "allow_rebase_update": True, + "default_delete_branch_after_merge": False, + "default_merge_style": "merge", + "default_allow_maintainer_edit": False, + "avatar_url": "", + "internal": False, + "mirror_interval": "", + "mirror_updated": "0001-01-01T00:00:00Z", + "repo_transfer": None, + }, + "pusher": { + "id": 5, + "login": "ksenia_mikhailova", + "login_name": "", + "full_name": "", + "email": "ksenia_mikhailova@noreply.localhost", + "avatar_url": "https://git.svs-tech.pro/avatar/656964d6d4fe71056017525a6d035721", + "language": "", + "is_admin": False, + "last_login": "0001-01-01T00:00:00Z", + "created": "2024-03-26T09:48:12+03:00", + "restricted": False, + "active": False, + "prohibit_login": False, + "location": "", + "website": "", + "description": "", + "visibility": "public", + "followers_count": 0, + "following_count": 0, + "starred_repos_count": 0, + "username": "ksenia_mikhailova", + }, + "sender": { + "id": 5, + "login": "ksenia_mikhailova", + "login_name": "", + "full_name": "", + "email": "ksenia_mikhailova@noreply.localhost", + "avatar_url": "https://git.svs-tech.pro/avatar/656964d6d4fe71056017525a6d035721", + "language": "", + "is_admin": False, + "last_login": "0001-01-01T00:00:00Z", + "created": "2024-03-26T09:48:12+03:00", + "restricted": False, + "active": False, + "prohibit_login": False, + "location": "", + "website": "", + "description": "", + "visibility": "public", + "followers_count": 0, + "following_count": 0, + "starred_repos_count": 0, + "username": "ksenia_mikhailova", + }, +} +create_branch = { + "ref": "refs/heads/bx-423-test", + "before": "0000000000000000000000000000000000000000", + "after": "e1e647f1b93bec40ba8fc26fe939b061eb31226c", + "compare_url": "https://git.svs-tech.pro/ksenia_mikhailova/test-webhook/compare/main...e1e647f1b93bec40ba8fc26fe939b061eb31226c", + "commits": [], + "total_commits": 0, + "head_commit": { + "id": "e1e647f1b93bec40ba8fc26fe939b061eb31226c", + "message": "remove test\n", + "url": "https://git.svs-tech.pro/ksenia_mikhailova/test-webhook/commit/e1e647f1b93bec40ba8fc26fe939b061eb31226c", + "author": { + "name": "aarizona", + "email": "ar.ariz.arizona@gmail.com", + "username": "", + }, + "committer": { + "name": "aarizona", + "email": "ar.ariz.arizona@gmail.com", + "username": "", + }, + "verification": None, + "timestamp": "2024-05-02T13:01:15+03:00", + "added": [".env"], + "removed": [], + "modified": ["app/constants.py", "app/main.py"], + }, + "repository": { + "id": 16, + "owner": { + "id": 5, + "login": "ksenia_mikhailova", + "login_name": "", + "full_name": "", + "email": "k.mikhailova@svs-tech.pro", + "avatar_url": "https://git.svs-tech.pro/avatar/656964d6d4fe71056017525a6d035721", + "language": "", + "is_admin": False, + "last_login": "0001-01-01T00:00:00Z", + "created": "2024-03-26T09:48:12+03:00", + "restricted": False, + "active": False, + "prohibit_login": False, + "location": "", + "website": "", + "description": "", + "visibility": "public", + "followers_count": 0, + "following_count": 0, + "starred_repos_count": 0, + "username": "ksenia_mikhailova", + }, + "name": "test-webhook", + "full_name": "ksenia_mikhailova/test-webhook", + "description": "", + "empty": False, + "private": False, + "fork": False, + "template": False, + "parent": None, + "mirror": False, + "size": 38, + "language": "", + "languages_url": "https://git.svs-tech.pro/api/v1/repos/ksenia_mikhailova/test-webhook/languages", + "html_url": "https://git.svs-tech.pro/ksenia_mikhailova/test-webhook", + "url": "https://git.svs-tech.pro/api/v1/repos/ksenia_mikhailova/test-webhook", + "link": "", + "ssh_url": "git@git.svs-tech.pro:ksenia_mikhailova/test-webhook.git", + "clone_url": "https://git.svs-tech.pro/ksenia_mikhailova/test-webhook.git", + "original_url": "", + "website": "", + "stars_count": 0, + "forks_count": 0, + "watchers_count": 1, + "open_issues_count": 0, + "open_pr_counter": 0, + "release_counter": 0, + "default_branch": "main", + "archived": False, + "created_at": "2024-05-02T11:12:56+03:00", + "updated_at": "2024-05-02T13:01:19+03:00", + "archived_at": "1970-01-01T03:00:00+03:00", + "permissions": {"admin": True, "push": True, "pull": True}, + "has_issues": True, + "internal_tracker": { + "enable_time_tracker": True, + "allow_only_contributors_to_track_time": True, + "enable_issue_dependencies": True, + }, + "has_wiki": True, + "has_pull_requests": True, + "has_projects": True, + "has_releases": True, + "has_packages": True, + "has_actions": False, + "ignore_whitespace_conflicts": False, + "allow_merge_commits": True, + "allow_rebase": True, + "allow_rebase_explicit": True, + "allow_squash_merge": True, + "allow_rebase_update": True, + "default_delete_branch_after_merge": False, + "default_merge_style": "merge", + "default_allow_maintainer_edit": False, + "avatar_url": "", + "internal": False, + "mirror_interval": "", + "mirror_updated": "0001-01-01T00:00:00Z", + "repo_transfer": None, + }, + "pusher": { + "id": 5, + "login": "ksenia_mikhailova", + "login_name": "", + "full_name": "", + "email": "ksenia_mikhailova@noreply.localhost", + "avatar_url": "https://git.svs-tech.pro/avatar/656964d6d4fe71056017525a6d035721", + "language": "", + "is_admin": False, + "last_login": "0001-01-01T00:00:00Z", + "created": "2024-03-26T09:48:12+03:00", + "restricted": False, + "active": False, + "prohibit_login": False, + "location": "", + "website": "", + "description": "", + "visibility": "public", + "followers_count": 0, + "following_count": 0, + "starred_repos_count": 0, + "username": "ksenia_mikhailova", + }, + "sender": { + "id": 5, + "login": "ksenia_mikhailova", + "login_name": "", + "full_name": "", + "email": "ksenia_mikhailova@noreply.localhost", + "avatar_url": "https://git.svs-tech.pro/avatar/656964d6d4fe71056017525a6d035721", + "language": "", + "is_admin": False, + "last_login": "0001-01-01T00:00:00Z", + "created": "2024-03-26T09:48:12+03:00", + "restricted": False, + "active": False, + "prohibit_login": False, + "location": "", + "website": "", + "description": "", + "visibility": "public", + "followers_count": 0, + "following_count": 0, + "starred_repos_count": 0, + "username": "ksenia_mikhailova", + }, +} diff --git a/app/main.py b/app/main.py index 72bec1c..b1db67a 100644 --- a/app/main.py +++ b/app/main.py @@ -12,6 +12,30 @@ def read_root(): @app.post("/integration") +<<<<<<< Updated upstream def intgr(body): logger.info(body) +======= +async def intgr(request: Request): + body = await request.json() + ref = body["ref"] + branch = ref.split("/")[-1] + + [tag, number, *args] = branch.split("-") + logger.info(f"input tag {tag} number {number} args {args}") + logger.info(body) + + bx_comment = ( + f"Сообщение от GITEA для задачи {number} (ветка {body['ref']} в репозитории {body['repository']['full_name']})" + "\n\n" + f"{body['head_commit']['message']}" + ) + + bx_res = requests.get( + f"{WEBHOOK}/task.commentitem.add.json?" + f"taskId={number}" + f"&fields[POST_MESSAGE]={bx_comment}" + ) + logger.info(f"result {json.loads(bx_res.text)}") +>>>>>>> Stashed changes return {"status": "success"}