Last active
November 6, 2024 14:28
-
-
Save mpociot/896b9d97ee40d8647f094a08cde816c4 to your computer and use it in GitHub Desktop.
GitHub component for the excellent Spatie dashboard package from https://github.com/spatie/dashboard.spatie.be
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Components\GitHub; | |
use App\Events\GitHub\FileContentFetched; | |
use App\Events\GitHub\TotalsFetched; | |
use GitHub; | |
use Illuminate\Console\Command; | |
class FetchGitHubTotals extends Command | |
{ | |
/** | |
* The console command name. | |
* | |
* @var string | |
*/ | |
protected $signature = 'dashboard:github-totals'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'Fetch GitHub forks, issues, PRs.'; | |
/** | |
* Execute the console command. | |
* | |
* @return mixed | |
*/ | |
public function handle() | |
{ | |
$username = config('services.github.username'); | |
$repos = collect(Github::user()->repositories($username)); | |
$forks = $repos->sum('forks_count'); | |
$issues = $repos->sum('open_issues'); | |
$pullRequests = $repos->sum(function($repo) use ($username) { | |
return count(Github::pull_request()->all($username, $repo['name'])); | |
}); | |
$contributors = $repos->sum(function($repo) use ($username) { | |
return count(Github::repo()->contributors($username, $repo['name'])); | |
}); | |
event(new TotalsFetched([ | |
'issues' => $issues, | |
'forks' => $forks, | |
'pullRequests' => $pullRequests, | |
'contributors' => $contributors | |
])); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<grid :position="grid" modifiers="padded overflow blue"> | |
<section class="packagist-statistics"> | |
<h1>GitHub</h1> | |
<ul> | |
<li class="packagist-statistic"> | |
<span class="packagist-statistics__period">Issues</span> | |
<span class="packagist-statistics__count">{{ formatNumber(issues) }}</span> | |
</li> | |
<li class="packagist-statistic"> | |
<h2 class="packagist-statistics__period">Pull Requests</h2> | |
<span class="packagist-statistics__count">{{ formatNumber(pullRequests) }}</span> | |
</li> | |
<li class="packagist-statistic"> | |
<h2 class="packagist-statistics__period">Forks</h2> | |
<span class="packagist-statistics__count">{{ formatNumber(forks) }}</span> | |
</li> | |
<li class="packagist-statistic"> | |
<h2 class="packagist-statistics__period">Contributors</h2> | |
<span class="packagist-statistics__count">{{ formatNumber(contributors) }}</span> | |
</li> | |
</ul> | |
</section> | |
</grid> | |
</template> | |
<script> | |
import { formatNumber } from '../helpers'; | |
import echo from '../mixins/echo'; | |
import Grid from './Grid'; | |
import saveState from 'vue-save-state'; | |
export default { | |
components: { | |
Grid, | |
}, | |
mixins: [echo, saveState], | |
props: ['grid'], | |
data() { | |
return { | |
issues: 0, | |
contributors: 0, | |
pullRequests: 0, | |
forks: 0 | |
}; | |
}, | |
methods: { | |
formatNumber, | |
getEventHandlers() { | |
return { | |
'GitHub.TotalsFetched': response => { | |
this.issues = response.issues; | |
this.contributors = response.contributors; | |
this.pullRequests = response.pullRequests; | |
this.forks = response.forks; | |
}, | |
}; | |
}, | |
getSaveStateConfig() { | |
return { | |
cacheKey: `github-statistics`, | |
}; | |
}, | |
}, | |
}; | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Events\GitHub; | |
use App\Events\DashboardEvent; | |
class TotalsFetched extends DashboardEvent | |
{ | |
public $issues; | |
public $pullRequests; | |
public $forks; | |
public $contributors; | |
public function __construct(array $totals) | |
{ | |
foreach ($totals as $sumName => $total) { | |
$this->$sumName = $total; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment