def _custom_fields_from_pull_request(pull_request: PullRequest) -> Dict: """ We currently expect the project to have two custom fields with its corresponding enum options: • PR Status: "Open", "Closed", "Merged" • Build: "Success", "Failure" """ repository_id = pull_request.repository_id() project_id = dynamodb_client.get_asana_id_from_github_node_id( repository_id) if project_id is None: logger.info( f"Task not found for pull request {pull_request.id()}. Running a full sync!" ) # TODO: Full sync return {} else: custom_field_settings = list( asana_client.get_project_custom_fields(project_id)) data = {} for custom_field_name, action in _custom_fields_to_extract_map.items(): enum_option_name = action(pull_request) if enum_option_name: custom_field_id = _get_custom_field_id(custom_field_name, custom_field_settings) enum_option_id = _get_custom_field_enum_option_id( custom_field_name, enum_option_name, custom_field_settings) if custom_field_id and enum_option_id: data[custom_field_id] = enum_option_id return data
def upsert_pull_request(pull_request: PullRequest): pull_request_id = pull_request.id() task_id = dynamodb_client.get_asana_id_from_github_node_id(pull_request_id) if task_id is None: task_id = asana_controller.create_task(pull_request.repository_id()) if task_id is None: # TODO: Handle this case return logger.info( f"Task created for pull request {pull_request_id}: {task_id}") dynamodb_client.insert_github_node_to_asana_id_mapping( pull_request_id, task_id) asana_helpers.create_attachments(pull_request.body(), task_id) _add_asana_task_to_pull_request(pull_request, task_id) else: logger.info( f"Task found for pull request {pull_request_id}, updating task {task_id}" ) asana_controller.update_task(pull_request, task_id)