30 lines
1.1 KiB
JavaScript
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);
|
|
}
|