DEV Community

Cover image for Building jargons.dev [#6]: The Branch Script
Olabode Lawal-Shittabey
Olabode Lawal-Shittabey

Posted on

1

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

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

Top comments (2)

Collapse
 
tobisupreme profile image
Tobi Balogun •

Amazing

Collapse
 
babblebey profile image
Olabode Lawal-Shittabey •

Thanks bro :hehe:

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay