Get (List) All Repositories using GitHub API

 import os
import requests
from flask import Flask, request, render_template

app = Flask(__name__)

GITHUB_API_URL = "{}/repos"

def fetch_repositories(username):
    headers = {"Authorization": f"token {GITHUB_API_TOKEN}"}
    response = requests.get(GITHUB_API_URL.format(username), headers=headers)
    if response.status_code == 200:
        repos = response.json()
        for repo in repos:
            # Manually parse and reshape the "last updated" information
            last_updated = repo.get('updated_at')
            if last_updated:
                # Splitting the date and time components
                date, time = last_updated.split('T')
                year, month, day = date.split('-')
                repo['updated_at'] = f"{day}-{month}-{year}"  # Reshaping to DD-MM-YYYY format
        return repos

About this template

This application utilizes Flask for the backend to fetch GitHub repositories of a specified user or organization. The frontend is built with HTML, CSS, and JavaScript to provide a simple user interface for inputting the GitHub username or organization. Upon submission, the backend fetches the repositories using the GitHub API and renders the results dynamically on the frontend. Users can also reset the table to clear the displayed repositories. Additionally, error handling is implemented to handle cases where no repositories are found or there is an issue with the GitHub API token. Made by BaranDev[]

Introduction to the GitHub Repositories Viewer Template

Welcome to the GitHub Repositories Viewer Template! This template allows you to create a simple web application that fetches and displays a list of GitHub repositories for a given user or organization. It's a great way to showcase your projects or to keep track of repositories you're interested in. The application uses the GitHub API to retrieve repository data and presents it in a user-friendly interface.

Getting Started with the Template

To begin using this template, click on "Start with this Template" on the Lazy platform. This will set up the template in your Lazy Builder interface, pre-populating the code so you can customize it as needed without any copy-pasting.

Initial Setup: Adding Environment Secrets

Before you can use the GitHub Repositories Viewer, you'll need to set up an environment secret for the GitHub API token. This token is necessary for the application to authenticate with the GitHub API and fetch repository data.

  • Go to the GitHub Developer Settings to generate a new Personal Access Token (PAT).
  • Select the appropriate scopes for your token. For this application, you'll need at least the public_repo scope.
  • Once you have your token, go to the Environment Secrets tab within the Lazy Builder.
  • Create a new secret with the key GITHUB_API_TOKEN and paste your GitHub Personal Access Token as the value.

Test: Deploying the App

With your environment secret in place, you're ready to deploy the app. Press the "Test" button on the Lazy platform. This will begin the deployment process and launch the Lazy CLI. You won't need to provide any additional input at this stage, as the user input will be handled through the web interface once the app is running.

Using the App

After pressing the "Test" button, Lazy will provide you with a dedicated server link to access your application. Navigate to this link to view the GitHub Repositories Viewer interface.

Here's how to use the interface:

  • Enter a GitHub username or organization name into the text field provided.
  • Click the "Get Repositories" button to fetch and display the list of repositories.
  • If you wish to reset the table and clear the current results, click the "Reset Table" button.

If the application encounters any issues fetching repositories, such as an invalid GitHub API token, it will alert you through the interface.

Integrating the App

If you wish to integrate this GitHub Repositories Viewer into another service or frontend, you can use the server link provided by Lazy as the endpoint for your requests. For example, you could embed the viewer into a personal website or a dashboard by creating an iframe that points to the server link.

Here's a sample code snippet for embedding the viewer:

<iframe src="YOUR_SERVER_LINK" width="100%" height="600"></iframe>

Replace YOUR_SERVER_LINK with the actual link provided by Lazy after deployment.

By following these steps, you should now have a fully functional GitHub Repositories Viewer that you can use and integrate as you see fit. Enjoy showcasing your GitHub projects!

Last published
July 19, 2024

More templates like this

FALLBACK | Flask, HTML, JS and Tailwind Based Website

This is a good starting point for styled website. It has a header, footer. Has Tailwind and Flowbite loaded so you can build nice looking pages from here.


MP3ify: Youtube to MP3 Converter

A web application that allows users to download YouTube videos from URLs and provides the option to convert them to MP3 format.


Login and Registration

This is a good starting point for any app that requires login and registration

React JS
Get (List) All Repositories using GitHub API