Skip to content

Commit 74c21cc

Browse files
Fix installation id
Signed-off-by: Lukasz Gryglicki <[email protected]> Assisted by [OpenAI](https://platform.openai.com/) Assisted by [GitHub Copilot](https://github.com/features/copilot)
1 parent 1d80a76 commit 74c21cc

File tree

3 files changed

+21
-56
lines changed

3 files changed

+21
-56
lines changed

cla-backend/cla/controllers/github.py

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import json
99
import os
1010
import uuid
11-
import traceback
1211
from datetime import datetime
1312
from pprint import pprint
1413
from typing import Optional, List
@@ -320,34 +319,23 @@ def handle_installation_event(action: str, body: dict):
320319
return {'status': f'GitHub installation {action} event malformed.'}
321320

322321
cla.log.debug(f'Locating organization using name: {org_name}')
323-
try:
324-
existing = get_organization(org_name)
325-
cla.log.debug(
326-
f"{func_name} - post-get_organization type={type(existing)} "
327-
f"keys={list(existing.keys()) if isinstance(existing, dict) else '(n/a)'} "
328-
f"values={list(existing.values()) if isinstance(existing, dict) else '(n/a)'}"
329-
)
330-
if 'errors' in existing:
331-
cla.log.warning(f'{func_name} - Received github installation created event for organization: {org_name}, '
332-
'but the organization is not configured in EasyCLA')
333-
# TODO: Need a way of keeping track of new organizations that don't have projects yet.
334-
return {'status': 'Github Organization must be created through the Project Management Console.'}
335-
elif not existing.get('organization_installation_id'):
336-
cla.log.info(f'{func_name} - Setting installation ID for github organization: {existing.get("organization_name")} to {installation_id}')
337-
update_organization(existing.get('organization_name'), existing.get('organization_sfid'), installation_id)
338-
cla.log.info(f'{func_name} - Organization enrollment completed: {existing.get("organization_name")}')
339-
return {'status': 'Organization Enrollment Completed. CLA System is operational'}
340-
else:
341-
cla.log.info(f'{func_name} - Organization already enrolled: {existing.get("organization_name")}')
342-
cla.log.info(f'{func_name} - installation ID: {existing.get("organization_installation_id")}')
343-
cla.log.info(f'{func_name} - Updating installation ID for github organization: {existing.get("organization_name")} to {installation_id}')
344-
update_organization(existing.get('organization_name'), existing.get('organization_sfid'), installation_id)
345-
return {'status': 'Already Enrolled Organization Updated. CLA System is operational'}
346-
except Exception as e:
347-
cla.log.error(f"{func_name} - exception entering/enforcing enrollment branches: {type(e).__name__}: {e}\n"
348-
f"{traceback.format_exc()}"
349-
)
350-
raise
322+
existing = get_organization(org_name)
323+
if 'errors' in existing:
324+
cla.log.warning(f'{func_name} - Received github installation created event for organization: {org_name}, '
325+
'but the organization is not configured in EasyCLA')
326+
# TODO: Need a way of keeping track of new organizations that don't have projects yet.
327+
return {'status': 'Github Organization must be created through the Project Management Console.'}
328+
elif not existing.get('organization_installation_id'):
329+
cla.log.info(f'{func_name} - Setting installation ID for github organization: {existing.get("organization_name")} to {installation_id}')
330+
update_organization(existing.get('organization_name'), existing.get('organization_sfid'), installation_id)
331+
cla.log.info(f'{func_name} - Organization enrollment completed: {existing.get("organization_name")}')
332+
return {'status': 'Organization Enrollment Completed. CLA System is operational'}
333+
else:
334+
cla.log.info(f'{func_name} - Organization already enrolled: {existing.get("organization_name")}')
335+
cla.log.info(f'{func_name} - installation ID: {existing.get("organization_installation_id")}')
336+
cla.log.info(f'{func_name} - Updating installation ID for github organization: {existing.get("organization_name")} to {installation_id}')
337+
update_organization(existing.get('organization_name'), existing.get('organization_sfid'), installation_id)
338+
return {'status': 'Already Enrolled Organization Updated. CLA System is operational'}
351339

352340
elif action == 'deleted':
353341
cla.log.debug(f'{func_name} - processing github installation activity for action: {action}')

cla-backend/cla/models/dynamo_models.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4000,6 +4000,10 @@ def __str__(self):
40004000
)
40014001

40024002
def to_dict(self):
4003+
if getattr(self.model, 'skip_cla', None) is None:
4004+
self.model.skip_cla = {}
4005+
if getattr(self.model, 'enable_co_authors', None) is None:
4006+
self.model.enable_co_authors = {}
40034007
ret = dict(self.model)
40044008

40054009
if "organization_installation_id" not in ret:

cla-backend/cla/models/github_models.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,6 @@ def received_activity(self, data):
139139
elif data["action"] == "checks_requested":
140140
cla.log.debug("github_models.received_activity - Handling checks requested pull request")
141141
return self.process_checks_requested_merge_group(data)
142-
elif data["action"] == "enqueued":
143-
cla.log.debug("github_models.received_activity - Handling enqueued pull request")
144-
return self.process_enqueued_pull_request(data)
145142
else:
146143
cla.log.debug("github_models.received_activity - Ignoring unsupported action: {}".format(data["action"]))
147144

@@ -459,30 +456,6 @@ def process_opened_pull_request(self, data):
459456
installation_id = data["installation"]["id"]
460457
self.update_change_request(installation_id, github_repository_id, pull_request_id)
461458

462-
def process_enqueued_pull_request(self, data):
463-
"""
464-
Helper method to handle a webhook fired from GitHub for an enqueued PR.
465-
466-
:param data: The data returned from GitHub on this webhook.
467-
:type data: dict
468-
"""
469-
merge_group_sha = data.get("pull_request", {}).get("merge_commit_sha")
470-
github_repository_id = data.get("repository", {}).get("id")
471-
installation_id = data.get("installation", {}).get("id")
472-
pull_request_id = data.get("pull_request", {}).get("number")
473-
if None in (installation_id, github_repository_id, merge_group_sha, pull_request_id):
474-
cla.log.warning(
475-
"process_enqueued_pull_request: Missing required field(s): "
476-
f"installation_id={installation_id}, "
477-
f"github_repository_id={github_repository_id}, "
478-
f"merge_group_sha={merge_group_sha}, "
479-
f"pull_request_id={pull_request_id}. "
480-
"Aborting update_merge_group."
481-
)
482-
return
483-
484-
self.update_merge_group(installation_id, github_repository_id, merge_group_sha, pull_request_id)
485-
486459
def process_checks_requested_merge_group(self, data):
487460
"""
488461
Helper method to handle a webhook fired from GitHub for a merge group event.

0 commit comments

Comments
 (0)