Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

introduce RefreshMixin#426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
gpocentek merged 1 commit intopython-gitlab:masterfromtardyp:readmixin
Mar 5, 2018
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletionsdocs/gl_objects/builds.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -44,6 +44,22 @@
trigger.delete()
# end trigger delete

# pipeline trigger
def get_or_create_trigger(project):
trigger_decription = 'my_trigger_id'
for t in project.triggers.list():
if t.description == trigger_decription:
return t
return project.triggers.create({'description': trigger_decription})

trigger = get_or_create_trigger(project)
pipeline = project.trigger_pipeline('master', trigger.token, variables={"DEPLOY_ZONE": "us-west1"})
while pipeline.finished_at is None:
pipeline.refresh()
os.sleep(1)

# end pipeline trigger

# list
builds = project.builds.list() # v3
jobs = project.jobs.list() # v4
Expand Down
6 changes: 6 additions & 0 deletionsdocs/gl_objects/builds.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -102,6 +102,12 @@ Remove a trigger:
:start-after: # trigger delete
:end-before: # end trigger delete

Full example with wait for finish:

.. literalinclude:: builds.py
:start-after: # pipeline trigger
:end-before: # end pipeline trigger

Pipeline schedule
=================

Expand Down
19 changes: 19 additions & 0 deletionsgitlab/mixins.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -68,6 +68,25 @@ def get(self, id=None, **kwargs):
return self._obj_cls(self, server_data)


class RefreshMixin(object):
@exc.on_http_error(exc.GitlabGetError)
def refresh(self, **kwargs):
"""Refresh a single object from server.

Args:
**kwargs: Extra options to send to the Gitlab server (e.g. sudo)

Returns None (updates the object)

Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabGetError: If the server cannot perform the request
"""
path = '%s/%s' % (self.manager.path, self.id)
server_data = self.manager.gitlab.http_get(path, **kwargs)
self._update_attrs(server_data)


class ListMixin(object):
@exc.on_http_error(exc.GitlabListError)
def list(self, **kwargs):
Expand Down
19 changes: 19 additions & 0 deletionsgitlab/tests/test_mixins.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -153,6 +153,25 @@ def resp_cont(url, request):
self.assertEqual(obj.foo, 'bar')
self.assertEqual(obj.id, 42)

def test_refresh_mixin(self):
class O(RefreshMixin, FakeObject):
pass

@urlmatch(scheme="http", netloc="localhost", path='/api/v4/tests/42',
method="get")
def resp_cont(url, request):
headers = {'Content-Type': 'application/json'}
content = '{"id": 42, "foo": "bar"}'
return response(200, content, headers, None, 5, request)

with HTTMock(resp_cont):
mgr = FakeManager(self.gl)
obj = O(mgr, {'id': 42})
res = obj.refresh()
self.assertIsNone(res)
self.assertEqual(obj.foo, 'bar')
self.assertEqual(obj.id, 42)

def test_get_without_id_mixin(self):
class M(GetWithoutIdMixin, FakeManager):
pass
Expand Down
6 changes: 3 additions & 3 deletionsgitlab/v4/objects.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -909,7 +909,7 @@ class ProjectCustomAttributeManager(RetrieveMixin, SetMixin, DeleteMixin,
_from_parent_attrs = {'project_id': 'id'}


class ProjectJob(RESTObject):
class ProjectJob(RESTObject, RefreshMixin):
@cli.register_custom_action('ProjectJob')
@exc.on_http_error(exc.GitlabJobCancelError)
def cancel(self, **kwargs):
Expand DownExpand Up@@ -1045,7 +1045,7 @@ class ProjectJobManager(RetrieveMixin, RESTManager):
_from_parent_attrs = {'project_id': 'id'}


class ProjectCommitStatus(RESTObject):
class ProjectCommitStatus(RESTObject, RefreshMixin):
pass


Expand DownExpand Up@@ -1964,7 +1964,7 @@ class ProjectPipelineJobsManager(ListMixin, RESTManager):
_list_filters = ('scope',)


class ProjectPipeline(RESTObject):
class ProjectPipeline(RESTObject, RefreshMixin):
_managers = (('jobs', 'ProjectPipelineJobManager'), )

@cli.register_custom_action('ProjectPipeline')
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp