Skip to content

Commit

Permalink
Implement create/delete build type
Browse files Browse the repository at this point in the history
  • Loading branch information
msabramo committed Aug 9, 2016
1 parent 6dd1852 commit 2a4fdd1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
2 changes: 0 additions & 2 deletions pyteamcity/future/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
@todo: Allow creating build types
@todo: Allow deleting build types
@todo: Allow pausing build types
@todo: Allow triggering builds
@todo: Allow canceling builds
Expand Down
18 changes: 16 additions & 2 deletions pyteamcity/future/build_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class BuildType(object):
def __init__(self, id, name, description, href, web_url,
project_id, project_name,
paused, template_flag,
build_type_query_set, data_dict=None):
teamcity, build_type_query_set, data_dict=None):
self.id = id
self.name = name
self.description = description
Expand All @@ -16,7 +16,10 @@ def __init__(self, id, name, description, href, web_url,
self.project_name = project_name
self.paused = paused
self.template_flag = template_flag
self.teamcity = teamcity
self.build_type_query_set = build_type_query_set
if self.teamcity is None and self.build_type_query_set is not None:
self.teamcity = self.build_type_query_set.teamcity
self._data_dict = data_dict

def __repr__(self):
Expand All @@ -28,7 +31,7 @@ def __repr__(self):
self.project_name)

@classmethod
def from_dict(cls, d, build_type_query_set=None):
def from_dict(cls, d, build_type_query_set=None, teamcity=None):
return BuildType(
id=d.get('id'),
name=d.get('name'),
Expand All @@ -40,6 +43,7 @@ def from_dict(cls, d, build_type_query_set=None):
paused=d.get('paused'),
template_flag=d.get('templateFlag'),
build_type_query_set=build_type_query_set,
teamcity=teamcity,
data_dict=d)

@property
Expand All @@ -63,6 +67,16 @@ def parameters_dict(self):

return d

def delete(self):
url = self.teamcity.base_base_url + self.href
res = self.teamcity.session.delete(url)
if not res.ok:
raise exceptions.HTTPError(
status_code=res.status_code,
reason=res.reason,
text=res.text)
return url


class BuildTypeQuerySet(QuerySet):
uri = '/app/rest/buildTypes/'
Expand Down
21 changes: 20 additions & 1 deletion pyteamcity/future/project.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from . import exceptions
from .build_type import BuildType
from .core.parameter import Parameter
from .core.queryset import QuerySet
from .core.web_browsable import WebBrowsable
Expand Down Expand Up @@ -37,8 +38,8 @@ def from_dict(cls, d, project_query_set=None, teamcity=None):
href=d.get('href'),
web_url=d.get('webUrl'),
parent_project_id=d.get('parentProjectId'),
teamcity=teamcity,
project_query_set=project_query_set,
teamcity=teamcity,
data_dict=d)

@property
Expand Down Expand Up @@ -84,6 +85,24 @@ def delete(self):
text=res.text)
return url

def create_build_type(self, name):
"""
Add an empty build type with name `name` to the project
"""

url = self.teamcity.base_base_url + self.href + '/buildTypes'
res = self.teamcity.session.post(
url=url,
headers={'Content-Type': 'text/plain'},
data=name)
if not res.ok:
raise exceptions.HTTPError(
status_code=res.status_code,
reason=res.reason,
text=res.text)
build_type = BuildType.from_dict(res.json(), teamcity=self.teamcity)
return build_type


class ProjectQuerySet(QuerySet):
uri = '/app/rest/projects/'
Expand Down

0 comments on commit 2a4fdd1

Please sign in to comment.