Commit b331ff2e authored by Andrii Pozdieiev's avatar Andrii Pozdieiev

[FEATURE] add basic functionality

parent f0419ca8
<?php
namespace T3O\GitlabApi\Controller;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Merge Controller
*/
class MergeController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
{
public function listAction() {
//get params from plugin options
$host = $this->settings['host'];
$projectId = $this->settings['project'];
$targetBranch = $this->settings['branch'];
//set date restriction param if it was in plugin options
if ($this->settings['created_after'] && $this->settings['created_after'] != ''){
$createdAfter = '&created_after=' . date('Y-m-d', $this->settings['created_after']);
} else {
$createdAfter = '';
}
//set access token param if it was in plugin options
if ($this->settings['token'] && $this->settings['token'] != ''){
$token = '&private_token=' . $this->settings['token'];
} else {
$token = '';
}
/* @todo add possibility to fetch more than 100 records (navigate through pages) */
//Build API call URL;
$url = $host . '/api/v4/projects/' . $projectId . '/merge_requests?page=1&per_page=100&target_branch=' . $targetBranch . '&state=merged' . $createdAfter . $token;
//simple way to do API call :)
$json = file_get_contents($url);
$data = json_decode($json, true);
$releases = array();
//build structure for FE
foreach ($data as $release){
$releases[$release['id']]['title'] = $release['title'];
$descriptionArray = explode('* ', $release['description']);
if ($descriptionArray[0] == '') array_shift($descriptionArray);
//build array devided by description item type
foreach ($descriptionArray as $descItem){
switch (true){
case stripos($descItem,'[TASK]') !== false:
$releases[$release['id']]['tasks'][] = $descItem;
break;
case stripos($descItem,'[FEATURE]') !== false:
$releases[$release['id']]['features'][] = $descItem;
break;
case stripos($descItem,'[BUGFIX]') !== false:
$releases[$release['id']]['bugfixes'][] = $descItem;
break;
default:
$releases[$release['id']]['other'][] = $descItem;
}
}
}
$this->view->assign('releases', $releases);
}
/* Get the list of projects (used in flexform) */
public function getProjectList ($config){
//get the gitlab host parameter from flexform field
$host = $config['row']['settings.host'];
if ($host && $host != ''){
// build API call url
$url = $host . '/api/v4/projects?page=1&per_page=100' . ($config['row']['settings.token'] ? '&private_token=' . $config['row']['settings.token'] : '');
//call the projects endpoint and decode
$json = file_get_contents($url);
$data = json_decode($json, true);
//fill the valid list structure for select field
if ($data){
$projects = array();
$counter = 0;
foreach ($data as $project){
$projects[$counter][1] = $project['id'];
$projects[$counter][0] = $project['name'];
$counter++;
}
$config['items'] = $projects;
} else {
$config['items'] = '';
}
}
return $config;
}
}
<T3DataStructure>
<sheets>
<sDEF>
<ROOT>
<TCEforms>
<sheetTitle>LLL:EXT:gitlab_api/Resources/Private/Language/locallang.xlf:flexFormLabels.title</sheetTitle>
</TCEforms>
<type>array</type>
<el>
<settings.host>
<TCEforms>
<label>LLL:EXT:gitlab_api/Resources/Private/Language/locallang.xlf:flexFormLabels.host</label>
<config>
<type>input</type>
<size>200</size>
</config>
</TCEforms>
</settings.host>
<settings.project>
<TCEforms>
<label>LLL:EXT:gitlab_api/Resources/Private/Language/locallang.xlf:flexFormLabels.project</label>
<config>
<type>select</type>
<itemsProcFunc>T3O\GitlabApi\Controller\MergeController->getProjectList</itemsProcFunc>
<maxitems>1</maxitems>
</config>
<displayCond>FIELD:settings.host:REQ:true</displayCond>
</TCEforms>
</settings.project>
<settings.branch>
<TCEforms>
<label>LLL:EXT:gitlab_api/Resources/Private/Language/locallang.xlf:flexFormLabels.branch</label>
<config>
<type>input</type>
<size>200</size>
</config>
<displayCond>FIELD:settings.host:REQ:true</displayCond>
</TCEforms>
</settings.branch>
<settings.token>
<TCEforms>
<label>LLL:EXT:gitlab_api/Resources/Private/Language/locallang.xlf:flexFormLabels.token</label>
<config>
<type>input</type>
<size>200</size>
</config>
<displayCond>FIELD:settings.host:REQ:true</displayCond>
</TCEforms>
</settings.token>
<settings.created_after>
<TCEforms>
<label>LLL:EXT:gitlab_api/Resources/Private/Language/locallang.xlf:flexFormLabels.created_after</label>
<config>
<type>input</type>
<size>200</size>
<renderType>inputDateTime</renderType>
<eval>date</eval>
</config>
<displayCond>FIELD:settings.host:REQ:true</displayCond>
</TCEforms>
</settings.created_after>
</el>
</ROOT>
</sDEF>
</sheets>
</T3DataStructure>
\ No newline at end of file
plugin.tx_gitlabapi {
settings{
}
}
\ No newline at end of file
plugin.tx_bdstlocationsuggest {
view {
templateRootPaths.0 = EXT:gitlab_api/Resources/Private/Templates/
}
}
# GitLab API
TYPO3 Extension to fetch merge requests list for selected project.
## Install:
- add to project and install over Extension Manager
- add static includes
## Get GitLab personal access token:
- On GitLab go to _**Settings**_ → _**Access Tokens**_ and use _**Add a personal access token**_ form
## Usage:
- Add a plugin _**GitLab API**_ to the page
- Enter a GitLab host URL in format like this: [https://git-t3o.typo3.org](https://git-t3o.typo3.org/)
- Save the plugin options to see rest of params
- Select a project from the dropdown
- Enter the target branch you’re interested in (in most cases _**master**_)
- Enter your access token (see previous section)
- Select the earlies merge request date to display (will show all if skipped)
- Save plugin options
# Apache < 2.3
<IfModule !mod_authz_core.c>
Order allow,deny
Deny from all
Satisfy All
</IfModule>
# Apache >= 2.3
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<xliff version="1.0">
<file source-language="en" datatype="plaintext" original="messages" date="2018-04-09T10:10:20Z" product-name="gitlab_api">
<header/>
<body>
<trans-unit id="flexFormLabels.title">
<source>GitLab API Options</source>
</trans-unit>
<trans-unit id="flexFormLabels.host">
<source>GitLab host URL</source>
</trans-unit>
<trans-unit id="flexFormLabels.project">
<source>GitLab Project</source>
</trans-unit>
<trans-unit id="flexFormLabels.branch">
<source>Target Branch</source>
</trans-unit>
<trans-unit id="flexFormLabels.token">
<source>GitLab Personal Access Token</source>
</trans-unit>
<trans-unit id="flexFormLabels.created_after">
<source>Use only merge requests created after this date</source>
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
<f:if condition="{releases}">
<f:for each="{releases}" as="release">
<section class="container">
<div class="frame frame-default">
<header>
<h2>{release.title}</h2>
</header>
<f:if condition="{release.tasks}">
<p>Tasks:</p>
<ul>
<f:for each="{release.tasks}" as="item">
<li>{item}</li>
</f:for>
</ul>
</f:if>
<f:if condition="{release.features}">
<p>Features:</p>
<ul>
<f:for each="{release.features}" as="item">
<li>{item}</li>
</f:for>
</ul>
</f:if>
<f:if condition="{release.bugfixes}">
<p>Bugfixes:</p>
<ul>
<f:for each="{release.bugfixes}" as="item">
<li>{item}</li>
</f:for>
</ul>
</f:if>
<f:if condition="{release.other}">
<p>Other:</p>
<ul>
<f:for each="{release.other}" as="item">
<li>{item}</li>
</f:for>
</ul>
</f:if>
</div>
</section>
</f:for>
</f:if>
\ No newline at end of file
{
"name": "t3o/gitlab-api",
"type": "typo3-cms-extension",
"description": "",
"keywords": [
"TYPO3 CMS"
],
"authors": [
],
"autoload": {
"psr-4": {
"T3O\\GitlabApi\\": "Classes/"
}
},
"replace": {
"bdst_location_suggest": "self.version",
"typo3-ter/bdst_location_suggest": "self.version"
}
}
<?php
/***************************************************************
* Extension Manager/Repository config file for ext: "gitlab_api"
***************************************************************/
$EM_CONF[$_EXTKEY] = [
'title' => 'GitLab API',
'description' => 'Get all the merge requests for project as list',
'category' => 'plugin',
'author' => '',
'author_email' => '',
'state' => 'beta',
'internal' => '',
'uploadfolder' => '1',
'createDirs' => '',
'clearCacheOnLoad' => 0,
'version' => '1.0.0',
'constraints' => [
'depends' => [
'typo3' => '7.6.0-8.7.99',
],
'conflicts' => [],
'suggests' => [],
],
];
ext_icon.gif

177 Bytes

<?php
defined('TYPO3_MODE') || die('Access denied.');
call_user_func(
function($extKey)
{
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'T3O.GitlabApi',
'MergeRequests',
array(
'Merge' => 'list'
),
// non-cacheable actions
array(
'Merge' => 'list'
)
);
},
$_EXTKEY
);
<?php
defined('TYPO3_MODE') || die('Access denied.');
call_user_func(
function($extKey)
{
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($extKey, 'Configuration/TypoScript', 'GitLab API');
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
'T3O.GitlabApi',
'MergeRequests',
'GitLab API'
);
$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist']['gitlabapi_mergerequests'] = 'pi_flexform';
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue('gitlabapi_mergerequests', 'FILE:EXT:gitlab_api/Configuration/FlexForms/FlexForm.xml');
},
$_EXTKEY
);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment