facepunch-commits
TypeScript icon, indicating that this package has built-in type declarations

3.6.4 • Public • Published

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 CodeQL

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.getLikes()
  • Type: Function.
    • Description: Get likes and dislikes in commit
    • Return: Object
      {
      	likes: Number
      	dislikes: Number
      }
commit.isHide()
  • Type: Function.
    • Description: Checks whether the switch is hidden. (blues with symbols)
    • Return: boolean
commit.getDate()
  • Type: Function.
    • Description: get Date commit in js format
    • Return: Date
commit.toUnixTime()
  • Type: Function.
    • Description: Convects date in unixtime
    • Return: number
commit.likes
  • Type: Number | Null
    • Description: count likes in commit (if you called function getLikes())
commit.dislikes
  • Type: Number | Null
    • Description: count dislikes in commit (if you called function getLikes())
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(387280)
		.then(async (commit) => {
			console.log('Get commit', commit);
			
			const {likes, dislikes} = await commit.getLikes();
			console.log('likes:', likes);
			console.log('dislikes:', dislikes);
			
			// or
			await commit.getLikes();
			console.log('likes:', commit.likes);
			console.log('dislikes:', commit.dislikes);
		})
		
	// or
	commits.options.autoGetLikes = true;
	commits.getCommitById(387280)
		.then(async (commit) => {
			console.log('Get commit', commit);
			console.log('likes:', commit.likes);
			console.log('dislikes:', commit.dislikes);
		})
})();

Running test

$ npm run validator
$ npm test

Members

Author Zakhar Yaitskih

License

MIT

Package Sidebar

Install

npm i facepunch-commits

Weekly Downloads

3

Version

3.6.4

License

MIT

Unpacked Size

46.5 kB

Total Files

25

Last publish

Collaborators

  • zakharya