Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,27 @@ concurrency:

jobs:
basic:
name: Run tests on PHP ${{ matrix.php_version }}
name: Run tests on PHP ${{ matrix.php-versions }}
runs-on: ubuntu-latest
strategy:
max-parallel: 1
matrix:
php_version: ['8.0', '8.1', '8.2']
fail-fast: false
php-versions: ['8.0', '8.1', '8.2']
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php_version }}
tools: composer
php-version: ${{ matrix.php-versions }}
tools: composer:v2

- name: Install dependencies
run: composer install
- name: Deps
run: composer install --no-interaction

- name: Run tests
run: ./vendor/bin/phpunit
- name: Quality
if: matrix.php-versions == '8.0'
run: vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php -v --dry-run --stop-on-violation

- name: Test
run: vendor/bin/phpunit
47 changes: 47 additions & 0 deletions .github/workflows/initiate_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Create release PR

on:
workflow_dispatch:
inputs:
version:
description: "The new version number. Example: 1.40.1"
required: true

jobs:
init_release:
name: 🚀 Create release PR
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Update CHANGELOG.md, Client.php and push release branch
env:
VERSION: ${{ github.event.inputs.version }}
run: |
npx --yes standard-version@9.3.2 --release-as "$VERSION" --skip.tag --skip.commit --tag-prefix=
git config --global user.name 'github-actions'
git config --global user.email 'release@getstream.io'
git checkout -q -b "release-$VERSION"
git commit -am "chore(release): $VERSION"
git push -q -u origin "release-$VERSION"

- name: Get changelog diff
uses: actions/github-script@v6
with:
script: |
const get_change_log_diff = require('./scripts/get_changelog_diff.js')
core.exportVariable('CHANGELOG', get_change_log_diff())

- name: Open pull request
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr create \
-t "chore(release): release ${{ github.event.inputs.version }}" \
-b "# :rocket: ${{ github.event.inputs.version }}
Make sure to use squash & merge when merging!
Once this is merged, another job will kick off automatically and publish the package.
# :memo: Changelog
${{ env.CHANGELOG }}"
35 changes: 35 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Release

on:
pull_request:
types: [closed]
branches:
- master

jobs:
Release:
name: 🚀 Release
if: github.event.pull_request.merged && startsWith(github.head_ref, 'release-')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/github-script@v6
with:
script: |
const get_change_log_diff = require('./scripts/get_changelog_diff.js')
core.exportVariable('CHANGELOG', get_change_log_diff())

// Getting the release version from the PR source branch
// Source branch looks like this: release-1.0.0
const version = context.payload.pull_request.head.ref.split('-')[1]
core.exportVariable('VERSION', version)

- name: Create release on GitHub
uses: ncipollo/release-action@v1
with:
body: ${{ env.CHANGELOG }}
tag: ${{ env.VERSION }}
token: ${{ secrets.GITHUB_TOKEN }}
14 changes: 14 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

$finder = PhpCsFixer\Finder::create()
->exclude('vendor')
->in(__DIR__)
;

$config = new PhpCsFixer\Config();
return $config->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
])
->setFinder($finder)
;
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"get-stream/stream": "^7.0.1"
},
"require-dev": {
"phpunit/phpunit": "^9.6",
"friendsofphp/php-cs-fixer": "^3.14.0",
"phpunit/phpunit": "^9.6.3",
"mockery/mockery": "^1.5"
},
"autoload": {
Expand Down
26 changes: 26 additions & 0 deletions scripts/get_changelog_diff.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Here we're trying to parse the latest changes from CHANGELOG.md file.
The changelog looks like this:

## 0.0.3
- Something #3
## 0.0.2
- Something #2
## 0.0.1
- Something #1

In this case we're trying to extract "- Something #3" since that's the latest change.
*/
module.exports = () => {
const fs = require('fs')

changelog = fs.readFileSync('CHANGELOG.md', 'utf8')
releases = changelog.match(/## [?[0-9](.+)/g)

current_release = changelog.indexOf(releases[0])
previous_release = changelog.indexOf(releases[1])

latest_changes = changelog.substr(current_release, previous_release - current_release)

return latest_changes
}
9 changes: 3 additions & 6 deletions src/GetStream/StreamLaravel/Eloquent/ActivityTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,16 @@ public function createActivity()

$to = $this->activityNotify();

if ( $to !== null )
{
if ($to !== null) {
$activity['to'] = [];
foreach ( $to as $feed )
{
foreach ($to as $feed) {
$activity['to'][] = $feed->getId();
}
}

$extra_data = $this->activityExtraData();

if ( $extra_data !== null )
{
if ($extra_data !== null) {
$activity = array_merge($activity, $extra_data);
}

Expand Down
6 changes: 4 additions & 2 deletions src/GetStream/StreamLaravel/Enrich.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ public function fromDb($model, $ids, $with = [])
'Illuminate\Database\Eloquent\SoftDeletingTrait'
];

if ((bool)array_intersect($softDeleteTraits, class_uses(get_class($model))) && $this->withTrashed) // previous withTrash method deprecated in Laravel 4.2
if ((bool)array_intersect($softDeleteTraits, class_uses(get_class($model))) && $this->withTrashed) { // previous withTrash method deprecated in Laravel 4.2
$query = $query->withTrashed();
}
$objects = $query->get();
foreach ($objects as $object) {
$results[$object->getKey()] = $object; // support for non-default UUID keys
Expand Down Expand Up @@ -80,8 +81,9 @@ private function injectObjects(&$activities, $objects)
{
foreach ($activities as $key => $activity) {
foreach ($this->fields as $field) {
if (!isset($activity[$field]))
if (!isset($activity[$field])) {
continue;
}
$value = $activity[$field];
$reference = explode(':', $value);
if (!array_key_exists($reference[0], $objects)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ protected function registerResources()
} else {
//only set if we dont have a config file for stream-laravel
$namespace = 'stream-laravel.';
foreach($config as $key => $value) {
$this->app['config']->set($namespace . $key , $value);
foreach ($config as $key => $value) {
$this->app['config']->set($namespace . $key, $value);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/GetStream/StreamLaravel/StreamLumenServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function register()
$this->registerResources();
}

$this->app->singleton('feed_manager', function($app) {
$this->app->singleton('feed_manager', function ($app) {
$manager_class = config('stream-laravel.feed_manager_class');
$api_key = config('stream-laravel.api_key');
$api_secret = config('stream-laravel.api_secret');
Expand All @@ -62,8 +62,8 @@ protected function registerResources()
} else {
//only set if we dont have a config file for stream-laravel
$namespace = 'stream-laravel.';
foreach($config as $key => $value) {
$this->app['config']->set($namespace . $key , $value);
foreach ($config as $key => $value) {
$this->app['config']->set($namespace . $key, $value);
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions tests/ActivityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ public function activityActorMethodName()
}
public function activityNotify()
{
return array($this->client->feed('feed', '1'));
return [$this->client->feed('feed', '1')];
}
}

class ActivityTest extends TestCase
{

private $instance = null;

public function setUp(): void
Expand All @@ -54,6 +53,6 @@ public function testCreateActivity()
public function testToField()
{
$activity = $this->instance->createActivity();
$this->assertSame($activity['to'], array('feed:1'));
$this->assertSame($activity['to'], ['feed:1']);
}
}
12 changes: 6 additions & 6 deletions tests/EnrichedActivityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@ class EnrichedActivityTest extends TestCase
{
public function testArrayImplementation()
{
$activity = new EnrichedActivity(array('actor' => 'stream'));
$activity = new EnrichedActivity(['actor' => 'stream']);
$this->assertSame($activity['actor'], 'stream');
$activity['x'] = 1;
$this->assertSame($activity['x'], 1);
}

public function testTrackNotEnrichedData()
{
$activity = new EnrichedActivity(array());
$this->assertSame($activity->getNotEnrichedData(), array());
$activity = new EnrichedActivity([]);
$this->assertSame($activity->getNotEnrichedData(), []);
}

public function testTrackNotEnrichedField()
{
$activity = new EnrichedActivity(array());
$activity = new EnrichedActivity([]);
$this->assertTrue($activity->enriched());
$activity->trackNotEnrichedField('missing', 'value');
$this->assertFalse($activity->enriched());
$this->assertSame($activity->getNotEnrichedData(), array('missing' => 'value'));
$this->assertSame($activity->getNotEnrichedData(), ['missing' => 'value']);
}

public function testIterable()
{
$activity = new EnrichedActivity(array('1' => 1, '2' => 3));
$activity = new EnrichedActivity(['1' => 1, '2' => 3]);
$sum = 0;
foreach ($activity as $field => $value) {
$sum += $value;
Expand Down
4 changes: 2 additions & 2 deletions tests/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function setUp(): void
$config->shouldReceive('get')->once()->with('stream-laravel.location')
->andReturn('');
$config->shouldReceive('get')->once()->with('stream-laravel.news_feeds')
->andReturn(array('flat' => 'flat', 'aggregated' => 'aggregated'));
->andReturn(['flat' => 'flat', 'aggregated' => 'aggregated']);
$config->shouldReceive('get')->once()->with('stream-laravel.timeout', 3)
->andReturn(3);
$this->manager = new StreamLaravelManager('key', 'secret', $config);
Expand All @@ -42,7 +42,7 @@ public function testCustomTimeout()
$config->shouldReceive('get')->once()->with('stream-laravel.location')
->andReturn('');
$config->shouldReceive('get')->once()->with('stream-laravel.news_feeds')
->andReturn(array('flat' => 'flat', 'aggregated' => 'aggregated'));
->andReturn(['flat' => 'flat', 'aggregated' => 'aggregated']);
$config->shouldReceive('get')->once()->with('stream-laravel.timeout', 3)
->andReturn(6);
$manager = new StreamLaravelManager('key', 'secret', $config);
Expand Down