/ docs-website / versioned_docs / version-2.19 / pipeline-components / connectors / githubissuecommenter.mdx
githubissuecommenter.mdx
1 --- 2 title: "GitHubIssueCommenter" 3 id: githubissuecommenter 4 slug: "/githubissuecommenter" 5 description: "This component posts comments to GitHub issues using the GitHub API." 6 --- 7 8 # GitHubIssueCommenter 9 10 This component posts comments to GitHub issues using the GitHub API. 11 12 <div className="key-value-table"> 13 14 | | | 15 | --- | --- | 16 | **Most common position in a pipeline** | After a Chat Generator that provides the comment text to post or right at the beginning of a pipeline | 17 | **Mandatory init variables** | `github_token`: GitHub personal access token. Can be set with `GITHUB_TOKEN` env var. | 18 | **Mandatory run variables** | `url`: A GitHub issue URL <br /> <br />`comment`: Comment text to post | 19 | **Output variables** | `success`: Boolean indicating whether the comment was posted successfully | 20 | **API reference** | [GitHub](/reference/integrations-github) | 21 | **GitHub link** | https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/github | 22 23 </div> 24 25 ## Overview 26 27 `GitHubIssueCommenter` takes a GitHub issue URL and comment text, then posts the comment to the specified issue. 28 29 The component requires authentication with a GitHub personal access token since posting comments is an authenticated operation. 30 31 ### Authorization 32 33 This component requires GitHub authentication with a personal access token. You can set the token using the `GITHUB_TOKEN` environment variable, or pass it directly during initialization via the `github_token` parameter. 34 35 To create a personal access token, visit [GitHub's token settings page](https://github.com/settings/tokens). Make sure to grant the appropriate permissions for repository access and issue management. 36 37 ### Installation 38 39 Install the GitHub integration with pip: 40 41 ```shell 42 pip install github-haystack 43 ``` 44 45 ## Usage 46 47 :::note[Repository Placeholder] 48 49 To run the following code snippets, you need to replace the `owner/repo` with your own GitHub repository name. 50 ::: 51 52 ### On its own 53 54 Basic usage with environment variable authentication: 55 56 ```python 57 from haystack_integrations.components.connectors.github import GitHubIssueCommenter 58 59 commenter = GitHubIssueCommenter() 60 result = commenter.run( 61 url="https://github.com/owner/repo/issues/123", 62 comment="Thanks for reporting this issue! We'll look into it.", 63 ) 64 65 print(result) 66 ``` 67 68 ```bash 69 {'success': True} 70 ``` 71 72 ### In a pipeline 73 74 The following pipeline analyzes a GitHub issue and automatically posts a response: 75 76 ```python 77 from haystack import Pipeline 78 from haystack.components.builders.chat_prompt_builder import ChatPromptBuilder 79 from haystack.components.converters import OutputAdapter 80 from haystack.components.generators.chat import OpenAIChatGenerator 81 from haystack.dataclasses import ChatMessage 82 from haystack_integrations.components.connectors.github import ( 83 GitHubIssueViewer, 84 GitHubIssueCommenter, 85 ) 86 87 issue_viewer = GitHubIssueViewer() 88 issue_commenter = GitHubIssueCommenter() 89 90 prompt_template = [ 91 ChatMessage.from_system( 92 "You are a helpful assistant that analyzes GitHub issues and creates appropriate responses.", 93 ), 94 ChatMessage.from_user( 95 "Based on the following GitHub issue:\n" 96 "{% for document in documents %}" 97 "{% if document.meta.type == 'issue' %}" 98 "**Issue Title:** {{ document.meta.title }}\n" 99 "**Issue Description:** {{ document.content }}\n" 100 "{% endif %}" 101 "{% endfor %}\n" 102 "Generate a helpful response comment for this issue. Keep it professional and concise.", 103 ), 104 ] 105 106 prompt_builder = ChatPromptBuilder(template=prompt_template, required_variables="*") 107 llm = OpenAIChatGenerator(model="gpt-4o-mini") 108 adapter = OutputAdapter(template="{{ replies[-1].text }}", output_type=str) 109 110 pipeline = Pipeline() 111 pipeline.add_component("issue_viewer", issue_viewer) 112 pipeline.add_component("prompt_builder", prompt_builder) 113 pipeline.add_component("llm", llm) 114 pipeline.add_component("adapter", adapter) 115 pipeline.add_component("issue_commenter", issue_commenter) 116 117 pipeline.connect("issue_viewer.documents", "prompt_builder.documents") 118 pipeline.connect("prompt_builder.prompt", "llm.messages") 119 pipeline.connect("llm.replies", "adapter.replies") 120 pipeline.connect("adapter", "issue_commenter.comment") 121 122 issue_url = "https://github.com/owner/repo/issues/123" 123 result = pipeline.run( 124 data={"issue_viewer": {"url": issue_url}, "issue_commenter": {"url": issue_url}}, 125 ) 126 127 print(f"Comment posted successfully: {result['issue_commenter']['success']}") 128 ``` 129 130 ``` 131 Comment posted successfully: True 132 ```