Files
kredits-web/app/utils/contribution-grouping-key.js
T
raucao 33a429c448
CI / Lint (pull_request) Successful in 51s
CI / Test (pull_request) Successful in 1m33s
Group same contributions without URL, make grouping more precise
2026-07-26 17:22:53 +02:00

30 lines
1.1 KiB
JavaScript

import ethers from 'ethers';
import { isEmpty } from '@ember/utils';
// Derives a stable grouping key for a contribution, so that contributions
// created for the same issue/pull request (one per contributor) can be
// linked together in the UI.
//
// The key is a 6-char keccak256 prefix of a combination of fields:
// url (optional), description, date, amount, kind. When the URL is present
// (bot contributions) it is included; when absent (manual contributions)
// the remaining fields still produce a reliable key. All of description,
// date, amount, and kind must be present — if any is missing, the
// contribution is treated as a singleton (null key).
export default function contributionGroupingKey (contribution) {
if (!contribution) return null;
const { url, description, date, amount, kind } = contribution;
if (isEmpty(description) || isEmpty(date) || isEmpty(amount) || isEmpty(kind)) {
return null;
}
const input = isEmpty(url)
? `${description}|${date}|${amount}|${kind}`
: `${url}|${description}|${date}|${amount}|${kind}`;
return ethers.utils.id(input).slice(2, 8);
}