Skip to content

Commit

Permalink
Merge pull request #42 from src-d/tidy_github
Browse files Browse the repository at this point in the history
Tidy github provider
  • Loading branch information
smacker authored Oct 14, 2019
2 parents 7d14c5c + 706093c commit 0a799e2
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 126 deletions.
5 changes: 0 additions & 5 deletions database/migrations/000001_init.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,18 @@ CREATE TABLE IF NOT EXISTS organizations_versioned (
versions integer ARRAY,

avatar_url text,
billing_email text,
collaborators bigint,
created_at timestamptz,
description text,
email text,
htmlurl text,
id bigint,
location text,
login text,
name text,
node_id text,
owned_private_repos bigint,
public_repos bigint,
total_private_repos bigint,
two_factor_requirement_enabled boolean,
updated_at timestamptz
);

Expand Down Expand Up @@ -47,7 +44,6 @@ CREATE TABLE IF NOT EXISTS users_versioned (
private_gists bigint,
public_gists bigint,
public_repos bigint,
site_admin boolean,
total_private_repos bigint,
updated_at timestamptz
);
Expand Down Expand Up @@ -76,7 +72,6 @@ CREATE TABLE IF NOT EXISTS repositories_versioned (
htmlurl text,
id bigint,
language text,
mirror_url text,
name text,
node_id text,
open_issues_count bigint,
Expand Down
30 changes: 15 additions & 15 deletions github/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type storer interface {
SavePullRequest(ctx context.Context, repositoryOwner, repositoryName string, pr *graphql.PullRequest, assignees []string, labels []string) error
SavePullRequestComment(ctx context.Context, repositoryOwner, repositoryName string, pullRequestNumber int, comment *graphql.IssueComment) error
SavePullRequestReview(ctx context.Context, repositoryOwner, repositoryName string, pullRequestNumber int, review *graphql.PullRequestReview) error
SavePullRequestReviewComment(ctx context.Context, repositoryOwner, repositoryName string, pullRequestNumber int, pullRequestReviewId int, comment *graphql.PullRequestReviewComment) error
SavePullRequestReviewComment(ctx context.Context, repositoryOwner, repositoryName string, pullRequestNumber int, pullRequestReviewID int, comment *graphql.PullRequestReviewComment) error

Begin() error
Commit() error
Expand Down Expand Up @@ -197,7 +197,7 @@ func (d Downloader) downloadTopics(ctx context.Context, repository *graphql.Repo
}

variables := map[string]interface{}{
"id": githubv4.ID(repository.Id),
"id": githubv4.ID(repository.ID),

"repositoryTopicsPage": githubv4.Int(repositoryTopicsPage),
"repositoryTopicsCursor": (*githubv4.String)(nil),
Expand Down Expand Up @@ -269,7 +269,7 @@ func (d Downloader) downloadIssues(ctx context.Context, owner string, name strin
}

variables := map[string]interface{}{
"id": githubv4.ID(repository.Id),
"id": githubv4.ID(repository.ID),

"assigneesPage": githubv4.Int(assigneesPage),
"issueCommentsPage": githubv4.Int(issueCommentsPage),
Expand Down Expand Up @@ -331,7 +331,7 @@ func (d Downloader) downloadIssueAssignees(ctx context.Context, issue *graphql.I
}

variables := map[string]interface{}{
"id": githubv4.ID(issue.Id),
"id": githubv4.ID(issue.ID),

"assigneesPage": githubv4.Int(assigneesPage),
"assigneesCursor": (*githubv4.String)(nil),
Expand Down Expand Up @@ -378,7 +378,7 @@ func (d Downloader) downloadIssueLabels(ctx context.Context, issue *graphql.Issu
}

variables := map[string]interface{}{
"id": githubv4.ID(issue.Id),
"id": githubv4.ID(issue.ID),

"labelsPage": githubv4.Int(labelsPage),
"labelsCursor": (*githubv4.String)(nil),
Expand Down Expand Up @@ -426,7 +426,7 @@ func (d Downloader) downloadIssueComments(ctx context.Context, owner string, nam
}

variables := map[string]interface{}{
"id": githubv4.ID(issue.Id),
"id": githubv4.ID(issue.ID),

"issueCommentsPage": githubv4.Int(issueCommentsPage),
"issueCommentsCursor": (*githubv4.String)(nil),
Expand Down Expand Up @@ -510,7 +510,7 @@ func (d Downloader) downloadPullRequests(ctx context.Context, owner string, name
}

variables := map[string]interface{}{
"id": githubv4.ID(repository.Id),
"id": githubv4.ID(repository.ID),

"assigneesPage": githubv4.Int(assigneesPage),
"issueCommentsPage": githubv4.Int(issueCommentsPage),
Expand Down Expand Up @@ -576,7 +576,7 @@ func (d Downloader) downloadPullRequestAssignees(ctx context.Context, pr *graphq
}

variables := map[string]interface{}{
"id": githubv4.ID(pr.Id),
"id": githubv4.ID(pr.ID),

"assigneesPage": githubv4.Int(assigneesPage),
"assigneesCursor": (*githubv4.String)(nil),
Expand Down Expand Up @@ -623,7 +623,7 @@ func (d Downloader) downloadPullRequestLabels(ctx context.Context, pr *graphql.P
}

variables := map[string]interface{}{
"id": githubv4.ID(pr.Id),
"id": githubv4.ID(pr.ID),

"labelsPage": githubv4.Int(assigneesPage),
"labelsCursor": (*githubv4.String)(nil),
Expand Down Expand Up @@ -671,7 +671,7 @@ func (d Downloader) downloadPullRequestComments(ctx context.Context, owner strin
}

variables := map[string]interface{}{
"id": githubv4.ID(pr.Id),
"id": githubv4.ID(pr.ID),

"issueCommentsPage": githubv4.Int(issueCommentsPage),
"issueCommentsCursor": (*githubv4.String)(nil),
Expand Down Expand Up @@ -730,7 +730,7 @@ func (d Downloader) downloadPullRequestReviews(ctx context.Context, owner string
}

variables := map[string]interface{}{
"id": githubv4.ID(pr.Id),
"id": githubv4.ID(pr.ID),

"pullRequestReviewCommentsPage": githubv4.Int(pullRequestReviewCommentsPage),
"pullRequestReviewsPage": githubv4.Int(pullRequestReviewsPage),
Expand Down Expand Up @@ -776,11 +776,11 @@ func (d Downloader) downloadPullRequestReviews(ctx context.Context, owner string

func (d Downloader) downloadReviewComments(ctx context.Context, repositoryOwner, repositoryName string, pullRequestNumber int, review *graphql.PullRequestReview) error {
process := func(comment *graphql.PullRequestReviewComment) error {
err := d.storer.SavePullRequestReviewComment(ctx, repositoryOwner, repositoryName, pullRequestNumber, review.DatabaseId, comment)
err := d.storer.SavePullRequestReviewComment(ctx, repositoryOwner, repositoryName, pullRequestNumber, review.DatabaseID, comment)
if err != nil {
return fmt.Errorf(
"failed to save PullRequestReviewComment for PR #%v, review ID %v: %v",
pullRequestNumber, review.Id, err)
pullRequestNumber, review.ID, err)
}

return nil
Expand All @@ -795,7 +795,7 @@ func (d Downloader) downloadReviewComments(ctx context.Context, repositoryOwner,
}

variables := map[string]interface{}{
"id": githubv4.ID(review.Id),
"id": githubv4.ID(review.ID),

"pullRequestReviewCommentsPage": githubv4.Int(pullRequestReviewCommentsPage),
"pullRequestReviewCommentsCursor": (*githubv4.String)(nil),
Expand All @@ -820,7 +820,7 @@ func (d Downloader) downloadReviewComments(ctx context.Context, repositoryOwner,
if err != nil {
return fmt.Errorf(
"failed to query PR review comments for PR #%v, review ID %v: %v",
pullRequestNumber, review.Id, err)
pullRequestNumber, review.ID, err)
}

for _, comment := range q.Node.PullRequestReview.Comments.Nodes {
Expand Down
4 changes: 2 additions & 2 deletions github/downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func testOnlineRepo(t *testing.T, oracle RepositoryTest, d *Downloader, storer *
require := require.New(t) // Make a new require object for the specified test, so no need to pass it around
require.Nil(err)
// Sample some properties that will not change, no topics available in git-fixtures
require.Equal(oracle.URL, storer.Repository.Url)
require.Equal(oracle.URL, storer.Repository.URL)
require.Equal(oracle.CreatedAt, storer.Repository.CreatedAt.String())
require.Equal(oracle.IsPrivate, storer.Repository.IsPrivate)
require.Equal(oracle.IsArchived, storer.Repository.IsArchived)
Expand Down Expand Up @@ -125,7 +125,7 @@ func testOnlineOrg(t *testing.T, oracle OrganizationTest, d *Downloader, storer
require.Nil(err, "DownloadOrganization(%s) failed", oracle.Org)
// Sample some properties that will not change, no topics available in git-fixtures
require.Equal(oracle.Org, storer.Organization.Name)
require.Equal(oracle.URL, storer.Organization.Url)
require.Equal(oracle.URL, storer.Organization.URL)
require.Equal(oracle.CreatedAt, storer.Organization.CreatedAt.String())
require.Equal(oracle.PublicRepos, storer.Organization.PublicRepos.TotalCount)
require.Equal(oracle.TotalPrivateRepos, storer.Organization.TotalPrivateRepos.TotalCount)
Expand Down
79 changes: 35 additions & 44 deletions github/graphql/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,15 @@ type Organization struct {
// OrganizationFields defines the fields for Organization
// https://developer.github.com/v4/object/organization/
type OrganizationFields struct {
AvatarUrl string // avatar_url text,
// TODO: requires admin:org scope
//OrganizationBillingEmail string // billing_email text,
AvatarURL string // avatar_url text,
CreatedAt time.Time // created_at timestamptz,
Description string // description text,
Email string // email text,
Url string // htmlurl text,
DatabaseId int // id bigint,
Location string // location text,
URL string // htmlurl text,
DatabaseID int // id bigint,
Login string // login text,
Name string // name text,
Id string // node_id text,
ID string // node_id text,
OwnedPrivateRepos struct {
TotalCount int // owned_private_repos bigint,
} `graphql:"owned_private_repos: repositories(privacy:PRIVATE, ownerAffiliations:OWNER)"`
Expand All @@ -44,8 +41,6 @@ type OrganizationFields struct {
TotalPrivateRepos struct {
TotalCount int // total_private_repos bigint,
} `graphql:"total_private_repos: repositories(privacy:PRIVATE)"`
// TODO: requires admin:org scope
//RequiresTwoFactorAuthentication bool // two_factor_requirement_enabled boolean,
UpdatedAt string // updated_at timestamptz,
}

Expand All @@ -58,7 +53,7 @@ type OrganizationMemberConnection struct {
// UserExtended is the same type as User, but requesting more fields.
// Represents https://developer.github.com/v4/object/user/
type UserExtended struct {
AvatarUrl string // avatar_url text,
AvatarURL string // avatar_url text,
Bio string // bio text,
Company string // company text,
CreatedAt time.Time // created_at timestamptz,
Expand All @@ -71,12 +66,12 @@ type UserExtended struct {
TotalCount int // following bigint,
}
IsHireable bool // hireable boolean,
Url string // htmlurl text,
DatabaseId int // id bigint,
URL string // htmlurl text,
DatabaseID int // id bigint,
Location string // location text,
Login string // login text,
Name string // name text,
Id string // node_id text,
ID string // node_id text,
OwnedPrivateRepos struct {
TotalCount int // owned_private_repos bigint,
} `graphql:"owned_private_repos: repositories(privacy:PRIVATE, ownerAffiliations:OWNER)"`
Expand All @@ -92,7 +87,6 @@ type UserExtended struct {
PublicRepos struct {
TotalCount int // public_repos bigint,
} `graphql:"public_repos: repositories(privacy:PUBLIC)"`
IsSiteAdmin bool // site_admin boolean,
TotalPrivateRepos struct {
TotalCount int // total_private_repos bigint,
} `graphql:"total_private_repos: repositories(privacy:PRIVATE)"`
Expand All @@ -114,7 +108,6 @@ type RepositoryFields struct {
RebaseMergeAllowed bool // allow_rebase_merge boolean
SquashMergeAllowed bool // allow_squash_merge boolean
IsArchived bool // archived boolean
Url string // clone_url text
CreatedAt time.Time // created_at timestamptz
DefaultBranchRef struct {
Name string // default_branch text
Expand All @@ -126,32 +119,30 @@ type RepositoryFields struct {
NameWithOwner string // full_name text
HasIssuesEnabled bool // has_issues boolean
HasWikiEnabled bool // has_wiki boolean
HomepageUrl string // homepage text
//Url string // htmlurl text
DatabaseId int // id bigint,
PrimaryLanguage struct {
HomepageURL string // homepage text
URL string // htmlurl text
DatabaseID int // id bigint,
PrimaryLanguage struct {
Name string // language text
}
MirrorUrl string // mirror_url text
Name string // name text
Id string // node_id text
ID string // node_id text
OpenIssues struct {
TotalCount int // open_issues_count bigint
} `graphql:"openIssues: issues(states:[OPEN])"`
Owner struct {
Organization struct {
DatabaseId int // owner_id bigint NOT NULL,
DatabaseID int // owner_id bigint NOT NULL,
} `graphql:"... on Organization"`
User struct {
DatabaseId int // owner_id bigint NOT NULL,
DatabaseID int // owner_id bigint NOT NULL,
} `graphql:"... on User"`
Login string // owner_login text NOT NULL,
Typename string `graphql:"__typename"` // owner_type text NOT NULL
}

IsPrivate bool // private boolean
PushedAt time.Time // pushed_at timestamptz
SshUrl string // sshurl text
SSHURL string // sshurl text
Stargazers struct {
TotalCount int // stargazers_count bigint
}
Expand Down Expand Up @@ -193,8 +184,8 @@ type Issue struct {

// User represents https://developer.github.com/v4/object/user/
type User struct {
DatabaseId int
Id string
DatabaseID int
ID string
Login string
}

Expand All @@ -208,14 +199,14 @@ type IssueFields struct {
Body string // body text,
ClosedAt time.Time // closed_at timestamptz,
CreatedAt time.Time // created_at timestamptz,
Url string // htmlurl text,
DatabaseId int // id bigint,
URL string // htmlurl text,
DatabaseID int // id bigint,
Locked bool // locked boolean,
Milestone struct {
Id string // milestone_id text NOT NULL,
ID string // milestone_id text NOT NULL,
Title string // milestone_title text NOT NULL,
}
Id string // node_id text,
ID string // node_id text,
Number int // number bigint,
State string // state text,
Title string // title text,
Expand Down Expand Up @@ -252,9 +243,9 @@ type IssueComment struct {
AuthorAssociation string // author_association text,
Body string // body text,
CreatedAt time.Time // created_at timestamptz,
Url string // htmlurl text,
DatabaseId int // id bigint,
Id string // node_id text,
URL string // htmlurl text,
DatabaseID int // id bigint,
ID string // node_id text,
UpdatedAt string // updated_at timestamptz,
Author Actor // user_id bigint NOT NULL, user_login text NOT NULL,
}
Expand Down Expand Up @@ -305,8 +296,8 @@ type PullRequestFields struct {
CreatedAt time.Time // created_at timestamptz,
Deletions int // deletions bigint,
HeadRef Ref // head_*
Url string // htmlurl text,
DatabaseId int // id bigint,
URL string // htmlurl text,
DatabaseID int // id bigint,
MaintainerCanModify bool // maintainer_can_modify boolean,
MergeCommit struct {
Oid string // merge_commit_sha text,
Expand All @@ -316,10 +307,10 @@ type PullRequestFields struct {
MergedAt time.Time // merged_at timestamptz,
MergedBy Actor // merged_by_id bigint NOT NULL, merged_by_login text NOT NULL,
Milestone struct {
Id string // milestone_id text NOT NULL,
ID string // milestone_id text NOT NULL,
Title string // milestone_title text NOT NULL,
}
Id string // node_id text,
ID string // node_id text,
Number int // number bigint,
ReviewThreads struct {
TotalCount int // review_comments bigint,
Expand All @@ -345,9 +336,9 @@ type PullRequestReviewFields struct {
Commit struct {
Oid string // commit_id text,
}
Url string // htmlurl text,
DatabaseId int // id bigint,
Id string // node_id text,
URL string // htmlurl text,
DatabaseID int // id bigint,
ID string // node_id text,
State string // state text,
SubmittedAt time.Time // submitted_at timestamptz,
Author Actor // user_id bigint NOT NULL, user_login text NOT NULL,
Expand All @@ -368,10 +359,10 @@ type PullRequestReviewComment struct {
}
CreatedAt time.Time // created_at timestamptz,
DiffHunk string // diff_hunk text,
Url string // htmlurl text,
DatabaseId int // id bigint,
URL string // htmlurl text,
DatabaseID int // id bigint,
//in_reply_to string // in_reply_to bigint,
Id string // node_id text,
ID string // node_id text,
OriginalCommit struct {
Oid string // original_commit_id text,
}
Expand Down
Loading

0 comments on commit 0a799e2

Please sign in to comment.