data_importer/lib/github_api/owner_repos.rb

69 lines
No EOL
1.4 KiB
Ruby

require '/data_importer/lib/github_api/github_api.rb'
module GithubApi
class OwnerRepos
OwnerReposQuery = GithubApi::Client.parse <<-'GRAPHQL'
query($owner: String!, $cursor: String) {
repositoryOwner(login: $owner) {
repositories(
first: 100
ownerAffiliations: OWNER
privacy: PUBLIC
isFork: false
isLocked: false
orderBy: {field: NAME, direction: ASC}
after: $cursor
) {
totalCount
pageInfo {
hasNextPage
endCursor
}
nodes {
name
url
homepageUrl
mirrorUrl
openGraphImageUrl
resourcePath
description
descriptionHTML
shortDescriptionHTML
createdAt
pushedAt
updatedAt
forkCount
hasIssuesEnabled
hasProjectsEnabled
hasWikiEnabled
isArchived
isFork
isInOrganization
isLocked
isMirror
isPrivate
isTemplate
licenseInfo {
id
}
lockReason
usesCustomOpenGraphImage
visibility
}
}
}
}
GRAPHQL
def self.find(username)
response = GithubApi::Client.query(OwnerReposQuery, variables: { owner: username })
if response.errors.any?
raise QueryExecutionError.new(response.errors[:data].join(", "))
else
response.data.repository_owner.repositories.nodes.map(&:to_h)
end
end
end
end
class QueryExecutionError < StandardError; end