Skip to content

Commit

Permalink
Merge 53ab80b into ca99c19
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriksm committed Aug 19, 2021
2 parents ca99c19 + 53ab80b commit c006b67
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 7 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"violinist-dev/process-factory": "^1.0",
"symfony/process": "^3",
"violinist-dev/composer-changelog-fetcher": "dev-master",
"violinist-dev/violinist-config": "dev-master"
"violinist-dev/violinist-config": "dev-master",
"violinist-dev/commit-message-creator": "^1.1"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
24 changes: 20 additions & 4 deletions src/CosyComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
use eiriksm\CosyComposer\Exceptions\GitPushException;
use eiriksm\CosyComposer\Exceptions\OutsideProcessingHoursException;
use eiriksm\CosyComposer\Providers\PublicGithubWrapper;
use eiriksm\ViolinistMessages\UpdateListItem;
use GuzzleHttp\Psr7\Request;
use Http\Client\HttpClient;
use Violinist\ChangelogFetcher\ChangelogRetriever;
use Violinist\ChangelogFetcher\DependencyRepoRetriever;
use Violinist\CommitMessageCreator\Constant\Type;
use Violinist\CommitMessageCreator\Creator;
use Violinist\ComposerLockData\ComposerLockData;
use Violinist\ComposerUpdater\Exception\ComposerUpdateProcessFailedException;
use Violinist\ComposerUpdater\Exception\NotUpdatedException;
Expand Down Expand Up @@ -945,18 +948,30 @@ protected function handleUpdateAll()
}
}

protected function commitFiles($package_name)
protected function commitFiles($package_name, UpdateListItem $item = null, Config $config = null, $is_dev = false)
{
// Clean up the composer.lock file if it was not part of the repo.
$this->execCommand('git clean -f composer.*');
$creator = new Creator();
$type = Type::NONE;
$msg = sprintf('Update %s', $package_name);
$creator->setType($type);
if ($item) {
try {
$creator->setType($config->getCommitMessageConvention());
} catch (\InvalidArgumentException $e) {
// Fall back to using none.
}
$msg = $creator->generateMessage($item, $is_dev);
}
$command = sprintf(
'GIT_AUTHOR_NAME="%s" GIT_AUTHOR_EMAIL="%s" GIT_COMMITTER_NAME="%s" GIT_COMMITTER_EMAIL="%s" git commit %s -m "Update %s"',
'GIT_AUTHOR_NAME="%s" GIT_AUTHOR_EMAIL="%s" GIT_COMMITTER_NAME="%s" GIT_COMMITTER_EMAIL="%s" git commit %s -m "%s"',
$this->githubUserName,
$this->githubEmail,
$this->githubUserName,
$this->githubEmail,
$this->lockFileContents ? 'composer.json composer.lock' : 'composer.json',
$package_name
$msg
);
if ($this->execCommand($command, false)) {
$this->log($this->getLastStdOut(), Message::COMMAND);
Expand Down Expand Up @@ -1184,7 +1199,8 @@ protected function handleIndividualUpdates($data, $lockdata, $cdata, $one_pr_per
}
$this->log('Successfully ran command composer update for package ' . $package_name);
$new_lock_data = json_decode(file_get_contents($this->compserJsonDir . '/composer.lock'));
$this->commitFiles($package_name);
$list_item = new UpdateListItem($package_name, $post_update_data->version, $item->version);
$this->commitFiles($package_name, $list_item, $config, $is_require_dev);
$this->runAuthExport($hostname);
$origin = 'fork';
if ($this->isPrivate) {
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/composer-commit-conventional.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"require": {
"psr/log": "~1.0.0"
},
"extra": {
"violinist": {
"commit_message_convention": "conventional"
}
}
}
57 changes: 57 additions & 0 deletions test/fixtures/composer-commit-conventional.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"_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": "2865f724e23cffb23b3afd3a968e0359",
"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"
],
"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": "1.1.0"
}
66 changes: 66 additions & 0 deletions test/fixtures/composer-commit-conventional.lock.updated
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"_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": "5c85e8d105e895432d3e3efc7ea068c5",
"packages": [
{
"name": "psr/log",
"version": "1.0.2",
"source": {
"type": "git",
"url": "https://github.com/php-fig/log.git",
"reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d",
"reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Log\\": "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",
"homepage": "https://github.com/php-fig/log",
"keywords": [
"log",
"psr",
"psr-3"
],
"time": "2016-10-10T12:19:37+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
"plugin-api-version": "1.1.0"
}
16 changes: 16 additions & 0 deletions test/integration/CommitMessageConventionalTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace eiriksm\CosyComposerTest\integration;

/**
* Test for commit message type coventional commits.
*/
class CommitMessageConventionalTest extends CommitMessageTest
{
protected $composerAssetFiles = 'composer-commit-conventional';

protected function getCorrectCommit()
{
return 'git commit composer.json composer.lock -m "build(deps): Update psr/log from 1.0.0 to 1.0.2"';
}
}
4 changes: 2 additions & 2 deletions test/integration/CommitMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace eiriksm\CosyComposerTest\integration;

/**
* Test for issue 164.
* Test for a default commit message.
*/
class CommitMessageTest extends ComposerUpdateIntegrationBase
{
Expand All @@ -13,7 +13,7 @@ class CommitMessageTest extends ComposerUpdateIntegrationBase
protected $composerAssetFiles = 'composer-commit';
protected $hasCorrectCommit = false;

public function testRequireDevAdded()
public function testCommitMessage()
{
$this->runtestExpectedOutput();
self::assertEquals($this->hasCorrectCommit, true);
Expand Down

0 comments on commit c006b67

Please sign in to comment.