@@ -9,7 +9,9 @@ if [[ $(jq --version 1>/dev/null 2>&1 && echo yes) != "yes" ]]; then
9
9
exit 1
10
10
fi
11
11
12
- if [ -z " $1 " ]; then
12
+ PR_NUMBER=" $1 "
13
+ PATCH_FILE=" $2 "
14
+ if [ -z " $PR_NUMBER " ]; then
13
15
echo " Please provide a PR link or number. For example: https://github.com/ossrs/ffmpeg-webrtc/pull/20"
14
16
exit 1
15
17
fi
@@ -29,92 +31,119 @@ echo "Fetching PR #$PR_NUMBER from $PR_URL"
29
31
PR_DATA=$( curl -s " https://api.github.com/repos/ossrs/ffmpeg-webrtc/pulls/$PR_NUMBER " )
30
32
REPO_NAME=$( printf ' %s' " $PR_DATA " | jq -r ' .head.repo.full_name' )
31
33
BRANCH_NAME=$( printf ' %s' " $PR_DATA " | jq -r ' .head.ref' )
34
+ echo " Repository: $REPO_NAME , Branch: $BRANCH_NAME "
32
35
if [[ -z " $REPO_NAME " || -z " $BRANCH_NAME " ]]; then
33
36
echo " Error: REPO_NAME or BRANCH_NAME is empty!"
34
37
exit 1
35
38
fi
36
- echo " Repository: $REPO_NAME , Branch: $BRANCH_NAME "
37
39
38
40
PR_TITLE=$( printf ' %s' " $PR_DATA " | jq -r ' .title' )
39
41
PR_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
-
45
42
echo " PR information:"
46
43
echo " ==================================================================="
47
44
echo " $PR_TITLE "
48
45
echo " $PR_DESCRIPTION "
49
46
echo " ==================================================================="
50
47
echo " "
48
+ if [[ -z " $PR_TITLE " ]]; then
49
+ echo " Error: PR title is empty!"
50
+ exit 1
51
+ fi
51
52
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." &&
57
55
git pull
58
56
echo " 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
59
61
60
- REMOTE_NAME=patch-tmp
62
+ REMOTE_NAME=patch-tmp &&
61
63
if git remote | grep -q " ^$REMOTE_NAME $" ; then
62
64
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 &&
66
68
echo " 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
67
73
68
- TMP_BRANCH=tmp-branch-for-patch-$PR_NUMBER
74
+ TMP_BRANCH=tmp-branch-for-patch-$PR_NUMBER &&
69
75
if git branch --list " $TMP_BRANCH " | grep -q " ^..$TMP_BRANCH $" ; then
70
76
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 &&
73
79
echo " 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
74
84
75
85
FIRST_AUTHOR_NAME=$( git log workflows..HEAD --reverse --format=' %an' | head -n1)
76
86
FIRST_AUTHOR_EMAIL=$( git log workflows..HEAD --reverse --format=' %ae' | head -n1)
77
87
echo " 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
78
92
79
93
COAUTHORS=$( git log workflows..HEAD --format=' Co-authored-by: %an <%ae>' | grep -v " $FIRST_AUTHOR_NAME " | sort -u)
80
94
COAUTHOR_COUNT=$( echo " $COAUTHORS " | wc -l)
81
- if [ " $COAUTHOR_COUNT " -gt 0 ]; then
95
+ if [[ " $COAUTHOR_COUNT " -gt 0 ] ]; then
82
96
echo " $COAUTHORS "
83
97
fi
84
98
85
99
COMMIT_MSG=" $PR_TITLE "
86
- if [ -n " $PR_DESCRIPTION " ]; then
100
+ if [[ -n " $PR_DESCRIPTION " ] ]; then
87
101
COMMIT_MSG=" $COMMIT_MSG \n\n$PR_DESCRIPTION "
88
102
fi
89
103
90
- if [ " $COAUTHOR_COUNT " -gt 0 ]; then
104
+ if [[ " $COAUTHOR_COUNT " -gt 0 ] ]; then
91
105
COMMIT_MSG=" $COMMIT_MSG \n"
92
106
COMMIT_MSG=" $COMMIT_MSG \n$COAUTHORS "
93
107
fi
94
108
95
109
echo " Commit information:"
96
110
echo " Author: $FIRST_AUTHOR_NAME <$FIRST_AUTHOR_EMAIL >"
97
111
echo " ==================================================================="
98
- echo -e " $COMMIT_MSG "
112
+ echo -n - e " $COMMIT_MSG "
99
113
echo " ==================================================================="
100
114
echo " "
101
115
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 &&
106
126
git 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
107
131
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
111
142
112
143
git checkout workflows
113
144
# git br -D $TMP_BRANCH
114
145
# echo "Removed temporary branch $TMP_BRANCH."
115
146
116
- set +e +u +x +o pipefail
117
-
118
147
echo " "
119
148
echo " Patch file created: $PATCH_FILE "
120
149
echo " "
0 commit comments