Home  >  Article  >  Web Front-end  >  Building jargons.dev [# The Branch Script

Building jargons.dev [# The Branch Script

DDD
DDDOriginal
2024-11-24 05:41:14501browse

Building jargons.dev [# 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

Building jargons.dev [# The Branch Script feat: implement `branch` creation script #17

Building jargons.dev [# The Branch Script
babblebey posted on

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

View on GitHub

The above is the detailed content of Building jargons.dev [# The Branch Script. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn