arcade-github 0.0.13__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,137 @@
1
+ import json
2
+ from typing import Annotated, Optional
3
+
4
+ import httpx
5
+
6
+ from arcade.core.schema import ToolContext
7
+ from arcade.sdk import tool
8
+ from arcade.sdk.auth import GitHub
9
+ from arcade_github.tools.utils import (
10
+ get_github_json_headers,
11
+ get_url,
12
+ handle_github_response,
13
+ remove_none_values,
14
+ )
15
+
16
+
17
+ # Implements https://docs.github.com/en/rest/issues/issues?apiVersion=2022-11-28#create-an-issue
18
+ # Example `arcade chat` usage: "create an issue in the <REPO> repo owned by <OWNER> titled 'Found a bug' with the body 'I'm having a problem with this.' Assign it to <USER> and label it 'bug'"
19
+ @tool(requires_auth=GitHub())
20
+ async def create_issue(
21
+ context: ToolContext,
22
+ owner: Annotated[str, "The account owner of the repository. The name is not case sensitive."],
23
+ repo: Annotated[
24
+ str,
25
+ "The name of the repository without the .git extension. The name is not case sensitive.",
26
+ ],
27
+ title: Annotated[str, "The title of the issue."],
28
+ body: Annotated[Optional[str], "The contents of the issue."] = None,
29
+ assignees: Annotated[Optional[list[str]], "Logins for Users to assign to this issue."] = None,
30
+ milestone: Annotated[
31
+ Optional[int], "The number of the milestone to associate this issue with."
32
+ ] = None,
33
+ labels: Annotated[Optional[list[str]], "Labels to associate with this issue."] = None,
34
+ include_extra_data: Annotated[
35
+ bool,
36
+ "If true, return all the data available about the pull requests. This is a large payload and may impact performance - use with caution.",
37
+ ] = False,
38
+ ) -> Annotated[
39
+ str,
40
+ "A JSON string containing the created issue's details, including id, url, title, body, state, html_url, creation and update timestamps, user, assignees, and labels. If include_extra_data is True, returns all available data about the issue.",
41
+ ]:
42
+ """
43
+ Create an issue in a GitHub repository.
44
+
45
+ Example:
46
+ ```
47
+ create_issue(owner="octocat", repo="Hello-World", title="Found a bug", body="I'm having a problem with this.", assignees=["octocat"], milestone=1, labels=["bug"])
48
+ ```
49
+ """
50
+ url = get_url("repo_issues", owner=owner, repo=repo)
51
+ data = {
52
+ "title": title,
53
+ "body": body,
54
+ "labels": labels,
55
+ "milestone": milestone,
56
+ "assignees": assignees,
57
+ }
58
+ data = remove_none_values(data)
59
+ headers = get_github_json_headers(context.authorization.token)
60
+
61
+ async with httpx.AsyncClient() as client:
62
+ response = await client.post(url, headers=headers, json=data)
63
+
64
+ handle_github_response(response, url)
65
+
66
+ issue_data = response.json()
67
+ if include_extra_data:
68
+ return json.dumps(issue_data)
69
+
70
+ important_info = {
71
+ "id": issue_data.get("id"),
72
+ "url": issue_data.get("url"),
73
+ "title": issue_data.get("title"),
74
+ "body": issue_data.get("body"),
75
+ "state": issue_data.get("state"),
76
+ "html_url": issue_data.get("html_url"),
77
+ "created_at": issue_data.get("created_at"),
78
+ "updated_at": issue_data.get("updated_at"),
79
+ "user": issue_data.get("user", {}).get("login"),
80
+ "assignees": [assignee.get("login") for assignee in issue_data.get("assignees", [])],
81
+ "labels": [label.get("name") for label in issue_data.get("labels", [])],
82
+ }
83
+ return json.dumps(important_info)
84
+
85
+
86
+ # Implements https://docs.github.com/en/rest/issues/comments?apiVersion=2022-11-28#create-an-issue-comment
87
+ # Example `arcade chat` usage: "create a comment in the vscode repo owned by microsoft for issue 1347 that says 'Me too'"
88
+ @tool(requires_auth=GitHub())
89
+ async def create_issue_comment(
90
+ context: ToolContext,
91
+ owner: Annotated[str, "The account owner of the repository. The name is not case sensitive."],
92
+ repo: Annotated[
93
+ str,
94
+ "The name of the repository without the .git extension. The name is not case sensitive.",
95
+ ],
96
+ issue_number: Annotated[int, "The number that identifies the issue."],
97
+ body: Annotated[str, "The contents of the comment."],
98
+ include_extra_data: Annotated[
99
+ bool,
100
+ "If true, return all the data available about the pull requests. This is a large payload and may impact performance - use with caution.",
101
+ ] = False,
102
+ ) -> Annotated[
103
+ str,
104
+ "A JSON string containing the created comment's details, including id, url, body, user, and creation and update timestamps. If include_extra_data is True, returns all available data about the comment.",
105
+ ]:
106
+ """
107
+ Create a comment on an issue in a GitHub repository.
108
+
109
+ Example:
110
+ ```
111
+ create_issue_comment(owner="octocat", repo="Hello-World", issue_number=1347, body="Me too")
112
+ ```
113
+ """
114
+ url = get_url("repo_issue_comments", owner=owner, repo=repo, issue_number=issue_number)
115
+ data = {
116
+ "body": body,
117
+ }
118
+ headers = get_github_json_headers(context.authorization.token)
119
+
120
+ async with httpx.AsyncClient() as client:
121
+ response = await client.post(url, headers=headers, json=data)
122
+
123
+ handle_github_response(response, url)
124
+
125
+ comment_data = response.json()
126
+ if include_extra_data:
127
+ return json.dumps(comment_data)
128
+
129
+ important_info = {
130
+ "id": comment_data.get("id"),
131
+ "url": comment_data.get("url"),
132
+ "body": comment_data.get("body"),
133
+ "user": comment_data.get("user", {}).get("login"),
134
+ "created_at": comment_data.get("created_at"),
135
+ "updated_at": comment_data.get("updated_at"),
136
+ }
137
+ return json.dumps(important_info)
@@ -0,0 +1,98 @@
1
+ from enum import Enum
2
+
3
+
4
+ # Pull Request specific
5
+ class PRSortProperty(str, Enum):
6
+ CREATED = "created"
7
+ UPDATED = "updated"
8
+ POPULARITY = "popularity"
9
+ LONG_RUNNING = "long-running"
10
+
11
+
12
+ class PRState(str, Enum):
13
+ OPEN = "open"
14
+ CLOSED = "closed"
15
+ ALL = "all"
16
+
17
+
18
+ class ReviewCommentSortProperty(str, Enum):
19
+ CREATED = "created"
20
+ UPDATED = "updated"
21
+
22
+
23
+ class ReviewCommentSubjectType(str, Enum):
24
+ FILE = "file"
25
+ LINE = "line"
26
+
27
+
28
+ class DiffSide(str, Enum):
29
+ """
30
+ The side of the diff that the pull request's changes appear on.
31
+ Use LEFT for deletions that appear in red.
32
+ Use RIGHT for additions that appear in green or unchanged lines that appear in white and are shown for context
33
+ """
34
+
35
+ LEFT = "LEFT"
36
+ RIGHT = "RIGHT"
37
+
38
+
39
+ # Repo specific
40
+ class RepoType(str, Enum):
41
+ """
42
+ The types of repositories you want returned when listing organization repositories.
43
+ Default is all repositories.
44
+ """
45
+
46
+ ALL = "all"
47
+ PUBLIC = "public"
48
+ PRIVATE = "private"
49
+ FORKS = "forks"
50
+ SOURCES = "sources"
51
+ MEMBER = "member"
52
+
53
+
54
+ class RepoSortProperty(str, Enum):
55
+ """
56
+ The property to sort the results by when listing organization repositories.
57
+ Default is created.
58
+ """
59
+
60
+ CREATED = "created"
61
+ UPDATED = "updated"
62
+ PUSHED = "pushed"
63
+ FULL_NAME = "full_name"
64
+
65
+
66
+ class RepoTimePeriod(str, Enum):
67
+ """
68
+ The time period to filter by when listing repository activities.
69
+ """
70
+
71
+ DAY = "day"
72
+ WEEK = "week"
73
+ MONTH = "month"
74
+ QUARTER = "quarter"
75
+ YEAR = "year"
76
+
77
+
78
+ class ActivityType(str, Enum):
79
+ """
80
+ The activity type to filter by when listing repository activities.
81
+ """
82
+
83
+ PUSH = "push"
84
+ FORCE_PUSH = "force_push"
85
+ BRANCH_CREATION = "branch_creation"
86
+ BRANCH_DELETION = "branch_deletion"
87
+ PR_MERGE = "pr_merge"
88
+ MERGE_QUEUE_MERGE = "merge_queue_merge"
89
+
90
+
91
+ class SortDirection(str, Enum):
92
+ """
93
+ The order to sort by when listing organization repositories.
94
+ Default is asc.
95
+ """
96
+
97
+ ASC = "asc"
98
+ DESC = "desc"