@@ -117,7 +117,7 @@ github_api() {
117117 curl -s " ${headers[@]} " " $GITHUB_API_URL$endpoint "
118118 ;;
119119 POST)
120- # For POST requests, always set the Content-Type header>
120+ # For POST requests, always set the Content-Type header:
121121 headers+=(" -H" " Content-Type: application/json" )
122122
123123 # If data is provided, include it in the request:
@@ -156,13 +156,22 @@ main() {
156156 pr_commits=$( github_api " GET" " /repos/$REPO_OWNER /$REPO_NAME /pulls/$pr_number /commits" )
157157
158158 # Extract co-authors from commit messages:
159+ co_authors=$( echo " $pr_commits " | jq -r ' .[].commit.message' | grep -Eio ' Co-authored-by:.*' | sort -u)
159160 processed_co_authors=" "
160161 while IFS= read -r co_author_line; do
162+ # Skip empty lines:
163+ if [ -z " $co_author_line " ]; then
164+ continue
165+ fi
161166 name_email=$( echo " $co_author_line " | sed -E ' s/Co-authored-by:[[:space:]]*(.*)/\1/' )
162167 name=$( echo " $name_email " | sed -E ' s/^(.*)<.*>$/\1/' | xargs)
163168 email=$( echo " $name_email " | sed -E ' s/^.*<(.*)>$/\1/' | xargs)
164169 resolved_author=$( resolve_name_email " $name " " $email " )
165170
171+ # Skip if the resolved author matches the resolved PR author:
172+ if [ " $resolved_author " == " $pr_author_resolved " ]; then
173+ continue
174+ fi
166175 processed_co_authors+=" Co-authored-by: $resolved_author " $' \n '
167176 done <<< " $co_authors"
168177
@@ -195,11 +204,13 @@ main() {
195204 # Remove any empty lines and duplicates:
196205 commit_authors=$( echo " $commit_authors " | sort -u | sed ' /^$/d' )
197206
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
200211
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 )
203214
204215 # Extract 'Signed-off-by' lines from commits:
205216 signed_off_bys=$( echo " $pr_commits " | jq -r ' .[].commit.message' | grep -Eio ' Signed-off-by:.*' | sort -u)
0 commit comments