40
40
});
41
41
42
42
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;
44
63
} catch (error) {
45
64
core.setFailed(error.message);
46
65
return [];
@@ -51,26 +70,13 @@ jobs:
51
70
uses : actions/github-script@v7
52
71
with :
53
72
script : |
54
- const commits = ${{ steps.authors.outputs.result }};
73
+ const authors = ${{ steps.authors.outputs.result }};
55
74
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');
58
77
return '';
59
78
}
60
79
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
-
74
80
// Create a string of the form "Co-authored-by: Name <email>"
75
81
// ref: https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors
76
82
const coAuthors = Object.values(authors).map(author => {
0 commit comments