Skip to content

Commit

Permalink
Initial repository query functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
mschwager committed Sep 25, 2016
1 parent 7039968 commit d1050a5
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
32 changes: 31 additions & 1 deletion lib/gitem/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,37 @@ def repository_popularity(repository):


def repository(ghapi, *args, **kwargs):
pass
repository = kwargs['name']
owner = kwargs['owner']
verbose = kwargs['verbose']

repository_info = analytics.get_repository_information(
ghapi,
owner,
repository
)
repository_contributors = analytics.get_repository_contributors(
ghapi,
owner,
repository
)

for human_readable_name, api_info in repository_info.items():
leftpad_print(
"{}: {}".format(human_readable_name, api_info),
leftpad_length=0
)

leftpad_print("Contributors:", leftpad_length=0)

contributor_count = len(repository_contributors) if verbose else CONCISE_COUNT

for contributor in repository_contributors[:contributor_count]:
for human_readable_name, api_info in contributor.items():
leftpad_print(
"{}: {}".format(human_readable_name, api_info),
leftpad_length=2
)


def user(ghapi, *args, **kwargs):
Expand Down
29 changes: 29 additions & 0 deletions lib/gitem/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,35 @@ def get_organization_members(ghapi, organization):
return human_readable_name_to_api_info


def get_repository_information(ghapi, owner, repository):
repository_info, _ = ghapi.get_public_repository(
owner,
repository
)

# Order it so we get the same keys first every time
api_name_to_human_readable_name = collections.OrderedDict([
('name', 'Repository Name'),
('description', 'Description'),
('homepage', 'Homepage'),
('html_url', 'Github URL'),
('created_at', 'Created'),
('updated_at', 'Last Updated'),
('pushed_at', 'Last Pushed'),
('language', 'Language'),
('forks_count', 'Forks'),
('stargazers_count', 'Stars'),
('watchers_count', 'Watchers'),
])

human_readable_name_to_api_info = {
human_readable_name: repository_info[api_name]
for api_name, human_readable_name in api_name_to_human_readable_name.items()
}

return human_readable_name_to_api_info


def get_repository_contributors(ghapi, owner, repository):
paged_repository_contributors = ghapi.get_repository_contributors(
owner,
Expand Down
14 changes: 14 additions & 0 deletions lib/gitem/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,20 @@ def get_organizations_public_members(self, organization):

return result

def get_public_repository(self, owner, repository):
"""
Return public information associated with a repository
https://developer.github.com/v3/repos/#get
"""
method = "GET"
endpoint = "/repos/{}/{}".format(owner, repository)
params = {}

result = self.json_call(method, endpoint, params)

return result

def get_repository_contributors(self, owner, repository, anon=None):
"""
Return contributor information associated with a given repository
Expand Down

0 comments on commit d1050a5

Please sign in to comment.