facepunch-commits

parser commits from commits.facepunch.com

Usage no npm install needed!

<script type="module">
  import facepunchCommits from 'https://cdn.skypack.dev/facepunch-commits';
</script>

README

Watch facepunch commits

Facepunch logo

This library allows you to track the commits from the facepunch site.

NPM Version NPM Downloads Node CI NPM Publish

Installation

This is a Node.js module available through the npm registry.

$ npm i facepunch-commits

Features

  • Ability to subscribe to commits
  • Set the interval after which the next request to view the commits will be executed
  • Strict typing
  • Additional methods that allow you to check whether the commit is hidden, as well as convect the date in unixtime

Functions

subscribeToAuthor(name, callback)
  • Description: The function that will be called with the new commit.
  • Key: name
    • Type: String.
    • Description: Name of the author to subscribe to.
  • Key: callback
    • Type: Function.
    • Return: Commit
subscribeToRepository(name, callback)
  • Description: The function that will be called with the new commit.
  • Key: name
    • Type: String.
    • Description: Name of the repository to subscribe to.
  • Key: callback
    • Type: Function.
    • Return: Commit
subscribeToAuthorRepository(authorName, repositoryName, callback)
  • Description: The function that will be called with the new commit.
  • Key: authorName
    • Type: String.
    • Description: Name of the author to subscribe to.
  • Key: repositoryName
    • Type: String.
    • Description: Name of the repository to subscribe to.
  • Key: callback
    • Type: Function.
    • Return Commit
subscribeToAll(callback)
  • Description: The function that will be called with the new commit.
  • Key: callback
    • Type: Function.
    • Return: Commit
catchRequest(callback)
  • Description: Called when a request has occurred. Return error
  • Key: callback
    • Type: Function.
    • Return: Error
getCommitById(id)
  • Description: Get commit by id.
  • Key: id
    • Type: Function.
    • Return: Promise Commit.

Callback also has additional features

commit.isHide
  • Type: Function.
    • Description: Checks whether the switch is hidden. (blues with symbols)
    • Return: boolean
commit.toUnixTime
  • Type: Function.
    • Description: Convects date in unixtime
    • Return: number
commit.urlCommit
  • Type: Function.
    • Description: Get url link commit
    • Return: string
commit.username
  • Type: Function.
    • Description: Get username author commit
    • Return: string
commit.avatar
  • Type: Function.
    • Description: Get avatar author commit
    • Return: string

Example return in callback function (commit)

interface Commit {
    /**
     * unique id commit
     */
    id: number;
    /**
     * name repository
     */
    repo: string;
    /**
     * name branch
     */
    branch: string;
    /**
     * changeset id
     */
    changeset: string;
    /**
     * date created fixation commit
     */
    created: string;
    /**
     * commit message
     */
    message: string;
    /**
     * user info commit
     */
    user: {
        /**
         * name author commit
         */
        name: string;
        /**
         * avatar author commit
         */
        avatar: string
    };
}

Example usage

const FacepunchCommits = require('facepunch-commits');

const commits = new FacepunchCommits({ 
    interval: 15000 // interval check commits in ms
});

commits.subscribeToAuthor('Garry Newman', (commit) => {
    // Here we subscribe to commits from author Garry Newman
    console.log('Ohh... New commit from Garry!!!', commit);
})

commits.subscribeToRepository('sbox', (commit) => {
    // Here we subscribe to the comments on the repository sandbox.source
    console.log(commit.isHide() ? 'Ohh, is hide. fuck....' : commit.message);
})

commits.subscribeToAuthorRepository('Garry Newman', 'Fad', (commit) => {
    console.log('fad?? New commit from Garry in rep Fad', commit);
})

commits.subscribeToAll((commit) => {
    console.log(`new commit from ${commit.user.name}:`, commit);
})

commits.catchRequest((err) => {
    console.log('new error', err);
})

(() => {
    commits.getCommitById(1)
        .then((commit) => {
            console.log('Get commit', commit);
        })
})();

Running test

$ npm run validator
$ npm test

For developers (suggest an idea)

Usage

git clone https://github.com/ZakharYA/facepunch-commits.git
npm i
# code...
npm run validator
npm run build
# create pull request

People

Author Zakhar Yaitskih

License

MIT