Skip to content

Commit d86c82d

Browse files
committed
v11.3.0 - default cents thresholds, don't complain about invalid usernames in offline mode
1 parent 2b14107 commit d86c82d

File tree

7 files changed

+105
-94
lines changed

7 files changed

+105
-94
lines changed

.github/workflows/bevry.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
- run: npm run our:compile
6868
- run: npm run our:meta
6969
- name: publish to npm
70-
uses: bevry-actions/[email protected].4
70+
uses: bevry-actions/[email protected].5
7171
with:
7272
npmAuthToken: ${{ secrets.NPM_AUTH_TOKEN }}
7373
npmBranchTag: ':next'

HISTORY.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# History
22

3+
## v11.3.0 2023 December 28
4+
5+
- Default cents thresholds to `100` in the API, rather than just the CLI
6+
- Don't complain about invalid usernames in offline mode, as usernames aren't used in offline mode
7+
- Thank you to the sponsors: [Andrew Nesbitt](https://nesbitt.io), [Balsa](https://balsa.com), [Codecov](https://codecov.io/), [Poonacha Medappa](https://poonachamedappa.com), [Rob Morris](https://github.com/Rob-Morris), [Sentry](https://sentry.io), [Syntax](https://syntax.fm)
8+
39
## v11.2.0 2023 December 28
410

511
- If able to fetch the current sponsors, drop the old sponsors to donors

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,27 +56,27 @@ Interact with the GitHub API, fetching commits, repositories, members, and backe
5656
### [Deno](https://deno.land "Deno is a secure runtime for JavaScript and TypeScript, it is an alternative for Node.js")
5757

5858
``` typescript
59-
import pkg from 'https://unpkg.com/@bevry/github-api@^11.2.0/edition-deno/index.ts'
59+
import pkg from 'https://unpkg.com/@bevry/github-api@^11.3.0/edition-deno/index.ts'
6060
```
6161
### [Skypack](https://www.skypack.dev "Skypack is a JavaScript Delivery Network for modern web apps")
6262

6363
``` html
6464
<script type="module">
65-
import pkg from '//cdn.skypack.dev/@bevry/github-api@^11.2.0'
65+
import pkg from '//cdn.skypack.dev/@bevry/github-api@^11.3.0'
6666
</script>
6767
```
6868
### [unpkg](https://unpkg.com "unpkg is a fast, global content delivery network for everything on npm")
6969

7070
``` html
7171
<script type="module">
72-
import pkg from '//unpkg.com/@bevry/github-api@^11.2.0'
72+
import pkg from '//unpkg.com/@bevry/github-api@^11.3.0'
7373
</script>
7474
```
7575
### [jspm](https://jspm.io "Native ES Modules CDN")
7676

7777
``` html
7878
<script type="module">
79-
import pkg from '//dev.jspm.io/@bevry/github-api@11.2.0'
79+
import pkg from '//dev.jspm.io/@bevry/github-api@11.3.0'
8080
</script>
8181
```
8282
### [Editions](https://editions.bevry.me "Editions are the best way to produce and consume packages you care about.")
@@ -114,7 +114,7 @@ This package is published with the following editions:
114114

115115
#### Maintainers
116116

117-
- [Benjamin Lupton](https://github.com/balupton) — Accelerating collaborative wisdom.
117+
- [Benjamin Lupton](https://balupton.com) — Accelerating collaborative wisdom.
118118

119119
#### Contributors
120120

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@bevry/github-api",
3-
"version": "11.2.0",
3+
"version": "11.3.0",
44
"license": "Artistic-2.0",
55
"description": "Interact with the GitHub API, fetching commits, repositories, members, and backers (authors, maintainers, contributors, funders, sponsors, donors)",
66
"homepage": "https://github.com/bevry/github-api",
@@ -300,7 +300,7 @@
300300
"our:meta": "npm run our:meta:docs && npm run our:meta:projectz",
301301
"our:meta:docs": "npm run our:meta:docs:typedoc",
302302
"our:meta:docs:typedoc": "rm -rf ./docs && typedoc --exclude '**/+(*test*|node_modules)' --excludeExternals --out ./docs ./source",
303-
"our:meta:projectz": "projectz",
303+
"our:meta:projectz": "projectz --offline",
304304
"our:release": "npm run our:release:prepare && npm run our:release:check-changelog && npm run our:release:check-dirty && npm run our:release:tag && npm run our:release:push",
305305
"our:release:check-changelog": "cat ./HISTORY.md | grep \"v$npm_package_version\" || (printf '%s\n' \"add a changelog entry for v$npm_package_version\" && exit -1)",
306306
"our:release:check-dirty": "git diff --exit-code",

source/bin.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ const queryOptions: CliBackersQueryOptions = {
8585
githubSponsorsUsername: null,
8686
opencollectiveUsername: null,
8787
thanksdevGithubUsername: null,
88-
sponsorCentsThreshold: 100,
89-
donorCentsThreshold: 100,
88+
sponsorCentsThreshold: null,
89+
donorCentsThreshold: null,
9090
}
9191
function auto(value: any) {
9292
return value == null || value === true
@@ -212,12 +212,15 @@ async function parse(args: string[]) {
212212
case 'githubSponsorsUsername':
213213
case 'opencollectiveUsername':
214214
case 'thanksdevGithubUsername': {
215-
queryOptions[a.key] = a.string({ enabled: true })
215+
queryOptions[a.key] = a.string({ enabled: true, disabled: false })
216216
break
217217
}
218218
case 'sponsorCentsThreshold':
219219
case 'donorCentsThreshold': {
220-
queryOptions[a.key] = a.number()
220+
queryOptions[a.key] = a.number({
221+
enabled: null,
222+
disabled: 0,
223+
})
221224
break
222225
}
223226
case 'write': {

source/index.ts

Lines changed: 75 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)