@aurahelper/git-manager
TypeScript icon, indicating that this package has built-in type declarations

2.1.5 • Public • Published

Aura Helper Git Manager Module

Version Total Downloads Downloads/Month Issues Known Vulnerabilities Code Size License

The Git Manager Module has an util methods to handle and manage git repository and has features to use in Aura Helper Framework. Yo can fetch data, list branches, get commits or get diffs from two branches, tags, commits...

You can use Aura Helper Metadata Factory Module @ah/metadata-factory to create a Metadata JSON Object from the Git diffs result, to create a package with Aura Helper Package Generator Module @ah/package-generator to create de package and destructive files from git changes to deploy or delete from your org. If you want, can use too the Aura Helper Ignore Module @ah/ignore to avoid deploy or delete some metadata types. With this workflow, refactor code, work with git and teams or implement Continuous Integration among other development processes and tasks are easy.

GitManager Class

Class with util methods to handle and manage git repository and has features to use in Aura Helper Framework. Yo can fetch data, list branches, get commits or get diffs from two branches, tags, commits...

Can cobine this module with @ah/metadata-factory, @ah/package-generator and @ah/ignore to refactor code, work with git and teams or implement Continuous Integration among other development processes and tasks easy.

Class Members

Fields

The fields that start with _ are for internal use only (Does not modify this fields to a correct GitManager work). To the rest of fields, setter methods are recommended instead modify fields.

projectFolder

Path to the project under a git repository

  • string

Constructors

constructor(projectFolder)

Constructor to instance a new GitManager object. All parameters are optional and you can use the setters methods to set the values when you want.

Parameters:

  • projectFolder: Path to the ignore file
    • string

Methods


setProjectFolder(projectFolder)

Method to set the git project folder path

Return:

Return the GitManager instance

  • GitManager

Examples:

Set Project folder

    import { GitManager } from '@aurahelper/git-manager';

    const gitManager = new GitManager();
    gitManager.setProjectFolder('path/to/project/root');

getUserName()

Method to get the User Name set on git config

Return:

Return a String promise with the Git User Name

  • Promise<string>

Throws:

This method can throw the next exceptions:

  • WrongDirectoryPathException: If the project folder is not a String or can't convert to absolute path
  • DirectoryNotFoundException: If the project folder not exists or not have access to it
  • InvalidDirectoryPathException: If the project folder is not a directory
  • OSNotSupportedException: When run this processes with not supported operative system

Examples:

Get git user name

    import { GitManager } from '@aurahelper/git-manager';
    
    const gitManager = new GitManager('path/to/project/root');

    gitManager.getUserName().then((username) => {
        console.log(username);
    }).catch((error) => {
        // handle error
    });

getUserEmail()

Method to get the User Email set on git config

Return:

Return a String promise with the Git User Email

  • Promise<string>

Throws:

This method can throw the next exceptions:

  • WrongDirectoryPathException: If the project folder is not a String or can't convert to absolute path
  • DirectoryNotFoundException: If the project folder not exists or not have access to it
  • InvalidDirectoryPathException: If the project folder is not a directory
  • OSNotSupportedException: When run this processes with not supported operative system

Examples:

Get git user email

    import { GitManager } from '@aurahelper/git-manager';
    
    const gitManager = new GitManager('path/to/project/root');

    gitManager.getUserEmail().then((userEmail) => {
        console.log(userEmail);
    }).catch((error) => {
        // handle error
    });

getAuthorName()

Method to get the Author Name set on git config

Return:

Return a String promise with the Git Author Name

  • Promise<string>

Throws:

This method can throw the next exceptions:

  • WrongDirectoryPathException: If the project folder is not a String or can't convert to absolute path
  • DirectoryNotFoundException: If the project folder not exists or not have access to it
  • InvalidDirectoryPathException: If the project folder is not a directory
  • OSNotSupportedException: When run this processes with not supported operative system

Examples:

Get git author name

    import { GitManager } from '@aurahelper/git-manager';
    
    const gitManager = new GitManager('path/to/project/root');

    gitManager.getAuthorName().then((authorName) => {
        console.log(authorName);
    }).catch((error) => {
        // handle error
    });

getAuthorEmail()

Method to get the Author Email set on git config

Return:

Return a String promise with the Git Author Email

  • Promise<string>

Throws:

This method can throw the next exceptions:

  • WrongDirectoryPathException: If the project folder is not a String or can't convert to absolute path
  • DirectoryNotFoundException: If the project folder not exists or not have access to it
  • InvalidDirectoryPathException: If the project folder is not a directory
  • OSNotSupportedException: When run this processes with not supported operative system

Examples:

Get git author email

    import { GitManager } from '@aurahelper/git-manager';

    const gitManager = new GitManager('path/to/project/root');

    gitManager.getAuthorEmail().then((authorEmail) => {
        console.log(authorEmail);
    }).catch((error) => {
        // handle error
    });

getCommitterName()

Method to get the Committer Name set on git config

Return:

Return a String promise with the Git Committer Name

  • Promise<string>

Throws:

This method can throw the next exceptions:

  • WrongDirectoryPathException: If the project folder is not a String or can't convert to absolute path
  • DirectoryNotFoundException: If the project folder not exists or not have access to it
  • InvalidDirectoryPathException: If the project folder is not a directory
  • OSNotSupportedException: When run this processes with not supported operative system

Examples:

Get git committer name

    import { GitManager } from '@aurahelper/git-manager';

    const gitManager = new GitManager('path/to/project/root');
    
    gitManager.getCommitterName().then((committerName) => {
        console.log(committerName);
    }).catch((error) => {
        // handle error
    });

getCommitterEmail()

Method to get the Committer Email set on git config

Return:

Return a String promise with the Git Committer Email

  • Promise<string>

Throws:

This method can throw the next exceptions:

  • WrongDirectoryPathException: If the project folder is not a String or can't convert to absolute path
  • DirectoryNotFoundException: If the project folder not exists or not have access to it
  • InvalidDirectoryPathException: If the project folder is not a directory
  • OSNotSupportedException: When run this processes with not supported operative system

Examples:

Get git committer email

    import { GitManager } from '@aurahelper/git-manager';

    const gitManager = new GitManager('path/to/project/root');

    gitManager.getCommitterEmail().then((committerEmail) => {
        console.log(committerEmail);
    }).catch((error) => {
        // handle error
    });


fetch()

Method to fetch repository data into your local Salesforce gitr project

Return:

Return an empty promise when finish fetch process

  • Promise<void>

Throws:

This method can throw the next exceptions:

  • WrongDirectoryPathException: If the project folder is not a String or can't convert to absolute path
  • DirectoryNotFoundException: If the project folder not exists or not have access to it
  • InvalidDirectoryPathException: If the project folder is not a directory
  • OSNotSupportedException: When run this processes with not supported operative system

Examples:

Fetch data to the local project

    import { GitManager } from '@aurahelper/git-manager';

    const gitManager = new GitManager('path/to/project/root');

    gitManager.fetch().then(() => {
        // data retrieved
    }).catch((error) => {
        // handle error
    });

getBranches()

Method to get branch names from the Salesforce git repository

Return:

Returns a promise with an object list with branch name and active status

  • Promise<GitBranch[]>

Throws:

This method can throw the next exceptions:

  • WrongDirectoryPathException: If the project folder is not a String or can't convert to absolute path
  • DirectoryNotFoundException: If the project folder not exists or not have access to it
  • InvalidDirectoryPathException: If the project folder is not a directory
  • OSNotSupportedException: When run this processes with not supported operative system

Examples:

Get branches from git project

    import { GitManager } from '@aurahelper/git-manager';

    const gitManager = new GitManager('path/to/project/root');

    gitManager.getBranches().then((branches) => {
        console.log(branches);
        // [{ name: 'master', active: false }, { name: 'branch1', active: true }, {...}]
    }).catch((error) => {
        // handle error
    });

getTags(sortField)

Method to list all git tags. You can also sort by field

Parameters:

  • sortField: Field to sort the result (Optional)
    • String

Return:

Returns a promise with a list of tags

  • Promise<GitTag[]>

Throws:

This method can throw the next exceptions:

  • WrongDirectoryPathException: If the project folder is not a String or can't convert to absolute path
  • DirectoryNotFoundException: If the project folder not exists or not have access to it
  • InvalidDirectoryPathException: If the project folder is not a directory
  • OSNotSupportedException: When run this processes with not supported operative system

Examples:

Get tags from git project

    import { GitManager } from '@aurahelper/git-manager';

    const gitManager = new GitManager('path/to/project/root');

    gitManager.getTags().then((tags) => {
        console.log(tags);
        // [{ name: 'v.1.0.0', description: 'tag description' }, { name: 'v.1.0.1', description: 'tag description' }, {...}]
    }).catch((error) => {
        // handle error
    });

getCommits()

Method to get the commits data from the Salesforce git repository

Return:

Returns a promise with list of Commit objects

  • Promise<Commit[]>

Throws:

This method can throw the next exceptions:

  • WrongDirectoryPathException: If the project folder is not a String or can't convert to absolute path
  • DirectoryNotFoundException: If the project folder not exists or not have access to it
  • InvalidDirectoryPathException: If the project folder is not a directory
  • OSNotSupportedException: When run this processes with not supported operative system

Examples:

Get commits data from git project

    import { GitManager } from '@aurahelper/git-manager';

    const gitManager = new GitManager('path/to/project/root');

    gitManager.getCommits().then((commits) => {
        for(const commit of commits){
            console.log(commit.pointer);
            console.log(commit.author);
            console.log(commit.authorEmail);
            console.log(commit.date.dayName);
            console.log(commit.date.monthName);
            console.log(commit.date.day);
            console.log(commit.date.time);
            console.log(commit.date.year);
            console.log(commit.date.timeoffset);
            console.log(commit.date.dateStr);
            console.log(commit.title);
            console.log(commit.message);
        }
    }).catch((error) => {
        // handle error
    });

getDiffs(source, target)

Method to get a list of GitDiff object with the differences between two branches, commits, tags...

Parameters:

  • source: Source branch name, tag or commit for get diffs
    • string
  • target: Target branch name, tag or commit for get diffs
    • string

Return:

Returns a promise with GitDiffs objects list with the difference data

  • Promise<GitDiff[]>

Throws:

This method can throw the next exceptions:

  • WrongDirectoryPathException: If the project folder is not a String or can't convert to absolute path
  • DirectoryNotFoundException: If the project folder not exists or not have access to it
  • InvalidDirectoryPathException: If the project folder is not a directory
  • OSNotSupportedException: When run this processes with not supported operative system
  • DataRequiredException: If source is not provided

Examples:

Get diffs from two branches

    import { GitManager } from '@aurahelper/git-manager';

    const gitManager = new GitManager('path/to/project/root');

    gitManager.getDiffs('branch1', 'master').then((diffs) => {
        for(const diff of diffs){
            console.log(diff.path);
            console.log(diff.mode);
            console.log(diff.addChanges); // Array with every added line per file
            console.log(diff.removeChanges);  // Array with every removed line per file
        }
    }).catch((error) => {
        // handle error
    });

Package Sidebar

Install

npm i @aurahelper/git-manager

Weekly Downloads

95

Version

2.1.5

License

GPLv3

Unpacked Size

102 kB

Total Files

9

Last publish

Collaborators

  • jjlongoria