diff --git a/CodeGenerator/templates/GithubObject.MethodBody.DoRequest.py b/CodeGenerator/templates/GithubObject.MethodBody.DoRequest.py new file mode 100644 index 00000000..107427a1 --- /dev/null +++ b/CodeGenerator/templates/GithubObject.MethodBody.DoRequest.py @@ -0,0 +1,22 @@ +{% if method.request.post_parameters %} + post_parameters = { + {% for parameter in method.mandatory_parameters %} + "{{ parameter.name }}": {{ parameter.name }}, + {% endfor %} + } + {% for parameter in method.optional_parameters %} + if {{ parameter.name }} is not None: + post_parameters[ "{{ parameter.name }}" ] = {{ parameter.name }} + {% endfor %} +{% endif %} + + result = self.__github._{{ method.request.information }}Request( + "{{ method.request.verb }}", + {% include "GithubObject.Concatenation.py" with concatenation=method.request.url only %}, + None, +{% if method.request.post_parameters %} + post_parameters +{% else %} + None +{% endif %} + ) diff --git a/CodeGenerator/templates/GithubObject.MethodBody.UseResult.py b/CodeGenerator/templates/GithubObject.MethodBody.UseResult.py new file mode 100644 index 00000000..8fc741ea --- /dev/null +++ b/CodeGenerator/templates/GithubObject.MethodBody.UseResult.py @@ -0,0 +1,24 @@ +{% if method.is_mutation %} + self.__useAttributes( result ) +{% endif %} + +{% if method.type.simple %} + +{% if method.type.name == "bool" %} + return result == 204 +{% endif %} + +{% else %} + +{% if method.type.cardinality == "scalar" %} + return {% if method.type.name != class.name %}{{ method.type.name }}.{% endif %}{{ method.type.name }}( self.__github, result, lazy = True ) +{% endif %} + +{% if method.type.cardinality == "list" %} + return [ + {% if method.type.name != class.name %}{{ method.type.name }}.{% endif %}{{ method.type.name }}( self.__github, element, lazy = True ) + for element in result + ] +{% endif %} + +{% endif %} diff --git a/CodeGenerator/templates/GithubObject.py b/CodeGenerator/templates/GithubObject.py index 45cd5531..e75bb925 100644 --- a/CodeGenerator/templates/GithubObject.py +++ b/CodeGenerator/templates/GithubObject.py @@ -20,65 +20,16 @@ class {{ class.name }}( object ): {% for method in class.methods|dictsort:"name" %} def {{ method.name|join:"_" }}( {% include "GithubObject.Parameters.py" with function=method only %} ): -{% if method.request %} - -{% if method.request.post_parameters %} - post_parameters = { -{% for parameter in method.mandatory_parameters %} - "{{ parameter.name }}": {{ parameter.name }}, -{% endfor %} - } - -{% for parameter in method.optional_parameters %} - if {{ parameter.name }} is not None: - post_parameters[ "{{ parameter.name }}" ] = {{ parameter.name }} -{% endfor %} - -{% endif %} - - result = self.__github._{{ method.request.information }}Request( - "{{ method.request.verb }}", - {% include "GithubObject.Concatenation.py" with concatenation=method.request.url only %}, - None, -{% if method.request.post_parameters %} - post_parameters -{% else %} - None -{% endif %} - ) - -{% if method.is_mutation %} - self.__useAttributes( result ) -{% endif %} - -{% if method.type.simple %} - -{% if method.type.name == "bool" %} - return result == 204 -{% endif %} - -{% else %} - -{% if method.type.cardinality == "scalar" %} - return {% if method.type.name != class.name %}{{ method.type.name }}.{% endif %}{{ method.type.name }}( self.__github, result, lazy = True ) -{% endif %} - -{% if method.type.cardinality == "list" %} - return [ - {% if method.type.name != class.name %}{{ method.type.name }}.{% endif %}{{ method.type.name }}( self.__github, element, lazy = True ) - for element in result - ] -{% endif %} - -{% endif %} - -{% else %} + {% if method.request %} + {% include "GithubObject.MethodBody.DoRequest.py" %} + {% include "GithubObject.MethodBody.UseResult.py" %} + {% else %} pass -{% endif %} + {% endif %} {% endfor %} def __initAttributes( self ): -{% for attribute in class.attributes %} +{% for attribute in class.attributes|dictsort:"name" %} self.__{{ attribute.name }} = None {% endfor %} @@ -99,7 +50,7 @@ class {{ class.name }}( object ): def __useAttributes( self, attributes ): #@todo No need to check if attribute is in attributes when attribute is mandatory -{% for attribute in class.attributes %} +{% for attribute in class.attributes|dictsort:"name" %} if "{{ attribute.name }}" in attributes: {% if attribute.type.simple %} self.__{{ attribute.name }} = attributes[ "{{ attribute.name }}" ] diff --git a/GenerateCode.py b/GenerateCode.py index 7ea5e030..8f895164 100644 --- a/GenerateCode.py +++ b/GenerateCode.py @@ -10,7 +10,8 @@ import django.template.loader django.conf.settings.configure( TEMPLATE_DIRS = ( "CodeGenerator/templates", - ) + ), + TEMPLATE_STRING_IF_INVALID = "We have a logic error in our template or API description", ) description = json.load( open( "JsonDescriptionOfGithubApiV3/description.001.normalized.json" ) ) diff --git a/JsonDescriptionOfGithubApiV3/description.000.human_readable.json b/JsonDescriptionOfGithubApiV3/description.000.human_readable.json index 7612a63e..e8fc8727 100644 --- a/JsonDescriptionOfGithubApiV3/description.000.human_readable.json +++ b/JsonDescriptionOfGithubApiV3/description.000.human_readable.json @@ -181,7 +181,8 @@ { "type": "constant", "value": "/" }, { "type": "argument", "value": [ "repo", "name" ] }, { "type": "constant", "value": "/forks" } - ] + ], + "information": "status" } }, { diff --git a/JsonDescriptionOfGithubApiV3/description.001.normalized.json b/JsonDescriptionOfGithubApiV3/description.001.normalized.json index d7b38d05..cc955df4 100644 --- a/JsonDescriptionOfGithubApiV3/description.001.normalized.json +++ b/JsonDescriptionOfGithubApiV3/description.001.normalized.json @@ -1311,6 +1311,7 @@ "value": "/forks" } ], + "information": "status", "verb": "POST" }, "optional_parameters": [], diff --git a/github/GithubObjects/AuthenticatedUser.py b/github/GithubObjects/AuthenticatedUser.py index 3ac65a8d..4eed36d1 100644 --- a/github/GithubObjects/AuthenticatedUser.py +++ b/github/GithubObjects/AuthenticatedUser.py @@ -167,7 +167,7 @@ class AuthenticatedUser( object ): pass def create_fork( self, repo ): - result = self.__github._Request( + result = self.__github._statusRequest( "POST", "/repos/" + repo.owner.login + "/" + repo.name + "/forks", None,