Skip to content

Instantly share code, notes, and snippets.

@insin
Last active February 26, 2024 12:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save insin/4bcc281289b37a582624 to your computer and use it in GitHub Desktop.
Save insin/4bcc281289b37a582624 to your computer and use it in GitHub Desktop.
stargaze - watch a GitHub repo's star count, with change notifications

Stargaze

Watch a GitHub repo's star count, with change notifications.

Usage

Download and extract the Gist (over there somewhere →).

Install dependencies:

npm install

Pass a GitHub repo name:

node index.js facebook/react
var notifier = require('node-notifier')
var request = require('request')
var repo = process.argv[2]
if (!repo) {
console.error('You must provide a GitHub repo in user/repo format')
process.exit(1)
}
var lastStars = 0
var options = {
url: 'https://api.github.com/repos/' + repo,
headers: {
'User-Agent': 'request'
}
}
function handleResponse(err, res, body) {
if (err) {
console.error(err)
notifier.notify({
title: 'Stargaze Error',
message: err.message
})
process.exit(1)
}
else if (res.statusCode !== 200) {
console.error(body)
notifier.notify({
title: 'Stargaze Error',
message: 'Got an HTTP ' + res.statusCode + ' response'
})
process.exit(1)
}
var stars = JSON.parse(body).stargazers_count
if (stars > lastStars) {
notifier.notify({
title: 'Stargaze',
message: repo + ' has ' + stars + ' stars'
})
lastStars = stars
}
console.log(lastStars)
setTimeout(checkStars, 60000)
}
function checkStars() {
console.log(new Date().toISOString(), 'Requesting stars for ' + repo)
request(options, handleResponse)
}
checkStars()
{
"name": "stargaze",
"version": "1.0.0",
"description": "Watch a GitHub repo's star count, with change notifications",
"main": "index.js",
"dependencies": {
"request": "^2.55.0",
"node-notifier": "^4.1.2"
},
"license": "MIT"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment