Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for change details. #89

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions pyteamcity/future/change.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .change_details import ChangeDetails
from .core.queryset import QuerySet
from .core.utils import parse_date_string

Expand All @@ -13,13 +14,24 @@ def __init__(self, id,
self.date_str = date_str
self.href = href
self.web_url = web_url
self.query_set = query_set
self.change_query_set = query_set
self._data_dict = data_dict

@property
def api_url(self):
teamcity = self.change_query_set.teamcity
base_url = teamcity.base_url
url = base_url + '/app/rest/changes/id:%s' % self.id
return url

@property
def date(self):
return parse_date_string(self.date_str)

@property
def details(self):
return ChangeDetails(change=self)

def __repr__(self):
return '<%s.%s: id=%r version=%r username=%r date=%r>' % (
self.__module__,
Expand All @@ -46,6 +58,7 @@ def from_dict(cls, d, query_set=None):
class ChangeQuerySet(QuerySet):
uri = '/app/rest/changes/'
_entity_factory = Change
entityName = 'change'

def filter(self,
id=None,
Expand Down Expand Up @@ -75,5 +88,8 @@ def filter(self,
return self

def __iter__(self):
data = self._data()
if self.entityName not in data:
return iter(())
return (self.__class__._entity_factory.from_dict(d, self)
for d in self._data()['change'])
for d in data[self.entityName])
26 changes: 26 additions & 0 deletions pyteamcity/future/change_details.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from . import exceptions
from .core.utils import raise_on_status


class ChangeDetails(object):
def __init__(self, change):
self.change = change
teamcity = self.change.change_query_set.teamcity
url = self.change.api_url
res = teamcity.session.get(url)
if res.status_code == 404:
raise exceptions.ChangeDetailsNotFound(id=self.change.id)
raise_on_status(res)
self._data = res.json()
self._metadata_url = url

@property
def comment(self):
return self._data['comment']

def __repr__(self):
return '<%s.%s: change.id=%r comment=%r>' % (
self.__module__,
self.__class__.__name__,
self.change.id,
self.comment)
4 changes: 2 additions & 2 deletions pyteamcity/future/core/queryset.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ def get(self, just_url=False,
raise exceptions.MultipleObjectsReturned()
self._data_dict = None
if just_url:
return self._get_url(details=True)
return self._get_url(details=False)
else:
return self.__class__._from_dict(
self._data(details=True), self)
self._data(details=False), self)

def __len__(self):
data = self._data()
Expand Down
8 changes: 8 additions & 0 deletions pyteamcity/future/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ def __str__(self):
return 'Artifact not found: %s' % self.path


class ChangeDetailsNotFound(Error):
def __init__(self, id):
self.iud = id

def __str__(self):
return 'Change details not found: %s' % self.id


class HTTPError(Error):
def __init__(self, status_code, reason, text):
self.status_code = status_code
Expand Down