Group same contributions without URL, make grouping more precise
This commit is contained in:
@@ -1,14 +1,29 @@
|
||||
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.
|
||||
//
|
||||
// Until we have identical IPFS documents for different contributions, we will
|
||||
// use the URL as grouping key
|
||||
// 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) {
|
||||
let url = contribution ? contribution.url : null;
|
||||
if (isEmpty(url)) return null;
|
||||
return url;
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user