Helper to post a comment to a GitHub PR.
(session, pr_id, body)
| 124 | } |
| 125 | |
| 126 | def post_github_comment(session, pr_id, body): |
| 127 | """Helper to post a comment to a GitHub PR.""" |
| 128 | if RedmineUpkeep.GITHUB_RATE_LIMITED: |
| 129 | log.warning("GitHub API rate limit hit previously. Skipping posting comment.") |
| 130 | return False |
| 131 | |
| 132 | log.info(f"Posting a comment to GitHub PR #{pr_id}.") |
| 133 | endpoint = f"{GITHUB_API_ENDPOINT}/issues/{pr_id}/comments" |
| 134 | payload = {'body': body} |
| 135 | try: |
| 136 | response = session.post(endpoint, headers=GITHUB_HEADERS, json=payload) |
| 137 | response.raise_for_status() |
| 138 | log.info(f"Successfully posted comment to PR #{pr_id}.") |
| 139 | return True |
| 140 | except requests.exceptions.HTTPError as e: |
| 141 | if e.response.status_code == 403 and "rate limit exceeded" in e.response.text: |
| 142 | log.error(f"GitHub API rate limit exceeded when commenting on PR #{pr_id}.") |
| 143 | RedmineUpkeep.GITHUB_RATE_LIMITED = True |
| 144 | else: |
| 145 | log.error(f"GitHub API error posting comment to PR #{pr_id}: {e} - Response: {e.response.text}") |
| 146 | return False |
| 147 | except requests.exceptions.RequestException as e: |
| 148 | log.error(f"Network or request error posting comment to GitHub PR #{pr_id}: {e}") |
| 149 | return False |
| 150 | |
| 151 | |
| 152 | class UpkeepException(Exception): |
no test coverage detected