Get (List) All Repositories using GitHub API

Test this app for free
58
import os
import requests
from flask import Flask, request, render_template

app = Flask(__name__)

GITHUB_API_URL = "https://api.github.com/users/{}/repos"
GITHUB_API_TOKEN = os.environ['GITHUB_API_TOKEN']

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
    else:
Get full code

Frequently Asked Questions

How can businesses benefit from using this GitHub Repositories Viewer?

The GitHub Repositories Viewer offers several benefits for businesses: - It provides a quick and easy way to assess a potential hire's or partner's GitHub projects. - Companies can use it to showcase their open-source contributions to clients or investors. - It helps in conducting competitive analysis by easily viewing competitors' public repositories. - The tool can be used for internal project management, allowing teams to get an overview of all company repositories.

Can this template be customized for enterprise use?

Yes, the GitHub Repositories Viewer template is highly customizable for enterprise use. Companies can: - Modify the styling to match their brand guidelines. - Add additional columns to display more repository information. - Integrate it with internal systems for more comprehensive project management. - Implement user authentication to restrict access to authorized personnel only.

How does this tool compare to GitHub's native repository listing feature?

While GitHub's native feature is comprehensive, the GitHub Repositories Viewer offers several advantages: - It provides a cleaner, more focused view of repositories. - The tool allows for easy integration into company websites or internal tools. - It offers the flexibility to customize the display and add additional features as needed. - The viewer can be used to display repositories from multiple users or organizations in a single interface.

How can I add pagination to the GitHub Repositories Viewer to handle users with many repositories?

To add pagination, you can modify the fetch_repositories function in main.py to use GitHub's pagination API. Here's an example:

```python def fetch_repositories(username, page=1, per_page=30): headers = {"Authorization": f"token {GITHUB_API_TOKEN}"} params = {"page": page, "per_page": per_page} response = requests.get(GITHUB_API_URL.format(username), headers=headers, params=params) if response.status_code == 200: repos = response.json() # Process repos as before return repos, response.links.get('next') else: return None, None

@app.route("/", methods=["GET", "POST"]) def root_route(): if request.method == "POST": username = request.form.get("username") page = int(request.form.get("page", 1)) repos, next_page = fetch_repositories(username, page) if repos is not None: return render_template('template.html', repos=repos, username=username, next_page=next_page) else: return render_template('template.html', error="Failed to fetch repositories.") return render_template('template.html') ```

You'll also need to update the HTML template to include pagination controls.

How can I extend the GitHub Repositories Viewer to display additional information like star count and fork count?

You can modify the fetch_repositories function to include this information, and update the HTML template to display it. Here's an example:

python def fetch_repositories(username): # ... existing code ... if response.status_code == 200: repos = response.json() for repo in repos: # ... existing code ... repo['star_count'] = repo.get('stargazers_count', 0) repo['fork_count'] = repo.get('forks_count', 0) return repos else: return None

Then in your HTML template, add new table headers and cells:

```html
Stars Forks

{% for repo in repos %}
{{ repo.star_count }} {{ repo.fork_count }}

{% endfor %} ```

This will extend the GitHub Repositories Viewer to display star and fork counts for each repository.

Created: | Last Updated:

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[https://github.com/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!



Here are 5 key business benefits for this template:

Template Benefits

  1. Efficient Repository Management: This tool allows businesses to quickly view and assess all repositories for a given GitHub user or organization, streamlining project management and code review processes.

  2. Enhanced Due Diligence: For companies considering acquisitions or partnerships, this template provides a rapid way to evaluate a target's GitHub presence and development activity.

  3. Competitive Analysis: Businesses can use this tool to analyze competitors' public repositories, gaining insights into their technology stacks and development focus areas.

  4. Talent Scouting: HR departments can leverage this template to efficiently review potential hires' GitHub profiles, assessing their coding activity and project involvement.

  5. Open Source Contribution Tracking: Organizations can easily monitor their employees' or departments' contributions to open source projects, supporting transparency and recognition of external development efforts.

Technologies

Streamline CSS Development with Lazy AI: Automate Styling, Optimize Workflows and More Streamline CSS Development with Lazy AI: Automate Styling, Optimize Workflows and More
Enhance GitHub Workflows with Lazy AI Automation Templates for Issues, Pull Requests and More Enhance GitHub Workflows with Lazy AI Automation Templates for Issues, Pull Requests and More
Enhance HTML Development with Lazy AI: Automate Templates, Optimize Workflows and More Enhance HTML Development with Lazy AI: Automate Templates, Optimize Workflows and More

Similar templates