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
createBranchfunction 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
getBranchhelper (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.
- It initially fetches the forked repository main branch where we wished to create the new branch off of; it does this using the
I also took the initiative of moving the
getBranchhelper 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.
-
Implemented the main
createBranchfunction in thebranchscript atsrc/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 therepoFullnameandrepoMainBranchRefas properties in the object type param -
newBranchName- name of the branch that will be created for the user
The
createBranchfunction 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
getBranchhelper function; this return theSHAof the branch - Then we make a request to the endpoint
"POST /repos/{owner}/{repo}/git/refs"to create the new branch; passing in therepoDetails.repoFullnameproperties, the head branchSHAand thenewBranchName.
-
-
Moved the
getBranchfunction from theforkscript to thebranchscript
screencast-bpconcjcammlapcogcnnelfmaeghhagj-2024.04.01-13_54_14.webm
Top comments (2)
Amazing
Thanks bro :hehe: