diff --git a/IntegrationTest.py b/IntegrationTest.py index 64692316..13975aa2 100644 --- a/IntegrationTest.py +++ b/IntegrationTest.py @@ -166,6 +166,14 @@ class IntegrationTest: i = r.create_issue( "Issue created by PyGithub" ) i.edit( body = "Body edited by PyGithub" ) + la = r.create_label( "a", "00FF00" ) + lb = r.create_label( "b", "00FF00" ) + lc = r.create_label( "c", "00FF00" ) + i.set_labels( la, lb ) + i.remove_from_labels( lb ) + i.delete_labels() + i.add_to_labels( lc ) + self.dumpRepository( r ) def dumpUser( self, u ): @@ -217,7 +225,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 " Issues:", ", ".join( i.title + " (" + ", ".join( l.name for l in i.get_labels() ) + ")" 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 afa1b277..af6b16cc 100644 --- a/ReferenceOfApis.md +++ b/ReferenceOfApis.md @@ -250,14 +250,14 @@ API `/repos/:user/:repo/issues/:id/comments` API `/repos/:user/:repo/issues/:id/labels` ========================================== -* GET: (TODO SOON) -* POST: (TODO SOON) -* PUT: (TODO SOON) -* DELETE: (TODO SOON) +* GET: `Issue.get_labels()`: list of `Label` +* POST: `Issue.add_to_labels( ... )` +* PUT: `Issue.set_labels( ... )` +* DELETE: `Issue.delete_labels()` -API `/repos/:user/:repo/issues/:id/labels/:id` -============================================== -* DELETE: (TODO SOON) +API `/repos/:user/:repo/issues/:id/labels/:name` +================================================ +* DELETE: `Issue.remove_from_labels( name )` API `/repos/:user/:repo/issues/:id/events` ========================================== diff --git a/ReferenceOfClasses.md b/ReferenceOfClasses.md index 938679f3..119529a2 100644 --- a/ReferenceOfClasses.md +++ b/ReferenceOfClasses.md @@ -159,6 +159,11 @@ 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 +* `get_labels()`: list of `Label` +* `add_to_labels( label, ... )` +* `set_labels( label, ... )` +* `delete_labels()` +* `remove_from_labels( label )` Class `Milestone` ================ diff --git a/github/GithubObject.py b/github/GithubObject.py index 11ae69c4..449268de 100644 --- a/github/GithubObject.py +++ b/github/GithubObject.py @@ -2,7 +2,7 @@ import itertools import ObjectCapacities.ArgumentsChecker as ArgumentsChecker from ObjectCapacities.Basic import AttributeFromCallable, MethodFromCallable -from ObjectCapacities.List import ListAttribute, ListGetable, ElementCreatable, ElementGetable, ElementAddable, ElementRemovable, ElementHasable +from ObjectCapacities.List import ListAttribute, ListGetable, ElementCreatable, ElementGetable, ElementAddable, ElementRemovable, ElementHasable, ListAddable, ListSetable, ListDeletable class BadGithubObjectException( Exception ): pass diff --git a/github/GithubObjects.py b/github/GithubObjects.py index 25c82053..e3649d2b 100644 --- a/github/GithubObjects.py +++ b/github/GithubObjects.py @@ -118,7 +118,8 @@ GitTag = GithubObject( Label = GithubObject( "Label", - BaseUrl( lambda obj: obj._repo._baseUrl + "/labels/" + urllib.quote( obj.name ) ), + BaseUrl( lambda obj: obj._repo._baseUrl + "/labels/" + obj._identity ), + Identity( lambda obj: urllib.quote( obj.name ) ), BasicAttributes( "url", "name", "color", "_repo", ### Ugly hack @@ -154,6 +155,13 @@ Issue = GithubObject( ComplexAttribute( "assignee", NamedUser ), ComplexAttribute( "milestone", Milestone ), Editable( [], [ "title", "body", "assignee", "state", "milestone", "labels" ] ), + ListAttribute( "labels", Label, + ListGetable( [], [], lambda obj, attributes: dict( itertools.chain( attributes.iteritems(), { "_repo": obj._repo }.iteritems() ) ) ), + ListAddable(), + ListSetable(), + ListDeletable(), + ElementRemovable(), + ), ) __modifyAttributesForObjectsReferingRepo = lambda obj, attributes: dict( itertools.chain( attributes.iteritems(), { "_repo": obj }.iteritems() ) ) diff --git a/github/ObjectCapacities/List.py b/github/ObjectCapacities/List.py index acc8dd9e..a3f05348 100644 --- a/github/ObjectCapacities/List.py +++ b/github/ObjectCapacities/List.py @@ -77,6 +77,37 @@ class ElementGetable: def __execute( self, obj, *args, **kwds ): return self.__type( obj._github, self.__attributes( obj, *args, **kwds ), lazy = False ) +class ListAddable: + def apply( self, list, cls ): + self.__type = list.type + self.__attributeName = list.attributeName + cls._addMethod( "add_to_" + list.attributeName.replace( "/", "_" ), self.__execute ) + + def __execute( self, obj, *toBeAddeds ): + for toBeAdded in toBeAddeds: + assert isinstance( toBeAdded, self.__type ) + obj._github._statusRequest( "POST", obj._baseUrl + "/" + self.__attributeName, None, [ toBeAdded._identity for toBeAdded in toBeAddeds ] ) + +class ListSetable: + def apply( self, list, cls ): + self.__type = list.type + self.__attributeName = list.attributeName + cls._addMethod( "set_" + list.attributeName.replace( "/", "_" ), self.__execute ) + + def __execute( self, obj, *toBeSets ): + for toBeSet in toBeSets: + assert isinstance( toBeSet, self.__type ) + obj._github._statusRequest( "PUT", obj._baseUrl + "/" + self.__attributeName, None, [ toBeSet._identity for toBeSet in toBeSets ] ) + +class ListDeletable: + def apply( self, list, cls ): + self.__type = list.type + self.__attributeName = list.attributeName + cls._addMethod( "delete_" + list.attributeName.replace( "/", "_" ), self.__execute ) + + def __execute( self, obj ): + obj._github._statusRequest( "DELETE", obj._baseUrl + "/" + self.__attributeName, None, None ) + class ListAttribute: def __init__( self, attributeName, type, *capacities ): self.attributeName = attributeName diff --git a/github/Requester.py b/github/Requester.py index 12aa1aeb..d37fd85b 100644 --- a/github/Requester.py +++ b/github/Requester.py @@ -1,3 +1,5 @@ +### @todo Add a copyright and license notice in all files + import httplib import json import base64