Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
NoteReview.gs
// レビュー待ちのpull requestをお知らせ。
// トリガーから定期実行するのを想定している。
var CHANNEL = "your_review_channel";
var REPOSITORIES = [
"your_github/your_repository1",
"your_github/your_repository2"
];
function noteReviews() {
if (shouldSleep()) return;
REPOSITORIES.forEach(function(repository){
noteReview(repository);
});
}
function noteReview(repository) {
var githubApiURL = "https://api.github.com/repos/" + repository + "/pulls";
var userProperties = PropertiesService.getUserProperties();
var options =
{
"headers" : {
"Content-type": "application/json",
"Authorization" : "token " + PropertiesService.getScriptProperties().getProperty('GITHUB_TOKEN')
}
};
var response = UrlFetchApp.fetch(githubApiURL, options);
var pulls = JSON.parse(response.getContentText());
pulls.forEach(function(pull){
notifySlack(pull);
});
}
function notifySlack(pull) {
if (pull["title"].indexOf("WIP") > -1 ||
pull["title"].indexOf("PEND") > -1 ||
pull["title"].indexOf("Release ") > -1) {
return;
}
var prop = PropertiesService.getScriptProperties().getProperties();
var slackApp = SlackApp.create(prop.SLACK_TOKEN);
if (pull["requested_reviewers"].length <= 0) {
slackApp.chatPostMessage(CHANNEL, pull["user"]["login"] + "さん、レビューアーがいないかレビューが終わってるみたい? 大丈夫?\n" +
pull["title"] + " " + pull["html_url"],
{ username: "lily", icon_emoji: ":lily_bot:"});
return;
}
// FIXME: siderが0番目に来るため最後を取ってみる。もっと賢い方法にしたい。
var reviewer = pull["requested_reviewers"][pull["requested_reviewers"].length - 1]["login"];
slackApp.chatPostMessage(CHANNEL, reviewer + "さんへ。\n"+"レビューの進捗はいかがですか?\n" +
pull["title"] + " " + pull["html_url"],
{ username: "lily", icon_emoji: ":lily_bot:"});
}
function shouldSleep() {
var date = new Date();
var day = date.getDay(); // 0:日曜日
if (day == 0 || day == 6) return true;
var hh = Utilities.formatDate(date, 'Asia/Tokyo', 'HH');
if (hh == 10) return false;
if (hh == 14) return false;
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.