Create Repository from Template using Github API

 import logging
from fastapi import FastAPI, HTTPException
from fastapi.responses import RedirectResponse
from some_get_request_handler import handle_get_endpoint
from some_post_request_handler import handle_post_endpoint, Data
from github_api_handler import create_repo_from_template

logger = logging.getLogger(__name__)

app = FastAPI()

@app.get("/", include_in_schema=False)
def root():
    return RedirectResponse(url='/docs')"/create_repo")
def create_repository():
        result = create_repo_from_template()
        return result
    except Exception as e:
        logger.error(f"Failed to create repository: {e}")
        raise HTTPException(status_code=500, detail="Internal server error")

About this template

This app creates a GitHub repository using a template repository with user-defined environment variables. The user can add the template repository name and repository owner details as environment variables. They can also add the custom name they would like to give the new repository created from the template. The app uses FastAPI for making the api call to Github endpoints.

Introduction to the Create Repository from Template using Github API Template

Welcome to the "Create Repository from Template using Github API" template! This template is designed to help you create a new GitHub repository using an existing template repository. It automates the process through a simple API call, allowing you to specify the new repository's name and description. This is particularly useful for quickly setting up new projects with a predefined structure and files.

Clicking Start with this Template

To begin using this template, simply click on the "Start with this Template" button. This will initialize the template in the Lazy Builder interface, pre-populating the code for you.

Initial Setup: Adding Environment Secrets

Before you can use this template, you need to set up some environment secrets within the Lazy Builder. These secrets will store sensitive information required by the GitHub API to create a repository from a template.

Here are the environment secrets you need to set up:

  • GITHUB_TOKEN: Your GitHub personal access token. You can create one by following the instructions on the GitHub documentation.
  • TEMPLATE_OWNER: The username of the owner of the template repository.
  • TEMPLATE_REPO: The name of the template repository.
  • NEW_REPO_NAME: The name you want to give your new repository.
  • NEW_REPO_DESCRIPTION: A description for your new repository.

To add these secrets:

  1. Go to the Environment Secrets tab within the Lazy Builder.
  2. Click on the "Add Secret" button.
  3. Enter the name of the secret (e.g., GITHUB_TOKEN) and its value.
  4. Repeat the process for each secret.

Test: Pressing the Test Button

Once you have set up the environment secrets, you can test the template by clicking the "Test" button. This will deploy the app and launch the Lazy CLI.

Using the App

After pressing the "Test" button, the Lazy CLI will handle the deployment of your application. Once the deployment is complete, Lazy will provide you with a dedicated server link. You can use this link to interact with the API.

Since this template uses FastAPI, you will also be provided with a link to the API documentation. This documentation will be accessible at the /docs endpoint and will allow you to see all the available API routes and test them directly from your browser.

Integrating the App

If you wish to integrate the newly created repository into another service or frontend, you can use the URL provided by the Lazy CLI after the repository is successfully created. This URL will point to the new GitHub repository, where you can clone the repository or set up webhooks and other integrations as needed.

For example, if you want to clone the repository, you can use the following command in your terminal:

git clone [URL provided by Lazy CLI]

Replace [URL provided by Lazy CLI] with the actual URL provided after the repository creation.

Remember, all the steps listed above are mandatory to run and integrate the template. Follow them carefully to ensure a smooth experience with the "Create Repository from Template using Github API" template on Lazy.

Last published
April 7, 2024

More templates like this

Backend Server

This skeleton is streamlined for creating backend services using FastAPI. It's an excellent choice for building microservices or APIs with minimal frontend requirements.

Fast API

Search Email with GMail API

This is a FastAPI-based application that uses Google’s Gmail API to fetch and display emails based on user-defined search queries. It provides a /search_emails endpoint for email searches and a /oauth2callback endpoint for OAuth2 callbacks. The app requires the environment variables CLIENT_ID, CLIENT_SECRET, and REDIRECT_URI for OAuth2 authentication. These credentials pertain to your Google API and must be set correctly for the application to function as expected.

Fast API

Moderate Comments on Facebook Page

An app that moderates comments on your page feed using Facebook API and webhooks. This app uses the FastAPI to create a webhook endpoint for moderating posts on your page. A facebook access token for the page will be needed to make the API call. The permission scopes you will need for the access token are `pages_read_engagement` and `pages_manage_posts permissions` as an admin of the page you are posting to. The app moderates comments on Facebook ads/posts by removing and flagging hateful speech.

Fast API
Create Repository from Template using Github API