-
Notifications
You must be signed in to change notification settings - Fork 41
Add the github_project_v2 table
#548
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dark-panda
wants to merge
1
commit into
turbot:main
Choose a base branch
from
dark-panda:add-project-v2-table
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package models | ||
|
|
||
| // ProjectV2Owner represents the owner of a project, which can be an Organization or User. | ||
| type ProjectV2Owner struct { | ||
| TypeName string `graphql:"type: __typename" json:"type"` | ||
| Organization struct { | ||
| Id int `graphql:"id: databaseId" json:"id"` | ||
| Login string `json:"login"` | ||
| } `graphql:"... on Organization" json:"organization,omitempty"` | ||
| User struct { | ||
| Id int `graphql:"id: databaseId" json:"id"` | ||
| Login string `json:"login"` | ||
| } `graphql:"... on User" json:"user,omitempty"` | ||
| } | ||
|
|
||
| // ProjectV2StatusUpdate represents a single status update on a project. | ||
| type ProjectV2StatusUpdate struct { | ||
| Id string `graphql:"id: fullDatabaseId" json:"id"` | ||
| NodeId string `graphql:"nodeId: id" json:"node_id"` | ||
| Status string `json:"status"` | ||
| Body string `json:"body"` | ||
| StartDate string `json:"start_date"` | ||
| TargetDate string `json:"target_date"` | ||
| CreatedAt NullableTime `json:"created_at"` | ||
| UpdatedAt NullableTime `json:"updated_at"` | ||
| Creator Actor `json:"creator"` | ||
| } | ||
|
|
||
| type ProjectV2 struct { | ||
| Id string `graphql:"id: fullDatabaseId @include(if:$includeId)" json:"id"` | ||
| NodeId string `graphql:"nodeId: id @include(if:$includeNodeId)" json:"node_id"` | ||
| Number int `json:"number"` | ||
| Owner ProjectV2Owner `graphql:"owner @include(if:$includeOwner)" json:"owner,omitempty"` | ||
| Creator Actor `graphql:"creator @include(if:$includeCreator)" json:"creator,omitempty"` | ||
| Title string `graphql:"title @include(if:$includeTitle)" json:"title"` | ||
| Description string `graphql:"description: shortDescription @include(if:$includeDescription)" json:"description"` | ||
| IsPublic bool `graphql:"public @include(if:$includeIsPublic)" json:"public"` | ||
| ClosedAt NullableTime `graphql:"closedAt @include(if:$includeClosedAt)" json:"closed_at"` | ||
| CreatedAt NullableTime `graphql:"createdAt @include(if:$includeCreatedAt)" json:"created_at"` | ||
| UpdatedAt NullableTime `graphql:"updatedAt @include(if:$includeUpdatedAt)" json:"updated_at"` | ||
| Closed bool `graphql:"closed @include(if:$includeState)" json:"closed"` | ||
| LatestStatusUpdate struct { | ||
| Nodes []ProjectV2StatusUpdate | ||
| } `graphql:"statusUpdates(last: 1) @include(if:$includeLatestStatusUpdate)" json:"latest_status_update"` | ||
| IsTemplate bool `graphql:"template @include(if:$includeIsTemplate)" json:"template"` | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| package github | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "slices" | ||
|
|
||
| "github.com/shurcooL/githubv4" | ||
| "github.com/turbot/steampipe-plugin-github/github/models" | ||
| "github.com/turbot/steampipe-plugin-sdk/v5/plugin" | ||
| ) | ||
|
|
||
| func extractProjectV2FromHydrateItem(h *plugin.HydrateData) (models.ProjectV2, error) { | ||
| if project, ok := h.Item.(models.ProjectV2); ok { | ||
| return project, nil | ||
| } else { | ||
| return models.ProjectV2{}, fmt.Errorf("unable to parse hydrate item %v as a ProjectV2", h.Item) | ||
| } | ||
| } | ||
| func appendProjectV2ColumnIncludes(m *map[string]interface{}, cols []string) { | ||
| (*m)["includeId"] = githubv4.Boolean(slices.Contains(cols, "id")) | ||
| (*m)["includeNodeId"] = githubv4.Boolean(slices.Contains(cols, "node_id")) | ||
| (*m)["includeOwner"] = githubv4.Boolean(slices.Contains(cols, "owner")) | ||
| (*m)["includeCreator"] = githubv4.Boolean(slices.Contains(cols, "creator")) | ||
| (*m)["includeTitle"] = githubv4.Boolean(slices.Contains(cols, "title")) | ||
| (*m)["includeDescription"] = githubv4.Boolean(slices.Contains(cols, "description")) | ||
| (*m)["includeIsPublic"] = githubv4.Boolean(slices.Contains(cols, "is_public")) | ||
| (*m)["includeClosedAt"] = githubv4.Boolean(slices.Contains(cols, "closed_at")) | ||
| (*m)["includeCreatedAt"] = githubv4.Boolean(slices.Contains(cols, "created_at")) | ||
| (*m)["includeUpdatedAt"] = githubv4.Boolean(slices.Contains(cols, "updated_at")) | ||
| (*m)["includeState"] = githubv4.Boolean(slices.Contains(cols, "state")) | ||
| (*m)["includeLatestStatusUpdate"] = githubv4.Boolean(slices.Contains(cols, "latest_status_update")) | ||
| (*m)["includeIsTemplate"] = githubv4.Boolean(slices.Contains(cols, "is_template")) | ||
| } | ||
|
|
||
| func projectV2HydrateId(_ context.Context, _ *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { | ||
| project, err := extractProjectV2FromHydrateItem(h) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return project.Id, nil | ||
| } | ||
|
|
||
| func projectV2HydrateNodeId(_ context.Context, _ *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { | ||
| project, err := extractProjectV2FromHydrateItem(h) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return project.NodeId, nil | ||
| } | ||
|
|
||
| func projectV2HydrateOwner(_ context.Context, _ *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { | ||
| project, err := extractProjectV2FromHydrateItem(h) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return project.Owner, nil | ||
| } | ||
|
|
||
| func projectV2HydrateCreator(_ context.Context, _ *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { | ||
| project, err := extractProjectV2FromHydrateItem(h) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return project.Creator, nil | ||
| } | ||
|
|
||
| func projectV2HydrateTitle(_ context.Context, _ *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { | ||
| project, err := extractProjectV2FromHydrateItem(h) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return project.Title, nil | ||
| } | ||
|
|
||
| func projectV2HydrateDescription(_ context.Context, _ *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { | ||
| project, err := extractProjectV2FromHydrateItem(h) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return project.Description, nil | ||
| } | ||
|
|
||
| func projectV2HydrateIsPublic(_ context.Context, _ *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { | ||
| project, err := extractProjectV2FromHydrateItem(h) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return project.IsPublic, nil | ||
| } | ||
|
|
||
| func projectV2HydrateClosedAt(_ context.Context, _ *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { | ||
| project, err := extractProjectV2FromHydrateItem(h) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return project.ClosedAt, nil | ||
| } | ||
|
|
||
| func projectV2HydrateCreatedAt(_ context.Context, _ *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { | ||
| project, err := extractProjectV2FromHydrateItem(h) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return project.CreatedAt, nil | ||
| } | ||
|
|
||
| func projectV2HydrateUpdatedAt(_ context.Context, _ *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { | ||
| project, err := extractProjectV2FromHydrateItem(h) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return project.UpdatedAt, nil | ||
| } | ||
|
|
||
| // projectV2HydrateState derives the REST-compatible "open"/"closed" state string from the GraphQL boolean. | ||
| func projectV2HydrateState(_ context.Context, _ *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { | ||
| project, err := extractProjectV2FromHydrateItem(h) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if project.Closed { | ||
| return "closed", nil | ||
| } | ||
| return "open", nil | ||
| } | ||
|
|
||
| // projectV2HydrateLatestStatusUpdate returns the most recent status update from the statusUpdates connection. | ||
| func projectV2HydrateLatestStatusUpdate(_ context.Context, _ *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { | ||
| project, err := extractProjectV2FromHydrateItem(h) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if len(project.LatestStatusUpdate.Nodes) > 0 { | ||
| return project.LatestStatusUpdate.Nodes[0], nil | ||
| } | ||
| return nil, nil | ||
| } | ||
|
|
||
| func projectV2HydrateIsTemplate(_ context.Context, _ *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { | ||
| project, err := extractProjectV2FromHydrateItem(h) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return project.IsTemplate, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this column, similar to
assigneesandlabels, I think we should return more project data, including its scalar fields as part of the project object. So we can reuse theProjectV2model you already defined and include its scalar fields:idnode_idnumbertitledescriptionstateis_publiccreated_atupdated_atclosed_atNotably, we should skip the pageable connections (items/fields/views), and
@include-gate anything heavy likelatest_status_update. Users can still join onnode_id, but now get titles/state without one.Can you please also add a
projects_v2_total_countcolumn with the descriptionCount of ProjectV2 projects associated with the issue.? The model already fetchesProjectItems.TotalCount, so it's basically free, and it matches the existingprojects_v2_total_countcolumns in thegithub_organizationandgithub_teamtables.