0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

githubのPull Requestをコマンド一発で作成する!

Posted at

背景

https://github.com/newsdict/newsdict.io

https://github.com/newsdict/docker_rails
にPRするのがめんどくさいのでコマンド一つで済ませたい

前提

  • PR先がいつも同一
  • githubを使ってる
  • レポジトリを集めたディレクトリがある(prsコマンドのみ)

ディレクトリ構成

+ repositories
  + newsdict.io
  + docker_rails
  + ・・・・

作成するコマンド

コマンド パス 実行する場所 説明
create-pr ~/bin/create-pr 対象レポジトリ配下 直前のコミットログ名でPRを作成する
list-pr ~/bin/list-pr 対象レポジトリ配下 PR一覧を見る
prs ~/bin/prs 対象レポジトリの上層ディレクトリ すべてのPRリストを出す

コマンドを置くディレクトリを作る

$ mkdir ~/bin

create-pr

$ cat << EOF > ~/bin/create-pr
#!/bin/bash
pr_destination=newsdict

if [ "\$(git status 2> /dev/null)" != "" ];then
        project_name=\$(basename \$(pwd))
        git_message=(\$(git log -n 1 --oneline | cut -f2- -d' ' | sed 's/ /_/g'))

        hub pull-request -b \$pr_destination/\$project_name:master -m "\${git_message[@]}"
else
        echo "[ERROR] NOT UNDER GIT" >&2
fi
EOF
$ chmod +x ~/bin/create-pr

list-pr

$ cat << EOF > ~/bin/list-pr
#!/bin/bash
pr_destination=newsdict
pr_src=yubele

if [ -f .git/config ];then 
        sed -i "s/git@github.com:\$pr_src/git@github.com:\$pr_destination/" .git/config
        hub pr list -f"%pC%i%Creset %t | %U%n"
        sed -i "s/git@github.com:\$pr_destination/git@github.com:\$pr_src/" .git/config
else
        echo "[ERROR] NOT GIT TOP DIR" >&2
fi
EOF
$ chmod +x ~/bin/list-pr

prs

$ cat << EOF > ~/bin/prs
#!/bin/bash
pushd ~/environment
for i in \$(ls);do 
        if [ -d $i ];then
                echo "####" $i
                pushd \$i >/dev/null
                list-pr 2>/dev/null
                popd >/dev/null
        fi
done
EOF
$ chmod +x ~/bin/prs

最後に~/binのパスを通す

$ echo 'PATH=$PATH:~/bin' >> ~/.bashrc
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?