| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7ed34ed commit 967595f
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,4 +5,5 @@ API objects manipulation | |||
| 5 | 5 | .. toctree:: | |
| 6 | 6 | ||
| 7 | 7 | gl_objects/branches | |
| 8 | + gl_objects/projects | ||
| 8 | 9 | gl_objects/users | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,67 @@ | |||
| 1 | + # list | ||
| 2 | + # Active projects | ||
| 3 | + projects = gl.projects.list() | ||
| 4 | + # Archived projects | ||
| 5 | + projects = gl.projects.list(archived=1) | ||
| 6 | + # Limit to projects with a defined visibility | ||
| 7 | + projects = gl.projects.list(visibility='public') | ||
| 8 | + | ||
| 9 | + # List owned projects | ||
| 10 | + projects = gl.projects.owned() | ||
| 11 | + | ||
| 12 | + # List starred projects | ||
| 13 | + projects = gl.projects.starred() | ||
| 14 | + | ||
| 15 | + # List all the projects | ||
| 16 | + projects = gl.projects.all() | ||
| 17 | + # end list | ||
| 18 | + | ||
| 19 | + # get | ||
| 20 | + # Get a project by ID | ||
| 21 | + project = gl.projects.get(10) | ||
| 22 | + # Get a project by userspace/name | ||
| 23 | + project = gl.projects.get('myteam/myproject') | ||
| 24 | + # end get | ||
| 25 | + | ||
| 26 | + # create | ||
| 27 | + project = gl.projects.create({'name': 'project1'}) | ||
| 28 | + # end create | ||
| 29 | + | ||
| 30 | + # user create | ||
| 31 | + alice gl.users.list(username='alice')[0] | ||
| 32 | + user_project = gl.user_projects.create({'name': 'project', | ||
| 33 | + 'user_id': alice.id}) | ||
| 34 | + # end user create | ||
| 35 | + | ||
| 36 | + # update | ||
| 37 | + project.snippets_enabled = 1 | ||
| 38 | + project.save() | ||
| 39 | + # end update | ||
| 40 | + | ||
| 41 | + # delete | ||
| 42 | + gl.projects.delete(1) | ||
| 43 | + # or | ||
| 44 | + project.delete() | ||
| 45 | + # end delete | ||
| 46 | + | ||
| 47 | + # fork | ||
| 48 | + fork = gl.project_forks.create(project_id=1) | ||
| 49 | + # or | ||
| 50 | + fork = project.fork() | ||
| 51 | + # end fork | ||
| 52 | + | ||
| 53 | + # star | ||
| 54 | + p.star() | ||
| 55 | + p.unstar() | ||
| 56 | + # end star | ||
| 57 | + | ||
| 58 | + # archive | ||
| 59 | + p.archive_() | ||
| 60 | + p.unarchive_() | ||
| 61 | + # end archive | ||
| 62 | + | ||
| 63 | + # events list | ||
| 64 | + gl.project_events.list(project_id=1) | ||
| 65 | + # or | ||
| 66 | + project.events.list() | ||
| 67 | + # end events list | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,96 @@ | |||
| 1 | + ######## | ||
| 2 | + Projects | ||
| 3 | + ######## | ||
| 4 | + | ||
| 5 | + Use :class:`~gitlab.objects.Project` objects to manipulate projects. The | ||
| 6 | + :attr:`gitlab.Gitlab.projects` manager objects provides helper functions. | ||
| 7 | + | ||
| 8 | + Examples | ||
| 9 | + ======== | ||
| 10 | + | ||
| 11 | + List projects: | ||
| 12 | + | ||
| 13 | + The API provides several filtering parameters for the listing methods: | ||
| 14 | + | ||
| 15 | + * ``archived``: if ``True`` only archived projects will be returned | ||
| 16 | + * ``visibility``: returns only projects with the specified visibility (can be | ||
| 17 | + ``public``, ``internal`` or ``private``) | ||
| 18 | + * ``search``: returns project matching the given pattern | ||
| 19 | + | ||
| 20 | + Results can also be sorted using the following parameters: | ||
| 21 | + | ||
| 22 | + * ``order_by``: sort using the given argument. Valid values are ``id``, | ||
| 23 | + ``name``, ``path``, ``created_at``, ``updated_at`` and ``last_activity_at``. | ||
| 24 | + The default is to sort by ``created_at`` | ||
| 25 | + * ``sort``: sort order (``asc`` or ``desc``) | ||
| 26 | + | ||
| 27 | + .. literalinclude:: projects.py | ||
| 28 | + :start-after: # list | ||
| 29 | + :end-before: # end list | ||
| 30 | + | ||
| 31 | + Get a single project: | ||
| 32 | + | ||
| 33 | + .. literalinclude:: projects.py | ||
| 34 | + :start-after: # get | ||
| 35 | + :end-before: # end get | ||
| 36 | + | ||
| 37 | + Create a project: | ||
| 38 | + | ||
| 39 | + .. literalinclude:: projects.py | ||
| 40 | + :start-after: # create | ||
| 41 | + :end-before: # end create | ||
| 42 | + | ||
| 43 | + Create a project for a user (admin only): | ||
| 44 | + | ||
| 45 | + .. literalinclude:: projects.py | ||
| 46 | + :start-after: # user create | ||
| 47 | + :end-before: # end user create | ||
| 48 | + | ||
| 49 | + Update a project: | ||
| 50 | + | ||
| 51 | + .. literalinclude:: projects.py | ||
| 52 | + :start-after: # update | ||
| 53 | + :end-before: # end update | ||
| 54 | + | ||
| 55 | + Delete a project: | ||
| 56 | + | ||
| 57 | + .. literalinclude:: projects.py | ||
| 58 | + :start-after: # delete | ||
| 59 | + :end-before: # end delete | ||
| 60 | + | ||
| 61 | + Fork a project : | ||
| 62 | + | ||
| 63 | + .. literalinclude:: projects.py | ||
| 64 | + :start-after: # fork | ||
| 65 | + :end-before: # end fork | ||
| 66 | + | ||
| 67 | + Star/unstar a project: | ||
| 68 | + | ||
| 69 | + .. literalinclude:: projects.py | ||
| 70 | + :start-after: # star | ||
| 71 | + :end-before: # end star | ||
| 72 | + | ||
| 73 | + Archive/unarchive a project: | ||
| 74 | + | ||
| 75 | + .. literalinclude:: projects.py | ||
| 76 | + :start-after: # archive | ||
| 77 | + :end-before: # end archive | ||
| 78 | + | ||
| 79 | + .. note:: | ||
| 80 | + | ||
| 81 | + The underscore character at the end of the methods is used to workaround a | ||
| 82 | + conflict with a previous misuse of the ``archive`` method (deprecated but | ||
| 83 | + not yet removed). | ||
| 84 | + | ||
| 85 | + Events | ||
| 86 | + ------ | ||
| 87 | + | ||
| 88 | + Use :class:`~gitlab.objects.ProjectEvent` objects to manipulate projects. The | ||
| 89 | + :attr:`gitlab.Gitlab.project_events` and :attr:`Project.events | ||
| 90 | + <gitlab.objects.Project.events>` manager objects provide helper functions. | ||
| 91 | + | ||
| 92 | + List the project events: | ||
| 93 | + | ||
| 94 | + .. literalinclude:: projects.py | ||
| 95 | + :start-after: # events list | ||
| 96 | + :end-before: # end events list | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,7 +10,7 @@ | |||
| 10 | 10 | # by ID | |
| 11 | 11 | user = gl.users.get(2) | |
| 12 | 12 | # by username | |
| 13 | - user = gl.users.list(username='root') | ||
| 13 | + user = gl.users.list(username='root')[0] | ||
| 14 | 14 | # end get | |
| 15 | 15 | ||
| 16 | 16 | # create | |
| Back | FazBrowse Home | New Git URL |
0 commit comments