4040 });
4141
4242 const commits = await github.paginate(commitOpts);
43- return commits;
43+
44+ if (commits.length === 0) {
45+ core.setFailed('No commits found in the PR');
46+ return '';
47+ }
48+
49+ // Get unique authors from the commits list
50+ const authors = commits.reduce((acc, commit) => {
51+ const username = commit.author?.login || commit.commit.author?.name;
52+ if (username && !acc[username]) {
53+ acc[username] = {
54+ name: commit.commit.author?.name,
55+ email: commit.commit.author?.email,
56+ }
57+ }
58+
59+ return acc;
60+ }, {});
61+
62+ return authors;
4463 } catch (error) {
4564 core.setFailed(error.message);
4665 return [];
@@ -51,26 +70,13 @@ jobs:
5170 uses : actions/github-script@v7
5271 with :
5372 script : |
54- const commits = ${{ steps.authors.outputs.result }};
73+ const authors = ${{ steps.authors.outputs.result }};
5574
56- if (commits .length === 0) {
57- core.setFailed('No commits found in the PR');
75+ if (Object.keys(authors) .length === 0) {
76+ core.setFailed('No authors found in the PR');
5877 return '';
5978 }
6079
61- // Get unique authors from the commits list
62- const authors = commits.reduce((acc, commit) => {
63- const username = commit.author?.login || commit.commit.author?.name;
64- if (username && !acc[username]) {
65- acc[username] = {
66- name: commit.commit.author?.name,
67- email: commit.commit.author?.email,
68- }
69- }
70-
71- return acc;
72- }, {});
73-
7480 // Create a string of the form "Co-authored-by: Name <email>"
7581 // ref: https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors
7682 const coAuthors = Object.values(authors).map(author => {
0 commit comments