8000 Split up Repository object by sigmavirus24 · Pull Request #681 · sigmavirus24/github3.py · GitHub
[go: up one dir, main page]

Skip to content

Split up Repository object #681

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

Merged
merged 36 commits into from
Dec 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
9a166b4
Split up Repository object
sigmavirus24 Feb 4, 2017
b4211b0
Fix up github3.repos.repo docstrings
sigmavirus24 Feb 5, 2017
f732540
Simplify initialization of StarredRepository
sigmavirus24 Feb 5, 2017
ac20a46
Start documenting repo attributes
sigmavirus24 Feb 5, 2017
199ba28
Finish documenting attributes
sigmavirus24 Feb 5, 2017
80707b4
Add attribute docs to StarredRepository
sigmavirus24 Feb 6, 2017
8c6035f
Add ShortRepository to `github3.repos`
sigmavirus24 Feb 7, 2017
d6b80a9
Convert CodeSearchResult to ShortRepository
sigmavirus24 Feb 7, 2017
d0f1e68
Re-record cassettes to account for newer attributes
sigmavirus24 Feb 7, 2017
3a62f69
Convert RepositorySearchResult to ShortRepository
sigmavirus24 Feb 7, 2017
f9bf53a
Fix up usage of Repository and ShortRepository
sigmavirus24 Feb 11, 2017
aec247e
Fix-up integration tests
sigmavirus24 Feb 11, 2017
bb25158
Rerecord cassettes involving repositories
sigmavirus24 Feb 11, 2017
cf5c0d7
Re-record more cassettes
sigmavirus24 Feb 12, 2017
dc337de
Fix-up a few bugs in our code
sigmavirus24 Feb 12, 2017
cc4b765
Re-record some Repository integration tests
sigmavirus24 Feb 26, 2017
c07889d
Add in progress from a few months ago
sigmavirus24 Dec 15, 2017
2e3226d
Re-record Repository.hooks test
sigmavirus24 Dec 15, 2017
1f64f3a
Re-record and re-write Repository.key* tests
sigmavirus24 Dec 15, 2017
9b1cb50
Re-record and re-write Repository.merge test
sigmavirus24 Dec 16, 2017
6b7862f
Re-record and re-write Repository.notifications test
sigmavirus24 Dec 16, 2017
05e33ea
Re-record test cassettes for Repository methods
sigmavirus24 Dec 16, 2017
ad6e4ed
Re-write and re-record Repository.subscription test
sigmavirus24 Dec 16, 2017
ec67974
Re-record Repository.teams test
sigmavirus24 Dec 18, 2017
0fe2ba0
Fix User.organization_events test and AuthenticatedUser
sigmavirus24 Dec 21, 2017
0f9a1ea
Fix tests of organization_events and received_events
sigmavirus24 Dec 21, 2017
f978b7b
Fix up last of cassettes not using ShortRepository
sigmavirus24 Dec 21, 2017
c903cdf
Replace out-dated example JSON bodies
sigmavirus24 Dec 21, 2017
4c4bd45
Give test_delete_subscription the correct name
sigmavirus24 Dec 21, 2017
d56c32f
Adjust example URL to example data updated earlier
sigmavirus24 Dec 21, 2017
135a994
Fix ReviewComment.reply test
sigmavirus24 Dec 22, 2017
4b210a7
Merge remote-tracking branch 'origin/develop' into split-up-repository
sigmavirus24 Dec 22, 2017
5042881
Fix up last few things post merge
sigmavirus24 Dec 22, 2017
4a0205d
Correct flake8 violation
sigmavirus24 Dec 22, 2017
3f5b17a
Re-record cassettes after removing xfail decorators
sigmavirus24 Dec 22, 2017
2c46fda
Change Requests requirement and remove unused imports
sigmavirus24 Dec 22, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ build/
*.egg
.env
.ipynb_checkpoints
.cache/
.cache/
tests/id_rsa
8 changes: 0 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ env:

matrix:
include:
- python: 2.7
env: TOXENV=py27 REQUESTS_VERSION="===2.0.1"
- python: 3.4
env: TOXENV=py34 REQUESTS_VERSION="===2.0.1"
- python: 3.5
env: TOXENV=py35 REQUESTS_VERSION="===2.0.1"
- python: pypy
env: TOXENV=pypy REQUESTS_VERSION="===2.0.1"
- python: 2.7
env: TOXENV=py27 REQUESTS_VERSION=""
- python: 3.4
Expand Down
46 changes: 26 additions & 20 deletions github3/github.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from .orgs import Membership, ShortOrganization, Organization, Team
from .projects import Project, ProjectCard, ProjectColumn
from .pulls import PullRequest
from .repos.repo import Repository, repo_issue_params
from .repos import repo
from .search import (CodeSearchResult, IssueSearchResult,
RepositorySearchResult, UserSearchResult)
from .structs import SearchIterator
Expand Down Expand Up @@ -126,10 +126,10 @@ def all_repositories(self, number=-1, since=None, etag=None,
endpoint
:param int per_page: (optional), number of repositories to list per
request
:returns: generator of :class:`Repository <github3.repos.Repository>`
:returns: generator of :class:`~github3.repos.ShortRepository`
"""
url = self._build_url('repositories')
return self._iter(int(number), url, Repository,
return self._iter(int(number), url, repo.ShortRepository,
params={'since': since, 'per_page': per_page},
etag=etag)

Expand Down Expand Up @@ -344,7 +344,7 @@ def create_repository(self, name, description='', homepage='',
'auto_init': auto_init,
'gitignore_template': gitignore_template}
json = self._json(self._post(url, data=data), 201)
return self._instance_or_null(Repository, json)
return self._instance_or_null(repo.Repository, json)

@requires_auth
def delete_email_addresses(self, addresses=[]):
Expand Down Expand Up @@ -696,8 +696,10 @@ def issues_on(self, username, repository, milestone=None, state=None,
if username and repository:
url = self._build_url('repos', username, repository, 'issues')

params = repo_issue_params(milestone, state, assignee, mentioned,
labels, sort, direction, since)
params = repo.repo_issue_params(
milestone, state, assignee, mentioned,
labels, sort, direction, since,
)
return self._iter(int(number), url, ShortIssue, params=params,
etag=etag)
return iter([])
Expand Down Expand Up @@ -1119,7 +1121,7 @@ def repositories(self, type=None, sort=None, direction=None, number=-1,
Default: -1 returns all repositories
:param str etag: (optional), ETag from a previous request to the same
endpoint
:returns: generator of :class:`Repository <github3.repos.Repository>`
:returns: generator of :class:`~github3.repos.ShortRepository`
objects
"""
url = self._build_url('user', 'repos')
Expand All @@ -1132,7 +1134,8 @@ def repositories(self, type=None, sort=None, direction=None, number=-1,
if direction in ('asc', 'desc'):
params.update(direction=direction)

return self._iter(int(number), url, Repository, params, etag)
return self._iter(int(number), url, repo.ShortRepository, params,
etag)

def repositories_by(self, username, type=None, sort=None, direction=None,
number=-1, etag=None):
Expand All @@ -1154,7 +1157,7 @@ def repositories_by(self, username, type=None, sort=None, direction=None,
Default: -1 returns all repositories
:param str etag: (optional), ETag from a previous request to the same
endpoint
:returns: generator of :class:`Repository <github3.repos.Repository>`
:returns: generator of :class:`~github3.repos.ShortRepository`
objects
"""
url = self._build_url('users', username, 'repos')
Expand All @@ -1167,7 +1170,8 @@ def repositories_by(self, username, type=None, sort=None, direction=None,
if direction in ('asc', 'desc'):
params.update(direction=direction)

return self._iter(int(number), url, Repository, params, etag)
return self._iter(int(number), url, repo.ShortRepository, params,
etag)

def repository(self, owner, repository):
"""Returns a Repository object for the specified combination of
Expand All @@ -1182,7 +1186,7 @@ def repository(self, owner, repository):
url = self._build_url('repos', owner, repository)
json = self._json(self._get(url, headers=License.CUSTOM_HEADERS),
200)
return self._instance_or_null(Repository, json)
return self._instance_or_null(repo.Repository, json)

def repository_with_id(self, number):
"""Returns the Repository with id ``number``.
Expand All @@ -1195,7 +1199,7 @@ def repository_with_id(self, number):
if number > 0:
url = self._build_url('repositories', str(number))
json = self._json(self._get(url), 200)
return self._instance_or_null(Repository, json)
return self._instance_or_null(repo.Repository, json)

@requires_app_credentials
def revoke_authorization(self, access_token):
Expand Down Expand Up @@ -1524,12 +1528,13 @@ def starred(self, sort=None, direction=None, number=-1, etag=None):
Default: -1 returns all repositories
:param str etag: (optional), ETag from a previous request to the same
endpoint
:returns: generator of :class:`Repository <github3.repos.Repository>`
:returns: generator of :class:`~github3.repos.ShortRepository>`
"""
params = {'sort': sort, 'direction': direction}
self._remove_none(params)
url = self._build_url('user', 'starred')
return self._iter(int(number), url, Repository, params, etag)
return self._iter(int(number), url, repo.ShortRepository, params,
etag)

def starred_by(self, username, sort=None, direction=None, number=-1,
etag=None):
Expand All @@ -1549,12 +1554,13 @@ def starred_by(self, username, sort=None, direction=None, number=-1,
Default: -1 returns all repositories
:param str etag: (optional), ETag from a previous request to the same
endpoint
:returns: generator of :class:`Repository <github3.repos.Repository>`
:returns: generator of :class:`~github3.repos.ShortRepository`
"""
params = {'sort': sort, 'direction': direction}
self._remove_none(params)
url = self._build_url('users', str(username), 'starred')
return self._iter(int(number), url, Repository, params, etag)
return self._iter(int(number), url, repo.ShortRepository, params,
etag)

@requires_auth
def subscriptions(self, number=-1, etag=None):
Expand All @@ -1564,10 +1570,10 @@ def subscriptions(self, number=-1, etag=None):
Default: -1 returns all repositories
:param str etag: (optional), ETag from a previous request to the same
endpoint
:returns: generator of :class:`Repository <github3.repos.Repository>`
:returns: generator of :class:`~github3.repos.ShortRepository`
"""
url = self._build_url('user', 'subscriptions')
return self._iter(int(number), url, Repository, etag=etag)
return self._iter(int(number), url, repo.ShortRepository, etag=etag)

def subscriptions_for(self, username, number=-1, etag=None):
"""Iterate over repositories subscribed to by ``username``.
Expand All @@ -1578,10 +1584,10 @@ def subscriptions_for(self, username, number=-1, etag=None):
Default: -1 returns all repositories
:param str etag: (optional), ETag from a previous request to the same
endpoint
:returns: generator of :class:`Repository <github3.repos.Repository>`
:returns: generator of :class:`~github3.repos.ShortRepository`
"""
url = self._build_url('users', str(username), 'subscriptions')
return self._iter(int(number), url, Repository, etag=etag)
return self._iter(int(number), url, repo.ShortRepository, etag=etag)

@requires_auth
def unfollow(self, username):
Expand Down
4 changes: 2 additions & 2 deletions github3/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ def _update_attributes(self, notif):
#: Thread information
self.thread = self._get_attribute(notif, 'thread', {})

from .repos import Repository
from . import repos
#: Repository the comment was made on
self.repository = self._class_attribute(
notif, 'repository', Repository, self
notif, 'repository', repos.ShortRepository, self
)

#: When the thread was last updated
Expand Down
21 changes: 16 additions & 5 deletions github3/pulls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class PullDestination(models.GitHubCore):

def __init__(self, dest, direction):
super(PullDestination, self).__init__(dest)
from .repos.repo import Repository
from .repos.repo import ShortRepository
#: Direction of the merge with respect to this destination
self.direction = direction
#: Full reference string of the object
Expand All @@ -44,7 +44,7 @@ def __init__(self, dest, direction):
if dest.get('repo'):
self._repo_name = dest['repo'].get('name')
self._repo_owner = dest['repo']['owner'].get('login')
self.repository = Repository(dest.get('repo'), self)
self.repository = ShortRepository(dest.get('repo'), self)
self.repo = (self._repo_owner, self._repo_name)

def _repr(self):
Expand Down Expand Up @@ -367,15 +367,26 @@ def reviews(self, number=-1, etag=None):
return self._iter(int(number), url, PullReview, etag=etag)

@requires_auth
def update(self, title=None, body=None, state=None):
def update(self, title=None, body=None, state=None, base=None,
maintainer_can_modify=None):
"""Update this pull request.

:param str title: (optional), title of the pull
:param str body: (optional), body of the pull request
:param str state: (optional), ('open', 'closed')
:param str base: (optional), Name of the branch on the current
repository that the changes should be pulled into.
:param bool maintainer_can_modify: (optional), Indicates whether
a maintainer is allowed to modify the pull request or not.
:returns: bool
"""
data = {'title': title, 'body': body, 'state': state}
data = {
'title': title,
'body': body,
'state': state,
'base': base,
'maintainer_can_modify': maintainer_can_modify,
}
json = None
self._remove_none(data)

Expand Down Expand Up @@ -552,7 +563,7 @@ def reply(self, body):
"""
url = self._build_url('comments', base_url=self.pull_request_url)
index = self._api.rfind('/') + 1
in_reply_to = self._api[index:]
in_reply_to = int(self._api[index:])
json = self._json(self._post(url, data={
'body': body, 'in_reply_to': in_reply_to
}), 201)
Expand Down
7 changes: 6 additions & 1 deletion github3/repos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
"""

from .repo import Repository
from .repo import ShortRepository
from .repo import StarredRepository

__all__ = ('Repository', 'StarredRepository')
__all__ = (
'Repository',
'ShortRepository',
'StarredRepository',
)
Loading
0