Skip to content

Commit

Permalink
Create Product & BugSystem when installation_repositores change
Browse files Browse the repository at this point in the history
Fixes #21.

WARNING: ATM not handling repositories_removed. Although there will
be no integration for them anymore they could be linked to various
other data in Kiwi TCMS and we may still want to use these existing
products just without any GH integration.
  • Loading branch information
atodorov committed Jul 21, 2020
1 parent 413587c commit dc16887
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tcms_github_app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tcms_github_app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down

0 comments on commit dc16887

Please sign in to comment.