Logo

dev-resources.site

for different kinds of informations.

Building jargons.dev [#6]: The Branch Script

Published at
11/19/2024
Categories
javascript
opensource
productivity
buildinpublic
Author
babblebey
Author
9 person written this
babblebey
open
Building jargons.dev [#6]: The Branch Script

This should be really short haha šŸ˜ƒ, considering the branch script is the smallest of them (The Scripts) all.

The Branch Script's primary assignment is to hold all helper functions that can be used to perform operation related to References (aka Branch) on the GitHub APIs.

The Script

Noting the primary responsibility of the branch script which is
to create a reference/branch of repo (in this case would be the jargons.dev repo fork) on an authenticated user's account. I got to work quickly by doing the following...

  • Implemented the main createBranch function in the branch script which accepts necessary param to perform the following operation in the stated order...

    • It initially fetches the forked repository main branch where we wished to create the new branch off of; it does this using the getBranch helper (a function that was created in the fork script); this return the SHA of the branch
    • Then makes a POST request to the endpoint "/repos/{owner}/{repo}/git/refs" to create the new branch; passing in the full name of the user's fork, the head branch SHA and the name of the new branch we wish to create.
  • I also took the initiative of moving the getBranch helper function from the fork script to a the branch script ā€” feels more like home šŸ˜‰.

The PR

feat: implement `branch` creation script #17

This Pull request implements the branch creation script whose primary function is to create a new branch from the forked repository for an authenticated user.

Changes Made

  • Implemented the main createBranch function in the branch script at src/lib/branch.js; this function takes in 3 params;

    • userOctokit - a user authenticated instance of octokit that can be used to perform action on user's behalf
    • repoDetails - the user's forked repo details; hold the repoFullname and repoMainBranchRef as properties in the object type param
    • newBranchName - name of the branch that will be created for the user

    The createBranch function performs the following operation in the stated order...

    • It initially fetches the forked repository main branch where we wished to create the new branch off of; it does this using the getBranch helper function; this return the SHA of the branch
    • Then we make a request to the endpoint "POST /repos/{owner}/{repo}/git/refs" to create the new branch; passing in the repoDetails.repoFullname properties, the head branch SHA and the newBranchName.
  • Moved the getBranch function from the fork script to the branch script

Screencast/Screenshot

screencast-bpconcjcammlapcogcnnelfmaeghhagj-2024.04.01-13_54_14.webm

buildinpublic Article's
30 articles in total
Favicon
Week Seven Recap of #100DaysOfCode
Favicon
I built timeconvert.org - scratching my own itch
Favicon
Simplifying Static Site Hosting: Why Iā€™m Building Rollout
Favicon
Predicting House Rent with Linear Regression in Python
Favicon
Building CrossPost: A Publishing Tool for Technical Writers
Favicon
Week 6 Recap of #100DaysOfCode
Favicon
I built the HackerNews for IndieHackers.
Favicon
The 10-Minute Company: zero to PoC 10 minutes per day
Favicon
Getting My First Users From Building Something Unexpected
Favicon
Introducing iWebhook.today: Simplify Payment Webhook Testing for Indie Developers
Favicon
Fediverse - The new sound of social networking
Favicon
Shipping a joke-rating app in 24 hours
Favicon
Week 5 Recap of #100DaysOfCode
Favicon
Promote Your Product via My Dev Community Blog
Favicon
Easiest way to find collaborators for your project idea
Favicon
Week Two of #100DaysOfCode
Favicon
Introducing gleam.so: Create Perfect OpenGraph (OG) Images Without The Hassle šŸŽØ
Favicon
Week 4 Recap of #100DaysOfCode
Favicon
Building jargons.dev [#6]: The Branch Script
Favicon
Week Three of #100DaysOfCode
Favicon
How to Fix Google Auth Platform Verification Issues (Your home page URL is unresponsive)
Favicon
Building a SaaS as a Solo Developer: Month 1 Learnings
Favicon
Making OpenGraph (OG) Images More Accessible: Now Design & Preview Everything for Free šŸŽØ
Favicon
How to Think Like an Engineer: Lessons Beyond Technical Skills
Favicon
Setting up my writing journey
Favicon
Building jargons.dev [#7]: The Word Editor Script
Favicon
Adding Custom Vendor Packages to Android Source Code: A Complete Guide
Favicon
Week One of #100DaysOfCode
Favicon
Why and How I Created an Explorer for GitHub Awesome Lists
Favicon
Let's Boxing - Train Boxing Anywhere šŸ„Š

Featured ones: