mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 19:01:15 +00:00
On the way to alternative inputs. Still needs unit and integration testing
This commit is contained in:
@@ -37,3 +37,21 @@ class Parameters:
|
||||
|
||||
def NoParameters():
|
||||
return Parameters( [], [] )
|
||||
|
||||
class Alternative:
|
||||
def __init__( self, *checkers ):
|
||||
self.__checkers = checkers
|
||||
|
||||
def check( self, args, kwds ):
|
||||
# Try the n - 1 first checkers
|
||||
for checker in self.__checkers[ : -1 ]:
|
||||
try:
|
||||
return checker.check( args, kwds )
|
||||
except TypeError:
|
||||
pass
|
||||
# Use the last checker
|
||||
# This way, the call stack will point to an actual validation failure
|
||||
return self.__checkers[ -1 ].check( args, kwds )
|
||||
|
||||
def documentParameters( self ):
|
||||
return " <" + "> or <".join( checker.documentParameters() for checker in self.__checkers ) + "> "
|
||||
|
||||
@@ -33,7 +33,7 @@ PullRequest = GithubObject(
|
||||
ExternalListOfObjects( "comments", "comment", PullRequestComment,
|
||||
ListGetable( Parameters( [], [] ), __modifyAttributesForObjectsReferingReferedRepo ),
|
||||
ElementGetable( Parameters( [ "id" ], [] ), __modifyAttributesForObjectsReferingReferedRepo ),
|
||||
ElementCreatable( Parameters( [ "body", "commit_id", "path", "position" ], [] ), __modifyAttributesForObjectsReferingReferedRepo ),
|
||||
ElementCreatable( Alternative( Parameters( [ "body", "commit_id", "path", "position" ], [] ), Parameters( [ "body", "in_reply_to" ], [] ) ), __modifyAttributesForObjectsReferingReferedRepo ),
|
||||
),
|
||||
MethodFromCallable( "is_merged", Parameters( [], [] ), __pullRequestIsMerged, SimpleTypePolicy( "bool" ) ),
|
||||
MethodFromCallable( "merge", Parameters( [], [ "commit_message" ] ), __mergePullRequest, SimpleTypePolicy( None ) ),
|
||||
|
||||
@@ -134,6 +134,6 @@ Repository._addAttributePolicy( SeveralAttributePolicies( [
|
||||
ExternalListOfObjects( "pulls", "pull", PullRequest,
|
||||
ListGetable( Parameters( [], [ "state" ] ), __modifyAttributesForObjectsReferingRepo ),
|
||||
ElementGetable( Parameters( [ "number" ], [] ), __modifyAttributesForObjectsReferingRepo ),
|
||||
ElementCreatable( Parameters( [ "title", "body", "base", "head" ], [] ), __modifyAttributesForObjectsReferingRepo ),
|
||||
ElementCreatable( Alternative( Parameters( [ "title", "body", "base", "head" ], [] ), Parameters( [ "issue", "base", "head" ], [] ) ), __modifyAttributesForObjectsReferingRepo ),
|
||||
),
|
||||
] ) )
|
||||
|
||||
Reference in New Issue
Block a user