Skip to content

Commit

Permalink
Merge pull request #3 from seequent/LF-44544-allow-project-copying
Browse files Browse the repository at this point in the history
Add functionality for leapfrog release automation
  • Loading branch information
loganbeard-seequent authored Jun 1, 2022
2 parents 3f79dbb + 0acdce4 commit 0806aee
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 8 deletions.
53 changes: 53 additions & 0 deletions pyteamcity/future/build_type.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

from .core.parameter import Parameter
from .core.queryset import QuerySet
from .core.utils import raise_on_status
Expand Down Expand Up @@ -89,6 +91,57 @@ def reset_build_counter(self, counter):
data=str(counter))
raise_on_status(res)

def get_triggers(self):
url = ''.join([
self.teamcity.base_base_url,
self.href,
'/triggers'])
res = self.teamcity.session.get(
url,
headers={'Content-Type': 'application/xml'}
)
raise_on_status(res)
json = res.json()
triggers = json.get('trigger', [])
return triggers

def get_trigger(self, trigger_locator):
url = ''.join([
self.teamcity.base_base_url,
self.href,
f'/triggers/{trigger_locator}'])
res = self.teamcity.session.get(
url,
headers={'Content-Type': 'application/xml'}
)
raise_on_status(res)
return res.json()

def set_trigger(self, trigger_locator, trigger_data):
url = ''.join([
self.teamcity.base_base_url,
self.href,
f'/triggers/{trigger_locator}'])
res = self.teamcity.session.put(
url=url,
headers={'Content-Type': 'application/json'},
data=trigger_data)
raise_on_status(res)

def set_trigger_property(self, trigger_locator, property_name, property_value):
trigger_data = self.get_trigger(trigger_locator)
trigger_properties = trigger_data['properties']['property']
for i, prop in enumerate(trigger_properties):
if prop['name'] == property_name:
# Update the value of the existing property
prop['value'] = property_value
break
else:
# No existing property with name found, append a new property
trigger_properties.append({'name': property_name, 'value': property_value})
trigger_json_data = json.dumps(trigger_data)
self.set_trigger(trigger_locator, trigger_json_data)

def delete(self):
url = self.teamcity.base_base_url + self.href
res = self.teamcity.session.delete(url)
Expand Down
25 changes: 17 additions & 8 deletions pyteamcity/future/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ def create_build_type(self, name):
build_type = BuildType.from_dict(res.json(), teamcity=self.teamcity)
return build_type

def set_description(self, description):
url = self.teamcity.base_base_url + self.href + '/description'
res = self.teamcity.session.put(
url=url,
headers={'Content-Type': 'text/plain',
'Accept': 'text/plain'},
data=description)
raise_on_status(res)


class ProjectQuerySet(QuerySet):
uri = '/app/rest/projects/'
Expand All @@ -109,21 +118,21 @@ def filter(self, id=None, name=None):
def __iter__(self):
return (Project.from_dict(d, self) for d in self._data()['project'])

def create(self, name, id=None, parent_project_locator='id:_Root'):
def create(self, name, id=None, parent_project_locator='id:_Root', source_project_locator=None):
""" source_project_locator is an optional locator string of the project to create a copy of. """
url = self.base_url
attrs_dict = {'name': name}
if id is not None:
attrs_dict['id'] = id
attrs = ' '.join([
'%s="%s"' % (k, v) for k, v in attrs_dict.items()
])
xml = """
<newProjectDescription {attrs}>
<parentProject locator='{parent_project_locator}'/>
</newProjectDescription>
""".format(
attrs=attrs,
parent_project_locator=parent_project_locator)
xml = f"""
<newProjectDescription {attrs}>
{f"<sourceProject locator='{source_project_locator}'/>" if source_project_locator is not None else ""}
<parentProject locator='{parent_project_locator}'/>
</newProjectDescription>
"""
res = self.teamcity.session.post(
url=url,
headers={'Content-Type': 'application/xml'},
Expand Down

0 comments on commit 0806aee

Please sign in to comment.