Skip to content

Commit

Permalink
Fix the model dependencies (#387)
Browse files Browse the repository at this point in the history
  • Loading branch information
bigdatasourav authored Dec 6, 2023
1 parent 37652ea commit 7a7c94e
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 28 deletions.
33 changes: 32 additions & 1 deletion github/models/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package models
type Branch struct {
Name string
Target struct {
Commit Commit `graphql:"... on Commit"`
Commit BaseCommit `graphql:"... on Commit"`
}
BranchProtectionRule BranchProtectionRule `graphql:"branchProtectionRule @include(if:$includeBranchProtectionRule)" json:"branch_protection_rule"`
}
Expand Down Expand Up @@ -102,3 +102,34 @@ func (b *BranchActorAllowances) Explode() ([]NameSlug, []NameSlug, []NameLogin)

return apps, teams, users
}

type BaseBranchProtectionRule struct {
AllowsDeletions bool `json:"allows_deletions"`
AllowsForcePushes bool `json:"allows_force_pushes"`
BlocksCreations bool `json:"blocks_creations"`
Creator Actor `json:"creator"`
Id int `graphql:"id: databaseId" json:"id"`
NodeId string `graphql:"nodeId: id" json:"node_id"`
DismissesStaleReviews bool `json:"dismisses_stale_reviews"`
IsAdminEnforced bool `json:"is_admin_enforced"`
LockAllowsFetchAndMerge bool `json:"lock_allows_fetch_and_merge"`
LockBranch bool `json:"lock_branch"`
Pattern string `json:"pattern"`
RequireLastPushApproval bool `json:"require_last_push_approval"`
RequiredApprovingReviewCount int `json:"required_approving_review_count"`
RequiredDeploymentEnvironments []string `json:"required_deployment_environments"`
RequiredStatusChecks []string `graphql:"requiredStatusChecks: requiredStatusCheckContexts" json:"required_status_checks"`
RequiresApprovingReviews bool `json:"requires_approving_reviews"`
RequiresConversationResolution bool `json:"requires_conversation_resolution"`
RequiresCodeOwnerReviews bool `json:"requires_code_owner_reviews"`
RequiresCommitSignatures bool `json:"requires_commit_signatures"`
RequiresDeployments bool `json:"requires_deployments"`
RequiresLinearHistory bool `json:"requires_linear_history"`
RequiresStatusChecks bool `json:"requires_status_checks"`
RequiresStrictStatusChecks bool `json:"requires_strict_status_checks"`
RestrictsPushes bool `json:"restricts_pushes"`
RestrictsReviewDismissals bool `json:"restricts_review_dismissals"`
MatchingBranches struct {
TotalCount int `json:"total_count"`
} `graphql:"matchingBranches: matchingRefs" json:"matching_branches"`
}
42 changes: 34 additions & 8 deletions github/models/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,25 @@ package models
// BasicCommit returns the core fields of a Commit.
type BasicCommit struct {
Sha string `graphql:"sha: oid" json:"sha"`
ShortSha string `graphql:"shortSha: abbreviatedOid @include(if:$includeCommitShortSha)" json:"short_sha"`
AuthoredDate NullableTime `graphql:"authoredDate @include(if:$includeCommitAuthoredDate)" json:"authored_date"`
Author GitActor `graphql:"author @include(if:$includeCommitAuthor)" json:"author"`
CommittedDate NullableTime `graphql:"committedDate @include(if:$includeCommitCommittedDate)" json:"committed_date"`
Committer GitActor `graphql:"committer @include(if:$includeCommitCommitter)" json:"committer"`
Message string `graphql:"message @include(if:$includeCommitMessage)" json:"message"`
Url string `graphql:"url @include(if:$includeCommitUrl)" json:"url"`
ShortSha string `graphql:"shortSha: abbreviatedOid" json:"short_sha"`
AuthoredDate NullableTime `json:"authored_date"`
Author GitActor `json:"author"`
CommittedDate NullableTime `json:"committed_date"`
Committer GitActor `json:"committer"`
Message string `json:"message"`
Url string `json:"url"`
}

// Commit returns the full detail of a Commit
type Commit struct {
BasicCommit
Sha string `graphql:"sha: oid" json:"sha"`
ShortSha string `graphql:"shortSha: abbreviatedOid @include(if:$includeCommitShortSha)" json:"short_sha"`
AuthoredDate NullableTime `graphql:"authoredDate @include(if:$includeCommitAuthoredDate)" json:"authored_date"`
Author GitActor `graphql:"author @include(if:$includeCommitAuthor)" json:"author"`
CommittedDate NullableTime `graphql:"committedDate @include(if:$includeCommitCommittedDate)" json:"committed_date"`
Committer GitActor `graphql:"committer @include(if:$includeCommitCommitter)" json:"committer"`
Message string `graphql:"message @include(if:$includeCommitMessage)" json:"message"`
Url string `graphql:"url @include(if:$includeCommitUrl)" json:"url"`
Additions int `graphql:"additions @include(if:$includeCommitAdditions)" json:"additions"`
AuthoredByCommitter bool `graphql:"authoredByCommitter @include(if:$includeCommitAuthoredByCommitter)" json:"authored_by_committer"`
ChangedFiles int `graphql:"changedFiles: changedFilesIfAvailable @include(if:$includeCommitChangedFiles)" json:"changed_files"`
Expand Down Expand Up @@ -45,3 +52,22 @@ type Commit struct {
type CommitStatus struct {
State string `json:"state"`
}

type BaseCommit struct {
BasicCommit
Additions int `json:"additions"`
AuthoredByCommitter bool `json:"authored_by_committer"`
ChangedFiles int `graphql:"changedFiles: changedFilesIfAvailable" json:"changed_files"`
CommittedViaWeb bool `json:"committed_via_web"`
CommitUrl string `json:"commit_url"`
Deletions int `json:"deletions"`
Signature Signature `json:"signature"`
TarballUrl string `json:"tarball_url"`
TreeUrl string `json:"tree_url"`
CanSubscribe bool `graphql:"canSubscribe: viewerCanSubscribe" json:"can_subscribe"`
Subscription string `graphql:"subscription: viewerSubscription" json:"subscription"`
ZipballUrl string `json:"zipball_url"`
MessageHeadline string `json:"message_headline"`
Status CommitStatus `json:"status"`
NodeId string `graphql:"nodeId:id" json:"node_id"`
}
2 changes: 1 addition & 1 deletion github/models/community_profile.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package models

type CommunityProfile struct {
LicenseInfo License `graphql:"licenseInfo @include(if:$includeCPLicense)" json:"license_info"`
LicenseInfo BaseLicense `graphql:"licenseInfo @include(if:$includeCPLicense)" json:"license_info"`
CodeOfConduct RepositoryCodeOfConduct `graphql:"codeOfConduct @include(if:$includeCPCodeOfConduct)" json:"code_of_conduct"`
IssueTemplates []IssueTemplate `graphql:"issueTemplates @include(if:$includeCPIssueTemplates)" json:"issue_templates"`
PullRequestTemplates []PullRequestTemplate `graphql:"pullRequestTemplates @include(if:$includeCPPullRequestTemplates)" json:"pull_request_templates"`
Expand Down
2 changes: 1 addition & 1 deletion github/models/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type Issue struct {
} `graphql:"repo: repository" json:"repo"`
Assignees struct {
TotalCount int
Nodes []User
Nodes []BaseUser
} `graphql:"assignees(first: 10) @include(if:$includeIssueAssignees)" json:"assignees"`
}

Expand Down
27 changes: 22 additions & 5 deletions github/models/license.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package models

type License struct {
BasicLicense
Key string `json:"key"`
Name string `graphql:"name @include(if:$includeLicenseName)" json:"name"`
Nickname string `graphql:"nickname @include(if:$includeLicenseNickname)" json:"nickname"`
SpdxId string `graphql:"spdxId @include(if:$includeLicenseSpdxId)" json:"spdx_id"`
Url string `graphql:"url @include(if:$includeLicenseUrl)" json:"url"`
Body string `json:"body"`
Conditions []LicenseRule `graphql:"conditions @include(if:$includeLicenseConditions)" json:"conditions"`
Description string `graphql:"description @include(if:$includeLicenseDescription)" json:"description"`
Expand All @@ -15,10 +19,23 @@ type License struct {

type BasicLicense struct {
Key string `json:"key"`
Name string `graphql:"name @include(if:$includeLicenseName)" json:"name"`
Nickname string `graphql:"nickname @include(if:$includeLicenseNickname)" json:"nickname"`
SpdxId string `graphql:"spdxId @include(if:$includeLicenseSpdxId)" json:"spdx_id"`
Url string `graphql:"url @include(if:$includeLicenseUrl)" json:"url"`
Name string `json:"name"`
Nickname string `json:"nickname"`
SpdxId string `json:"spdx_id"`
Url string `json:"url"`
}

type BaseLicense struct {
BasicLicense
Body string `json:"body"`
Conditions []LicenseRule `json:"conditions"`
Description string `json:"description"`
Featured bool `json:"featured"`
Hidden bool `json:"hidden"`
Implementation string `json:"implementation"`
Limitations []LicenseRule `json:"limitations"`
Permissions []LicenseRule `json:"permissions"`
PseudoLicense bool `json:"pseudo_license"`
}

type LicenseRule struct {
Expand Down
5 changes: 3 additions & 2 deletions github/models/misc.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package models

import (
"github.com/shurcooL/githubv4"
"time"

"github.com/shurcooL/githubv4"
)

type NullableTime struct {
Expand Down Expand Up @@ -34,7 +35,7 @@ type BasicRef struct {

type BasicRefWithBranchProtectionRule struct {
BasicRef
BranchProtectionRule *BranchProtectionRule `json:"branch_protection_rule,omitempty"`
BranchProtectionRule *BaseBranchProtectionRule `json:"branch_protection_rule,omitempty"`
}

type Language struct {
Expand Down
2 changes: 1 addition & 1 deletion github/models/pull_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type PullRequest struct {
} `graphql:"labels(first: 100) @include(if:$includePRLabels)" json:"labels"`
Assignees struct {
TotalCount int
Nodes []User
Nodes []BaseUser
} `graphql:"assignees(first: 10) @include(if:$includePRAssignees)" json:"assignees"`

// ClosingIssueReferences [pageable]
Expand Down
11 changes: 10 additions & 1 deletion github/models/rate_limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@ package models
import "time"

// RateLimit information
type RateLimit struct {
type BaseRateLimit struct {
Remaining int `graphql:"remaining @include(if:$includeRLRemaining)" json:"remaining"`
Used int `graphql:"used @include(if:$includeRLUsed)" json:"used"`
Cost int `graphql:"cost @include(if:$includeRLCost)" json:"cost"`
Limit int `graphql:"limit @include(if:$includeRLLimit)" json:"limit"`
ResetAt time.Time `graphql:"resetAt @include(if:$includeRLResetAt)" json:"reset_at"`
NodeCount int `graphql:"remaining @include(if:$includeRLNodeCount)" json:"node_count"`
}

type RateLimit struct {
Remaining int
Used int
Cost int
Limit int
ResetAt time.Time
NodeCount int
}
4 changes: 2 additions & 2 deletions github/models/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "time"
type TagWithCommits struct {
Name string `graphql:"name @include(if:$includeTagName)" json:"name"`
Target struct {
Commit Commit `graphql:"... on Commit"`
Commit BaseCommit `graphql:"... on Commit"`
Tag struct {
Message string
Tagger struct {
Expand All @@ -16,7 +16,7 @@ type TagWithCommits struct {
}
}
Target struct {
Commit Commit `graphql:"... on Commit"`
Commit BaseCommit `graphql:"... on Commit"`
}
} `graphql:"... on Tag"`
} `graphql:"target @include(if:$includeTagTarget)" json:"target"`
Expand Down
36 changes: 36 additions & 0 deletions github/models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,39 @@ type userStatus struct {
Message string `json:"message,omitempty"`
IndicatesLimitedAvailability bool `json:"indicates_limited_availability,omitempty"`
}

type BaseUser struct {
BasicUser
AnyPinnableItems bool `json:"any_pinnable_items"`
AvatarUrl string `json:"avatar_url"`
Bio string `json:"bio"`
Company string `json:"company"`
EstimatedNextSponsorsPayoutInCents int `json:"estimated_next_sponsors_payout_in_cents"`
HasSponsorsListing bool `json:"has_sponsors_listing"`
InteractionAbility RepositoryInteractionAbility `json:"interaction_ability,omitempty"`
IsBountyHunter bool `json:"is_bounty_hunter"`
IsCampusExpert bool `json:"is_campus_expert"`
IsDeveloperProgramMember bool `json:"is_developer_program_member"`
IsEmployee bool `json:"is_employee"`
IsFollowingYou bool `graphql:"isFollowingYou: isFollowingViewer" json:"is_following_you"`
IsGitHubStar bool `json:"is_github_star"`
IsHireable bool `json:"is_hireable"`
IsSiteAdmin bool `json:"is_site_admin"`
IsSponsoringYou bool `graphql:"isSponsoringYou: isSponsoringViewer" json:"is_sponsoring_you"`
IsYou bool `graphql:"isYou: isViewer" json:"is_you"`
Location string `json:"location"`
MonthlyEstimatedSponsorsIncomeInCents int `json:"monthly_estimated_sponsors_income_in_cents"`
PinnedItemsRemaining int `json:"pinned_items_remaining"`
ProjectsUrl string `json:"projects_url"`
Pronouns string `json:"pronouns"`
SponsorsListing SponsorsListing `json:"sponsors_listing,omitempty"`
Status userStatus `json:"status,omitempty"`
TwitterUsername string `json:"twitter_username"`
CanChangedPinnedItems bool `graphql:"canChangedPinnedItems: viewerCanChangePinnedItems" json:"can_changed_pinned_items"`
CanCreateProjects bool `graphql:"canCreateProjects: viewerCanCreateProjects" json:"can_create_projects"`
CanFollow bool `graphql:"canFollow: viewerCanFollow" json:"can_follow"`
CanSponsor bool `graphql:"canSponsor: viewerCanSponsor" json:"can_sponsor"`
IsFollowing bool `graphql:"isFollowing: viewerIsFollowing" json:"is_following"`
IsSponsoring bool `graphql:"isSponsoring: viewerIsSponsoring" json:"is_sponsoring"`
WebsiteUrl string `json:"website_url"`
}
6 changes: 3 additions & 3 deletions github/rate_limit_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
)

func extractRateLimitFromHydrateItem(h *plugin.HydrateData) (models.RateLimit, error) {
if rl, ok := h.Item.(models.RateLimit); ok {
func extractRateLimitFromHydrateItem(h *plugin.HydrateData) (models.BaseRateLimit, error) {
if rl, ok := h.Item.(models.BaseRateLimit); ok {
return rl, nil
} else {
return models.RateLimit{}, fmt.Errorf("unable to parse hydrate item %v as an RateLimit", h.Item)
return models.BaseRateLimit{}, fmt.Errorf("unable to parse hydrate item %v as an RateLimit", h.Item)
}
}

Expand Down
3 changes: 1 addition & 2 deletions github/table_github_rate_limit_graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@ func tableGitHubRateLimitGraphQL() *plugin.Table {

func listGitHubRateLimitGraphQL(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
var query struct {
RateLimit models.RateLimit
RateLimit models.BaseRateLimit
}

variables := map[string]interface{}{}
appendRateLimitColumnIncludes(&variables, d.QueryContext.Columns)

client := connectV4(ctx, d)
err := client.Query(ctx, &query, variables)
plugin.Logger(ctx).Debug(rateLimitLogString("github_rate_limit_graphql", &query.RateLimit))
if err != nil {
plugin.Logger(ctx).Error("github_rate_limit_graphql", "api_error", err)
if strings.Contains(err.Error(), "Could not resolve to an Organization with the login of") {
Expand Down
2 changes: 1 addition & 1 deletion github/table_github_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ type tagRow struct {
TaggerName string
TaggerLogin string
Message string
Commit models.Commit
Commit models.BaseCommit
}

// mapTagRow is required as commit information may reside at upper target level or embedded into the tags target level.
Expand Down

0 comments on commit 7a7c94e

Please sign in to comment.