Skip to content

Commit 341ddcb

Browse files
committed
enable promoting changes to text-prompting
1 parent 16aaacd commit 341ddcb

File tree

2 files changed

+121
-0
lines changed

2 files changed

+121
-0
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SHELL:=/bin/bash
2+
3+
promote-changes:
4+
./scripts/promote_changes.sh

scripts/promote_changes.sh

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/bin/bash
2+
3+
RED='\033[0;31m'
4+
GREEN='\033[0;32m'
5+
YELLOW='\033[0;33m'
6+
CYAN='\033[0;36m'
7+
NC='\033[0m' # No Color
8+
9+
function echo_info {
10+
echo -e "${CYAN}[INFO ]${NC} $1"
11+
}
12+
13+
function echo_good_news {
14+
echo -e "${GREEN}[GOOD ]${NC} $1"
15+
}
16+
17+
function echo_warning {
18+
echo -e "${YELLOW}[OOPS ]${NC} $1"
19+
}
20+
21+
function echo_error {
22+
echo -e "${RED}[ERROR]${NC} $1"
23+
}
24+
25+
REMOTE_ORIGIN_SSH='SSH'
26+
REMOTE_ORIGIN_HTTP='HTTP'
27+
REMOTE_ORIGIN_UNEXPECTED='UNEXPECTED'
28+
function get_remote_origin_type {
29+
case "$1" in
30+
https:*)
31+
echo $REMOTE_ORIGIN_HTTP
32+
;;
33+
34+
echo $REMOTE_ORIGIN_SSH
35+
;;
36+
*)
37+
echo $REMOTE_ORIGIN_UNEXPECTED
38+
;;
39+
esac
40+
}
41+
42+
REMOTE_HTTP='https://github.com/opentensor/text-prompting.git'
43+
REMOTE_SSH='[email protected]:opentensor/text-prompting.git'
44+
REMOTE_NAME='tmp-promote-changes'
45+
46+
function check_if_remote_exists {
47+
URL_COUNT="$(git remote -v | grep -c $REMOTE_NAME)"
48+
if (( URL_COUNT > 0 )); then
49+
echo "yes"
50+
else
51+
echo "no"
52+
fi
53+
}
54+
55+
echo_info 'Checking git remote origin...'
56+
EXPECTE_REMOTE_ORIGIN='private'
57+
58+
ORIGIN_BRANCH="$(git remote -v | grep $EXPECTE_REMOTE_ORIGIN | grep push | awk '{ print $2 }')"
59+
case "$ORIGIN_BRANCH" in
60+
*opentensor/text-prompting-private*)
61+
echo_good_news 'Correct remote origin'
62+
;;
63+
*)
64+
echo_error 'Unexpected remote origin'
65+
echo_info 'finishing execution...'
66+
exit 1
67+
;;
68+
esac
69+
70+
71+
ORIGIN_TYPE="$(get_remote_origin_type "$ORIGIN_BRANCH")"
72+
case $ORIGIN_TYPE in
73+
"$REMOTE_ORIGIN_HTTP")
74+
REMOTE_URL=$REMOTE_HTTP
75+
;;
76+
"$REMOTE_ORIGIN_SSH")
77+
REMOTE_URL=$REMOTE_SSH
78+
;;
79+
esac
80+
81+
echo_info "Creating git remote '$REMOTE_NAME' '$REMOTE_URL' if not exists"
82+
83+
REMOTE_ALREADY_EXIST="$(check_if_remote_exists)"
84+
if [ "$REMOTE_ALREADY_EXIST" == "no" ]; then
85+
git remote add "$REMOTE_NAME" "$REMOTE_URL"
86+
fi
87+
88+
REMOTE_ALREADY_EXIST="$(check_if_remote_exists)"
89+
if [ "$REMOTE_ALREADY_EXIST" == "no" ]; then
90+
echo_error "Something went wrong, unable to create git remote $REMOTE_NAME"
91+
fi
92+
93+
echo_good_news "Remote exists '$REMOTE_NAME' -> $REMOTE_URL"
94+
95+
USER_NAME="$(git config user.name)"
96+
if [ -z "$USER_NAME" ]; then
97+
USER_NAME='unknown'
98+
fi
99+
100+
TS=$(date +%Y_%m_%d)
101+
BRANCH_TO_PUSH="promote-changes/$TS/$USER_NAME"
102+
103+
echo_info "Pushing changes to remote branch '$BRANCH_TO_PUSH'"
104+
git push "$REMOTE_NAME" "main:$BRANCH_TO_PUSH"
105+
106+
case $OSTYPE in
107+
"linux-gnu"*)
108+
xdg-open "https://github.com/opentensor/text-prompting/pull/new/$BRANCH_TO_PUSH"
109+
;;
110+
"darwin"*)
111+
open "https://github.com/opentensor/text-prompting/pull/new/$BRANCH_TO_PUSH"
112+
;;
113+
*)
114+
echo_warning "OS type '$OSTYPE' not supported."
115+
echo_good_news "You can open the PR with the following URL: https://github.com/opentensor/text-prompting/pull/new/$BRANCH_TO_PUSH"
116+
;;
117+
esac

0 commit comments

Comments
 (0)