semaphoreui-client 0.1.14__tar.gz → 0.1.16__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: semaphoreui-client
3
- Version: 0.1.14
3
+ Version: 0.1.16
4
4
  Summary: An api client for interacting with Semaphore UI
5
5
  Project-URL: Documentation, https://github.com/rockstar/semaphoreui-client#readme
6
6
  Project-URL: Issues, https://github.com/rockstar/semaphoreui-client/issues
@@ -0,0 +1 @@
1
+ __version__ = "0.1.16"
@@ -451,6 +451,37 @@ class SemaphoreUIClient:
451
451
  )
452
452
  return Template(**response.json(), client=self)
453
453
 
454
+ def run_template(
455
+ self,
456
+ template_id: int,
457
+ project_id: int,
458
+ debug: bool,
459
+ dry_run: bool,
460
+ diff: bool,
461
+ message: str,
462
+ git_branch: str,
463
+ limit: int,
464
+ environment_id: int,
465
+ playbook: str,
466
+ ) -> "Task":
467
+ response = self.http.post(
468
+ f"{self.api_endpoint}/project/{project_id}/tasks",
469
+ json={
470
+ "template_id": template_id,
471
+ "debug": debug,
472
+ "dry_run": dry_run,
473
+ "diff": diff,
474
+ "playbook": playbook,
475
+ "environment": environment_id,
476
+ "limit": limit,
477
+ "git_branch": git_branch,
478
+ "message": message,
479
+ },
480
+ )
481
+ assert response.status_code == 201
482
+ # The response is not quite a full task, so re-fetch it.
483
+ return self.get_project_task(project_id, response.json()["id"])
484
+
454
485
  def delete_project_template(self, project_id: int, id: int) -> None:
455
486
  response = self.http.delete(
456
487
  f"{self.api_endpoint}/project/{project_id}/templates/{id}"
@@ -534,14 +565,12 @@ class SemaphoreUIClient:
534
565
  )
535
566
  assert response.status_code == 204
536
567
 
537
- def get_project_task_output(
538
- self, project_id: int, id: int
539
- ) -> typing.List["TaskOutput"]:
568
+ def get_project_task_output(self, project_id: int, id: int) -> str:
540
569
  response = self.http.get(
541
570
  f"{self.api_endpoint}/project/{project_id}/tasks/{id}/output"
542
571
  )
543
572
  assert response.status_code == 200
544
- return [TaskOutput(**data) for data in response.json()]
573
+ return "\n".join(data["output"] for data in response.json())
545
574
 
546
575
 
547
576
  @dataclass
@@ -911,6 +940,33 @@ class Template:
911
940
 
912
941
  client: SemaphoreUIClient
913
942
 
943
+ def run(
944
+ self,
945
+ debug: bool = False,
946
+ dry_run: bool = False,
947
+ diff: bool = False,
948
+ message: str = "",
949
+ limit: int = 1,
950
+ ) -> "Task":
951
+ repo = [
952
+ repo
953
+ for repo in self.client.get_project_repositories(self.project_id)
954
+ if repo.id == self.repository_id
955
+ ][0]
956
+ git_branch = repo.git_branch
957
+ return self.client.run_template(
958
+ self.id,
959
+ self.project_id,
960
+ debug,
961
+ dry_run,
962
+ diff,
963
+ message,
964
+ git_branch,
965
+ limit,
966
+ self.environment_id,
967
+ self.playbook,
968
+ )
969
+
914
970
  def delete(self) -> None:
915
971
  self.client.delete_project_template(self.project_id, self.id)
916
972
 
@@ -982,16 +1038,5 @@ class Task:
982
1038
  def delete(self) -> None:
983
1039
  self.client.delete_project_task(self.project_id, self.id)
984
1040
 
985
- def output(self) -> typing.List["TaskOutput"]:
1041
+ def output(self) -> str:
986
1042
  return self.client.get_project_task_output(self.project_id, self.id)
987
-
988
- def normalized_output(self) -> typing.List[str]:
989
- return [output.output for output in self.output()]
990
-
991
-
992
- @dataclass
993
- class TaskOutput:
994
- task_id: int
995
- task: str
996
- time: str
997
- output: str
@@ -1 +0,0 @@
1
- __version__ = "0.1.14"