summaryrefslogtreecommitdiff
path: root/server/continuedev/plugins/context_providers/github.py
blob: c031f310df24fdbf56b73ef92e8ce94d4bd242e6 (plain)
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
40
41
42
43
44
45
46
47
48
49
from typing import List

from github import Auth, Github
from pydantic import Field

from ...core.context import (
    ContextItem,
    ContextItemDescription,
    ContextItemId,
    ContextProvider,
)


class GitHubIssuesContextProvider(ContextProvider):
    """
    The GitHubIssuesContextProvider is a ContextProvider that allows you to search GitHub issues in a repo. Type '@issue' to reference the title and contents of an issue.
    """

    title = "issues"
    repo_name: str = Field(
        ..., description="The name of the GitHub repo from which to pull issues"
    )
    auth_token: str = Field(
        ...,
        description="The GitHub auth token to use to authenticate with the GitHub API",
    )

    display_title = "GitHub Issues"
    description = "Reference GitHub issues"
    dynamic = False

    async def provide_context_items(self, workspace_dir: str) -> List[ContextItem]:
        auth = Auth.Token(self.auth_token)
        gh = Github(auth=auth)

        repo = gh.get_repo(self.repo_name)
        issues = repo.get_issues().get_page(0)

        return [
            ContextItem(
                content=issue.body,
                description=ContextItemDescription(
                    name=f"Issue #{issue.number}",
                    description=issue.title,
                    id=ContextItemId(provider_title=self.title, item_id=issue.id),
                ),
            )
            for issue in issues
        ]