Integrates GitLab API in your Craft templates.
To install GitLab integration, follow these steps:
- Download & unzip the file and place the
gitlab
directory into yourcraft/plugins
directory - -OR- do a
git clone https://github.com/r-ninja/gitlab.git
directly into yourcraft/plugins
folder. You can then update it withgit pull
- Install plugin in the Craft Control Panel under Settings > Plugins
- The plugin folder should be named
gitlab
for Craft to see it. GitHub recently started appending-master
(the branch name) to the name of the folder for zip file downloads.
GitLab works on Craft 2.4.x and Craft 2.5.x.
This plugin allows you to use the GitLab API to retrieve information directly in your Craft templates.
Please see https://github.com/gitlabhq/gitlabhq/tree/master/doc/api for more information about the GitLab API.
In the plugin settings window, set the GitLab URL (with trailing slash) and your private token. You can find or reset your private token in your GitLab account page (/profile/account)
Once installed and configured, you will be able to call different variables directly in your templates.
List all projects
{% set projects = craft.gitlab.projects('all') %}
<ul>
{% for project in projects.data %}
<li>
<strong>{{ project.name }}</strong> - {{ project.description }}<br>
URL: {{ project.http_url_to_repo }}<br>
Tags: {{ project.tag_list|join(', ') }}<br>
Owner: {{ project.owner.name }}
</li>
{% endfor %}
</ul>
Retrieve information about current user (user associated to private token)
{% set me = craft.gitlab.user.data %}
<p>Hello my name is {{ me.name }} ({{ me.username }})</p>
List opened merge requests
{% set projectid = 1 %}
{% set mergerequests = craft.gitlab.getMergeRequests(projectid, {state: 'opened'}) %}
<ul>
{% for mergerequest in mergerequests.data %}
<li>
Target branch: {{ mergerequest.target_branch }}<br>
Source branch: {{ mergerequest.source_branch }}<br>
Author: {{ mergerequest.author.username }}<br>
Assignee: {{ mergerequest.assignee.username }}<br>
Description: {{ mergerequest.description }}
</li>
{% endfor %}
</ul>
Some things to do, and ideas for potential features:
- Craft CMS dashboard widgets
- CP section
- Add other APIs using POST, PUT and DELETE
- Initial release
Brought to you by Richard Trudel