Skip to content

Commit 552b18a

Browse files
authored
Merge pull request sigmavirus24#758 from sigmavirus24/archive-repository
Add ability to archive a repository
2 parents f757c5f + 3af6035 commit 552b18a

File tree

173 files changed

+428
-322
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+428
-322
lines changed

github3/events.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ def _follow(payload, session):
168168

169169

170170
def _forkev(payload, session):
171-
from .repos import Repository
171+
from .repos import ShortRepository
172172
if payload.get('forkee'):
173-
payload['forkee'] = Repository(payload['forkee'], session)
173+
payload['forkee'] = ShortRepository(payload['forkee'], session)
174174
return payload
175175

176176

@@ -233,11 +233,11 @@ def _release(payload, session):
233233

234234
def _team(payload, session):
235235
from .orgs import Team
236-
from .repos import Repository
236+
from .repos import ShortRepository
237237
if payload.get('team'):
238238
payload['team'] = Team(payload['team'], session)
239239
if payload.get('repo'):
240-
payload['repo'] = Repository(payload['repo'], session)
240+
payload['repo'] = ShortRepository(payload['repo'], session)
241241
if payload.get('sender'):
242242
payload['sender'] = EventUser(payload['sender'], session)
243243
return payload

github3/orgs.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from .decorators import requires_auth
1313
from .events import Event
1414
from .projects import Project
15-
from .repos import Repository
15+
from .repos import Repository, ShortRepository
1616

1717

1818
class Team(models.GitHubCore):
@@ -184,7 +184,7 @@ def repositories(self, number=-1, etag=None):
184184
"""
185185
headers = {'Accept': 'application/vnd.github.ironman-preview+json'}
186186
url = self._build_url('repos', base_url=self._api)
187-
return self._iter(int(number), url, Repository, etag=etag,
187+
return self._iter(int(number), url, ShortRepository, etag=etag,
188188
headers=headers)
189189

190190
@requires_auth
@@ -599,7 +599,7 @@ def repositories(self, type='', number=-1, etag=None):
599599
params = {}
600600
if type in ('all', 'public', 'member', 'private', 'forks', 'sources'):
601601
params['type'] = type
602-
return self._iter(int(number), url, Repository, params, etag)
602+
return self._iter(int(number), url, ShortRepository, params, etag)
603603

604604
@requires_auth
605605
def teams(self, number=-1, etag=None):

github3/repos/branch.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def latest_sha(self, differs_from=''):
5151
"""
5252
# If-None-Match returns 200 instead of 304 value does not have quotes
5353
headers = {
54-
'Accept': 'application/vnd.github.chitauri-preview+sha',
54+
'Accept': 'application/vnd.github.v3.sha',
5555
'If-None-Match': '"{0}"'.format(differs_from)
5656
}
5757
base = self._api.split('/branches', 1)[0]
@@ -73,10 +73,12 @@ def protect(self, enforcement=None, status_checks=None):
7373
status checks that must pass before merging. Use `None` or omit to
7474
use the already associated value.
7575
"""
76-
previous_values = self.protection['required_status_checks']
77-
if enforcement is None:
76+
previous_values = None
77+
if self.protection:
78+
previous_values = self.protection['required_status_checks']
79+
if enforcement is None and previous_values:
7880
enforcement = previous_values['enforcement_level']
79-
if status_checks is None:
81+
if status_checks is None and previous_values:
8082
status_checks = previous_values['contexts']
8183

8284
edit = {'protection': {'enabled': True, 'required_status_checks': {

github3/repos/repo.py

+40-56
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def add_collaborator(self, username):
128128
return False
129129
url = self._build_url('collaborators', str(username),
130130
base_url=self._api)
131-
return self._boolean(self._put(url), 204, 404)
131+
return self._boolean(self._put(url), 201, 404)
132132

133133
def archive(self, format, path='', ref='master'):
134134
"""Get the tarball or zipball archive for this repo at ref.
@@ -956,7 +956,7 @@ def directory_contents(self, directory_path, ref=None, return_as=list):
956956
@requires_auth
957957
def edit(self, name, description=None, homepage=None, private=None,
958958
has_issues=None, has_wiki=None, has_downloads=None,
959-
default_branch=None):
959+
default_branch=None, archived=None):
960960
"""Edit this repository.
961961
962962
:param str name: (required), name of the repository
@@ -980,12 +980,15 @@ def edit(self, name, description=None, homepage=None, private=None,
980980
:param str default_branch: (optional), If not ``None``, change the
981981
default branch for this repository. API default: ``None`` - leave
982982
value unchanged.
983+
:param bool archived: (optional), If not ``None``, toggle the archived
984+
attribute on the repository to control whether it is archived or
985+
not.
983986
:returns: bool -- True if successful, False otherwise
984987
"""
985988
edit = {'name': name, 'description': description, 'homepage': homepage,
986989
'private': private, 'has_issues': has_issues,
987990
'has_wiki': has_wiki, 'has_downloads': has_downloads,
988-
'default_branch': default_branch}
991+
'default_branch': default_branch, 'archived': archived}
989992
self._remove_none(edit)
990993
json = None
991994
if edit:
@@ -1029,13 +1032,13 @@ def forks(self, sort='', number=-1, etag=None):
10291032
returns all forks
10301033
:param str etag: (optional), ETag from a previous request to the same
10311034
endpoint
1032-
:returns: generator of :class:`Repository <Repository>`
1035+
:returns: generator of :class:`~github3.repos.repo.ShortRepository`
10331036
"""
10341037
url = self._build_url('forks', base_url=self._api)
10351038
params = {}
10361039
if sort in ('newest', 'oldest', 'watchers'):
10371040
params = {'sort': sort}
1038-
return self._iter(int(number), url, Repository, params, etag)
1041+
return self._iter(int(number), url, ShortRepository, params, etag)
10391042

10401043
def git_commit(self, sha):
10411044
"""Get a single (git) commit.
@@ -1172,7 +1175,7 @@ def import_issue(self, title, body, created_at, assignee=None,
11721175
data = self._post(url, data=issue,
11731176
headers=ImportedIssue.IMPORT_CUSTOM_HEADERS)
11741177

1175-
json = self._json(data, 200)
1178+
json = self._json(data, 202)
11761179
return self._instance_or_null(ImportedIssue, json)
11771180

11781181
def is_assignee(self, username):
@@ -2107,6 +2110,11 @@ class Repository(_Repository):
21072110
This object has all the same attributes as
21082111
:class:`~github3.repos.repo.ShortRepository` as well as:
21092112
2113+
.. attribute:: archived
2114+
2115+
A boolean attribute that describes whether the current repository has
2116+
been archived or not.
2117+
21102118
.. attribute:: clone_url
21112119
21122120
This is the URL that can be used to clone the repository via HTTPS,
@@ -2178,6 +2186,12 @@ class Repository(_Repository):
21782186
21792187
The number of issues currently open on the repository.
21802188
2189+
.. attribute:: parent
2190+
2191+
A representation of the parent repository as
2192+
:class:`~github3.repos.repo.ShortRepository`. If this Repository has
2193+
no parent then this will be ``None``.
2194+
21812195
.. attribute:: pushed_at
21822196
21832197
A parsed :class:`~datetime.datetime` object representing the date a
@@ -2187,6 +2201,12 @@ class Repository(_Repository):
21872201
21882202
The size of the repository.
21892203
2204+
.. attribute:: source
2205+
2206+
A representation of the source repository as
2207+
:class:`~github3.repos.repo.ShortRepository`. If this Repository has
2208+
no source then this will be ``None``.
2209+
21902210
.. attribute:: ssh_url
21912211
21922212
This is the URL that can be used to clone the repository via the SSH
@@ -2223,6 +2243,7 @@ class Repository(_Repository):
22232243

22242244
def _update_attributes(self, repo):
22252245
super(Repository, self)._update_attributes(repo)
2246+
self.archived = repo['archived']
22262247
self.clone_url = repo['clone_url']
22272248
self.created_at = self._strptime(repo['created_at'])
22282249
self.default_branch = repo['default_branch']
@@ -2232,68 +2253,31 @@ def _update_attributes(self, repo):
22322253
self.has_downloads = repo['has_downloads']
22332254
self.has_issues = repo['has_issues']
22342255
self.has_pages = repo['has_pages']
2256+
self.has_projects = repo['has_projects']
22352257
self.has_wiki = repo['has_wiki']
22362258
self.homepage = repo['homepage']
22372259
self.language = repo['language']
2260+
self.original_license = repo['license']
2261+
if self.original_license is not None:
2262+
self.original_license = License(self.original_license, self)
22382263
self.mirror_url = repo['mirror_url']
2264+
self.network_count = repo['network_count']
22392265
self.open_issues_count = repo['open_issues_count']
2266+
self.parent = repo.get('parent', None)
2267+
if self.parent is not None:
2268+
self.parent = ShortRepository(self.parent, self)
22402269
self.pushed_at = self._strptime(repo['pushed_at'])
22412270
self.size = repo['size']
2271+
self.source = repo.get('source', None)
2272+
if self.source is not None:
2273+
self.source = ShortRepository(self.source, self)
22422274
self.ssh_url = repo['ssh_url']
22432275
self.stargazers_count = repo['stargazers_count']
2276+
self.subscribers_count = repo['subscribers_count']
22442277
self.svn_url = self._get_attribute(repo, 'svn_url')
22452278
self.updated_at = self._strptime_attribute(repo, 'updated_at')
22462279
self.watchers_count = self.watchers = repo['watchers_count']
22472280

2248-
# Some repositories do not have these attributes at all
2249-
self.original_license = repo.get('license')
2250-
if self.original_license is not None:
2251-
self.original_license = License(self.original_license, self)
2252-
self.network_count = repo.get('network_count')
2253-
self.subscribers_count = repo.get('subscribers_count')
2254-
2255-
# .......... OLD ...... Deprecated?
2256-
2257-
#: URL of the pure diff of the pull request
2258-
self.diff_url = self._get_attribute(repo, 'diff_url')
2259-
2260-
#: URL of the pure patch of the pull request
2261-
self.patch_url = self._get_attribute(repo, 'patch_url')
2262-
2263-
#: API URL of the issue representation of this Pull Request
2264-
self.issue_url = self._get_attribute(repo, 'issue_url')
2265-
2266-
#: Permissions for this repository
2267-
self.permissions = self._get_attribute(repo, 'permissions')
2268-
2269-
#: ``datetime`` object representing when the repository was starred
2270-
self.starred_at = self._strptime_attribute(repo, 'starred_at')
2271-
2272-
#: Parent of this fork, if it exists :class:`Repository`
2273-
self.source = self._class_attribute(repo, 'source', Repository, self)
2274-
2275-
#: Parent of this fork, if it exists :class:`Repository`
2276-
self.parent = self._class_attribute(repo, 'parent', Repository, self)
2277-
2278-
#: master (default) branch for the repository
2279-
self.master_branch = self._get_attribute(repo, 'master_branch')
2280-
2281-
# Template URLS
2282-
2283-
#: Pull Request Review Comments URL
2284-
self.review_comments_url = self._class_attribute(
2285-
repo,
2286-
'review_comments_url',
2287-
URITemplate
2288-
)
2289-
2290-
#: Pull Request Review Comments URL Template. Expand with ``number``
2291-
self.issue_events_urlt = self._class_attribute(
2292-
repo,
2293-
'review_comment_url',
2294-
URITemplate
2295-
)
2296-
22972281

22982282
class StarredRepository(GitHubCore):
22992283
"""This object represents the data returned about a user's starred repos.
@@ -2320,7 +2304,7 @@ class StarredRepository(GitHubCore):
23202304

23212305
def _update_attributes(self, starred_repository):
23222306
self.starred_at = self._strptime(starred_repository['starred_at'])
2323-
self.repository = Repository(starred_repository['repo'], self)
2307+
self.repository = ShortRepository(starred_repository['repo'], self)
23242308
self.repo = self.repository
23252309

23262310
def _repr(self):

github3/users.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,9 @@ def subscriptions(self, number=-1, etag=None):
372372
endpoint
373373
:returns: generator of :class:`Repository <github3.repos.Repository>`
374374
"""
375-
from .repos import Repository
375+
from .repos import ShortRepository
376376
url = self._build_url('subscriptions', base_url=self._api)
377-
return self._iter(int(number), url, Repository, etag=etag)
377+
return self._iter(int(number), url, ShortRepository, etag=etag)
378378

379379
@requires_auth
380380
def rename(self, login):

0 commit comments

Comments
 (0)