@@ -117,7 +117,7 @@ github_api() {
117
117
curl -s " ${headers[@]} " " $GITHUB_API_URL$endpoint "
118
118
;;
119
119
POST)
120
- # For POST requests, always set the Content-Type header>
120
+ # For POST requests, always set the Content-Type header:
121
121
headers+=(" -H" " Content-Type: application/json" )
122
122
123
123
# If data is provided, include it in the request:
@@ -156,13 +156,22 @@ main() {
156
156
pr_commits=$( github_api " GET" " /repos/$REPO_OWNER /$REPO_NAME /pulls/$pr_number /commits" )
157
157
158
158
# Extract co-authors from commit messages:
159
+ co_authors=$( echo " $pr_commits " | jq -r ' .[].commit.message' | grep -Eio ' Co-authored-by:.*' | sort -u)
159
160
processed_co_authors=" "
160
161
while IFS= read -r co_author_line; do
162
+ # Skip empty lines:
163
+ if [ -z " $co_author_line " ]; then
164
+ continue
165
+ fi
161
166
name_email=$( echo " $co_author_line " | sed -E ' s/Co-authored-by:[[:space:]]*(.*)/\1/' )
162
167
name=$( echo " $name_email " | sed -E ' s/^(.*)<.*>$/\1/' | xargs)
163
168
email=$( echo " $name_email " | sed -E ' s/^.*<(.*)>$/\1/' | xargs)
164
169
resolved_author=$( resolve_name_email " $name " " $email " )
165
170
171
+ # Skip if the resolved author matches the resolved PR author:
172
+ if [ " $resolved_author " == " $pr_author_resolved " ]; then
173
+ continue
174
+ fi
166
175
processed_co_authors+=" Co-authored-by: $resolved_author " $' \n '
167
176
done <<< " $co_authors"
168
177
@@ -195,11 +204,13 @@ main() {
195
204
# Remove any empty lines and duplicates:
196
205
commit_authors=$( echo " $commit_authors " | sort -u | sed ' /^$/d' )
197
206
198
- # Prefix with 'Co-authored-by: ':
199
- commit_authors_formatted=$( echo " $commit_authors " | sed ' s/^/Co-authored-by: /' | sort -u)
207
+ # Prefix with 'Co-authored-by: ' if not empty:
208
+ if [ -n " $commit_authors " ]; then
209
+ commit_authors=$( echo " $commit_authors " | sed ' s/^/Co-authored-by: /' | sort -u)
210
+ fi
200
211
201
- # Combine co-authors and commit authors:
202
- all_co_authors=$( echo -e " $co_authors \n$commit_authors_formatted " | sort -u | sed ' /^$/d' )
212
+ # Combine co-authors and commit authors, removing empty lines :
213
+ all_co_authors=$( echo -e " $processed_co_authors \n$commit_authors " | sed ' /^\s* $/d' | sort -u )
203
214
204
215
# Extract 'Signed-off-by' lines from commits:
205
216
signed_off_bys=$( echo " $pr_commits " | jq -r ' .[].commit.message' | grep -Eio ' Signed-off-by:.*' | sort -u)
0 commit comments