-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcomment_on_issue.py
39 lines (32 loc) · 967 Bytes
/
comment_on_issue.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import logging
from github import Github, GithubException
from git_bob._ai_github_utilities.utilities import (
get_github_token,
get_repository_from_environment,
handle_github_exception,
)
def comment_on_issue(issue_number: int, comment_text: str) -> bool:
"""
Add a comment to a GitHub issue.
Parameters
----------
issue_number : int
The issue number to comment on
comment_text : str
The text of the comment to add
Returns
-------
bool
True if successful, False otherwise
"""
try:
token = get_github_token()
github = Github(token)
repo = get_repository_from_environment(github)
issue = repo.get_issue(number=issue_number)
issue.create_comment(comment_text)
logging.info(f"Successfully commented on issue #{issue_number}")
return True
except GithubException as e:
handle_github_exception(e)
return False