Last active
August 17, 2016 07:33
-
-
Save matsu-chara/dd9936ef4227508c6b9c to your computer and use it in GitHub Desktop.
npmのパッケージでアップデートがあったら自動で上げてプルリクエストを送ってくれるjenkins job
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
#! /bin/sh | |
# VARS | |
# 完全一致でアップデートしたくないライブラリを書く。カンマは要らないので注意 | |
BLACK_LIST=("example1" "exmaple2") | |
REPO_OWNER="$1" | |
REPO_NAME="$2" | |
TOKEN="$3" | |
# CONSTANTS | |
DATE="$(date "+%Y-%m-%d-%H-%M-%S")" | |
TITLE="npm package updated" | |
BRANCH_PREFIX="npm-update" | |
BRANCH_NAME="${BRANCH_PREFIX}-${DATE}" | |
# === | |
# 掃除 | |
git branch | grep "$BRANCH_PREFIX" | |
if [ $? == 0 ]; then git branch | grep "$BRANCH_PREFIX" | xargs git branch -D; fi | |
JOIND_BLACK_LIST="$(IFS=\|; echo "${BLACK_LIST[*]}")" | |
# updateを実行して出力を受け取る | |
MSG="$($(npm bin)/ncu --packageFile ./package.json -u "/^(?!$JOIND_BLACK_LIST).*$/" )" | |
echo -e "$MSG\n" | |
# package.jsonが変更されているかを見て、変更なしだったら終了 | |
git status -s | grep ' M package.json' | |
if [ $? != 0 ]; then exit 0; fi | |
# 更新があったらプルリクエストを作成する | |
git checkout -b $BRANCH_NAME | |
git add package.json | |
git commit -F- <<EOM | |
$TITLE | |
$MSG | |
EOM | |
#プルリクエストを作成 | |
git push origin $BRANCH_NAME | |
JSON=$(python -c 'import sys; import json; print json.dumps({"title": sys.argv[1], "head": sys.argv[2], "base": sys.argv[3], "body": sys.argv[4]})' "$TITLE" "$BRANCH_NAME" "master" "$MSG") | |
curl -i \ | |
-H "Content-Type: application/json; charset=utf-8" \ | |
-H "Authorization: token $TOKEN" \ | |
-d "$JSON" ${ここにGITHUB ENTERPRISEのホスト名を入れる}/api/v3/repos/$REPO_OWNER/$REPO_NAME/pulls |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment