Skip to content

Commit

Permalink
Make it possible to have remove lines in messages (#10)
Browse files Browse the repository at this point in the history
* Make it possible to have remove lines in messages

* Add a test for package removed as well
  • Loading branch information
eiriksm authored Dec 21, 2020
1 parent ede6f88 commit b050800
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/UpdateListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class UpdateListItem
private $oldVersion;
private $newVersion;
private $isNew = false;
private $isRemoved = false;

public function __construct($packageName, $newVersion, $oldVersion = null)
{
Expand All @@ -20,6 +21,22 @@ public function __construct($packageName, $newVersion, $oldVersion = null)
}
}

/**
* @return bool
*/
public function isRemoved(): bool
{
return $this->isRemoved;
}

/**
* @param bool $isNew
*/
public function setIsRemoved(bool $isRemoved)
{
$this->isRemoved = $isRemoved;
}

/**
* @return bool
*/
Expand Down
2 changes: 2 additions & 0 deletions src/ViolinistMessages.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ protected function getUpdatedList(array $list)
foreach ($list as $item) {
if ($item->isNew()) {
$lines[] = sprintf('- %s: %s (new package, previously not installed)', $item->getPackageName(), $item->getNewVersion());
} else if ($item->isRemoved()) {
$lines[] = sprintf('- %s %s (package was removed)', $item->getPackageName(), $item->getNewVersion());
} else {
$lines[] = sprintf('- %s: %s (updated from %s)', $item->getPackageName(), $item->getNewVersion(), $item->getOldVersion());
}
Expand Down
35 changes: 35 additions & 0 deletions tests/Unit/UnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,41 @@ public function testUpdateList()
</details>
***
This is an automated pull request from [Violinist](https://violinist.io/): Continuously and automatically monitor and update your composer dependencies. Have ideas on how to improve this message? All violinist messages are open-source, and [can be improved here](https://github.com/violinist-dev/violinist-messages).
', $body);
}

public function testUpdateListOneRemoved()
{
$message = new ViolinistMessages();
$removed = new UpdateListItem('third/removed', 'x');
$removed->setIsRemoved(true);
$removed->setIsNew(false);
$update_items = [
new UpdateListItem('first/updated', '2.0.1', '2.0.2'),
new UpdateListItem('other/new', '2.0.0'),
$removed
];
$update = new ViolinistUpdate();
$update->setUpdatedList($update_items);
$body = $message->getPullRequestBody($update);
$this->assertEquals('If you have a high test coverage index, and your tests for this pull request are passing, it should be both safe and recommended to merge this update.
### Updated packages
Some times an update also needs new or updated dependencies to be installed. Even if this branch is for updating one dependency, it might contain other installs or updates. All of the updates in this branch can be found here.
<details>
<summary>List of updated packages</summary>
- first/updated: 2.0.1 (updated from 2.0.2)
- other/new: 2.0.0 (new package, previously not installed)
- third/removed x (package was removed)
</details>
***
This is an automated pull request from [Violinist](https://violinist.io/): Continuously and automatically monitor and update your composer dependencies. Have ideas on how to improve this message? All violinist messages are open-source, and [can be improved here](https://github.com/violinist-dev/violinist-messages).
', $body);
Expand Down

0 comments on commit b050800

Please sign in to comment.