Skip to content
Open
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
18 changes: 18 additions & 0 deletions fetch-github-project/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2

[docker-compose.yml]
indent_size = 4
66 changes: 66 additions & 0 deletions fetch-github-project/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_TIMEZONE=UTC
APP_URL=http://localhost

APP_LOCALE=en
APP_FALLBACK_LOCALE=en
APP_FAKER_LOCALE=en_US

APP_MAINTENANCE_DRIVER=file
# APP_MAINTENANCE_STORE=database

PHP_CLI_SERVER_WORKERS=4

BCRYPT_ROUNDS=12

LOG_CHANNEL=stack
LOG_STACK=single
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=sqlite
# DB_HOST=127.0.0.1
# DB_PORT=3306
# DB_DATABASE=laravel
# DB_USERNAME=root
# DB_PASSWORD=

SESSION_DRIVER=database
SESSION_LIFETIME=120
SESSION_ENCRYPT=false
SESSION_PATH=/
SESSION_DOMAIN=null

BROADCAST_CONNECTION=log
FILESYSTEM_DISK=local
QUEUE_CONNECTION=database

CACHE_STORE=database
CACHE_PREFIX=

MEMCACHED_HOST=127.0.0.1

REDIS_CLIENT=phpredis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=log
MAIL_HOST=127.0.0.1
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="hello@example.com"
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false

VITE_APP_NAME="${APP_NAME}"
11 changes: 11 additions & 0 deletions fetch-github-project/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
* text=auto eol=lf

*.blade.php diff=html
*.css diff=css
*.html diff=html
*.md diff=markdown
*.php diff=php

/.github export-ignore
CHANGELOG.md export-ignore
.styleci.yml export-ignore
22 changes: 22 additions & 0 deletions fetch-github-project/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/.phpunit.cache
/node_modules
/public/build
/public/hot
/public/storage
/storage/*.key
/storage/pail
/vendor
.env
.env.backup
.env.production
.phpactor.json
.phpunit.result.cache
Homestead.json
Homestead.yaml
auth.json
npm-debug.log
yarn-error.log
/.fleet
/.idea
/.vscode
/.zed
39 changes: 39 additions & 0 deletions fetch-github-project/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# GitHub Projects Viewer

## Overview

This project is a personal application that displays a user's GitHub projects in a visually appealing format. It fetches the user's repositories from GitHub and presents essential details about each project, including the project name, creation date, description, and a link to the GitHub repository.

## Features

- **Project Section**: Showcases all GitHub projects of the user.
- **Project Name**: The name of each project.
- **Created On**: The date when the project was created.
- **Description**: A brief description of the project.
- **GitHub URL**: A link to the project's repository on GitHub.

- **Refresh Button**: Allows users to check for any recently added projects. When clicked, it checks the user's GitHub account for any new repositories and updates the view accordingly.

## Tech Stack

- **Frontend**: HTML, CSS, JavaScript
- **Backend**: Laravel
- **Database**: MySQL
- **API**: GitHub API for fetching project details

## Installation

1. Clone the repository:
2. Navigate to the project directory: cd repo-name
3. Install dependencies: composer install

## Project Setup
1. Set up your environment file: cp .env.example .env
2. Generate an application key: [php artisan key:generate]
3. Configure your database settings in the .env file.
4. Run migrations: [php artisan migrate]
5. Serve the application: [php artisan serve]
6. Last, Access the application at http://localhost:8000.



8 changes: 8 additions & 0 deletions fetch-github-project/app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace App\Http\Controllers;

abstract class Controller
{
//
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace App\Http\Controllers;

use App\Models\gitHubProjects;
use App\Models\GithubUsername;
use App\Models\Setting;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;

class GithubProjectController extends Controller
{
protected $githubUrl = '';

public function __construct()
{
$GithubUsername = GithubUsername::get();
if(count($GithubUsername) > 0){
$userName = $GithubUsername[0]->username;
$this->githubUrl = "https://api.github.com/users/$userName/repos";

}
}

public function index()
{
$setting = Setting::firstOrCreate(
['key' => 'github_projects_updated'],
['value' => false]
);

// Defauly 1st time data will be fetched and added to the DB.
// Reason of creating DB is to avoid accessing api again & again.
if (!$setting->value) {
$response = Http::get($this->githubUrl);
$projects = $response->json();
foreach ($projects as $project) {
gitHubProjects::create([
'project_name' => $project['name'],
'project_url' => $project['html_url'],
'project_description' => isset($project['description']) ? $project['description'] : 'No Description Added.',
'created_on' => Carbon::parse($project['created_at'])->format('Y-m-d H:i:s'),
]);
}
$setting->value = true;
$setting->save();
}

$projects = gitHubProjects::orderBy('id', 'desc')->get();
return view('welcome', compact('projects'));
}

// Function that will be trigger on click of refresh button beside 'Project heading'
public function fetchProjects(Request $request){
$response = Http::get($this->githubUrl);
$response = $response->json();
$lastProject = $response[array_key_last($response)];
$isRecentProjectExist = gitHubProjects::where('project_url', $lastProject['html_url'])->first();
if(!$isRecentProjectExist->project_name){
gitHubProjects::create([
'project_name' => $lastProject['name'],
'project_url' => $lastProject['html_url'],
'project_description' => isset($lastProject['description']) ? $lastProject['description'] : 'No Description Added.',
'created_on' => Carbon::parse($lastProject['created_at'])->format('Y-m-d H:i:s'),
]);
$projects = gitHubProjects::orderBy('id', 'desc')->get();
return response()->json(['message' => 'New Project Added', 'data' => $projects], 200);
}else{
return response()->json(['message' => 'No new project added.', 'status' => 404]);
}
return $response->json();
}

public function saveUsername(Request $request){
GithubUsername::create([
'username' => $request->username
]);
return redirect('/');
}
}
10 changes: 10 additions & 0 deletions fetch-github-project/app/Models/GithubUsername.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class GithubUsername extends Model
{
//
}
11 changes: 11 additions & 0 deletions fetch-github-project/app/Models/Setting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Setting extends Model
{
protected $guarded = [];

}
48 changes: 48 additions & 0 deletions fetch-github-project/app/Models/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace App\Models;

// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable
{
/** @use HasFactory<\Database\Factories\UserFactory> */
use HasFactory, Notifiable;

/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
];

/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];

/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
}
}
10 changes: 10 additions & 0 deletions fetch-github-project/app/Models/gitHubProjects.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class gitHubProjects extends Model
{
protected $guarded = [];
}
24 changes: 24 additions & 0 deletions fetch-github-project/app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
//
}

/**
* Bootstrap any application services.
*/
public function boot(): void
{
//
}
}
15 changes: 15 additions & 0 deletions fetch-github-project/artisan
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env php
<?php

use Symfony\Component\Console\Input\ArgvInput;

define('LARAVEL_START', microtime(true));

// Register the Composer autoloader...
require __DIR__.'/vendor/autoload.php';

// Bootstrap Laravel and handle the command...
$status = (require_once __DIR__.'/bootstrap/app.php')
->handleCommand(new ArgvInput);

exit($status);
18 changes: 18 additions & 0 deletions fetch-github-project/bootstrap/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;

return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
//
})
->withExceptions(function (Exceptions $exceptions) {
//
})->create();
2 changes: 2 additions & 0 deletions fetch-github-project/bootstrap/cache/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
Loading