Add description to Organizations (#838)

As mentioned in https://developer.github.com/v3/orgs/, an organization also has a description. This PR adds this attribute to the `Organization` class, as well as modifies its `edit` method so that it's possible to update it.

I noticed too late the [`add_attribute.py` script](https://github.com/PyGithub/PyGithub/blob/8ae2bcb1e6f96beeec99fbbcf00f4af46bb38cde/scripts/add_attribute.py), so I did my modifications by hand, but I noticed that the output of the script and the style used for all the other attributes are different. I preferred the style that is prevalent in the file, rather than the output of the script.
This commit is contained in:
Jacopo Notarstefano
2018-07-10 15:04:29 +08:00
committed by Wan Liuyang
parent 8a589c9d73
commit 1d91880967
3 changed files with 25 additions and 6 deletions
+18 -2
View File
@@ -14,9 +14,10 @@
# Copyright 2016 Matthew Neal <meneal@matthews-mbp.raleigh.ibm.com> #
# Copyright 2016 Michael Pereira <pereira.m@gmail.com> #
# Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> #
# Copyright 2017 Balázs Rostás <rostas.balazs@gmail.com> #
# Copyright 2017 Balázs Rostás <rostas.balazs@gmail.com> #
# Copyright 2018 Anton Nguyen <afnguyen85@gmail.com> #
# Copyright 2018 sfdye <tsfdye@gmail.com> #
# Copyright 2018 Jacopo Notarstefano <jacopo.notarstefano@gmail.com> #
# #
# This file is part of PyGithub. #
# http://pygithub.readthedocs.io/ #
@@ -105,6 +106,14 @@ class Organization(github.GithubObject.CompletableGithubObject):
self._completeIfNotSet(self._created_at)
return self._created_at.value
@property
def description(self):
"""
:type: string
"""
self._completeIfNotSet(self._description)
return self._description.value
@property
def disk_usage(self):
"""
@@ -483,12 +492,13 @@ class Organization(github.GithubObject.CompletableGithubObject):
self.url + "/hooks/" + str(id)
)
def edit(self, billing_email=github.GithubObject.NotSet, blog=github.GithubObject.NotSet, company=github.GithubObject.NotSet, email=github.GithubObject.NotSet, location=github.GithubObject.NotSet, name=github.GithubObject.NotSet):
def edit(self, billing_email=github.GithubObject.NotSet, blog=github.GithubObject.NotSet, company=github.GithubObject.NotSet, description=github.GithubObject.NotSet, email=github.GithubObject.NotSet, location=github.GithubObject.NotSet, name=github.GithubObject.NotSet):
"""
:calls: `PATCH /orgs/:org <http://developer.github.com/v3/orgs>`_
:param billing_email: string
:param blog: string
:param company: string
:param description: string
:param email: string
:param location: string
:param name: string
@@ -497,6 +507,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
assert billing_email is github.GithubObject.NotSet or isinstance(billing_email, (str, unicode)), billing_email
assert blog is github.GithubObject.NotSet or isinstance(blog, (str, unicode)), blog
assert company is github.GithubObject.NotSet or isinstance(company, (str, unicode)), company
assert description is github.GithubObject.NotSet or isinstance(description, (str, unicode)), description
assert email is github.GithubObject.NotSet or isinstance(email, (str, unicode)), email
assert location is github.GithubObject.NotSet or isinstance(location, (str, unicode)), location
assert name is github.GithubObject.NotSet or isinstance(name, (str, unicode)), name
@@ -507,6 +518,8 @@ class Organization(github.GithubObject.CompletableGithubObject):
post_parameters["blog"] = blog
if company is not github.GithubObject.NotSet:
post_parameters["company"] = company
if description is not github.GithubObject.NotSet:
post_parameters["description"] = description
if email is not github.GithubObject.NotSet:
post_parameters["email"] = email
if location is not github.GithubObject.NotSet:
@@ -834,6 +847,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
self._collaborators = github.GithubObject.NotSet
self._company = github.GithubObject.NotSet
self._created_at = github.GithubObject.NotSet
self._description = github.GithubObject.NotSet
self._disk_usage = github.GithubObject.NotSet
self._email = github.GithubObject.NotSet
self._events_url = github.GithubObject.NotSet
@@ -871,6 +885,8 @@ class Organization(github.GithubObject.CompletableGithubObject):
self._company = self._makeStringAttribute(attributes["company"])
if "created_at" in attributes: # pragma no branch
self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
if "description" in attributes: # pragma no branch
self._description = self._makeStringAttribute(attributes["description"])
if "disk_usage" in attributes: # pragma no branch
self._disk_usage = self._makeIntAttribute(attributes["disk_usage"])
if "email" in attributes: # pragma no branch
+5 -2
View File
@@ -8,9 +8,10 @@
# Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> #
# Copyright 2016 Jannis Gebauer <ja.geb@me.com> #
# Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> #
# Copyright 2017 Balázs Rostás <rostas.balazs@gmail.com> #
# Copyright 2017 Balázs Rostás <rostas.balazs@gmail.com> #
# Copyright 2018 Anton Nguyen <afnguyen85@gmail.com> #
# Copyright 2018 sfdye <tsfdye@gmail.com> #
# Copyright 2018 Jacopo Notarstefano <jacopo.notarstefano@gmail.com> #
# #
# This file is part of PyGithub. #
# http://pygithub.readthedocs.io/ #
@@ -47,6 +48,7 @@ class Organization(Framework.TestCase):
self.assertEqual(self.org.collaborators, 9)
self.assertEqual(self.org.company, None)
self.assertEqual(self.org.created_at, datetime.datetime(2014, 1, 9, 16, 56, 17))
self.assertEqual(self.org.description, 'BeaverSoftware writes software.')
self.assertEqual(self.org.disk_usage, 2)
self.assertEqual(self.org.email, '')
self.assertEqual(self.org.followers, 0)
@@ -93,10 +95,11 @@ class Organization(Framework.TestCase):
self.org.edit()
def testEditWithAllArguments(self):
self.org.edit("BeaverSoftware2@vincent-jacques.net", "http://vincent-jacques.net", "Company edited by PyGithub", "BeaverSoftware2@vincent-jacques.net", "Location edited by PyGithub", "Name edited by PyGithub")
self.org.edit("BeaverSoftware2@vincent-jacques.net", "http://vincent-jacques.net", "Company edited by PyGithub", "Description edited by PyGithub", "BeaverSoftware2@vincent-jacques.net", "Location edited by PyGithub", "Name edited by PyGithub")
self.assertEqual(self.org.billing_email, "BeaverSoftware2@vincent-jacques.net")
self.assertEqual(self.org.blog, "http://vincent-jacques.net")
self.assertEqual(self.org.company, "Company edited by PyGithub")
self.assertEqual(self.org.description, "Description edited by PyGithub")
self.assertEqual(self.org.email, "BeaverSoftware2@vincent-jacques.net")
self.assertEqual(self.org.location, "Location edited by PyGithub")
self.assertEqual(self.org.name, "Name edited by PyGithub")
@@ -4,8 +4,8 @@ api.github.com
None
/orgs/BeaverSoftware
{'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
{"name": "Name edited by PyGithub", "billing_email": "BeaverSoftware2@vincent-jacques.net", "company": "Company edited by PyGithub", "blog": "http://vincent-jacques.net", "location": "Location edited by PyGithub", "email": "BeaverSoftware2@vincent-jacques.net"}
{"name": "Name edited by PyGithub", "billing_email": "BeaverSoftware2@vincent-jacques.net", "company": "Company edited by PyGithub", "blog": "http://vincent-jacques.net", "location": "Location edited by PyGithub", "email": "BeaverSoftware2@vincent-jacques.net", "description": "Description edited by PyGithub"}
200
[('status', '200 OK'), ('x-ratelimit-remaining', '4992'), ('content-length', '833'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"fe61098c87e054abfa5626e6a76bbcbd"'), ('date', 'Sat, 26 May 2012 20:50:35 GMT'), ('content-type', 'application/json; charset=utf-8')]
{"public_gists":0,"type":"Organization","disk_usage":112,"private_gists":0,"public_repos":2,"url":"https://api.github.com/orgs/BeaverSoftware","total_private_repos":0,"plan":{"private_repos":0,"name":"free","space":307200},"blog":"http://vincent-jacques.net","avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png","owned_private_repos":0,"collaborators":0,"company":"Company edited by PyGithub","login":"BeaverSoftware","email":"BeaverSoftware2@vincent-jacques.net","followers":0,"name":"Name edited by PyGithub","created_at":"2012-02-09T19:20:12Z","location":"Location edited by PyGithub","id":1424031,"billing_email":"BeaverSoftware2@vincent-jacques.net","following":0,"html_url":"https://github.com/BeaverSoftware"}
{"public_gists":0,"type":"Organization","disk_usage":112,"private_gists":0,"public_repos":2,"url":"https://api.github.com/orgs/BeaverSoftware","total_private_repos":0,"plan":{"private_repos":0,"name":"free","space":307200},"blog":"http://vincent-jacques.net","avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png","owned_private_repos":0,"collaborators":0,"company":"Company edited by PyGithub","login":"BeaverSoftware","email":"BeaverSoftware2@vincent-jacques.net","followers":0,"name":"Name edited by PyGithub","created_at":"2012-02-09T19:20:12Z","location":"Location edited by PyGithub","id":1424031,"billing_email":"BeaverSoftware2@vincent-jacques.net","following":0,"html_url":"https://github.com/BeaverSoftware", "description": "Description edited by PyGithub"}