Skip to content

Commit 0885601

Browse files
authored
Add tool for project fields and items (#1145)
* Add get project fields tool * Data types * Docs * Update projectNumber's type * Add list_project_items tool * Add get_project_item tool * Return minimal project * Remove unused per_page
1 parent 371b9ae commit 0885601

File tree

9 files changed

+1001
-39
lines changed

9 files changed

+1001
-39
lines changed

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,11 +663,30 @@ The following sets of tools are available (all are on by default):
663663
- `owner_type`: Owner type (string, required)
664664
- `project_number`: The project's number (number, required)
665665

666+
- **get_project_field** - Get project field
667+
- `field_id`: The field's id. (number, required)
668+
- `owner`: If owner_type == user it is the handle for the GitHub user account. If owner_type == org it is the name of the organization. The name is not case sensitive. (string, required)
669+
- `owner_type`: Owner type (string, required)
670+
- `project_number`: The project's number. (number, required)
671+
672+
- **get_project_item** - Get project item
673+
- `item_id`: The item's ID. (number, required)
674+
- `owner`: If owner_type == user it is the handle for the GitHub user account. If owner_type == org it is the name of the organization. The name is not case sensitive. (string, required)
675+
- `owner_type`: Owner type (string, required)
676+
- `project_number`: The project's number. (number, required)
677+
666678
- **list_project_fields** - List project fields
667679
- `owner`: If owner_type == user it is the handle for the GitHub user account. If owner_type == org it is the name of the organization. The name is not case sensitive. (string, required)
668680
- `owner_type`: Owner type (string, required)
669681
- `per_page`: Number of results per page (max 100, default: 30) (number, optional)
670-
- `projectNumber`: The project's number. (string, required)
682+
- `project_number`: The project's number. (number, required)
683+
684+
- **list_project_items** - List project items
685+
- `owner`: If owner_type == user it is the handle for the GitHub user account. If owner_type == org it is the name of the organization. The name is not case sensitive. (string, required)
686+
- `owner_type`: Owner type (string, required)
687+
- `per_page`: Number of results per page (max 100, default: 30) (number, optional)
688+
- `project_number`: The project's number. (number, required)
689+
- `query`: Search query to filter items (string, optional)
671690

672691
- **list_projects** - List projects
673692
- `owner`: If owner_type == user it is the handle for the GitHub user account. If owner_type == org it is the name of the organization. The name is not case sensitive. (string, required)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"annotations": {
3+
"title": "Get project field",
4+
"readOnlyHint": true
5+
},
6+
"description": "Get Project field for a user or org",
7+
"inputSchema": {
8+
"properties": {
9+
"field_id": {
10+
"description": "The field's id.",
11+
"type": "number"
12+
},
13+
"owner": {
14+
"description": "If owner_type == user it is the handle for the GitHub user account. If owner_type == org it is the name of the organization. The name is not case sensitive.",
15+
"type": "string"
16+
},
17+
"owner_type": {
18+
"description": "Owner type",
19+
"enum": [
20+
"user",
21+
"org"
22+
],
23+
"type": "string"
24+
},
25+
"project_number": {
26+
"description": "The project's number.",
27+
"type": "number"
28+
}
29+
},
30+
"required": [
31+
"owner_type",
32+
"owner",
33+
"project_number",
34+
"field_id"
35+
],
36+
"type": "object"
37+
},
38+
"name": "get_project_field"
39+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"annotations": {
3+
"title": "Get project item",
4+
"readOnlyHint": true
5+
},
6+
"description": "Get a specific Project item for a user or org",
7+
"inputSchema": {
8+
"properties": {
9+
"item_id": {
10+
"description": "The item's ID.",
11+
"type": "number"
12+
},
13+
"owner": {
14+
"description": "If owner_type == user it is the handle for the GitHub user account. If owner_type == org it is the name of the organization. The name is not case sensitive.",
15+
"type": "string"
16+
},
17+
"owner_type": {
18+
"description": "Owner type",
19+
"enum": [
20+
"user",
21+
"org"
22+
],
23+
"type": "string"
24+
},
25+
"project_number": {
26+
"description": "The project's number.",
27+
"type": "number"
28+
}
29+
},
30+
"required": [
31+
"owner_type",
32+
"owner",
33+
"project_number",
34+
"item_id"
35+
],
36+
"type": "object"
37+
},
38+
"name": "get_project_item"
39+
}

pkg/github/__toolsnaps__/list_project_fields.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
"description": "Number of results per page (max 100, default: 30)",
2323
"type": "number"
2424
},
25-
"projectNumber": {
25+
"project_number": {
2626
"description": "The project's number.",
27-
"type": "string"
27+
"type": "number"
2828
}
2929
},
3030
"required": [
3131
"owner_type",
3232
"owner",
33-
"projectNumber"
33+
"project_number"
3434
],
3535
"type": "object"
3636
},
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"annotations": {
3+
"title": "List project items",
4+
"readOnlyHint": true
5+
},
6+
"description": "List Project items for a user or org",
7+
"inputSchema": {
8+
"properties": {
9+
"owner": {
10+
"description": "If owner_type == user it is the handle for the GitHub user account. If owner_type == org it is the name of the organization. The name is not case sensitive.",
11+
"type": "string"
12+
},
13+
"owner_type": {
14+
"description": "Owner type",
15+
"enum": [
16+
"user",
17+
"org"
18+
],
19+
"type": "string"
20+
},
21+
"per_page": {
22+
"description": "Number of results per page (max 100, default: 30)",
23+
"type": "number"
24+
},
25+
"project_number": {
26+
"description": "The project's number.",
27+
"type": "number"
28+
},
29+
"query": {
30+
"description": "Search query to filter items",
31+
"type": "string"
32+
}
33+
},
34+
"required": [
35+
"owner_type",
36+
"owner",
37+
"project_number"
38+
],
39+
"type": "object"
40+
},
41+
"name": "list_project_items"
42+
}

pkg/github/minimal_types.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,97 @@ type MinimalResponse struct {
114114
URL string `json:"url"`
115115
}
116116

117+
type MinimalProject struct {
118+
ID *int64 `json:"id,omitempty"`
119+
NodeID *string `json:"node_id,omitempty"`
120+
Owner *MinimalUser `json:"owner,omitempty"`
121+
Creator *MinimalUser `json:"creator,omitempty"`
122+
Title *string `json:"title,omitempty"`
123+
Description *string `json:"description,omitempty"`
124+
Public *bool `json:"public,omitempty"`
125+
ClosedAt *github.Timestamp `json:"closed_at,omitempty"`
126+
CreatedAt *github.Timestamp `json:"created_at,omitempty"`
127+
UpdatedAt *github.Timestamp `json:"updated_at,omitempty"`
128+
DeletedAt *github.Timestamp `json:"deleted_at,omitempty"`
129+
Number *int `json:"number,omitempty"`
130+
ShortDescription *string `json:"short_description,omitempty"`
131+
DeletedBy *MinimalUser `json:"deleted_by,omitempty"`
132+
}
133+
134+
type MinimalProjectItem struct {
135+
ID *int64 `json:"id,omitempty"`
136+
NodeID *string `json:"node_id,omitempty"`
137+
ProjectNodeID *string `json:"project_node_id,omitempty"`
138+
ContentNodeID *string `json:"content_node_id,omitempty"`
139+
ProjectURL *string `json:"project_url,omitempty"`
140+
ContentType *string `json:"content_type,omitempty"`
141+
Creator *MinimalUser `json:"creator,omitempty"`
142+
CreatedAt *github.Timestamp `json:"created_at,omitempty"`
143+
UpdatedAt *github.Timestamp `json:"updated_at,omitempty"`
144+
ArchivedAt *github.Timestamp `json:"archived_at,omitempty"`
145+
ItemURL *string `json:"item_url,omitempty"`
146+
Fields []*projectV2Field `json:"fields,omitempty"`
147+
}
148+
117149
// Helper functions
118150

151+
func convertToMinimalProject(fullProject *github.ProjectV2) *MinimalProject {
152+
if fullProject == nil {
153+
return nil
154+
}
155+
156+
return &MinimalProject{
157+
ID: github.Ptr(fullProject.GetID()),
158+
NodeID: github.Ptr(fullProject.GetNodeID()),
159+
Owner: convertToMinimalUser(fullProject.GetOwner()),
160+
Creator: convertToMinimalUser(fullProject.GetCreator()),
161+
Title: github.Ptr(fullProject.GetTitle()),
162+
Description: github.Ptr(fullProject.GetDescription()),
163+
Public: github.Ptr(fullProject.GetPublic()),
164+
ClosedAt: github.Ptr(fullProject.GetClosedAt()),
165+
CreatedAt: github.Ptr(fullProject.GetCreatedAt()),
166+
UpdatedAt: github.Ptr(fullProject.GetUpdatedAt()),
167+
DeletedAt: github.Ptr(fullProject.GetDeletedAt()),
168+
Number: github.Ptr(fullProject.GetNumber()),
169+
ShortDescription: github.Ptr(fullProject.GetShortDescription()),
170+
DeletedBy: convertToMinimalUser(fullProject.GetDeletedBy()),
171+
}
172+
}
173+
174+
func convertToMinimalUser(user *github.User) *MinimalUser {
175+
if user == nil {
176+
return nil
177+
}
178+
179+
return &MinimalUser{
180+
Login: user.GetLogin(),
181+
ID: user.GetID(),
182+
ProfileURL: user.GetHTMLURL(),
183+
AvatarURL: user.GetAvatarURL(),
184+
}
185+
}
186+
187+
func convertToMinimalProjectItem(item *projectV2Item) *MinimalProjectItem {
188+
if item == nil {
189+
return nil
190+
}
191+
192+
return &MinimalProjectItem{
193+
ID: item.ID,
194+
NodeID: item.NodeID,
195+
ProjectNodeID: item.ProjectNodeID,
196+
ContentNodeID: item.ContentNodeID,
197+
ProjectURL: item.ProjectURL,
198+
ContentType: item.ContentType,
199+
Creator: convertToMinimalUser(item.Creator),
200+
CreatedAt: item.CreatedAt,
201+
UpdatedAt: item.UpdatedAt,
202+
ArchivedAt: item.ArchivedAt,
203+
ItemURL: item.ItemURL,
204+
Fields: item.Fields,
205+
}
206+
}
207+
119208
// convertToMinimalCommit converts a GitHub API RepositoryCommit to MinimalCommit
120209
func convertToMinimalCommit(commit *github.RepositoryCommit, includeDiffs bool) MinimalCommit {
121210
minimalCommit := MinimalCommit{

0 commit comments

Comments
 (0)