I can help you convert the suggested Pipedream component code into Python. However, please note that Pipedream primarily uses Node.js for its components. If you still want to proceed with Python, here’s the equivalent Python code for the provided Pipedream component: import requests def update_labels(token, pull_request, repo, issue_number, title): authorization = f"Bearer {token}" headers = { "Authorization": authorization, "X-GitHub-Api-Version": "2022-11-28", } url = f"https://api.github.com/repos/{repo['owner']['login']}/{repo['name']}/issues/{issue_number}/labels" # Fetch existing labels get_labels_response = requests.get(url, headers=headers) existing_labels = get_labels_response.json() # Remove the old label if it exists labels = [label for label in existing_labels if not label['name'].startswith("CR:")] label_name = get_label_name(pull_request) labels.append(label_name) data = {"labels": labels} # Update the labels using a PUT request response = requests.put(url, headers=headers, json=data) return response.json() def get_label_name(pull_request): review = pull_request['state'] condition_met = review['state'] == "changes_requested" if pull_request['draft']: label_name = "CR: [Creator] draft" elif condition_met: label_name = "CR: [Creator] need_to_address_comments" elif False: # Replace with the missing condition label_name = "CR: [Oncall] ready_to_be_merged" else: label_name = "CR: [Reviewer] review_needed" return label_name Please note that there’s a missing condition in the get_label_name function. You should replace False with the appropriate condition to determine when the label should be “CR: [Oncall] ready_to_be_merged”.
I understand that you want to set the label “CR: [Oncall] ready_to_be_merged” when someone submits a review with changes for the Pull Request. You can update the missing condition in the get_label_name function like this: ```
def get_label_name(pull_request): review = pull_request[‘state’] condition_met = review[‘state’] == “changes_requested” if pull_request[‘draft’]: label_name = “CR: [Creator] draft” elif condition_met: label_name = “CR: [Creator] need_to_address_comments” elif review[‘state’] == “approved”: # This is the missing condition label_name = “CR: [Oncall] ready_to_be_merged” else: label_name = “CR: [Reviewer] review_needed” return label_name