| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 88de2f0 commit 635f5a7
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -49,6 +49,11 @@ Delete a pipeline:: | |||
| 49 | 49 | ||
| 50 | 50 | pipeline.delete() | |
| 51 | 51 | ||
| 52 | + Get latest pipeline:: | ||
| 53 | + | ||
| 54 | + projet.pipelines.latest(ref="main") | ||
| 55 | + | ||
| 56 | + | ||
| 52 | 57 | Triggers | |
| 53 | 58 | ======== | |
| 54 | 59 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -139,6 +139,27 @@ def create( | |||
| 139 | 139 | ProjectPipeline, CreateMixin.create(self, data, path=path, **kwargs) | |
| 140 | 140 | ) | |
| 141 | 141 | ||
| 142 | + def latest(self, ref: Optional[str] = None, lazy: bool = False) -> ProjectPipeline: | ||
| 143 | + """Get the latest pipeline for the most recent commit | ||
| 144 | + on a specific ref in a project | ||
| 145 | + | ||
| 146 | + Args: | ||
| 147 | + ref: The branch or tag to check for the latest pipeline. | ||
| 148 | + Defaults to the default branch when not specified. | ||
| 149 | + Returns: | ||
| 150 | + A Pipeline instance | ||
| 151 | + """ | ||
| 152 | + data = {} | ||
| 153 | + if ref: | ||
| 154 | + data = {"ref": ref} | ||
| 155 | + if TYPE_CHECKING: | ||
| 156 | + assert self._obj_cls is not None | ||
| 157 | + assert self.path is not None | ||
| 158 | + server_data = self.gitlab.http_get(self.path + "/latest", query_data=data) | ||
| 159 | + if TYPE_CHECKING: | ||
| 160 | + assert not isinstance(server_data, requests.Response) | ||
| 161 | + return self._obj_cls(self, server_data, lazy=lazy) | ||
| 162 | + | ||
| 142 | 163 | ||
| 143 | 164 | class ProjectPipelineJob(RESTObject): | |
| 144 | 165 | pass | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,6 +39,62 @@ | |||
| 39 | 39 | "web_url": "https://example.com/foo/bar/pipelines/46", | |
| 40 | 40 | } | |
| 41 | 41 | ||
| 42 | + pipeline_latest = { | ||
| 43 | + "id": 47, | ||
| 44 | + "project_id": 1, | ||
| 45 | + "status": "pending", | ||
| 46 | + "ref": "main", | ||
| 47 | + "sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a", | ||
| 48 | + "before_sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a", | ||
| 49 | + "tag": False, | ||
| 50 | + "yaml_errors": None, | ||
| 51 | + "user": { | ||
| 52 | + "name": "Administrator", | ||
| 53 | + "username": "root", | ||
| 54 | + "id": 1, | ||
| 55 | + "state": "active", | ||
| 56 | + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", | ||
| 57 | + "web_url": "http://localhost:3000/root", | ||
| 58 | + }, | ||
| 59 | + "created_at": "2016-08-11T11:28:34.085Z", | ||
| 60 | + "updated_at": "2016-08-11T11:32:35.169Z", | ||
| 61 | + "started_at": None, | ||
| 62 | + "finished_at": "2016-08-11T11:32:35.145Z", | ||
| 63 | + "committed_at": None, | ||
| 64 | + "duration": None, | ||
| 65 | + "queued_duration": 0.010, | ||
| 66 | + "coverage": None, | ||
| 67 | + "web_url": "https://example.com/foo/bar/pipelines/46", | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + pipeline_latest_other_ref = { | ||
| 71 | + "id": 48, | ||
| 72 | + "project_id": 1, | ||
| 73 | + "status": "pending", | ||
| 74 | + "ref": "feature-ref", | ||
| 75 | + "sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a", | ||
| 76 | + "before_sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a", | ||
| 77 | + "tag": False, | ||
| 78 | + "yaml_errors": None, | ||
| 79 | + "user": { | ||
| 80 | + "name": "Administrator", | ||
| 81 | + "username": "root", | ||
| 82 | + "id": 1, | ||
| 83 | + "state": "active", | ||
| 84 | + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", | ||
| 85 | + "web_url": "http://localhost:3000/root", | ||
| 86 | + }, | ||
| 87 | + "created_at": "2016-08-11T11:28:34.085Z", | ||
| 88 | + "updated_at": "2016-08-11T11:32:35.169Z", | ||
| 89 | + "started_at": None, | ||
| 90 | + "finished_at": "2016-08-11T11:32:35.145Z", | ||
| 91 | + "committed_at": None, | ||
| 92 | + "duration": None, | ||
| 93 | + "queued_duration": 0.010, | ||
| 94 | + "coverage": None, | ||
| 95 | + "web_url": "https://example.com/foo/bar/pipelines/46", | ||
| 96 | + } | ||
| 97 | + | ||
| 42 | 98 | ||
| 43 | 99 | test_report_content = { | |
| 44 | 100 | "total_time": 5, | |
@@ -162,10 +218,37 @@ def resp_get_pipeline_test_report_summary(): | |||
| 162 | 218 | yield rsps | |
| 163 | 219 | ||
| 164 | 220 | ||
| 221 | + @pytest.fixture | ||
| 222 | + def resp_get_latest(): | ||
| 223 | + with responses.RequestsMock() as rsps: | ||
| 224 | + rsps.add( | ||
| 225 | + method=responses.GET, | ||
| 226 | + url="http://localhost/api/v4/projects/1/pipelines/latest", | ||
| 227 | + json=pipeline_latest, | ||
| 228 | + content_type="application/json", | ||
| 229 | + status=200, | ||
| 230 | + ) | ||
| 231 | + yield rsps | ||
| 232 | + | ||
| 233 | + | ||
| 234 | + @pytest.fixture | ||
| 235 | + def resp_get_latest_other_ref(): | ||
| 236 | + with responses.RequestsMock() as rsps: | ||
| 237 | + rsps.add( | ||
| 238 | + method=responses.GET, | ||
| 239 | + url="http://localhost/api/v4/projects/1/pipelines/latest", | ||
| 240 | + json=pipeline_latest_other_ref, | ||
| 241 | + content_type="application/json", | ||
| 242 | + status=200, | ||
| 243 | + ) | ||
| 244 | + yield rsps | ||
| 245 | + | ||
| 246 | + | ||
| 165 | 247 | def test_get_project_pipeline(project, resp_get_pipeline): | |
| 166 | 248 | pipeline = project.pipelines.get(1) | |
| 167 | 249 | assert isinstance(pipeline, ProjectPipeline) | |
| 168 | 250 | assert pipeline.ref == "main" | |
| 251 | + assert pipeline.id == 46 | ||
| 169 | 252 | ||
| 170 | 253 | ||
| 171 | 254 | def test_cancel_project_pipeline(project, resp_cancel_pipeline): | |
@@ -198,3 +281,17 @@ def test_get_project_pipeline_test_report_summary( | |||
| 198 | 281 | assert isinstance(test_report_summary, ProjectPipelineTestReportSummary) | |
| 199 | 282 | assert test_report_summary.total["count"] == 3363 | |
| 200 | 283 | assert test_report_summary.test_suites[0]["name"] == "test" | |
| 284 | + | ||
| 285 | + | ||
| 286 | + def test_latest_pipeline(project, resp_get_latest): | ||
| 287 | + pipeline = project.pipelines.latest() | ||
| 288 | + assert isinstance(pipeline, ProjectPipeline) | ||
| 289 | + assert pipeline.ref == "main" | ||
| 290 | + assert pipeline.id == 47 | ||
| 291 | + | ||
| 292 | + | ||
| 293 | + def test_latest_pipeline_other_ref(project, resp_get_latest_other_ref): | ||
| 294 | + pipeline = project.pipelines.latest(ref="feature-ref") | ||
| 295 | + assert isinstance(pipeline, ProjectPipeline) | ||
| 296 | + assert pipeline.ref == "feature-ref" | ||
| 297 | + assert pipeline.id == 48 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments