diff --git a/ReferenceOfApis.md b/ReferenceOfApis.md index 8230f5fd..8fab4012 100644 --- a/ReferenceOfApis.md +++ b/ReferenceOfApis.md @@ -321,7 +321,7 @@ API `/repos/:user/:repo/milestones/:number/labels` API `/repos/:user/:repo/pulls` ============================== * GET: `Repository.get_pulls` -* POST: `Repository.create_pull` (TODO: alternative input) +* POST: `Repository.create_pull` API `/repos/:user/:repo/pulls/:id` ================================== @@ -331,7 +331,7 @@ API `/repos/:user/:repo/pulls/:id` API `/repos/:user/:repo/pulls/:id/comments` =========================================== * GET: `PullRequest.get_comments` -* POST: `PullRequest.create_comment` (TODO: alternative input) +* POST: `PullRequest.create_comment` API `/repos/:user/:repo/pulls/:id/commits` ========================================== diff --git a/ReferenceOfClasses.md b/ReferenceOfClasses.md index 5c47e16d..695b67b1 100644 --- a/ReferenceOfClasses.md +++ b/ReferenceOfClasses.md @@ -703,7 +703,7 @@ Comments -------- * `get_comments()`: list of `PullRequestComment` * `get_comment( id )`: `PullRequestComment` -* `create_comment( body, commit_id, path, position )`: `PullRequestComment` +* `create_comment( < body, commit_id, path, position > or < body, in_reply_to > )`: `PullRequestComment` * `is_merged()`: bool * `merge( [commit_message] )` @@ -901,7 +901,7 @@ Pulls ----- * `get_pulls( [state] )`: list of `PullRequest` * `get_pull( number )`: `PullRequest` -* `create_pull( title, body, base, head )`: `PullRequest` +* `create_pull( < title, body, base, head > or < issue, base, head > )`: `PullRequest` Teams ----- diff --git a/github/GithubObjects/GithubObject/ArgumentsChecker.py b/github/GithubObjects/GithubObject/ArgumentsChecker.py index d96a2931..b2c5b054 100644 --- a/github/GithubObjects/GithubObject/ArgumentsChecker.py +++ b/github/GithubObjects/GithubObject/ArgumentsChecker.py @@ -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 ) + "> " diff --git a/github/GithubObjects/PullRequest.py b/github/GithubObjects/PullRequest.py index 6aaf0c4f..5ee414d5 100644 --- a/github/GithubObjects/PullRequest.py +++ b/github/GithubObjects/PullRequest.py @@ -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 ) ), diff --git a/github/GithubObjects/Repository.py b/github/GithubObjects/Repository.py index c981163c..8b8675fa 100644 --- a/github/GithubObjects/Repository.py +++ b/github/GithubObjects/Repository.py @@ -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 ), ), ] ) )