複数のリポジトリのプルリクエストを見ていくのが大変なので、いっきにプルリクを出すやつ。 LabelでWIP付いてると無視、一度表示したのは二度出なくなる機能付き。
- インポートのやつをgo getする
- tokenとuserとreposを好きなのに変更
- go run
cronとかに仕込めばいいんじゃないかな
package main | |
import ( | |
"fmt" | |
"strings" | |
"golang.org/x/net/context" | |
"golang.org/x/oauth2" | |
"github.com/google/go-github/github" | |
) | |
func main() { | |
token := "token" | |
user := "yoshida-mediba" | |
repos := []string{ | |
"study-go", | |
} | |
os.Mkdir("/var/tmp/prdump", 0777) | |
ctx := context.Background() | |
client := github.NewClient(oauth2.NewClient(ctx, oauth2.StaticTokenSource( | |
&oauth2.Token{AccessToken: token}, | |
))) | |
for _, repo := range repos { | |
issues, _, _ := client.Issues.ListByRepo(ctx, user, repo, nil) | |
fmt.Println("☆" + repo) | |
for _, issue := range issues { | |
if issue.PullRequestLinks == nil { | |
continue | |
} | |
wip := false | |
for _, label := range issue.Labels { | |
if strings.ToLower(*label.Name) == "wip" { | |
wip = true | |
} | |
if strings.ToLower(*label.Name) == "work in progress" { | |
wip = true | |
} | |
} | |
if ! wip { | |
if os.Mkdir("/var/tmp/prdump/"+strconv.Itoa(*issue.ID), 0777) != nil { | |
continue | |
} | |
fmt.Println(*issue.Title) | |
fmt.Println(*issue.HTMLURL) | |
} | |
} | |
fmt.Println() | |
} | |
} |
#!/bin/bash | |
# | |
# send_pr_to_talknote.sh [Mail] | |
# | |
function sendMailTalknote() { | |
mime="MIME-Version: 1.0" | |
type="Content-Type: text/plain; charset=UTF-8" | |
base="Content-Transfer-Encoding: base64" | |
from="From: [email protected]" | |
addr="To: $1" | |
body="$2" | |
if [ $(echo -e "${body}" | wc -l) -le 2 ]; then | |
exit | |
fi | |
body=$(echo "${body}" | nkf -wMB) | |
echo -e "${mime}\n${from}\n${addr}\n${type}\n${base}\n\n${body}" | /usr/sbin/sendmail -t -i | |
} | |
function isJapanHoliday() { | |
url="https://www.google.com/calendar/ical/ja.japanese%23holiday%40group.v.calendar.google.com/public/full" | |
now=$(date +%Y%m%d) | |
if [[ -n $(curl -sS $url | fgrep "DTSTART;VALUE=DATE:$now") ]]; then | |
return 0 | |
fi | |
return 1 | |
} | |
if ! isJapanHoliday; then | |
sendMailTalknote $1 "$(/home/h-yoshida/prdump)" | |
fi |