Skip to content

Commit 8eb631a

Browse files
authored
Add table github_repository_discussion Closes #510 (#513)
1 parent 9a38d73 commit 8eb631a

File tree

5 files changed

+656
-0
lines changed

5 files changed

+656
-0
lines changed
Lines changed: 271 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
1+
---
2+
title: "Steampipe Table: github_repository_discussion - Query GitHub Repository Discussions using SQL"
3+
description: "Allows users to query GitHub Repository Discussions, providing insights into discussions, comments, and replies within repositories."
4+
folder: "Repository"
5+
---
6+
7+
# Table: github_repository_discussion - Query GitHub Repository Discussions using SQL
8+
9+
GitHub Discussions are conversations that can be started by anyone and are organized into categories. They provide a place for having conversations that are not issues or pull requests. Discussions can be used to ask questions, share ideas, or have general conversations about a project.
10+
11+
## Table Usage Guide
12+
13+
The `github_repository_discussion` table provides insights into discussions within GitHub repositories. As a project manager or developer, explore discussion-specific details through this table, including comments, replies, categories, and associated metadata. Utilize it to uncover information about discussions, such as those with the most engagement, discussions by category, and the overall activity within a repository's discussion forum.
14+
15+
To query this table using a [fine-grained access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-fine-grained-personal-access-token), the following permissions are required:
16+
17+
- Repository permissions:
18+
- Discussions (Read-only): Required to access all columns.
19+
20+
**Important Notes**
21+
- You must specify the `repository_full_name` (owner/repository) column in the `where` or `join` clause to query the table.
22+
23+
## Examples
24+
25+
### List discussions in a repository
26+
Explore the discussions within a specific GitHub repository to understand community engagement and topics being discussed. This can help in tracking community activity and identifying popular discussion topics.
27+
28+
```sql+postgres
29+
select
30+
number,
31+
title,
32+
author_login,
33+
category_name,
34+
created_at,
35+
comments_total_count
36+
from
37+
github_repository_discussion
38+
where
39+
repository_full_name = 'turbot/steampipe';
40+
```
41+
42+
```sql+sqlite
43+
select
44+
number,
45+
title,
46+
author_login,
47+
category_name,
48+
created_at,
49+
comments_total_count
50+
from
51+
github_repository_discussion
52+
where
53+
repository_full_name = 'turbot/steampipe';
54+
```
55+
56+
### Get a specific discussion by number
57+
Retrieve detailed information about a specific discussion, including its full content, author details, and engagement metrics. This is useful for analyzing individual discussion threads and understanding their impact.
58+
59+
```sql+postgres
60+
select
61+
number,
62+
title,
63+
author_login,
64+
category_name,
65+
created_at,
66+
comments_total_count,
67+
answer
68+
from
69+
github_repository_discussion
70+
where
71+
repository_full_name = 'turbot/steampipe'
72+
and number = 1007;
73+
```
74+
75+
```sql+sqlite
76+
select
77+
number,
78+
title,
79+
author_login,
80+
category_name,
81+
created_at,
82+
comments_total_count,
83+
answer
84+
from
85+
github_repository_discussion
86+
where
87+
repository_full_name = 'turbot/steampipe'
88+
and number = 1007;
89+
```
90+
91+
### Find discussions with answers
92+
Identify discussions that have been answered, which can help in understanding which topics have been resolved and which discussions have received helpful responses from the community.
93+
94+
```sql+postgres
95+
select
96+
number,
97+
title,
98+
author_login,
99+
category_name,
100+
answer
101+
from
102+
github_repository_discussion
103+
where
104+
repository_full_name = 'turbot/steampipe'
105+
and answer is not null;
106+
```
107+
108+
```sql+sqlite
109+
select
110+
number,
111+
title,
112+
author_login,
113+
category_name,
114+
answer
115+
from
116+
github_repository_discussion
117+
where
118+
repository_full_name = 'turbot/steampipe'
119+
and answer is not null;
120+
```
121+
122+
### Find discussions by category
123+
Filter discussions by their category to focus on specific types of conversations, such as FAQs, feature requests, or general discussions. This helps in organizing and prioritizing community feedback.
124+
125+
```sql+postgres
126+
select
127+
number,
128+
title,
129+
author_login,
130+
category_name,
131+
created_at
132+
from
133+
github_repository_discussion
134+
where
135+
repository_full_name = 'turbot/steampipe'
136+
and category_name = 'FAQ';
137+
```
138+
139+
```sql+sqlite
140+
select
141+
number,
142+
title,
143+
author_login,
144+
category_name,
145+
created_at
146+
from
147+
github_repository_discussion
148+
where
149+
repository_full_name = 'turbot/steampipe'
150+
and category_name = 'FAQ';
151+
```
152+
153+
### Get all comments for a discussion
154+
Retrieve all comments for a specific discussion to understand the full conversation thread and community engagement. This includes both the comment content and metadata about each comment.
155+
156+
```sql+postgres
157+
select
158+
number,
159+
title,
160+
comments
161+
from
162+
github_repository_discussion
163+
where
164+
repository_full_name = 'turbot/steampipe'
165+
and number = 1007;
166+
```
167+
168+
```sql+sqlite
169+
select
170+
number,
171+
title,
172+
comments
173+
from
174+
github_repository_discussion
175+
where
176+
repository_full_name = 'turbot/steampipe'
177+
and number = 1007;
178+
```
179+
180+
### Get all replies for a discussion
181+
Retrieve all replies to comments in a specific discussion to understand the nested conversation structure and identify threads with high engagement.
182+
183+
```sql+postgres
184+
select
185+
number,
186+
title,
187+
replies
188+
from
189+
github_repository_discussion
190+
where
191+
repository_full_name = 'turbot/steampipe'
192+
and number = 1007;
193+
```
194+
195+
```sql+sqlite
196+
select
197+
number,
198+
title,
199+
replies
200+
from
201+
github_repository_discussion
202+
where
203+
repository_full_name = 'turbot/steampipe'
204+
and number = 1007;
205+
```
206+
207+
### Find discussions with the most comments
208+
Identify the most active discussions in a repository by sorting by comment count. This helps in understanding which topics generate the most community engagement and discussion.
209+
210+
```sql+postgres
211+
select
212+
number,
213+
title,
214+
author_login,
215+
comments_total_count
216+
from
217+
github_repository_discussion
218+
where
219+
repository_full_name = 'turbot/steampipe'
220+
order by
221+
comments_total_count desc
222+
limit 10;
223+
```
224+
225+
```sql+sqlite
226+
select
227+
number,
228+
title,
229+
author_login,
230+
comments_total_count
231+
from
232+
github_repository_discussion
233+
where
234+
repository_full_name = 'turbot/steampipe'
235+
order by
236+
comments_total_count desc
237+
limit 10;
238+
```
239+
240+
### Find recent discussions
241+
Identify recently created discussions to stay updated on the latest community activity and new topics being discussed in the repository.
242+
243+
```sql+postgres
244+
select
245+
number,
246+
title,
247+
author_login,
248+
created_at
249+
from
250+
github_repository_discussion
251+
where
252+
repository_full_name = 'turbot/steampipe'
253+
and created_at > now() - interval '30 days'
254+
order by
255+
created_at desc;
256+
```
257+
258+
```sql+sqlite
259+
select
260+
number,
261+
title,
262+
author_login,
263+
created_at
264+
from
265+
github_repository_discussion
266+
where
267+
repository_full_name = 'turbot/steampipe'
268+
and created_at > datetime('now', '-30 days')
269+
order by
270+
created_at desc;
271+
```

github/discussion_utils.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package github
2+
3+
import (
4+
"github.com/shurcooL/githubv4"
5+
"golang.org/x/exp/slices"
6+
)
7+
8+
func appendDiscussionColumnIncludes(m *map[string]interface{}, cols []string) {
9+
(*m)["includeDiscussionId"] = githubv4.Boolean(slices.Contains(cols, "id"))
10+
(*m)["includeDiscussionNodeId"] = githubv4.Boolean(slices.Contains(cols, "node_id"))
11+
(*m)["includeDiscussionCreatedAt"] = githubv4.Boolean(slices.Contains(cols, "created_at"))
12+
(*m)["includeDiscussionUpdatedAt"] = githubv4.Boolean(slices.Contains(cols, "updated_at"))
13+
(*m)["includeDiscussionAuthor"] = githubv4.Boolean(slices.Contains(cols, "author") || slices.Contains(cols, "author_login"))
14+
(*m)["includeDiscussionCategory"] = githubv4.Boolean(slices.Contains(cols, "category") || slices.Contains(cols, "category_name"))
15+
(*m)["includeDiscussionAnswer"] = githubv4.Boolean(slices.Contains(cols, "answer"))
16+
(*m)["includeDiscussionComments"] = githubv4.Boolean(slices.Contains(cols, "comments") || slices.Contains(cols, "comments_total_count"))
17+
}

github/models/discussion.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package models
2+
3+
type Discussion struct {
4+
Id int `graphql:"id: databaseId @include(if:$includeDiscussionId)" json:"id"`
5+
NodeId string `graphql:"nodeId: id @include(if:$includeDiscussionNodeId)" json:"node_id"`
6+
Number int `graphql:"number" json:"number"`
7+
Title string `graphql:"title" json:"title"`
8+
Url string `graphql:"url" json:"url"`
9+
CreatedAt NullableTime `graphql:"createdAt @include(if:$includeDiscussionCreatedAt)" json:"created_at"`
10+
UpdatedAt NullableTime `graphql:"updatedAt @include(if:$includeDiscussionUpdatedAt)" json:"updated_at"`
11+
Author Actor `graphql:"author @include(if:$includeDiscussionAuthor)" json:"author"`
12+
Category struct {
13+
Name string `graphql:"name" json:"name"`
14+
} `graphql:"category @include(if:$includeDiscussionCategory)" json:"category"`
15+
Answer *DiscussionComment `graphql:"answer @include(if:$includeDiscussionAnswer)" json:"answer"`
16+
Comments struct {
17+
TotalCount int
18+
Nodes []DiscussionComment
19+
} `graphql:"comments(first: 10) @include(if:$includeDiscussionComments)" json:"comments"`
20+
}
21+
22+
type DiscussionComments struct {
23+
Comments struct {
24+
PageInfo PageInfo
25+
TotalCount int
26+
Nodes []DiscussionComment
27+
} `graphql:"comments(first: $pageSize, after: $cursor)"`
28+
}
29+
30+
type DiscussionCommentReplies struct {
31+
Replies struct {
32+
PageInfo PageInfo
33+
TotalCount int
34+
Nodes []DiscussionComment
35+
} `graphql:"replies(first: $pageSize, after: $cursor)"`
36+
}
37+
38+
type DiscussionComment struct {
39+
Id int `graphql:"id: databaseId" json:"id"`
40+
NodeId string `graphql:"nodeId: id" json:"node_id"`
41+
Author Actor `graphql:"author" json:"author"`
42+
Body string `graphql:"body" json:"body"`
43+
BodyText string `graphql:"bodyText" json:"body_text"`
44+
CreatedAt NullableTime `graphql:"createdAt" json:"created_at"`
45+
UpdatedAt NullableTime `graphql:"updatedAt" json:"updated_at"`
46+
IsAnswer bool `graphql:"isAnswer" json:"is_answer"`
47+
}

github/plugin.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func Plugin(ctx context.Context) *plugin.Plugin {
6363
"github_repository_content": tableGitHubRepositoryContent(),
6464
"github_repository_dependabot_alert": tableGitHubRepositoryDependabotAlert(),
6565
"github_repository_deployment": tableGitHubRepositoryDeployment(),
66+
"github_repository_discussion": tableGitHubRepositoryDiscussion(),
6667
"github_repository_environment": tableGitHubRepositoryEnvironment(),
6768
"github_repository_ruleset": tableGitHubRepositoryRuleset(),
6869
"github_repository_sbom": tableGitHubRepositorySbom(),

0 commit comments

Comments
 (0)