@@ -243,9 +243,9 @@ export interface BackersQueryOptions extends QueryOptions {
243243 /** If true, do not fetch any remote data when determing backers. */
244244 offline ?: boolean | null
245245
246- /** The minimum amount of monthly cents to be considered a financial donor (only applies if we are aware of the financial amount). */
246+ /** The minimum amount of monthly cents to be considered a financial donor (only applies if we are aware of the financial amount, defaults to 100 ). */
247247 sponsorCentsThreshold ?: number | null
248- /** The minimum amount of eternal cents to be considered a financial donor (only applies if we are aware of the financial amount). */
248+ /** The minimum amount of eternal cents to be considered a financial donor (only applies if we are aware of the financial amount, defaults to 100 ). */
249249 donorCentsThreshold ?: number | null
250250}
251251
@@ -513,6 +513,8 @@ export async function getBackersFromThanksDev(
513513 username : string ,
514514 opts : BackersQueryOptions = { } ,
515515) : Promise < ThanksDevBackers > {
516+ const sponsorCentsThreshold = opts . sponsorCentsThreshold ?? 100
517+ const donorCentsThreshold = opts . donorCentsThreshold ?? 100
516518 let sponsors : Array < ThanksDevDonor > = [ ] ,
517519 donors : Array < ThanksDevDonor > = [ ]
518520 // monthly
@@ -522,8 +524,7 @@ export async function getBackersFromThanksDev(
522524 const data : ThanksDevResponse = await resp . json ( )
523525 sponsors = data . donors . filter (
524526 ( [ , , cents ] ) =>
525- cents &&
526- ( ! opts . sponsorCentsThreshold || cents >= opts . sponsorCentsThreshold ) ,
527+ cents && ( ! sponsorCentsThreshold || cents >= sponsorCentsThreshold ) ,
527528 )
528529 } catch ( err : any ) {
529530 throw new Errlop (
@@ -538,8 +539,7 @@ export async function getBackersFromThanksDev(
538539 const data : ThanksDevResponse = await resp . json ( )
539540 donors = data . donors . filter (
540541 ( [ , , cents ] ) =>
541- cents &&
542- ( ! opts . donorCentsThreshold || cents >= opts . donorCentsThreshold ) ,
542+ cents && ( ! donorCentsThreshold || cents >= donorCentsThreshold ) ,
543543 )
544544 } catch ( err : any ) {
545545 throw new Errlop (
@@ -618,6 +618,8 @@ export async function getBackersFromOpenCollective(
618618 opts : BackersQueryOptions = { } ,
619619) : Promise < OpenCollectiveBackers > {
620620 try {
621+ const sponsorCentsThreshold = opts . sponsorCentsThreshold ?? 100
622+ const donorCentsThreshold = opts . donorCentsThreshold ?? 100
621623 const url = `https://opencollective.com/${ username } /members.json`
622624 const resp = await fetch ( url , { } )
623625 const profiles : OpenCollectiveResponse = await resp . json ( )
@@ -639,16 +641,16 @@ export async function getBackersFromOpenCollective(
639641 ( member ) =>
640642 member . role === 'BACKER' &&
641643 member . lastTransactionAmount &&
642- ( ! opts . sponsorCentsThreshold ||
643- member . lastTransactionAmount * 100 > opts . sponsorCentsThreshold ) &&
644+ ( ! sponsorCentsThreshold ||
645+ member . lastTransactionAmount * 100 > sponsorCentsThreshold ) &&
644646 isWithinLastMonth ( member . lastTransactionAt , lastMonth ) ,
645647 )
646648 const donors = profiles . filter (
647649 ( member ) =>
648650 member . role === 'BACKER' &&
649651 member . totalAmountDonated &&
650- ( ! opts . donorCentsThreshold ||
651- member . totalAmountDonated * 100 > opts . donorCentsThreshold ) ,
652+ ( ! donorCentsThreshold ||
653+ member . totalAmountDonated * 100 > donorCentsThreshold ) ,
652654 )
653655 return {
654656 sponsors : Fellow . add ( sponsors . map ( getOpenCollectiveProfile ) ) ,
@@ -1991,60 +1993,31 @@ export async function getBackers(
19911993 githubSlug ,
19921994 )
19931995
1994- // add contributors
1995- if ( authed && opts . offline !== true ) {
1996- try {
1997- const fetchedContributors = await getGitHubContributors (
1998- githubSlug ,
1999- opts ,
2000- )
2001- append ( result . contributors , fetchedContributors )
2002- } catch ( err : any ) {
2003- console . warn ( err . stack )
2004- }
2005- }
2006-
2007- // order by least details, to most accurate details, so ThanksDev, OpenCollective, GitHub Sponsors
2008-
2009- // ThanksDev
2010- if ( thanksdevGithubUsername && opts . offline !== true ) {
2011- try {
2012- const fetchedBackers = await getBackersFromThanksDev (
2013- ThanksDevPlatform . GitHub ,
2014- thanksdevGithubUsername ,
2015- opts ,
2016- )
2017- appendBackers ( result , fetchedBackers )
2018- } catch ( err : any ) {
2019- console . warn ( err . stack )
2020- }
2021- } else {
2022- console . warn ( `Unable to determine ThanksDev username for ${ githubSlug } ` )
2023- }
2024-
2025- // OpenCollective
2026- if ( opencollectiveUsername && opts . offline !== true ) {
2027- try {
2028- const fetchedBackers = await getBackersFromOpenCollective (
2029- opencollectiveUsername ,
2030- opts ,
1996+ // if not offline, fetch from remote sources
1997+ if ( opts . offline !== true ) {
1998+ // ThanksDev
1999+ if ( thanksdevGithubUsername ) {
2000+ try {
2001+ const fetchedBackers = await getBackersFromThanksDev (
2002+ ThanksDevPlatform . GitHub ,
2003+ thanksdevGithubUsername ,
2004+ opts ,
2005+ )
2006+ appendBackers ( result , fetchedBackers )
2007+ } catch ( err : any ) {
2008+ console . warn ( err . stack )
2009+ }
2010+ } else {
2011+ console . warn (
2012+ `Unable to fetch backers from ThanksDev, as unable to resolve the ThanksDev username for ${ githubSlug } ` ,
20312013 )
2032- appendBackers ( result , fetchedBackers )
2033- } catch ( err : any ) {
2034- console . warn ( err . stack )
20352014 }
2036- } else {
2037- console . warn (
2038- `Unable to determine OpenCollective username for ${ githubSlug } ` ,
2039- )
2040- }
20412015
2042- // GitHubSponsors
2043- if ( authed && opts . offline !== true ) {
2044- if ( githubSponsorsUsername ) {
2016+ // OpenCollective
2017+ if ( opencollectiveUsername ) {
20452018 try {
2046- const fetchedBackers = await getBackersFromGitHubSponsors (
2047- githubSponsorsUsername ,
2019+ const fetchedBackers = await getBackersFromOpenCollective (
2020+ opencollectiveUsername ,
20482021 opts ,
20492022 )
20502023 appendBackers ( result , fetchedBackers )
@@ -2053,24 +2026,53 @@ export async function getBackers(
20532026 }
20542027 } else {
20552028 console . warn (
2056- `Unable to determine GitHub Sponsors username for ${ githubSlug } ` ,
2029+ `Unable to fetch backers from OpenCollective, as unable to resolve the OpenCollective username for ${ githubSlug } ` ,
20572030 )
20582031 }
2059- }
20602032
2061- // fetch additional details, if able
2062- if ( authed && opts . offline !== true ) {
2063- await Promise . all (
2064- Array . from ( result . donors ) . map ( async ( fellow ) => {
2065- if ( fellow . githubUsername && ! fellow . githubProfile ) {
2066- await getGitHubProfile ( fellow . githubUsername , opts )
2033+ // GitHub
2034+ if ( authed ) {
2035+ // GitHub Contributors
2036+ try {
2037+ const fetchedContributors = await getGitHubContributors (
2038+ githubSlug ,
2039+ opts ,
2040+ )
2041+ append ( result . contributors , fetchedContributors )
2042+ } catch ( err : any ) {
2043+ console . warn ( err . stack )
2044+ }
2045+
2046+ // GitHub Sponsors
2047+ if ( githubSponsorsUsername ) {
2048+ try {
2049+ const fetchedBackers = await getBackersFromGitHubSponsors (
2050+ githubSponsorsUsername ,
2051+ opts ,
2052+ )
2053+ appendBackers ( result , fetchedBackers )
2054+ } catch ( err : any ) {
2055+ console . warn ( err . stack )
20672056 }
2068- } ) ,
2069- )
2070- }
2057+ } else {
2058+ console . warn (
2059+ `Unable to fetch backers from GitHub Sponsors, as unable to resolve the GitHub Sponsors username for ${ githubSlug } ` ,
2060+ )
2061+ }
20712062
2072- // verify their details
2073- if ( opts . offline !== false ) verifyUrlsOfBackers ( result )
2063+ // fetch additional details, if able
2064+ await Promise . all (
2065+ Array . from ( result . donors ) . map ( async ( fellow ) => {
2066+ if ( fellow . githubUsername && ! fellow . githubProfile ) {
2067+ await getGitHubProfile ( fellow . githubUsername , opts )
2068+ }
2069+ } ) ,
2070+ )
2071+ }
2072+
2073+ // verify their details
2074+ verifyUrlsOfBackers ( result )
2075+ }
20742076
20752077 // attach to slug, which enables us to remove duplicates by fetching by slug
20762078 // (duplicates can occur if new details allowed us to merge two old entries)
0 commit comments