github.md
  1  ---
  2  title: "GitHub"
  3  id: integrations-github
  4  description: "GitHub integration for Haystack"
  5  slug: "/integrations-github"
  6  ---
  7  
  8  <a id="haystack_integrations.components.connectors.github.file_editor"></a>
  9  
 10  ## Module haystack\_integrations.components.connectors.github.file\_editor
 11  
 12  <a id="haystack_integrations.components.connectors.github.file_editor.Command"></a>
 13  
 14  ### Command
 15  
 16  Available commands for file operations in GitHub.
 17  
 18  **Attributes**:
 19  
 20  - `EDIT` - Edit an existing file by replacing content
 21  - `UNDO` - Revert the last commit if made by the same user
 22  - `CREATE` - Create a new file
 23  - `DELETE` - Delete an existing file
 24  
 25  <a id="haystack_integrations.components.connectors.github.file_editor.GitHubFileEditor"></a>
 26  
 27  ### GitHubFileEditor
 28  
 29  A Haystack component for editing files in GitHub repositories.
 30  
 31  Supports editing, undoing changes, deleting files, and creating new files
 32  through the GitHub API.
 33  
 34  ### Usage example
 35  ```python
 36  from haystack_integrations.components.connectors.github import Command, GitHubFileEditor
 37  from haystack.utils import Secret
 38  
 39  # Initialize with default repo and branch
 40  editor = GitHubFileEditor(
 41      github_token=Secret.from_env_var("GITHUB_TOKEN"),
 42      repo="owner/repo",
 43      branch="main"
 44  )
 45  
 46  # Edit a file using default repo and branch
 47  result = editor.run(
 48      command=Command.EDIT,
 49      payload={
 50          "path": "path/to/file.py",
 51          "original": "def old_function():",
 52          "replacement": "def new_function():",
 53          "message": "Renamed function for clarity"
 54      }
 55  )
 56  
 57  # Edit a file in a different repo/branch
 58  result = editor.run(
 59      command=Command.EDIT,
 60      repo="other-owner/other-repo",  # Override default repo
 61      branch="feature",  # Override default branch
 62      payload={
 63          "path": "path/to/file.py",
 64          "original": "def old_function():",
 65          "replacement": "def new_function():",
 66          "message": "Renamed function for clarity"
 67      }
 68  )
 69  ```
 70  
 71  <a id="haystack_integrations.components.connectors.github.file_editor.GitHubFileEditor.__init__"></a>
 72  
 73  #### GitHubFileEditor.\_\_init\_\_
 74  
 75  ```python
 76  def __init__(*,
 77               github_token: Secret = Secret.from_env_var("GITHUB_TOKEN"),
 78               repo: str | None = None,
 79               branch: str = "main",
 80               raise_on_failure: bool = True)
 81  ```
 82  
 83  Initialize the component.
 84  
 85  **Arguments**:
 86  
 87  - `github_token`: GitHub personal access token for API authentication
 88  - `repo`: Default repository in owner/repo format
 89  - `branch`: Default branch to work with
 90  - `raise_on_failure`: If True, raises exceptions on API errors
 91  
 92  **Raises**:
 93  
 94  - `TypeError`: If github_token is not a Secret
 95  
 96  <a id="haystack_integrations.components.connectors.github.file_editor.GitHubFileEditor.run"></a>
 97  
 98  #### GitHubFileEditor.run
 99  
100  ```python
101  @component.output_types(result=str)
102  def run(command: Command | str,
103          payload: dict[str, Any],
104          repo: str | None = None,
105          branch: str | None = None) -> dict[str, str]
106  ```
107  
108  Process GitHub file operations.
109  
110  **Arguments**:
111  
112  - `command`: Operation to perform ("edit", "undo", "create", "delete")
113  - `payload`: Dictionary containing command-specific parameters
114  - `repo`: Repository in owner/repo format (overrides default if provided)
115  - `branch`: Branch to perform operations on (overrides default if provided)
116  
117  **Raises**:
118  
119  - `ValueError`: If command is not a valid Command enum value
120  
121  **Returns**:
122  
123  Dictionary containing operation result
124  
125  <a id="haystack_integrations.components.connectors.github.file_editor.GitHubFileEditor.to_dict"></a>
126  
127  #### GitHubFileEditor.to\_dict
128  
129  ```python
130  def to_dict() -> dict[str, Any]
131  ```
132  
133  Serialize the component to a dictionary.
134  
135  <a id="haystack_integrations.components.connectors.github.file_editor.GitHubFileEditor.from_dict"></a>
136  
137  #### GitHubFileEditor.from\_dict
138  
139  ```python
140  @classmethod
141  def from_dict(cls, data: dict[str, Any]) -> "GitHubFileEditor"
142  ```
143  
144  Deserialize the component from a dictionary.
145  
146  <a id="haystack_integrations.components.connectors.github.issue_commenter"></a>
147  
148  ## Module haystack\_integrations.components.connectors.github.issue\_commenter
149  
150  <a id="haystack_integrations.components.connectors.github.issue_commenter.GitHubIssueCommenter"></a>
151  
152  ### GitHubIssueCommenter
153  
154  Posts comments to GitHub issues.
155  
156  The component takes a GitHub issue URL and comment text, then posts the comment
157  to the specified issue using the GitHub API.
158  
159  ### Usage example
160  ```python
161  from haystack_integrations.components.connectors.github import GitHubIssueCommenter
162  from haystack.utils import Secret
163  
164  commenter = GitHubIssueCommenter(github_token=Secret.from_env_var("GITHUB_TOKEN"))
165  result = commenter.run(
166      url="https://github.com/owner/repo/issues/123",
167      comment="Thanks for reporting this issue! We'll look into it."
168  )
169  
170  print(result["success"])
171  ```
172  
173  <a id="haystack_integrations.components.connectors.github.issue_commenter.GitHubIssueCommenter.__init__"></a>
174  
175  #### GitHubIssueCommenter.\_\_init\_\_
176  
177  ```python
178  def __init__(*,
179               github_token: Secret = Secret.from_env_var("GITHUB_TOKEN"),
180               raise_on_failure: bool = True,
181               retry_attempts: int = 2)
182  ```
183  
184  Initialize the component.
185  
186  **Arguments**:
187  
188  - `github_token`: GitHub personal access token for API authentication as a Secret
189  - `raise_on_failure`: If True, raises exceptions on API errors
190  - `retry_attempts`: Number of retry attempts for failed requests
191  
192  <a id="haystack_integrations.components.connectors.github.issue_commenter.GitHubIssueCommenter.to_dict"></a>
193  
194  #### GitHubIssueCommenter.to\_dict
195  
196  ```python
197  def to_dict() -> dict[str, Any]
198  ```
199  
200  Serialize the component to a dictionary.
201  
202  **Returns**:
203  
204  Dictionary with serialized data.
205  
206  <a id="haystack_integrations.components.connectors.github.issue_commenter.GitHubIssueCommenter.from_dict"></a>
207  
208  #### GitHubIssueCommenter.from\_dict
209  
210  ```python
211  @classmethod
212  def from_dict(cls, data: dict[str, Any]) -> "GitHubIssueCommenter"
213  ```
214  
215  Deserialize the component from a dictionary.
216  
217  **Arguments**:
218  
219  - `data`: Dictionary to deserialize from.
220  
221  **Returns**:
222  
223  Deserialized component.
224  
225  <a id="haystack_integrations.components.connectors.github.issue_commenter.GitHubIssueCommenter.run"></a>
226  
227  #### GitHubIssueCommenter.run
228  
229  ```python
230  @component.output_types(success=bool)
231  def run(url: str, comment: str) -> dict
232  ```
233  
234  Post a comment to a GitHub issue.
235  
236  **Arguments**:
237  
238  - `url`: GitHub issue URL
239  - `comment`: Comment text to post
240  
241  **Returns**:
242  
243  Dictionary containing success status
244  
245  <a id="haystack_integrations.components.connectors.github.issue_viewer"></a>
246  
247  ## Module haystack\_integrations.components.connectors.github.issue\_viewer
248  
249  <a id="haystack_integrations.components.connectors.github.issue_viewer.GitHubIssueViewer"></a>
250  
251  ### GitHubIssueViewer
252  
253  Fetches and parses GitHub issues into Haystack documents.
254  
255  The component takes a GitHub issue URL and returns a list of documents where:
256  - First document contains the main issue content
257  - Subsequent documents contain the issue comments
258  
259  ### Usage example
260  ```python
261  from haystack_integrations.components.connectors.github import GitHubIssueViewer
262  
263  viewer = GitHubIssueViewer()
264  docs = viewer.run(
265      url="https://github.com/owner/repo/issues/123"
266  )["documents"]
267  
268  print(docs)
269  ```
270  
271  <a id="haystack_integrations.components.connectors.github.issue_viewer.GitHubIssueViewer.__init__"></a>
272  
273  #### GitHubIssueViewer.\_\_init\_\_
274  
275  ```python
276  def __init__(*,
277               github_token: Secret | None = None,
278               raise_on_failure: bool = True,
279               retry_attempts: int = 2)
280  ```
281  
282  Initialize the component.
283  
284  **Arguments**:
285  
286  - `github_token`: GitHub personal access token for API authentication as a Secret
287  - `raise_on_failure`: If True, raises exceptions on API errors
288  - `retry_attempts`: Number of retry attempts for failed requests
289  
290  <a id="haystack_integrations.components.connectors.github.issue_viewer.GitHubIssueViewer.to_dict"></a>
291  
292  #### GitHubIssueViewer.to\_dict
293  
294  ```python
295  def to_dict() -> dict[str, Any]
296  ```
297  
298  Serialize the component to a dictionary.
299  
300  **Returns**:
301  
302  Dictionary with serialized data.
303  
304  <a id="haystack_integrations.components.connectors.github.issue_viewer.GitHubIssueViewer.from_dict"></a>
305  
306  #### GitHubIssueViewer.from\_dict
307  
308  ```python
309  @classmethod
310  def from_dict(cls, data: dict[str, Any]) -> "GitHubIssueViewer"
311  ```
312  
313  Deserialize the component from a dictionary.
314  
315  **Arguments**:
316  
317  - `data`: Dictionary to deserialize from.
318  
319  **Returns**:
320  
321  Deserialized component.
322  
323  <a id="haystack_integrations.components.connectors.github.issue_viewer.GitHubIssueViewer.run"></a>
324  
325  #### GitHubIssueViewer.run
326  
327  ```python
328  @component.output_types(documents=list[Document])
329  def run(url: str) -> dict
330  ```
331  
332  Process a GitHub issue URL and return documents.
333  
334  **Arguments**:
335  
336  - `url`: GitHub issue URL
337  
338  **Returns**:
339  
340  Dictionary containing list of documents
341  
342  <a id="haystack_integrations.components.connectors.github.pr_creator"></a>
343  
344  ## Module haystack\_integrations.components.connectors.github.pr\_creator
345  
346  <a id="haystack_integrations.components.connectors.github.pr_creator.GitHubPRCreator"></a>
347  
348  ### GitHubPRCreator
349  
350  A Haystack component for creating pull requests from a fork back to the original repository.
351  
352  Uses the authenticated user's fork to create the PR and links it to an existing issue.
353  
354  ### Usage example
355  ```python
356  from haystack_integrations.components.connectors.github import GitHubPRCreator
357  from haystack.utils import Secret
358  
359  pr_creator = GitHubPRCreator(
360      github_token=Secret.from_env_var("GITHUB_TOKEN")  # Token from the fork owner
361  )
362  
363  # Create a PR from your fork
364  result = pr_creator.run(
365      issue_url="https://github.com/owner/repo/issues/123",
366      title="Fix issue `123`",
367      body="This PR addresses issue `123`",
368      branch="feature-branch",     # The branch in your fork with the changes
369      base="main"                  # The branch in the original repo to merge into
370  )
371  ```
372  
373  <a id="haystack_integrations.components.connectors.github.pr_creator.GitHubPRCreator.__init__"></a>
374  
375  #### GitHubPRCreator.\_\_init\_\_
376  
377  ```python
378  def __init__(*,
379               github_token: Secret = Secret.from_env_var("GITHUB_TOKEN"),
380               raise_on_failure: bool = True)
381  ```
382  
383  Initialize the component.
384  
385  **Arguments**:
386  
387  - `github_token`: GitHub personal access token for authentication (from the fork owner)
388  - `raise_on_failure`: If True, raises exceptions on API errors
389  
390  <a id="haystack_integrations.components.connectors.github.pr_creator.GitHubPRCreator.run"></a>
391  
392  #### GitHubPRCreator.run
393  
394  ```python
395  @component.output_types(result=str)
396  def run(issue_url: str,
397          title: str,
398          branch: str,
399          base: str,
400          body: str = "",
401          draft: bool = False) -> dict[str, str]
402  ```
403  
404  Create a new pull request from your fork to the original repository, linked to the specified issue.
405  
406  **Arguments**:
407  
408  - `issue_url`: URL of the GitHub issue to link the PR to
409  - `title`: Title of the pull request
410  - `branch`: Name of the branch in your fork where changes are implemented
411  - `base`: Name of the branch in the original repo you want to merge into
412  - `body`: Additional content for the pull request description
413  - `draft`: Whether to create a draft pull request
414  
415  **Returns**:
416  
417  Dictionary containing operation result
418  
419  <a id="haystack_integrations.components.connectors.github.pr_creator.GitHubPRCreator.to_dict"></a>
420  
421  #### GitHubPRCreator.to\_dict
422  
423  ```python
424  def to_dict() -> dict[str, Any]
425  ```
426  
427  Serialize the component to a dictionary.
428  
429  <a id="haystack_integrations.components.connectors.github.pr_creator.GitHubPRCreator.from_dict"></a>
430  
431  #### GitHubPRCreator.from\_dict
432  
433  ```python
434  @classmethod
435  def from_dict(cls, data: dict[str, Any]) -> "GitHubPRCreator"
436  ```
437  
438  Deserialize the component from a dictionary.
439  
440  <a id="haystack_integrations.components.connectors.github.repo_forker"></a>
441  
442  ## Module haystack\_integrations.components.connectors.github.repo\_forker
443  
444  <a id="haystack_integrations.components.connectors.github.repo_forker.GitHubRepoForker"></a>
445  
446  ### GitHubRepoForker
447  
448  Forks a GitHub repository from an issue URL.
449  
450  The component takes a GitHub issue URL, extracts the repository information,
451  creates or syncs a fork of that repository, and optionally creates an issue-specific branch.
452  
453  ### Usage example
454  ```python
455  from haystack_integrations.components.connectors.github import GitHubRepoForker
456  from haystack.utils import Secret
457  
458  # Using direct token with auto-sync and branch creation
459  forker = GitHubRepoForker(
460      github_token=Secret.from_env_var("GITHUB_TOKEN"),
461      auto_sync=True,
462      create_branch=True
463  )
464  
465  result = forker.run(url="https://github.com/owner/repo/issues/123")
466  print(result)
467  # Will create or sync fork and create branch "fix-123"
468  ```
469  
470  <a id="haystack_integrations.components.connectors.github.repo_forker.GitHubRepoForker.__init__"></a>
471  
472  #### GitHubRepoForker.\_\_init\_\_
473  
474  ```python
475  def __init__(*,
476               github_token: Secret = Secret.from_env_var("GITHUB_TOKEN"),
477               raise_on_failure: bool = True,
478               wait_for_completion: bool = False,
479               max_wait_seconds: int = 300,
480               poll_interval: int = 2,
481               auto_sync: bool = True,
482               create_branch: bool = True)
483  ```
484  
485  Initialize the component.
486  
487  **Arguments**:
488  
489  - `github_token`: GitHub personal access token for API authentication
490  - `raise_on_failure`: If True, raises exceptions on API errors
491  - `wait_for_completion`: If True, waits until fork is fully created
492  - `max_wait_seconds`: Maximum time to wait for fork completion in seconds
493  - `poll_interval`: Time between status checks in seconds
494  - `auto_sync`: If True, syncs fork with original repository if it already exists
495  - `create_branch`: If True, creates a fix branch based on the issue number
496  
497  <a id="haystack_integrations.components.connectors.github.repo_forker.GitHubRepoForker.to_dict"></a>
498  
499  #### GitHubRepoForker.to\_dict
500  
501  ```python
502  def to_dict() -> dict[str, Any]
503  ```
504  
505  Serialize the component to a dictionary.
506  
507  **Returns**:
508  
509  Dictionary with serialized data.
510  
511  <a id="haystack_integrations.components.connectors.github.repo_forker.GitHubRepoForker.from_dict"></a>
512  
513  #### GitHubRepoForker.from\_dict
514  
515  ```python
516  @classmethod
517  def from_dict(cls, data: dict[str, Any]) -> "GitHubRepoForker"
518  ```
519  
520  Deserialize the component from a dictionary.
521  
522  **Arguments**:
523  
524  - `data`: Dictionary to deserialize from.
525  
526  **Returns**:
527  
528  Deserialized component.
529  
530  <a id="haystack_integrations.components.connectors.github.repo_forker.GitHubRepoForker.run"></a>
531  
532  #### GitHubRepoForker.run
533  
534  ```python
535  @component.output_types(repo=str, issue_branch=str)
536  def run(url: str) -> dict
537  ```
538  
539  Process a GitHub issue URL and create or sync a fork of the repository.
540  
541  **Arguments**:
542  
543  - `url`: GitHub issue URL
544  
545  **Returns**:
546  
547  Dictionary containing repository path in owner/repo format
548  
549  <a id="haystack_integrations.components.connectors.github.repo_viewer"></a>
550  
551  ## Module haystack\_integrations.components.connectors.github.repo\_viewer
552  
553  <a id="haystack_integrations.components.connectors.github.repo_viewer.GitHubItem"></a>
554  
555  ### GitHubItem
556  
557  Represents an item (file or directory) in a GitHub repository
558  
559  <a id="haystack_integrations.components.connectors.github.repo_viewer.GitHubItem.type"></a>
560  
561  #### type
562  
563  "file" or "dir"
564  
565  <a id="haystack_integrations.components.connectors.github.repo_viewer.GitHubRepoViewer"></a>
566  
567  ### GitHubRepoViewer
568  
569  Navigates and fetches content from GitHub repositories.
570  
571  For directories:
572  - Returns a list of Documents, one for each item
573  - Each Document's content is the item name
574  - Full path and metadata in Document.meta
575  
576  For files:
577  - Returns a single Document
578  - Document's content is the file content
579  - Full path and metadata in Document.meta
580  
581  For errors:
582  - Returns a single Document
583  - Document's content is the error message
584  - Document's meta contains type="error"
585  
586  ### Usage example
587  ```python
588  from haystack_integrations.components.connectors.github import GitHubRepoViewer
589  
590  viewer = GitHubRepoViewer()
591  
592  # List directory contents - returns multiple documents
593  result = viewer.run(
594      repo="owner/repository",
595      path="docs/",
596      branch="main"
597  )
598  print(result)
599  
600  # Get specific file - returns single document
601  result = viewer.run(
602      repo="owner/repository",
603      path="README.md",
604      branch="main"
605  )
606  print(result)
607  ```
608  
609  <a id="haystack_integrations.components.connectors.github.repo_viewer.GitHubRepoViewer.__init__"></a>
610  
611  #### GitHubRepoViewer.\_\_init\_\_
612  
613  ```python
614  def __init__(*,
615               github_token: Secret | None = None,
616               raise_on_failure: bool = True,
617               max_file_size: int = 1_000_000,
618               repo: str | None = None,
619               branch: str = "main")
620  ```
621  
622  Initialize the component.
623  
624  **Arguments**:
625  
626  - `github_token`: GitHub personal access token for API authentication
627  - `raise_on_failure`: If True, raises exceptions on API errors
628  - `max_file_size`: Maximum file size in bytes to fetch (default: 1MB)
629  - `repo`: Repository in format "owner/repo"
630  - `branch`: Git reference (branch, tag, commit) to use
631  
632  <a id="haystack_integrations.components.connectors.github.repo_viewer.GitHubRepoViewer.to_dict"></a>
633  
634  #### GitHubRepoViewer.to\_dict
635  
636  ```python
637  def to_dict() -> dict[str, Any]
638  ```
639  
640  Serialize the component to a dictionary.
641  
642  **Returns**:
643  
644  Dictionary with serialized data.
645  
646  <a id="haystack_integrations.components.connectors.github.repo_viewer.GitHubRepoViewer.from_dict"></a>
647  
648  #### GitHubRepoViewer.from\_dict
649  
650  ```python
651  @classmethod
652  def from_dict(cls, data: dict[str, Any]) -> "GitHubRepoViewer"
653  ```
654  
655  Deserialize the component from a dictionary.
656  
657  **Arguments**:
658  
659  - `data`: Dictionary to deserialize from.
660  
661  **Returns**:
662  
663  Deserialized component.
664  
665  <a id="haystack_integrations.components.connectors.github.repo_viewer.GitHubRepoViewer.run"></a>
666  
667  #### GitHubRepoViewer.run
668  
669  ```python
670  @component.output_types(documents=list[Document])
671  def run(path: str,
672          repo: str | None = None,
673          branch: str | None = None) -> dict[str, list[Document]]
674  ```
675  
676  Process a GitHub repository path and return documents.
677  
678  **Arguments**:
679  
680  - `repo`: Repository in format "owner/repo"
681  - `path`: Path within repository (default: root)
682  - `branch`: Git reference (branch, tag, commit) to use
683  
684  **Returns**:
685  
686  Dictionary containing list of documents
687