mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 10:51:14 +00:00
Generate code for complex parameters
(+ find bug in Repository.create_commit with parents !)
This commit is contained in:
@@ -555,6 +555,9 @@
|
||||
{ "name": "sha", "type": "string" },
|
||||
{ "name": "url", "type": "string" },
|
||||
{ "name": "tree", "type": "GitTree" }
|
||||
],
|
||||
"identity": [
|
||||
{ "type": "attribute", "value": [ "sha" ] }
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -3214,6 +3214,14 @@
|
||||
],
|
||||
"isCompletable": true,
|
||||
"name": "GitCommit",
|
||||
"identity": [
|
||||
{
|
||||
"type": "attribute",
|
||||
"value": [
|
||||
"sha"
|
||||
]
|
||||
}
|
||||
],
|
||||
"methods": []
|
||||
},
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
{% if method.mandatoryParameters %}
|
||||
post_parameters = {
|
||||
{% for parameter in method.mandatoryParameters %}
|
||||
"{{ parameter.name }}": {{ parameter.name }},
|
||||
"{{ parameter.name }}": {% if parameter.type.simple %}{{ parameter.name }}{% else %}{% if parameter.type.cardinality == "list" %}[ element._identity for element in {{ parameter.name }} ]{% else %}dict( ( key, value._identity ) for key, value in {{ parameter.name }}.iteritems() ){% endif %}{% endif %},
|
||||
{% endfor %}
|
||||
}
|
||||
{% else %}
|
||||
@@ -17,7 +17,7 @@
|
||||
{% endif %}
|
||||
{% for parameter in method.optionalParameters %}
|
||||
if {{ parameter.name }} is not GithubObject.NotSet:
|
||||
post_parameters[ "{{ parameter.name }}" ] = {{ parameter.name }}
|
||||
post_parameters[ "{{ parameter.name }}" ] = {% if parameter.type.simple %}{{ parameter.name }}{% else %}{% if parameter.type.cardinality == "dict" %}dict( ( key, value._identity ) for key, value in {{ parameter.name }}.iteritems() ){% else %}{{ parameter.name }}._identity{% endif %}{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
|
||||
@@ -209,7 +209,7 @@ class AuthenticatedUser( GithubObject.GithubObject ):
|
||||
assert description is GithubObject.NotSet or isinstance( description, ( str, unicode ) ), description
|
||||
post_parameters = {
|
||||
"public": public,
|
||||
"files": dict( ( key, value._identity() ) for key, value in files.iteritems() ),
|
||||
"files": dict( ( key, value._identity ) for key, value in files.iteritems() ),
|
||||
}
|
||||
if description is not GithubObject.NotSet:
|
||||
post_parameters[ "description" ] = description
|
||||
|
||||
+1
-1
@@ -127,7 +127,7 @@ class Gist( GithubObject.GithubObject ):
|
||||
if description is not GithubObject.NotSet:
|
||||
post_parameters[ "description" ] = description
|
||||
if files is not GithubObject.NotSet:
|
||||
post_parameters[ "files" ] = dict( ( key, value._identity() ) for key, value in files.iteritems() )
|
||||
post_parameters[ "files" ] = dict( ( key, value._identity ) for key, value in files.iteritems() )
|
||||
status, headers, data = self._request(
|
||||
"PATCH",
|
||||
str( self.url ),
|
||||
|
||||
@@ -43,6 +43,10 @@ class GitCommit( GithubObject.GithubObject ):
|
||||
self._completeIfNotSet( self._url )
|
||||
return self._NoneIfNotSet( self._url )
|
||||
|
||||
@property
|
||||
def _identity( self ):
|
||||
return str( self.sha )
|
||||
|
||||
def _initAttributes( self ):
|
||||
self._author = GithubObject.NotSet
|
||||
self._committer = GithubObject.NotSet
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
class InputFileContent:
|
||||
class InputFileContent( object ):
|
||||
def __init__( self, content ):
|
||||
self.__content = content
|
||||
|
||||
@property
|
||||
def _identity( self ):
|
||||
return {
|
||||
"content": self.__content,
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
class InputGitAuthor:
|
||||
class InputGitAuthor( object ):
|
||||
def __init__( self, name, email, date ):
|
||||
self.__name = name
|
||||
self.__email = email
|
||||
self.__date = date
|
||||
|
||||
@property
|
||||
def _identity( self ):
|
||||
return {
|
||||
"name": self.__name,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import GithubObject
|
||||
|
||||
class InputGitTreeElement:
|
||||
class InputGitTreeElement( object ):
|
||||
def __init__( self, path, mode, type, content = GithubObject.NotSet, sha = GithubObject.NotSet ):
|
||||
self.__path = path
|
||||
self.__mode = mode
|
||||
@@ -8,6 +8,7 @@ class InputGitTreeElement:
|
||||
self.__content = content
|
||||
self.__sha = sha
|
||||
|
||||
@property
|
||||
def _identity( self ):
|
||||
identity = {
|
||||
"path": self.__path,
|
||||
|
||||
@@ -149,7 +149,7 @@ class NamedUser( GithubObject.GithubObject ):
|
||||
assert description is GithubObject.NotSet or isinstance( description, ( str, unicode ) ), description
|
||||
post_parameters = {
|
||||
"public": public,
|
||||
"files": dict( ( key, value._identity() ) for key, value in files.iteritems() ),
|
||||
"files": dict( ( key, value._identity ) for key, value in files.iteritems() ),
|
||||
}
|
||||
if description is not GithubObject.NotSet:
|
||||
post_parameters[ "description" ] = description
|
||||
|
||||
@@ -253,12 +253,12 @@ class Repository( GithubObject.GithubObject ):
|
||||
post_parameters = {
|
||||
"message": message,
|
||||
"tree": tree,
|
||||
"parents": parents,
|
||||
"parents": [ element._identity for element in parents ],
|
||||
}
|
||||
if author is not GithubObject.NotSet:
|
||||
post_parameters[ "author" ] = author._identity()
|
||||
post_parameters[ "author" ] = author._identity
|
||||
if committer is not GithubObject.NotSet:
|
||||
post_parameters[ "committer" ] = committer._identity()
|
||||
post_parameters[ "committer" ] = committer._identity
|
||||
status, headers, data = self._request(
|
||||
"POST",
|
||||
str( self.url ) + "/git/commits",
|
||||
@@ -297,7 +297,7 @@ class Repository( GithubObject.GithubObject ):
|
||||
"type": type,
|
||||
}
|
||||
if tagger is not GithubObject.NotSet:
|
||||
post_parameters[ "tagger" ] = tagger._identity()
|
||||
post_parameters[ "tagger" ] = tagger._identity
|
||||
status, headers, data = self._request(
|
||||
"POST",
|
||||
str( self.url ) + "/git/tags",
|
||||
@@ -311,7 +311,7 @@ class Repository( GithubObject.GithubObject ):
|
||||
assert all( isinstance( element, InputGitTreeElement.InputGitTreeElement ) for element in tree ), tree
|
||||
assert base_tree is GithubObject.NotSet or isinstance( base_tree, ( str, unicode ) ), base_tree
|
||||
post_parameters = {
|
||||
"tree": [ element._identity() for element in tree ],
|
||||
"tree": [ element._identity for element in tree ],
|
||||
}
|
||||
if base_tree is not GithubObject.NotSet:
|
||||
post_parameters[ "base_tree" ] = base_tree
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
GET /repos/jacquev6/PyGithub/git/commits/7248e66831d4ffe09ef1f30a1df59ec0a9331ece {'Authorization': 'Basic login_and_password_removed'} null
|
||||
200
|
||||
[('status', '200 OK'), ('x-ratelimit-remaining', '4967'), ('content-length', '762'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"0cbf75a2a511c74f3df22dfd8d2ee42a"'), ('date', 'Fri, 01 Jun 2012 18:39:29 GMT'), ('content-type', 'application/json; charset=utf-8')]
|
||||
{"committer":{"email":"vincent@vincent-jacques.net","date":"2012-05-30T09:58:18-07:00","name":"Vincent Jacques"},"message":"Check HTTP status on all requests\n","url":"https://api.github.com/repos/jacquev6/PyGithub/git/commits/7248e66831d4ffe09ef1f30a1df59ec0a9331ece","sha":"7248e66831d4ffe09ef1f30a1df59ec0a9331ece","parents":[{"url":"https://api.github.com/repos/jacquev6/PyGithub/git/commits/81ca19a009b54e64226e3f9e51210fba989d5497","sha":"81ca19a009b54e64226e3f9e51210fba989d5497"}],"tree":{"url":"https://api.github.com/repos/jacquev6/PyGithub/git/trees/91655d55b309f520fd4b3fd9e5303cfc13855a21","sha":"91655d55b309f520fd4b3fd9e5303cfc13855a21"},"author":{"email":"vincent@vincent-jacques.net","date":"2012-05-30T09:58:18-07:00","name":"Vincent Jacques"}}
|
||||
|
||||
GET /repos/jacquev6/PyGithub/git/commits/12d427464f8d91c8e981043a86ba8a2a9e7319ea {'Authorization': 'Basic login_and_password_removed'} null
|
||||
200
|
||||
[('status', '200 OK'), ('x-ratelimit-remaining', '4966'), ('content-length', '769'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"87d790f22e47dbaa3148ad7872e32dde"'), ('date', 'Fri, 01 Jun 2012 18:39:30 GMT'), ('content-type', 'application/json; charset=utf-8')]
|
||||
{"tree":{"sha":"143dd39e465e5de953d944c9309b961af392da73","url":"https://api.github.com/repos/jacquev6/PyGithub/git/trees/143dd39e465e5de953d944c9309b961af392da73"},"sha":"12d427464f8d91c8e981043a86ba8a2a9e7319ea","message":"Remove the notion of ImmediateCompletion\n","parents":[{"sha":"7a622975d6a3f0ab80f573f577aa0e3ffb69e2f5","url":"https://api.github.com/repos/jacquev6/PyGithub/git/commits/7a622975d6a3f0ab80f573f577aa0e3ffb69e2f5"}],"author":{"email":"vincent@vincent-jacques.net","date":"2012-05-30T09:51:36-07:00","name":"Vincent Jacques"},"url":"https://api.github.com/repos/jacquev6/PyGithub/git/commits/12d427464f8d91c8e981043a86ba8a2a9e7319ea","committer":{"email":"vincent@vincent-jacques.net","date":"2012-05-30T10:00:37-07:00","name":"Vincent Jacques"}}
|
||||
|
||||
POST /repos/jacquev6/PyGithub/git/commits {'Authorization': 'Basic login_and_password_removed'} {"parents": ["7248e66831d4ffe09ef1f30a1df59ec0a9331ece", "12d427464f8d91c8e981043a86ba8a2a9e7319ea"], "message": "Commit created by PyGithub", "tree": "fae707821159639589bf94f3fb0a7154ec5d441b"}
|
||||
201
|
||||
[('status', '201 Created'), ('x-ratelimit-remaining', '4965'), ('content-length', '918'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"1ada1e7861f74fa4fefa922bf03e891e"'), ('date', 'Fri, 01 Jun 2012 18:39:31 GMT'), ('content-type', 'application/json; charset=utf-8'), ('location', 'https://api.github.com/repos/jacquev6/PyGithub/git/commits/6adf9ea25ff8a8f2a42bcb1c09e42526339037cd')]
|
||||
{"committer":{"email":"github.com@vincent-jacques.net","date":"2012-06-01T11:39:31-07:00","name":"Vincent Jacques"},"message":"Commit created by PyGithub","url":"https://api.github.com/repos/jacquev6/PyGithub/git/commits/6adf9ea25ff8a8f2a42bcb1c09e42526339037cd","sha":"6adf9ea25ff8a8f2a42bcb1c09e42526339037cd","parents":[{"url":"https://api.github.com/repos/jacquev6/PyGithub/git/commits/7248e66831d4ffe09ef1f30a1df59ec0a9331ece","sha":"7248e66831d4ffe09ef1f30a1df59ec0a9331ece"},{"url":"https://api.github.com/repos/jacquev6/PyGithub/git/commits/12d427464f8d91c8e981043a86ba8a2a9e7319ea","sha":"12d427464f8d91c8e981043a86ba8a2a9e7319ea"}],"tree":{"url":"https://api.github.com/repos/jacquev6/PyGithub/git/trees/fae707821159639589bf94f3fb0a7154ec5d441b","sha":"fae707821159639589bf94f3fb0a7154ec5d441b"},"author":{"email":"github.com@vincent-jacques.net","date":"2012-06-01T11:39:31-07:00","name":"Vincent Jacques"}}
|
||||
|
||||
@@ -163,6 +163,14 @@ class Repository( Framework.TestCase ):
|
||||
commit = self.repo.create_git_commit( "Commit created by PyGithub", "107139a922f33bab6fbeb9f9eb8787e7f19e0528", [] )
|
||||
self.assertEqual( commit.sha, "0b820628236ab8bab3890860fc414fa757ca15f4" )
|
||||
|
||||
def testCreateGitCommitWithParents( self ):
|
||||
parents = [
|
||||
self.repo.get_git_commit( "7248e66831d4ffe09ef1f30a1df59ec0a9331ece" ),
|
||||
self.repo.get_git_commit( "12d427464f8d91c8e981043a86ba8a2a9e7319ea" ),
|
||||
]
|
||||
commit = self.repo.create_git_commit( "Commit created by PyGithub", "fae707821159639589bf94f3fb0a7154ec5d441b", parents )
|
||||
self.assertEqual( commit.sha, "6adf9ea25ff8a8f2a42bcb1c09e42526339037cd" )
|
||||
|
||||
def testCreateGitCommitWithAllArguments( self ):
|
||||
commit = self.repo.create_git_commit( "Commit created by PyGithub", "107139a922f33bab6fbeb9f9eb8787e7f19e0528", [], github.InputGitAuthor( "John Doe", "j.doe@vincent-jacques.net", "2008-07-09T16:13:30+12:00" ), github.InputGitAuthor( "John Doe", "j.doe@vincent-jacques.net", "2008-07-09T16:13:30+12:00" ) )
|
||||
self.assertEqual( commit.sha, "526946197ae9da59c6507cacd13ad6f1cfb686ea" )
|
||||
|
||||
Reference in New Issue
Block a user