@@ -9,7 +9,9 @@ if [[ $(jq --version 1>/dev/null 2>&1 && echo yes) != "yes" ]]; then
99 exit 1
1010fi
1111
12- if [ -z " $1 " ]; then
12+ PR_NUMBER=" $1 "
13+ PATCH_FILE=" $2 "
14+ if [ -z " $PR_NUMBER " ]; then
1315 echo " Please provide a PR link or number. For example: https://github.com/ossrs/ffmpeg-webrtc/pull/20"
1416 exit 1
1517fi
@@ -29,92 +31,119 @@ echo "Fetching PR #$PR_NUMBER from $PR_URL"
2931PR_DATA=$( curl -s " https://api.github.com/repos/ossrs/ffmpeg-webrtc/pulls/$PR_NUMBER " )
3032REPO_NAME=$( printf ' %s' " $PR_DATA " | jq -r ' .head.repo.full_name' )
3133BRANCH_NAME=$( printf ' %s' " $PR_DATA " | jq -r ' .head.ref' )
34+ echo " Repository: $REPO_NAME , Branch: $BRANCH_NAME "
3235if [[ -z " $REPO_NAME " || -z " $BRANCH_NAME " ]]; then
3336 echo " Error: REPO_NAME or BRANCH_NAME is empty!"
3437 exit 1
3538fi
36- echo " Repository: $REPO_NAME , Branch: $BRANCH_NAME "
3739
3840PR_TITLE=$( printf ' %s' " $PR_DATA " | jq -r ' .title' )
3941PR_DESCRIPTION=$( printf ' %s' " $PR_DATA " | jq -r ' .body // ""' )
40- if [[ -z " $PR_TITLE " ]]; then
41- echo " Error: PR title is empty!"
42- exit 1
43- fi
44-
4542echo " PR information:"
4643echo " ==================================================================="
4744echo " $PR_TITLE "
4845echo " $PR_DESCRIPTION "
4946echo " ==================================================================="
5047echo " "
48+ if [[ -z " $PR_TITLE " ]]; then
49+ echo " Error: PR title is empty!"
50+ exit 1
51+ fi
5152
52- set -euxo pipefail
53-
54- git checkout workflows
55- echo " Switched to workflows branch."
56-
53+ git checkout workflows &&
54+ echo " Switched to workflows branch." &&
5755git pull
5856echo " Pulled latest changes from workflows branch."
57+ if [[ $? -ne 0 ]]; then
58+ echo " Failed to switch to workflows branch or pull latest changes."
59+ exit 1
60+ fi
5961
60- REMOTE_NAME=patch-tmp
62+ REMOTE_NAME=patch-tmp &&
6163if git remote | grep -q " ^$REMOTE_NAME $" ; then
6264 git remote rm " $REMOTE_NAME "
63- fi
64- git remote add $REMOTE_NAME https://github.com/${REPO_NAME} .git
65- git fetch $REMOTE_NAME $BRANCH_NAME
65+ fi &&
66+ git remote add $REMOTE_NAME https://github.com/${REPO_NAME} .git &&
67+ git fetch $REMOTE_NAME $BRANCH_NAME &&
6668echo " Fetch remote $REMOTE_NAME at $( git remote get-url $REMOTE_NAME ) "
69+ if [[ $? -ne 0 ]]; then
70+ echo " Failed to fetch remote branch $BRANCH_NAME from $REMOTE_NAME ."
71+ exit 1
72+ fi
6773
68- TMP_BRANCH=tmp-branch-for-patch-$PR_NUMBER
74+ TMP_BRANCH=tmp-branch-for-patch-$PR_NUMBER &&
6975if git branch --list " $TMP_BRANCH " | grep -q " ^..$TMP_BRANCH $" ; then
7076 git branch -D " $TMP_BRANCH "
71- fi
72- git checkout -b $TMP_BRANCH $REMOTE_NAME /$BRANCH_NAME
77+ fi &&
78+ git checkout -b $TMP_BRANCH $REMOTE_NAME /$BRANCH_NAME &&
7379echo " Checkout branch $TMP_BRANCH from $REMOTE_NAME /$BRANCH_NAME "
80+ if [[ $? -ne 0 ]]; then
81+ echo " Failed to checkout branch $TMP_BRANCH from $REMOTE_NAME /$BRANCH_NAME ."
82+ exit 1
83+ fi
7484
7585FIRST_AUTHOR_NAME=$( git log workflows..HEAD --reverse --format=' %an' | head -n1)
7686FIRST_AUTHOR_EMAIL=$( git log workflows..HEAD --reverse --format=' %ae' | head -n1)
7787echo " Author: $FIRST_AUTHOR_NAME <$FIRST_AUTHOR_EMAIL >"
88+ if [[ -z " $FIRST_AUTHOR_NAME " || -z " $FIRST_AUTHOR_EMAIL " ]]; then
89+ echo " Error: Unable to determine the first author of the PR."
90+ exit 1
91+ fi
7892
7993COAUTHORS=$( git log workflows..HEAD --format=' Co-authored-by: %an <%ae>' | grep -v " $FIRST_AUTHOR_NAME " | sort -u)
8094COAUTHOR_COUNT=$( echo " $COAUTHORS " | wc -l)
81- if [ " $COAUTHOR_COUNT " -gt 0 ]; then
95+ if [[ " $COAUTHOR_COUNT " -gt 0 ] ]; then
8296 echo " $COAUTHORS "
8397fi
8498
8599COMMIT_MSG=" $PR_TITLE "
86- if [ -n " $PR_DESCRIPTION " ]; then
100+ if [[ -n " $PR_DESCRIPTION " ] ]; then
87101 COMMIT_MSG=" $COMMIT_MSG \n\n$PR_DESCRIPTION "
88102fi
89103
90- if [ " $COAUTHOR_COUNT " -gt 0 ]; then
104+ if [[ " $COAUTHOR_COUNT " -gt 0 ] ]; then
91105 COMMIT_MSG=" $COMMIT_MSG \n"
92106 COMMIT_MSG=" $COMMIT_MSG \n$COAUTHORS "
93107fi
94108
95109echo " Commit information:"
96110echo " Author: $FIRST_AUTHOR_NAME <$FIRST_AUTHOR_EMAIL >"
97111echo " ==================================================================="
98- echo -e " $COMMIT_MSG "
112+ echo -n - e " $COMMIT_MSG "
99113echo " ==================================================================="
100114echo " "
101115
102- git rebase workflows
103- git reset --soft workflows
104- git commit --author " $FIRST_AUTHOR_NAME <$FIRST_AUTHOR_EMAIL >" -m " $( echo -e " $COMMIT_MSG " ) "
105- echo " Squashed commits into a single commit."
116+ git rebase workflows &&
117+ git reset --soft workflows &&
118+ git commit --author " $FIRST_AUTHOR_NAME <$FIRST_AUTHOR_EMAIL >" -m " $( echo -n -e " $COMMIT_MSG " ) " &&
119+ echo " Squashed commits into a single commit." &&
120+ if [[ $? -ne 0 ]]; then
121+ echo " Failed to rebase or commit changes."
122+ exit 1
123+ fi
124+
125+ git branch -vv &&
106126git log -1 --pretty=format:" %an <%ae> %h %s"
127+ if [[ $? -ne 0 ]]; then
128+ echo " Failed to display branch information or last commit."
129+ exit 1
130+ fi
107131
108- PATCH_FILE=" patch-$PR_NUMBER -$( date +%s) .patch"
109- rm -f $PATCH_FILE
110- git format-patch -1 --stdout > $PATCH_FILE
132+ if [[ -z " $PATCH_FILE " ]]; then
133+ PATCH_FILE=" whip-patch-$PR_NUMBER -$( date +%s) .patch"
134+ fi &&
135+ rm -f $PATCH_FILE &&
136+ git format-patch -1 --stdout > $PATCH_FILE &&
137+ echo " Created patch file: $PATCH_FILE "
138+ if [[ $? -ne 0 ]]; then
139+ echo " Failed to create patch file."
140+ exit 1
141+ fi
111142
112143git checkout workflows
113144# git br -D $TMP_BRANCH
114145# echo "Removed temporary branch $TMP_BRANCH."
115146
116- set +e +u +x +o pipefail
117-
118147echo " "
119148echo " Patch file created: $PATCH_FILE "
120149echo " "
0 commit comments