Skip to content

Commit

Permalink
Support prefix on one per pr as well (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriksm committed Mar 10, 2022
1 parent e4fa118 commit 9a2a586
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/CosyComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1653,7 +1653,12 @@ protected function createBranchName($item, $one_per_package = false, $config = n

if ($one_per_package) {
// Add a prefix.
return 'violinist' . $this->createBranchNameFromVersions($item->name, '', '');
$prefix = '';
if ($config) {
/** @var Config $config */
$prefix = $config->getBranchPrefix();
}
return sprintf('%sviolinist%s', $prefix, $this->createBranchNameFromVersions($item->name, '', ''));
}
$name = $this->createBranchNameFromVersions($item->name, $item->version, $item->latest);
$prefix = '';
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/composerbranch.one_per.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"require": {
"psr/log": "^1.0.0"
},
"extra": {
"violinist": {
"one_pull_request_per_package": 1,
"branch_prefix": "my_prefix"
}
}
}
61 changes: 61 additions & 0 deletions test/fixtures/composerbranch.one_per.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "8113594d4f68a877528c59397540c3f0",
"packages": [
{
"name": "psr/log",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/log.git",
"reference": "fe0936ee26643249e916849d48e3a51d5f5e278b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/log/zipball/fe0936ee26643249e916849d48e3a51d5f5e278b",
"reference": "fe0936ee26643249e916849d48e3a51d5f5e278b",
"shasum": ""
},
"type": "library",
"autoload": {
"psr-0": {
"Psr\\Log\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for logging libraries",
"keywords": [
"log",
"psr",
"psr-3"
],
"support": {
"issues": "https://github.com/php-fig/log/issues",
"source": "https://github.com/php-fig/log/tree/1.0.0"
},
"time": "2012-12-21T11:40:51+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
"plugin-api-version": "2.1.0"
}
69 changes: 69 additions & 0 deletions test/fixtures/composerbranch.one_per.lock.updated
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "8113594d4f68a877528c59397540c3f0",
"packages": [
{
"name": "psr/log",
"version": "1.1.4",
"source": {
"type": "git",
"url": "https://github.com/php-fig/log.git",
"reference": "d49695b909c3b7628b6289db5479a1c204601f11"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/log/zipball/d49695b909c3b7628b6289db5479a1c204601f11",
"reference": "d49695b909c3b7628b6289db5479a1c204601f11",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.1.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Log\\": "Psr/Log/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "https://www.php-fig.org/"
}
],
"description": "Common interface for logging libraries",
"homepage": "https://github.com/php-fig/log",
"keywords": [
"log",
"psr",
"psr-3"
],
"support": {
"source": "https://github.com/php-fig/log/tree/1.1.4"
},
"time": "2021-05-03T11:20:27+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
"plugin-api-version": "2.1.0"
}
31 changes: 31 additions & 0 deletions test/integration/BranchPrefixOnePerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace eiriksm\CosyComposerTest\integration;

use Bitbucket\Api\Repositories;
use Bitbucket\Client;
use eiriksm\CosyComposer\CommandExecuter;
use eiriksm\CosyComposer\CosyComposer;
use eiriksm\CosyComposer\ProviderFactory;
use eiriksm\CosyComposer\Providers\Bitbucket;
use eiriksm\CosyComposer\Providers\Github;
use eiriksm\CosyComposerTest\integration\Base;
use eiriksm\CosyComposerTest\integration\ComposerUpdateIntegrationBase;

/**
* Test for branch prefix with one_per option set.
*/
class BranchPrefixOnePerTest extends ComposerUpdateIntegrationBase
{
protected $packageForUpdateOutput = 'psr/log';
protected $packageVersionForFromUpdateOutput = '1.0.0';
protected $packageVersionForToUpdateOutput = '1.1.4';
protected $composerAssetFiles = 'composerbranch.one_per';
protected $checkPrUrl = true;

public function testBranchPrefixUsed()
{
$this->runtestExpectedOutput();
self::assertEquals('my_prefixviolinistpsrlog', $this->prParams["head"]);
}
}

0 comments on commit 9a2a586

Please sign in to comment.