medicorenl / stash-api-bundle
Stash REST api integration in Symfony
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 2 042
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 5
Forks: 3
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=5.3.2
- guzzle/guzzle: 3.5.*
- symfony/framework-bundle: >=2.2.0,<3.0-dev
This package is not auto-updated.
Last update: 2024-06-17 12:48:10 UTC
README
StashApiBundle
A Symfony2 bundle that integrates the Stash REST API into native Symfony2 services.
Installation
-
Install Composer.
# Install Composer curl -sS https://getcomposer.org/installer | php
-
Add this bundle to the
composer.json
file of your project.# Add StashApiBundle as a dependency php composer.phar require medicorenl/stash-api-bundle dev-master
-
After installing, you need to require Composer's autloader in the bootstrap of your project.
// app/autoload.php $loader = require __DIR__ . '/../vendor/autoload.php';
-
Add the bundle to your application kernel.
// app/AppKernel.php public function registerBundles() { return array( // ... new StashApiBundle\StashApiBundle(), // ... ); }
-
Configure the bundle by adding parameters to the
config.yml
file:# app/config/config.yml stash_api.url: "http://stash.your-organisation.com/rest/api/latest/" stash_api.credentials: "username:password"
Usage
This bundle contains a number of services, to access them through the service container:
// Get the StashApiBundle\Service\BranchService $branchService = $this->get('stash_api.branch'); $branchService->searchBranch($project, $repository, $branch); // Get the StashApiBundle\Service\TagService $tagService = $this->get('stash_api.tag'); $tagService->getAll($project, $repository, $params); // Get the StashApiBundle\Service\CommitService $commitService = $this->get('stash_api.commit'); $commitService->getAll($project, $repository, $params); // Get the StashApiBundle\Service\FileService $fileService = $this->get('stash_api.file'); $fileService->getAll($project, $repository, $reference, $path); // Get the StashApiBundle\Service\PullRequestService $pullRequestService = $this->get('stash_api.pullrequest'); $pullRequestService->getAll($project, $repository, $params);
You can also add them to the service container of your own bundle:
<!-- src/Project/Bundle/Resources/config/services.xml --> <?xml version="1.0" encoding="UTF-8"?> <container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services$ <services> <service id="myproject.myservice" class="MyProject\MyBundle\Services\MyService.php" public="true"> <argument type="service" id="stash_api.commit" /> <argument type="service" id="stash_api.file" /> <argument type="service" id="stash_api.branch" /> <argument type="service" id="stash_api.tag" /> <argument type="service" id="stash_api.pullrequest" /> </service> </services> </container>
You can then use them in your own services
<?php namespace Project\Bundle\Services; use StashApiBundle\Service\CommitService; use StashApiBundle\Service\FileService; use StashApiBundle\Service\BranchService; use StashApiBundle\Service\TagService; use StashApiBundle\Service\PullRequestService; /** * Service class for my bundle. */ class MyService { /** * @var \StashApiBundle\Service\CommitService */ private $commitService; /** * @var \StashApiBundle\Service\FileService */ private $fileService; /** * @var \StashApiBundle\Service\BranchService */ private $branchService; /** * @var \StashApiBundle\Service\TagService */ private $tagService; /** * @var \StashApiBundle\Service\PullRequestService */ private $pullRequestService; /** * Constructor. * * @param \StashApiBundle\Service\CommitService $commitService * @param \StashApiBundle\Service\FileService $fileService * @param \StashApiBundle\Service\BranchServie $branchService * @param \StashApiBundle\Service\TagService $tagService * @param \StashApiBundle\Service\PullRequestService $pullRequestService */ public function __construct( CommitService $commitService, FileService $fileService, BranchService $branchService, TagService $tagService, PullRequestService $pullRequestService, ) { $this->commitService = $commitService; $this->fileService = $fileService; $this->branchService = $branchService; $this->tagService = $tagService; $this->pullRequestService = $pullRequestService; } }
Unit testing
StashApiBundle uses PHP Unit for unit testing.
-
Download PHP Unit.
# Download PHP Unit wget http://pear.phpunit.de/get/phpunit.phar chmod +x phpunit.phar
-
Make sure all dependencies are installed through Composer.
# Install dependencies php composer.phar install
-
Run the unit tests.
# Run unit tests php phpunit.phar