-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get latest CI status of a commit filtered by branch
Changes the CI status check to use the pipelines API, in order to filter status by ref (branch).
- Loading branch information
1 parent
98ee655
commit c5ce790
Showing
5 changed files
with
107 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from . import gitlab | ||
|
||
|
||
GET = gitlab.GET | ||
|
||
|
||
class Pipeline(gitlab.Resource): | ||
|
||
@classmethod | ||
def pipelines_by_branch(cls, project_id, branch, api): | ||
pipelines_info = api.call(GET( | ||
'/projects/{project_id}/pipelines'.format(project_id=project_id), | ||
{'ref': branch, 'order_by': 'id', 'sort': 'desc'}, | ||
)) | ||
|
||
return [cls(api, pipeline_info) for pipeline_info in pipelines_info] | ||
|
||
@property | ||
def ref(self): | ||
return self.info['ref'] | ||
|
||
@property | ||
def sha(self): | ||
return self.info['sha'] | ||
|
||
@property | ||
def status(self): | ||
return self.info['status'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from unittest.mock import Mock | ||
|
||
from marge.gitlab import Api, GET | ||
from marge.pipeline import Pipeline | ||
|
||
|
||
INFO = { | ||
"id": 47, | ||
"status": "pending", | ||
"ref": "new-pipeline", | ||
"sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a" | ||
} | ||
|
||
|
||
# pylint: disable=attribute-defined-outside-init | ||
class TestPipeline(object): | ||
|
||
def setup_method(self, _method): | ||
self.api = Mock(Api) | ||
|
||
def test_pipelines_by_branch(self): | ||
api = self.api | ||
pl1, pl2 = INFO, dict(INFO, id=48) | ||
api.call = Mock(return_value=[pl1, pl2]) | ||
|
||
result = Pipeline.pipelines_by_branch(project_id=1234, branch=INFO['ref'], api=api) | ||
api.call.assert_called_once_with(GET( | ||
'/projects/1234/pipelines', | ||
{'ref': INFO['ref'], 'order_by': 'id', 'sort': 'desc'}, | ||
)) | ||
assert [pl.info for pl in result] == [pl1, pl2] | ||
|
||
def test_properties(self): | ||
pipeline = Pipeline(api=self.api, info=INFO) | ||
assert pipeline.id == 47 | ||
assert pipeline.status == "pending" | ||
assert pipeline.ref == "new-pipeline" | ||
assert pipeline.sha == "a91957a858320c0e17f3a0eca7cfacbff50ea29a" |