3.6.4 • Published 2 years ago
facepunch-commits v3.6.4
This library allows you to track the commits from the facepunch site.
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
- Type: Function.
* Return:
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
- Type: Function.
* Return:
catchRequest(callback)
- Description: Called when a request has occurred. Return error
- Key:
callback
- Type: Function.
* Return:
Error
- Type: Function.
* Return:
getCommitById(id)
- Description: Get commit by id.
- Key:
id
Type: Function. Return: PromiseCommit
.
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
3.6.2
2 years ago
3.6.1
2 years ago
3.6.0
2 years ago
3.4.1
2 years ago
3.6.4
2 years ago
3.6.3
2 years ago
3.5.1
2 years ago
3.5.0
2 years ago
3.4.0
2 years ago
3.3.1
2 years ago
3.3.0
2 years ago
3.2.4
3 years ago
3.2.3
3 years ago
3.2.2
3 years ago
3.2.1
3 years ago
3.2.0
3 years ago
2.2.1
3 years ago
2.2.0
3 years ago
2.2.5
3 years ago
2.2.4
3 years ago
2.2.7
3 years ago
3.1.0
3 years ago
2.2.9
3 years ago
2.2.8
3 years ago
3.0.0
3 years ago
2.1.16
3 years ago
2.1.15
3 years ago
2.1.14
3 years ago
2.1.13
3 years ago
2.1.12
3 years ago
2.1.11
3 years ago
2.1.10
3 years ago
2.1.9
3 years ago
2.1.8
3 years ago
2.1.7
3 years ago
2.1.6
3 years ago
2.1.2
3 years ago
2.1.4
3 years ago
2.1.3
3 years ago
2.1.5
3 years ago
2.1.1
3 years ago
2.1.0
3 years ago
2.0.3
3 years ago
2.0.2
3 years ago
2.0.1
3 years ago
1.2.9
4 years ago
1.2.8
4 years ago
1.0.0
4 years ago