mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 10:51:14 +00:00
Reduce differences between generated code and correct code
This commit is contained in:
@@ -758,6 +758,9 @@
|
||||
{ "name": "color", "type": "@todo" },
|
||||
{ "name": "name", "type": "@todo" },
|
||||
{ "name": "url", "type": "@todo" }
|
||||
],
|
||||
"identity": [
|
||||
{ "type": "attribute", "value": [ "name" ] }
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1172,7 +1175,8 @@
|
||||
{ "type": "attribute", "value": [ "url" ] },
|
||||
{ "type": "constant", "value": "/merge" }
|
||||
],
|
||||
"information": "status"
|
||||
"information": "status",
|
||||
"postParameters": true
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -1404,11 +1408,18 @@
|
||||
]
|
||||
},
|
||||
"getElement": {
|
||||
"parameter": { "name": "ref", "type": "@todo" }
|
||||
"parameter": { "name": "ref", "type": "@todo" },
|
||||
"request": {
|
||||
"url": [
|
||||
{ "type": "attribute", "value": [ "url" ] },
|
||||
{ "type": "constant", "value": "/git/" },
|
||||
{ "type": "argument", "value": [ "ref" ] }
|
||||
]
|
||||
}
|
||||
},
|
||||
"url": [
|
||||
{ "type": "attribute", "value": [ "url" ] },
|
||||
{ "type": "constant", "value": "/git" }
|
||||
{ "type": "constant", "value": "/git/refs" }
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1586,6 +1597,15 @@
|
||||
},
|
||||
"getElement": {
|
||||
"parameter": { "name": "number", "type": "@todo" }
|
||||
},
|
||||
"createElement": {
|
||||
"optionalParameters": [
|
||||
{ "name": "title", "type": "@todo" },
|
||||
{ "name": "body", "type": "@todo" },
|
||||
{ "name": "issue", "type": "@todo" },
|
||||
{ "name": "base", "type": "@todo" },
|
||||
{ "name": "head", "type": "@todo" }
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -4037,6 +4037,22 @@
|
||||
"labels"
|
||||
],
|
||||
"mandatoryParameters": [],
|
||||
"request": {
|
||||
"url": [
|
||||
{
|
||||
"type": "attribute",
|
||||
"value": [
|
||||
"url"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "constant",
|
||||
"value": "/labels"
|
||||
}
|
||||
],
|
||||
"information": "status",
|
||||
"verb": "DELETE"
|
||||
},
|
||||
"isMutation": false,
|
||||
"optionalParameters": [],
|
||||
"type": {
|
||||
@@ -4143,6 +4159,23 @@
|
||||
},
|
||||
"name": "label"
|
||||
},
|
||||
"request": {
|
||||
"url": [
|
||||
{
|
||||
"type": "attribute",
|
||||
"value": [
|
||||
"url"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "constant",
|
||||
"value": "/labels"
|
||||
}
|
||||
],
|
||||
"information": "status",
|
||||
"verb": "PUT",
|
||||
"postParameters": true
|
||||
},
|
||||
"isMutation": false,
|
||||
"optionalParameters": [],
|
||||
"type": {
|
||||
@@ -4363,6 +4396,14 @@
|
||||
],
|
||||
"isCompletable": false,
|
||||
"name": "Label",
|
||||
"identity": [
|
||||
{
|
||||
"type": "attribute",
|
||||
"value": [
|
||||
"name"
|
||||
]
|
||||
}
|
||||
],
|
||||
"methods": [
|
||||
{
|
||||
"group": "modification",
|
||||
@@ -6913,7 +6954,8 @@
|
||||
}
|
||||
],
|
||||
"information": "status",
|
||||
"verb": "PUT"
|
||||
"verb": "PUT",
|
||||
"postParameters": true
|
||||
},
|
||||
"isMutation": false,
|
||||
"optionalParameters": [
|
||||
@@ -8415,7 +8457,7 @@
|
||||
},
|
||||
{
|
||||
"type": "constant",
|
||||
"value": "/git"
|
||||
"value": "/git/refs"
|
||||
}
|
||||
],
|
||||
"information": "status",
|
||||
@@ -8456,11 +8498,7 @@
|
||||
},
|
||||
{
|
||||
"type": "constant",
|
||||
"value": "/git"
|
||||
},
|
||||
{
|
||||
"type": "constant",
|
||||
"value": "/"
|
||||
"value": "/git/"
|
||||
},
|
||||
{
|
||||
"type": "argument",
|
||||
@@ -8497,7 +8535,7 @@
|
||||
},
|
||||
{
|
||||
"type": "constant",
|
||||
"value": "/git"
|
||||
"value": "/git/refs"
|
||||
}
|
||||
],
|
||||
"information": "data",
|
||||
@@ -9624,6 +9662,79 @@
|
||||
"name": "Milestone"
|
||||
}
|
||||
},
|
||||
{
|
||||
"group": "pulls",
|
||||
"name": [
|
||||
"create",
|
||||
"pull"
|
||||
],
|
||||
"mandatoryParameters": [],
|
||||
"request": {
|
||||
"url": [
|
||||
{
|
||||
"type": "attribute",
|
||||
"value": [
|
||||
"url"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "constant",
|
||||
"value": "/pulls"
|
||||
}
|
||||
],
|
||||
"information": "status",
|
||||
"verb": "POST",
|
||||
"postParameters": true
|
||||
},
|
||||
"isMutation": false,
|
||||
"optionalParameters": [
|
||||
{
|
||||
"type": {
|
||||
"simple": true,
|
||||
"cardinality": "scalar",
|
||||
"name": "@todo"
|
||||
},
|
||||
"name": "title"
|
||||
},
|
||||
{
|
||||
"type": {
|
||||
"simple": true,
|
||||
"cardinality": "scalar",
|
||||
"name": "@todo"
|
||||
},
|
||||
"name": "body"
|
||||
},
|
||||
{
|
||||
"type": {
|
||||
"simple": true,
|
||||
"cardinality": "scalar",
|
||||
"name": "@todo"
|
||||
},
|
||||
"name": "issue"
|
||||
},
|
||||
{
|
||||
"type": {
|
||||
"simple": true,
|
||||
"cardinality": "scalar",
|
||||
"name": "@todo"
|
||||
},
|
||||
"name": "base"
|
||||
},
|
||||
{
|
||||
"type": {
|
||||
"simple": true,
|
||||
"cardinality": "scalar",
|
||||
"name": "@todo"
|
||||
},
|
||||
"name": "head"
|
||||
}
|
||||
],
|
||||
"type": {
|
||||
"simple": false,
|
||||
"cardinality": "scalar",
|
||||
"name": "PullRequest"
|
||||
}
|
||||
},
|
||||
{
|
||||
"group": "pulls",
|
||||
"name": [
|
||||
|
||||
@@ -7,6 +7,19 @@ import itertools
|
||||
### @todo Mandatory/optional attributes
|
||||
### @todo Remove '_identity' from the normalized json description
|
||||
|
||||
def mergeDict( base, *additions ):
|
||||
r = dict( base )
|
||||
for addition in additions:
|
||||
for k in addition:
|
||||
if k in r:
|
||||
if isinstance( r[ k ], dict ):
|
||||
r[ k ] = mergeDict( r[ k ], addition[ k ] )
|
||||
# else:
|
||||
# we ignore the addition: the first dict which specifies a value wins
|
||||
else:
|
||||
r[ k ] = addition[ k ]
|
||||
return r
|
||||
|
||||
def checkKeys( d, mandatoryKeys, optionalKeys = [] ):
|
||||
assert set( d.keys() ) >= set( mandatoryKeys ), d.keys()
|
||||
assert set( d.keys() ) <= set( mandatoryKeys ) | set( optionalKeys ) | set( [ "@todo" ] ), d.keys()
|
||||
@@ -73,8 +86,7 @@ class Function:
|
||||
# POST parameters from input
|
||||
|
||||
def __init__( self, desc, *additionalDescs ):
|
||||
for additionalDesc in additionalDescs:
|
||||
desc.update( additionalDesc )
|
||||
desc = mergeDict( desc, *additionalDescs )
|
||||
checkKeys( desc, [ "name", "type", "group" ], [ "url", "isMutation", "mandatoryParameters", "optionalParameters", "variadicParameter", "parameter", "request" ] ) # @todo Move request to mandatoryKeys
|
||||
|
||||
self.name = desc[ "name" ]
|
||||
@@ -169,7 +181,16 @@ class Collection:
|
||||
) )
|
||||
if "deleteList" in desc:
|
||||
assert desc[ "deleteList" ] is True
|
||||
self.methods.append( Function( { "name": [ "delete" ] + name, "type": "void", "group": desc[ "name" ] } ) )
|
||||
self.methods.append( Function(
|
||||
{ "name": [ "delete" ] + name, "type": "void", "group": desc[ "name" ] },
|
||||
{
|
||||
"request": {
|
||||
"verb": "DELETE",
|
||||
"url": self.__url,
|
||||
"information": "status",
|
||||
}
|
||||
}
|
||||
) )
|
||||
if "getElement" in desc:
|
||||
if "url" in desc[ "getElement" ]:
|
||||
urlForGetElement = desc[ "getElement" ][ "url" ]
|
||||
@@ -247,7 +268,17 @@ class Collection:
|
||||
) )
|
||||
if "setList" in desc:
|
||||
assert desc[ "setList" ] is True
|
||||
self.methods.append( Function( { "name": [ "set" ] + name, "type": "void", "group": desc[ "name" ], "variadicParameter": { "name": desc[ "singularName" ], "type": desc[ "type" ] } } ) )
|
||||
self.methods.append( Function(
|
||||
{ "name": [ "set" ] + name, "type": "void", "group": desc[ "name" ], "variadicParameter": { "name": desc[ "singularName" ], "type": desc[ "type" ] } },
|
||||
{
|
||||
"request": {
|
||||
"verb": "PUT",
|
||||
"url": self.__url,
|
||||
"information": "status",
|
||||
"postParameters": True,
|
||||
}
|
||||
}
|
||||
) )
|
||||
|
||||
class Class:
|
||||
def __init__( self, desc ):
|
||||
|
||||
@@ -3,7 +3,7 @@ You obtain instances through calls to `get_` and `create_` methods.
|
||||
|
||||
Class `Github`
|
||||
==============
|
||||
* Constructed from user's login and password
|
||||
* Constructed from user's login and password or OAuth token
|
||||
* `get_user()`: `AuthenticatedUser`
|
||||
* `get_user( login )`: `NamedUser`
|
||||
* `get_organization( login )`: `Organization`
|
||||
|
||||
@@ -1166,6 +1166,11 @@ Modification
|
||||
Pulls
|
||||
-----
|
||||
* `create_pull( < title, body, base, head > or < issue, base, head > )`: `PullRequest`
|
||||
* `title`
|
||||
* `body`
|
||||
* `issue`
|
||||
* `base`
|
||||
* `head`
|
||||
* `get_pull( number )`: `PullRequest`
|
||||
* `number`
|
||||
* `get_pulls( [state] )`: list of `PullRequest`
|
||||
|
||||
@@ -45,7 +45,6 @@ class Label( object ):
|
||||
)
|
||||
self.__useAttributes( data )
|
||||
|
||||
# @todo Remove '_identity' from the normalized json description
|
||||
@property
|
||||
def _identity( self ):
|
||||
return urllib.quote( self.name )
|
||||
@@ -56,7 +55,6 @@ class Label( object ):
|
||||
self.__url = None
|
||||
|
||||
def __useAttributes( self, attributes ):
|
||||
# @todo No need to check if attribute is in attributes when attribute is mandatory
|
||||
if "color" in attributes and attributes[ "color" ] is not None: # pragma no branch
|
||||
self.__color = attributes[ "color" ]
|
||||
if "name" in attributes and attributes[ "name" ] is not None: # pragma no branch
|
||||
|
||||
@@ -240,11 +240,15 @@ class PullRequest( object ):
|
||||
return status == 204
|
||||
|
||||
def merge( self, commit_message = DefaultValueForOptionalParameters ):
|
||||
post_parameters = {
|
||||
}
|
||||
if commit_message is not DefaultValueForOptionalParameters:
|
||||
post_parameters[ "commit_message" ] = commit_message
|
||||
status, headers, data = self.__requester.request(
|
||||
"PUT",
|
||||
str( self.url ) + "/merge",
|
||||
None,
|
||||
{}
|
||||
post_parameters
|
||||
)
|
||||
|
||||
def __initAttributes( self ):
|
||||
|
||||
@@ -584,7 +584,7 @@ class Repository( object ):
|
||||
def get_git_ref( self, ref ):
|
||||
status, headers, data = self.__requester.request(
|
||||
"GET",
|
||||
str( self.url ) + "/git" + "/" + str( ref ),
|
||||
str( self.url ) + "/git/" + str( ref ),
|
||||
None,
|
||||
None
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user