Giter VIP home page Giter VIP logo

ghas-results / git-parse Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wayfair/git-parse

0.0 0.0 0.0 3.65 MB

JavaScript library that generates an array of JavaScript objects, representing the current branch of a local git repository's commit history

Home Page: https://www.npmjs.com/package/git-parse

License: BSD 2-Clause "Simplified" License

Shell 0.96% TypeScript 99.04%
wayfair

git-parse's Introduction

Git-Parse

NPM version NPM Downloads Bundlephobia

git-parse is a utility which generates an array of javascript objects representing the current branch of a local git repository's commit history.

Details

  • Support NodeJS >= 14

Installation

npm install git-parse

Usage

const { gitToJs } = require('git-parse');

const commitsPromise = gitToJs('path/to/repo/');

commitsPromise.then(commits => console.log(JSON.stringify(commits, null, 2)));
Console output:
[
  {
    "hash": "7cedc121ee163d859dfdb9911e627d4b5933cc6d",
    "authorName": "[email protected]",
    "authorEmail": "[email protected]",
    "date": "Wed, 10 Jan 2018 16:44:52 -0500",
    "message": "initial setup",
    "filesAdded":[
        { "path": "packages/raspberry-popsicle/index.js" },
        { "path": "packages/raspberry-popsicle/package-lock.json" },
        { "path": "packages/raspberry-popsicle/package.json" }
    ],
    "filesDeleted": [],
    "filesModified": [],
    "filesRenamed": []
  },
  {
    "hash": "226f032eb87ac1eb18b7212eeaf1356980a9ae03",
    "authorName": "[email protected]",
    "authorEmail": "[email protected]",
    "date": "Wed, 10 Jan 2018 15:25:16 -0500",
    "message": "add README",
    "filesAdded": [
      { "path": "README.md" }
    ],
    "filesDeleted": [],
    "filesModified": [],
    "filesRenamed": []
  }
]

API

.gitToJs(pathToRepo, [options])

Returns a promise which resolves with a list of objects describing git commits on the current branch. pathToRepo is a string. options is an optional object with one property, sinceCommit, which is a commit hash. If sinceCommit is present, gitToJs will return logs for commits after the commit specified.

const { gitToJs } = require('git-parse');

const commitsPromise = gitToJs('path/to/repo/');

commitsPromise.then(commits => console.log(JSON.stringify(commits, null, 2)));

.checkOutCommit(pathToRepo, commitHash, [options])

Checks a repository out to a given commit. hash is the commit hash. Options is an optional object with one property, force. force adds --force to the underlying git checkout. Returns a promise.

.gitPull(pathToRepo)

Runs 'git pull' on the repository at the given path. Returns a promise.

.gitDiff(pathToRepo, commitHash1, [commitHash2], [file])

Returns a git diff given a path to the repo, a commit, an optional second commit, and an optional file path.

Returns a promise resolving with the diff as a string.

Development

Build

To generate a local distribution for the git-parse library run the following command:

yarn build

To build the library in the background on file changes, use:

yarn build:watch

Code Formatting

To automatically format the code using Prettier run:

yarn format

or

yarn format:check

Linting

To lint the project using ESLint run:

yarn lint

Tests

To run the project tests using the Jest framework run:

yarn test

Type Checking

To check the project for type errors using Typescript run:

yarn tsc

Use --watch to run the type checker in the background:

yarn tsc --watch

License

This project is licensed under the BSD-2-Clause license.

git-parse's People

Contributors

renovate[bot] avatar erj826 avatar garypwhite avatar finn-orsini avatar kv979w avatar jashparekh avatar peterthehan avatar dependabot[bot] avatar rchl avatar raphaelts3 avatar crashmax-dev avatar morganpackard avatar letlm avatar kurt-r2c avatar cooperbuilt avatar draco2003 avatar c-tanner avatar artemruts avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.