Created
April 16, 2018 08:43
-
-
Save risou/81be3c2d774b4ea9cf013f99694f8754 to your computer and use it in GitHub Desktop.
GitHub の organization ごとの assigned issue の件数を Slack の custom status に設定するやつ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
各 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) | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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