GitHubIssueCommenter
GitHubIssueCommenter
GitHub API를 사용해 GitHub 이슈에 댓글을 게시하는 구성 요소예요.
출처: 문서
본문
GitHubIssueCommenter는 GitHub 이슈 URL과 댓글 텍스트를 받아 해당 이슈에 댓글을 게시해요. 댓글 게시는 인증이 필요한 작업이므로 개인 액세스 토큰을 사용한 GitHub 인증이 필요해요.
Authorization
이 컴포넌트는 개인 액세스 토큰을 사용한 GitHub 인증이 필요해요. GITHUB_TOKEN 환경 변수로 토큰을 설정하거나, 초기화 시점에 github_token 파라미터로 직접 전달할 수 있어요. 개인 액세스 토큰을 만들려면 GitHub의 토큰 설정 페이지를 방문하고, 저장소 접근과 이슈 관리를 위한 적절한 권한을 부여하세요.
Installation
pip install github-haystack
- 대표적인 파이프라인 위치: 게시할 댓글 텍스트를 제공하는 Chat Generator 뒤, 또는 파이프라인의 맨 시작
- 필수 init 변수:
github_token— GitHub 개인 액세스 토큰.GITHUB_TOKENenv var로 설정 가능. - 필수 run 변수:
url— GitHub 이슈 URL /comment— 게시할 댓글 텍스트 - 출력 변수:
success— 댓글 게시 성공 여부를 나타내는 Boolean - API reference: GitHub
- 패키지명:
github-haystack
Usage
저장소 플레이스홀더: 아래 코드 스니펫을 실행하려면 owner/repo를 자신의 GitHub 저장소 이름으로 바꿔야 해요.
On its own
환경 변수 인증을 사용한 기본 사용법:
from haystack_integrations.components.connectors.github import GitHubIssueCommenter
commenter = GitHubIssueCommenter()
result = commenter.run(
url="https://github.com/owner/repo/issues/123",
comment="Thanks for reporting this issue! We'll look into it.",
)
print(result)
{'success': True}
In a pipeline
다음 파이프라인은 GitHub 이슈를 분석하고 자동으로 응답을 게시해요:
from haystack import Pipeline
from haystack.components.builders.chat_prompt_builder import ChatPromptBuilder
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage
from haystack_integrations.components.connectors.github import (
GitHubIssueViewer,
GitHubIssueCommenter,
)
issue_viewer = GitHubIssueViewer()
issue_commenter = GitHubIssueCommenter()
prompt_template = [
ChatMessage.from_system(
"You are a helpful assistant that analyzes GitHub issues and creates appropriate responses.",
),
ChatMessage.from_user(
"Based on the following GitHub issue:\n"
"{% for document in documents %}"
"{% if document.meta.type == 'issue' %}"
"**Issue Title:** {{ document.meta.title }}\n"
"**Issue Description:** {{ document.content }}\n"
"{% endif %}"
"{% endfor %}\n"
"Generate a helpful response comment for this issue. Keep it professional and concise."
),
]
prompt_builder = ChatPromptBuilder(template=prompt_template, required_variables="*")
llm = OpenAIChatGenerator(model="gpt-4o-mini")
pipeline = Pipeline()
pipeline.add_component("issue_viewer", issue_viewer)
pipeline.add_component("prompt_builder", prompt_builder)
pipeline.add_component("llm", llm)
pipeline.add_component("issue_commenter", issue_commenter)
pipeline.connect("issue_viewer.documents", "prompt_builder.documents")
pipeline.connect("prompt_builder.prompt", "llm.messages")
pipeline.connect("llm.replies", "issue_commenter.comment")
issue_url = "https://github.com/owner/repo/issues/123"
result = pipeline.run(
data={"issue_viewer": {"url": issue_url}, "issue_commenter": {"url": issue_url}},
)
print(f"Comment posted successfully: {result['issue_commenter']['success']}")
Comment posted successfully: True