From 4539f80aa44e500422c5071d8e3d74de321b6225 Mon Sep 17 00:00:00 2001 From: Nat Williams Date: Tue, 17 Apr 2012 17:35:31 -0500 Subject: add pull request API there are a few little issues remaining. Mostly regarding handling meaningful non-20x response codes --- pygithub3/requests/pull_requests/__init__.py | 62 ++++++++++++++++++++++++++++ pygithub3/requests/pull_requests/comments.py | 43 +++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 pygithub3/requests/pull_requests/__init__.py create mode 100644 pygithub3/requests/pull_requests/comments.py (limited to 'pygithub3/requests/pull_requests') diff --git a/pygithub3/requests/pull_requests/__init__.py b/pygithub3/requests/pull_requests/__init__.py new file mode 100644 index 0000000..7e85f8f --- /dev/null +++ b/pygithub3/requests/pull_requests/__init__.py @@ -0,0 +1,62 @@ +from pygithub3.requests.base import Request, ValidationError +from pygithub3.resources.base import Raw +from pygithub3.resources.pull_requests import PullRequest, File +from pygithub3.resources.repos import Commit + + +class List(Request): + uri = 'repos/{user}/{repo}/pulls' + resource = PullRequest + + +class Get(Request): + uri = 'repos/{user}/{repo}/pulls/{number}' + resource = PullRequest + + +class Create(Request): + uri = 'repos/{user}/{repo}/pulls' + resource = PullRequest + body_schema = { + 'schema': ('title', 'body', 'base', 'head', 'issue'), + 'required': ('base', 'head'), + } + + def validate_body(self, parsed): + if (not ('title' in parsed and 'body' in parsed) and + not 'issue' in parsed): + raise ValidationError('pull request creation requires either an ' + 'issue number or a title and body') + +class Update(Request): + uri = 'repos/{user}/{repo}/pulls/{number}' + resource = PullRequest + body_schema = { + 'schema': ('title', 'body', 'state'), + 'required': (), + } + + def validate_body(self, body): + if 'state' in body and body['state'] not in ['open', 'closed']: + raise ValidationError('If a state is specified, it must be one ' + 'of "open" or "closed"') + + +class List_commits(Request): + uri = 'repos/{user}/{repo}/pulls/{number}/commits' + resource = Commit + + +class List_files(Request): + uri = 'repos/{user}/{repo}/pulls/{number}/files' + resource = File + + +class Merge_status(Request): + uri = 'repos/{user}/{repo}/pulls/{number}/merge' + resource = Raw + + +class Merge(Request): + uri = 'repos/{user}/{repo}/pulls/{number}/merge' + resource = Raw diff --git a/pygithub3/requests/pull_requests/comments.py b/pygithub3/requests/pull_requests/comments.py new file mode 100644 index 0000000..fa1e5b6 --- /dev/null +++ b/pygithub3/requests/pull_requests/comments.py @@ -0,0 +1,43 @@ +from pygithub3.requests.base import Request +from pygithub3.resources.pull_requests import Comment + + +class List(Request): + uri = 'repos/{user}/{repo}/pulls/{number}/comments' + resource = Comment + + +class Get(Request): + uri = 'repos/{user}/{repo}/pulls/comments/{number}' + resource = Comment + + +class Create(Request): + uri = 'repos/{user}/{repo}/pulls/{number}/comments' + resource = Comment + body_schema = { + 'schema': ('body', 'commit_id', 'path', 'position', 'in_reply_to'), + 'required': ('body',), + } + + def validate_body(self, body): + if (not ('commit_id' in body and + 'path' in body and + 'position' in body) and + not 'in_reply_to' in body): + raise ValidationError('supply either in_reply_to or commit_id, ' + 'path, and position') + + +class Edit(Request): + uri = 'repos/{user}/{repo}/pulls/comments/{number}' + resource = Comment + body_schema = { + 'schema': ('body',), + 'required': ('body',), + } + + +class Delete(Request): + uri = 'repos/{user}/{repo}/pulls/comments/{number}' + resource = Comment -- cgit v1.2.3-59-g8ed1b From efee843e8e46894ed236811c29bb9c07e9907000 Mon Sep 17 00:00:00 2001 From: Nat Williams Date: Thu, 19 Apr 2012 09:56:56 -0500 Subject: merge request won't json encode body without schema --- pygithub3/requests/pull_requests/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'pygithub3/requests/pull_requests') diff --git a/pygithub3/requests/pull_requests/__init__.py b/pygithub3/requests/pull_requests/__init__.py index 7e85f8f..bd03f3e 100644 --- a/pygithub3/requests/pull_requests/__init__.py +++ b/pygithub3/requests/pull_requests/__init__.py @@ -60,3 +60,7 @@ class Merge_status(Request): class Merge(Request): uri = 'repos/{user}/{repo}/pulls/{number}/merge' resource = Raw + body_schema = { + 'schema': ('commit_message',), + 'required': (), + } -- cgit v1.2.3-59-g8ed1b