From ce2135c9611bc191a289d68374df34b4b6b3da75 Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Fri, 24 Feb 2012 14:57:26 +0000 Subject: [PATCH] Repository issues --- IntegrationTest.py | 3 +++ ReferenceOfApis.md | 12 ++++++------ ReferenceOfClasses.md | 10 +++++++++- github/GithubObject.py | 5 ++++- github/GithubObjects.py | 22 +++++++++++++++++++++- 5 files changed, 43 insertions(+), 9 deletions(-) diff --git a/IntegrationTest.py b/IntegrationTest.py index 9c4533b8..64692316 100644 --- a/IntegrationTest.py +++ b/IntegrationTest.py @@ -163,6 +163,8 @@ class IntegrationTest: m.edit( title = m.title, description = "And the description was modified by PyGithub as well" ) m = r.create_milestone( title = "This milestone was also created by PyGithub" ) m.delete() + i = r.create_issue( "Issue created by PyGithub" ) + i.edit( body = "Body edited by PyGithub" ) self.dumpRepository( r ) @@ -215,6 +217,7 @@ class IntegrationTest: print base64.b64decode( blob.content ), print print " Labels:", ", ".join( l.name + " (" + l.color + ")" for l in r.get_labels() ) + print " Issues:", ", ".join( i.title for i in r.get_issues() ) print " Milestones:", ", ".join( m.title + " (created by " + m.creator.login + ", " + ", ".join( l.name for l in m.get_labels() ) + ")" for m in r.get_milestones() ) print " Closed milestones:", ", ".join( m.title for m in r.get_milestones( state = "closed" ) ) print diff --git a/ReferenceOfApis.md b/ReferenceOfApis.md index 6a0938b2..afa1b277 100644 --- a/ReferenceOfApis.md +++ b/ReferenceOfApis.md @@ -235,13 +235,13 @@ API `/repos/:user/:repo/hooks/:id/test` API `/repos/:user/:repo/issues` =============================== -* GET: (TODO SOON) -* POST: (TODO SOON) +* GET: `Repository.get_issues( ... )`: list of `Issue` +* POST: `Repository.create_issue( ... )`: `Issue` API `/repos/:user/:repo/issues/:id` =================================== -* GET: (TODO SOON) -* PATCH: (TODO SOON) +* GET: `Repository.get_issue( id )`: `Issue` +* PATCH: `Issue.edit( ... )` API `/repos/:user/:repo/issues/:id/comments` ============================================ @@ -259,8 +259,8 @@ API `/repos/:user/:repo/issues/:id/labels/:id` ============================================== * DELETE: (TODO SOON) -API `/repos/:user/:repo/issues/:issue_id/events` -================================================ +API `/repos/:user/:repo/issues/:id/events` +========================================== * GET: (TODO) API `/repos/:user/:repo/issues/comments/:id` diff --git a/ReferenceOfClasses.md b/ReferenceOfClasses.md index 40718b69..938679f3 100644 --- a/ReferenceOfClasses.md +++ b/ReferenceOfClasses.md @@ -142,16 +142,24 @@ Issues and milestones * `get_labels()`: list of `Label` * `create_label( ... )`: `Label`: see [API](http://developer.github.com/v3/issues/labels/#create-a-label) for parameters * `get_label( id )`: `Label` +* `get_issues( ... )`: list of `Issue`: see [API](http://developer.github.com/v3/issues/#list-issues-for-a-repository) for parameters +* `create_issue( ... )`: `Issue`: see [API](http://developer.github.com/v3/issues/#create-an-issue) for parameters +* `get_issue( id )`: `Issue` * `get_milestones( ... )`: list of `Milestone`: see [API](http://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository) for parameters * `create_milestone( ... )`: `Milestone`: see [API](http://developer.github.com/v3/issues/milestones/#create-a-milestone) for parameters * `get_milestone( number )`: `Milestone` Class `Label` -================ +============= * Attributes: see [API](http://developer.github.com/v3/issues/labels/#get-a-single-label) * `edit( ... )`: see [API](http://developer.github.com/v3/issues/labels/#update-a-label) for parameters * `delete()` +Class `Issue` +============= +* Attributes: see [API](http://developer.github.com/v3/issues/#get-a-single-issue) +* `edit( ... )`: see [API](http://developer.github.com/v3/issues/#edit-an-issue) for parameters + Class `Milestone` ================ * Attributes: see [API](http://developer.github.com/v3/issues/milestones/#get-a-single-milestone) diff --git a/github/GithubObject.py b/github/GithubObject.py index 06017d71..11ae69c4 100644 --- a/github/GithubObject.py +++ b/github/GithubObject.py @@ -38,7 +38,10 @@ class ComplexAttribute: self.__type = type def getValueFromRawValue( self, obj, rawValue ): - return self.__type( obj._github, rawValue, lazy = True ) + if rawValue is None: + return None + else: + return self.__type( obj._github, rawValue, lazy = True ) def updateAttributes( self, obj ): attributes = obj._github._dataRequest( "GET", obj._baseUrl, None, None ) diff --git a/github/GithubObjects.py b/github/GithubObjects.py index 9de6fc0e..25c82053 100644 --- a/github/GithubObjects.py +++ b/github/GithubObjects.py @@ -141,6 +141,21 @@ Milestone = GithubObject( ListAttribute( "labels", Label, ListGetable( [], [], lambda obj, attributes: dict( itertools.chain( attributes.iteritems(), { "_repo": obj._repo }.iteritems() ) ) ) ), ) +Issue = GithubObject( + "Issue", + BaseUrl( lambda obj: obj._repo._baseUrl + "/issues/" + str( obj.number ) ), + BasicAttributes( + "url", "html_url", "number", "state", "title", "body", "labels", + "comments", "closed_at", "created_at", "updated_at", "id", "closed_by", + "pull_request", ### @todo Structure + "_repo", ### Ugly hack + ), + ComplexAttribute( "user", NamedUser ), + ComplexAttribute( "assignee", NamedUser ), + ComplexAttribute( "milestone", Milestone ), + Editable( [], [ "title", "body", "assignee", "state", "milestone", "labels" ] ), +) + __modifyAttributesForObjectsReferingRepo = lambda obj, attributes: dict( itertools.chain( attributes.iteritems(), { "_repo": obj }.iteritems() ) ) Repository = GithubObject( "Repository", @@ -190,7 +205,12 @@ Repository = GithubObject( ListGetable( [], [ "state", "sort", "direction" ], __modifyAttributesForObjectsReferingRepo ), ElementGetable( "milestone", lambda repo, number: { "_repo": repo, "number": number } ), ElementCreatable( "milestone", [ "title" ], [ "state", "description", "due_on" ], __modifyAttributesForObjectsReferingRepo ) - ) + ), + ListAttribute( "issues", Issue, + ListGetable( [], [ "milestone", "state", "assignee", "mentioned", "labels", "sort", "direction", "since" ], __modifyAttributesForObjectsReferingRepo ), + ElementGetable( "issue", lambda repo, number: { "_repo": repo, "number": number } ), + ElementCreatable( "issue", [ "title" ], [ "body", "assignee", "milestone", "labels", ], __modifyAttributesForObjectsReferingRepo ) + ), ) Repository._addAttributePolicy( ComplexAttribute( "parent", Repository ) ) Repository._addAttributePolicy( ComplexAttribute( "source", Repository ) )