MCPcopy Create free account
hub / github.com/ceph/ceph / post_github_comment

Function post_github_comment

src/script/redmine-upkeep.py:126–149  ·  view source on GitHub ↗

Helper to post a comment to a GitHub PR.

(session, pr_id, body)

Source from the content-addressed store, hash-verified

124}
125
126def 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
152class UpkeepException(Exception):

Callers 2

_execute_pull_requestMethod · 0.85

Calls 4

warningMethod · 0.45
infoMethod · 0.45
postMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected