Skip to content

Instantly share code, notes, and snippets.

@risou
Created April 16, 2018 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save risou/81be3c2d774b4ea9cf013f99694f8754 to your computer and use it in GitHub Desktop.
Save risou/81be3c2d774b4ea9cf013f99694f8754 to your computer and use it in GitHub Desktop.
GitHub の organization ごとの assigned issue の件数を Slack の custom status に設定するやつ
/*
GitHub の API の rate limit まで何回リクエスト可能回数が残っているかを取得
*/
const request = require('request')
const token = ''
const options = {
url: 'https://api.github.com/rate_limit',
json: true,
headers: {
'User-Agent': 'request'
},
auth: {
'bearer': token
}
}
request.get(options, (error, response, body) => {
if (error) {
console.log(error)
throw error
}
console.log(body)
})
/*
各 organization の assigned issue の件数を取得
*/
const request = require('request')
const orgs = ['', '', '']
const token = ''
for (let i = 0; i < orgs.length; i++) {
const org = orgs[i]
const options = {
url: 'https://api.github.com/orgs/' + org + '/issues',
json: true,
headers: {
'User-Agent': 'request'
},
auth: {
'bearer': token
}
}
request.get(options, (error, response, body) => {
if (error) {
console.log(error)
throw error
}
const issueCount = body ? body.length : 0
console.log(org + ': ' + issueCount)
})
}
/*
slack の custom_status を更新
*/
const request = require('request')
const token = ''
let emoji = ':cry:'
request.post({
url: 'https://slack.com/api/users.profile.set',
json: true,
form: {
token: token,
profile: JSON.stringify({
status_emoji: emoji,
status_text: 'assigned issues risou-san has'
})
},
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
}, (error, response, body) => {
console.log(body)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment