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
62 changes: 0 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,68 +159,6 @@ class RepositoryClassifier implements Classifier
...
```

## Share Metrics with the Laravel Community

You can optionally share your projects statistic by using the `--share` option.

```shell
php artisan stats --share
```

Your project statistics is shared anonymously with [stats.laravelshift.com](https://stats.laravelshift.com). In regular intervals the dashboard and charts on the site are updated with shared data from other Laravel projects.

To learn more about this feature, please check out PR [#178](https://github.com/stefanzweifel/laravel-stats/pull/178).

### Share statistic through CI

If you would like to share your project statistic in a CI environment you can use the `--no-interaction` and `--name`-options.

Use the following command in your CI script to share your project statistic automatically. (Update `org/repo` with the name of your application (eg. `acme/podcasting-app`))

```shell
php artisan stats --share --no-interaction --name=org/repo
```

If you're code is hosted on GitHub, you can integrate `stats` with [GitHub Actions](https://docs.github.com/en/actions).
Copy the following Workflow to `.github/workflows/laravel-stats.yml`. It will share data when a commit is pushed to the `master` branch. The Action automatically uses your GitHub repository name in the `--name`-option.

```yaml
name: stats

on:
push:
branches:
- master

jobs:
stats:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
tools: composer:v2

- name: Install dependencies
run: composer install --prefer-dist --no-interaction --no-suggest

- name: Share Stats
run: php artisan stats --share --name=$GITHUB_REPOSITORY --no-interaction
```

### Inspect Data shared with the Community

If you would like to inspect the payload the command is sending to the API you can use the `--dry-run` and `--payload` options.

```shell
php artisan stats --share --no-interaction --name="org/repo" --dry-run --payload
```

## Treeware

You're free to use this package, but if it makes it to your production environment you are required to buy the world a tree.
Expand Down
77 changes: 4 additions & 73 deletions src/Console/StatsListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
use Wnx\LaravelStats\Project;
use Wnx\LaravelStats\ReflectionClass;
use Wnx\LaravelStats\RejectionStrategies\RejectVendorClasses;
use Wnx\LaravelStats\ShareableMetrics\CollectMetrics;
use Wnx\LaravelStats\ShareableMetrics\ProjectName;
use Wnx\LaravelStats\ShareableMetrics\SendToLaravelShift;

class StatsListCommand extends Command
{
Expand All @@ -24,9 +21,8 @@ class StatsListCommand extends Command
protected $signature = 'stats
{--json : Output the statistics as JSON}
{-c|--components= : Comma separated list of components which should be displayed}
{--s|share : Share project statistic with Laravel community <https://stats.laravelshift.com>}
{--s|share : DEPRECATED Share project statistic with Laravel community <https://stats.laravelshift.com>}
{--name= : Name used when sharing project statistic}
{--payload : Output payload to be shared with Laravel community <https://stats.laravelshift.com>}
{--dry-run : Do not make request to share statistic}';

/**
Expand Down Expand Up @@ -68,7 +64,7 @@ public function handle()
$this->renderOutput($project);

if ($this->option('share') === true) {
$this->shareDataWithShift($project);
$this->warn('The share option has been deprecated and will be removed in a future update.');
}
}

Expand All @@ -90,78 +86,13 @@ private function renderOutput(Project $project)
$this->getArrayOfComponentsToDisplay()
);

if ($this->option('payload') !== true) {
$this->output->text(json_encode($json));
}
} elseif ($this->option('payload') !== true) {
$this->output->text(json_encode($json));
} else {
(new AsciiTableOutput($this->output))->render(
$project,
$this->option('verbose'),
$this->getArrayOfComponentsToDisplay()
);
}
}

private function shareDataWithShift(Project $project): void
{
$metrics = app(CollectMetrics::class)->collect($project);

$defaultValueForConfirmation = $this->option('no-interaction') ?? false;

if ($this->confirm("Do you want to share stats above from your project with the Laravel Community to stats.laravelshift.com?", $defaultValueForConfirmation)) {
$projectName = $this->getProjectName();

if ($projectName === null) {
$this->error("Please provide a project name.");
return;
}

if (! Str::contains($projectName, '/')) {
$this->error("Please use the organisation/repository schema for naming your project.");
return;
}

$payload = $metrics->toHttpPayload($projectName);

if ($this->option('payload')) {
$this->output->text(json_encode($payload));
}

if ($this->option('dry-run')) {
return;
}

$wasSuccessful = app(SendToLaravelShift::class)->send($metrics->toHttpPayload($projectName));

if ($this->option('payload')) {
return;
}

if ($wasSuccessful) {
$this->info("Thanks for sharing your project statistic with the community!");
return;
}

$this->error("Unable to share stats. (Check logs for details)");
}
}

private function getProjectName(): ?string
{
if ($this->option('name')) {
return (string) $this->option('name');
}

if (app(ProjectName::class)->hasStoredProjectName() === false) {
$generatedProjectName = app(ProjectName::class)->determineProjectNameFromGit();

$projectName = $this->ask("We've determined the following name for your project: \"{$generatedProjectName}\".\n Type a new name or leave it blank to continue.", $generatedProjectName);

app(ProjectName::class)->storeNameInRcFile($projectName);

return $projectName;
}

return app(ProjectName::class)->get();
}
}
10 changes: 0 additions & 10 deletions src/Contracts/CollectableMetric.php

This file was deleted.

52 changes: 0 additions & 52 deletions src/ShareableMetrics/AllMetricPayloadKeys.php

This file was deleted.

93 changes: 0 additions & 93 deletions src/ShareableMetrics/CollectMetrics.php

This file was deleted.

18 changes: 0 additions & 18 deletions src/ShareableMetrics/Metrics/CodeTestRatio.php

This file was deleted.

22 changes: 0 additions & 22 deletions src/ShareableMetrics/Metrics/ComposerPsr4Sources.php

This file was deleted.

Loading