feat: add github_repo field to career applications and update intern dashboard UI
This commit is contained in:
@@ -194,6 +194,107 @@ class CareerController extends Controller
|
||||
return redirect()->back()->with('error', 'Dosya yüklenirken bir hata oluştu.');
|
||||
}
|
||||
|
||||
public function saveGithubRepo(Request $request)
|
||||
{
|
||||
if (!session()->has('intern_id')) {
|
||||
return redirect()->route('intern.login')->with('error', 'Lütfen önce giriş yapın.');
|
||||
}
|
||||
|
||||
$request->validate([
|
||||
'github_repo' => 'required|string|url|max:255',
|
||||
], [
|
||||
'github_repo.required' => 'Lütfen Github depo URL\'sini girin.',
|
||||
'github_repo.url' => 'Geçerli bir URL girilmelidir.',
|
||||
'github_repo.max' => 'Github depo URL\'si en fazla 255 karakter olabilir.',
|
||||
]);
|
||||
|
||||
$intern = CareerApplication::findOrFail(session('intern_id'));
|
||||
|
||||
// Sanitize & format github URL
|
||||
$repoUrl = trim($request->github_repo);
|
||||
|
||||
$intern->update([
|
||||
'github_repo' => $repoUrl
|
||||
]);
|
||||
|
||||
return redirect()->back()->with('success', 'Github deposu başarıyla güncellendi.');
|
||||
}
|
||||
|
||||
public function downloadMarkdown()
|
||||
{
|
||||
if (!session()->has('intern_id')) {
|
||||
return redirect()->route('intern.login')->with('error', 'Lütfen önce giriş yapın.');
|
||||
}
|
||||
$intern = CareerApplication::findOrFail(session('intern_id'));
|
||||
$repo = $intern->github_repo;
|
||||
if (!$repo) {
|
||||
return redirect()->back()->with('error', 'Lütfen önce Github deposunu tanımlayın.');
|
||||
}
|
||||
|
||||
// Parse owner and repo
|
||||
// E.g., https://github.com/owner/repo or owner/repo
|
||||
$repoClean = str_replace(['https://github.com/', 'http://github.com/', 'https://www.github.com/', 'http://www.github.com/'], '', $repo);
|
||||
$repoClean = trim($repoClean, '/');
|
||||
$parts = explode('/', $repoClean);
|
||||
if (count($parts) < 2) {
|
||||
return redirect()->back()->with('error', 'Geçersiz Github depo formatı.');
|
||||
}
|
||||
$owner = $parts[0];
|
||||
$repoName = explode('.', $parts[1])[0]; // Remove .git if exists
|
||||
|
||||
// Fetch commits
|
||||
$url = "https://api.github.com/repos/{$owner}/{$repoName}/commits?per_page=100";
|
||||
|
||||
$opts = [
|
||||
'http' => [
|
||||
'method' => 'GET',
|
||||
'header' => [
|
||||
'User-Agent: PHP-Github-Client',
|
||||
]
|
||||
]
|
||||
];
|
||||
$context = stream_context_create($opts);
|
||||
$response = @file_get_contents($url, false, $context);
|
||||
|
||||
if ($response === false) {
|
||||
return redirect()->back()->with('error', 'Github API\'den commit bilgileri alınamadı. Deponuzun public olduğundan emin olun.');
|
||||
}
|
||||
|
||||
$commits = json_decode($response, true);
|
||||
if (!is_array($commits)) {
|
||||
return redirect()->back()->with('error', 'Github API yanıtı çözümlenemedi.');
|
||||
}
|
||||
|
||||
// Sort commits chronological (ascending)
|
||||
$commits = array_reverse($commits);
|
||||
|
||||
// Generate Markdown content
|
||||
$md = "# Staj Günlüğü - " . $intern->name . "\n";
|
||||
$md .= "Depo: https://github.com/{$owner}/{$repoName}\n\n";
|
||||
|
||||
$day = 1;
|
||||
foreach ($commits as $c) {
|
||||
$message = $c['commit']['message'] ?? '';
|
||||
$dateStr = $c['commit']['author']['date'] ?? '';
|
||||
$date = $dateStr ? \Carbon\Carbon::parse($dateStr)->format('d.m.Y H:i') : '';
|
||||
$hash = substr($c['sha'] ?? '', 0, 7);
|
||||
|
||||
$md .= "## {$day}. Gün\n";
|
||||
$md .= "- **Tarih:** {$date}\n";
|
||||
$md .= "- **Commit:** `{$hash}`\n";
|
||||
$md .= "- **Mesaj:** {$message}\n\n";
|
||||
|
||||
$day++;
|
||||
}
|
||||
|
||||
$fileName = str()->slug($intern->name) . "-staj-gunlugu.md";
|
||||
|
||||
return response($md, 200, [
|
||||
'Content-Type' => 'text/markdown; charset=UTF-8',
|
||||
'Content-Disposition' => 'attachment; filename="' . $fileName . '"',
|
||||
]);
|
||||
}
|
||||
|
||||
public function internLogout()
|
||||
{
|
||||
session()->forget('intern_id');
|
||||
|
||||
Reference in New Issue
Block a user