diff --git a/tcms_github_app/utils.py b/tcms_github_app/utils.py index 9c06d76..55fa9b8 100644 --- a/tcms_github_app/utils.py +++ b/tcms_github_app/utils.py @@ -142,6 +142,25 @@ def create_product_from_repository(data): _bugtracker_from_repo(repo_object) +def create_product_from_installation_repositories(data): + """ + Warning: not handling `repositories_removed` for now b/c + there could be linked data which we don't want to destroy! + """ + tenant, installation = find_tenant(data) + + # can't handle requests from unconfigured installation + if not tenant: + return + + with tenant_context(tenant): + rpc = github_rpc_from_inst(installation) + for repo in data.payload['repositories_added']: + repo_object = rpc.get_repo(repo['full_name']) + _product_from_repo(repo_object) + _bugtracker_from_repo(repo_object) + + def create_installation(data): """ Records an AppInstallation object which will be used to diff --git a/tcms_github_app/views.py b/tcms_github_app/views.py index 1d6c144..7e5352c 100644 --- a/tcms_github_app/views.py +++ b/tcms_github_app/views.py @@ -95,6 +95,8 @@ class WebHook(View): # pylint: disable=missing-permission-required def handle_payload(payload): if payload.event == "repository" and payload.action == "created": utils.create_product_from_repository(payload) + elif payload.event == "installation_repositories": + utils.create_product_from_installation_repositories(payload) elif payload.event == "installation" and payload.action == "created": utils.create_installation(payload) elif payload.event == "create" and payload.payload.get('ref_type') == "tag":