-
Notifications
You must be signed in to change notification settings - Fork 0
/
issue-to-pull
executable file
·46 lines (37 loc) · 1.31 KB
/
issue-to-pull
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/sh
#/ Usage: issue-to-pull <user/repo> <issue_id>
#/ Converts an issue into a pull request
# show usage
[ $# -eq 0 -o "$1" = "--help" ] && {
grep '^#/'< "$0" |
cut -c4-
exit 2
}
# grab the current branch
branch=$(git symbolic-ref HEAD | sed 's/^refs\/heads\///')
[ -z "$branch" ] && {
echo "could not determine current branch" 1>&2
exit 2
}
# WIP
if ! [ -e ~/.githubauthorization ]
then
read -p "GitHub username: " name
read -s -p "GitHub password: " pass
curl -u "$name:$pass" https://api.github.com/authorizations -s \
-d '{"note":"for scripts", "scopes":["repo", "user", "public_repo", "gists"]}' \
| grep -Po '"token":.*?[^\\]",' | sed 's/\"token\": \"//g' | sed 's/\",//g' \
> ~/.githubauthorization
echo "Generated and saved an oauth token here ~/.githubauthorization"
fi
token=`cat ~/.githubauthorization`
echo "Turning issue $2 on $1 into a pull request for branch '$branch'"
curl -H "Authorization: token $token" https://api.github.com/repos/$1/pulls \
-d '{"issue":'$2', "head":"'$branch'", "base":"master"}' \
| grep -Po '"url":.*?[^\\]",' | sed 's/\"url\": \"//g' | sed 's/\",//g'
# Old Direct method
# read -s -p "GitHub Password: " pwd
# curl -u "tclem:$pwd" https://api.github.com/repos/$1/pulls \
# -d '{"issue":'$2', "head":"'$branch'", "base":"master"}'
#
# echo