Skip to content

Commit

Permalink
Better users aggregation for multiple commits
Browse files Browse the repository at this point in the history
show unique list of users/emails instead of just "multiple users"
  • Loading branch information
yrtimiD committed Jul 14, 2024
1 parent 71b6746 commit f376378
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
21 changes: 19 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ function getInput(name, options) {
}
return val.trim();
}

exports.getInput = getInput;
/**
* Gets the values of an multiline input. Each value is also trimmed.
Expand Down Expand Up @@ -52539,8 +52540,8 @@ function aggregateCommits(context, options, notifications) {
commit: {
html_url: context.compareLink,
commit: {
author: { name: '[Multiple authors]' },
committer: { name: '[Multiple committers]' },
author: aggregateUsers(n.map(n => n.commit.commit.author)),
committer: aggregateUsers(n.map(n => n.commit.commit.committer)),
message: `[${n.length} commits]`,
},
sha: '0000000000000000000000000000000000000000',
Expand Down Expand Up @@ -52597,6 +52598,22 @@ function stripUser(u) {
html_url: u.html_url
};
}
function aggregateUsers(users) {
if (users.length === 1)
return users[0];
let uniqueNames = new Set(users.map(u => u.name));
let unique = [...uniqueNames].map(un => users.find(u => u.name === un));
if (unique.length > 1) {
return ({
name: unique.map(u => u.name).join(', '),
email: unique.map(u => u.email).join(';'),
});
}
else {
let u = { name: users[0].name, email: users[0].email };
return u;
}
}


/***/ }),
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "github-codewatchers",
"version": "2.1.0",
"version": "2.1.1",
"description": "GitHub Action that triggers notifications about changed files to a list of subscribers",
"main": "dist/index.js",
"scripts": {
Expand Down
20 changes: 18 additions & 2 deletions src/match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ export function aggregateCommits(context: Context, options: Options, notificatio
commit: {
html_url: context.compareLink,
commit: {
author: { name: '[Multiple authors]' },
committer: { name: '[Multiple committers]' },
author: aggregateUsers(n.map(n => n.commit.commit.author)),
committer: aggregateUsers(n.map(n => n.commit.commit.committer)),
message: `[${n.length} commits]`,
},
sha: '0000000000000000000000000000000000000000',
Expand Down Expand Up @@ -143,4 +143,20 @@ function stripUser(u: Partial<GH.User>): Notif.User {
gravatar_id: u.gravatar_id,
html_url: u.html_url
}
}

function aggregateUsers<U extends { name?: string, email?: string }>(users: U[]): U {
if (users.length === 1) return users[0];

let uniqueNames = new Set(users.map(u => u.name));
let unique = [...uniqueNames].map(un => users.find(u => u.name === un));
if (unique.length > 1) {
return ({
name: unique.map(u => u.name).join(', '),
email: unique.map(u => u.email).join(';'),
}) as U;
} else {
let u = { name: users[0].name, email: users[0].email };
return u as U;
}
}

0 comments on commit f376378

Please sign in to comment.