Skip to content

Commit 29cc992

Browse files
committed
v11.3.1 - fixed provided packageData being discarded for remote data
1 parent d86c82d commit 29cc992

File tree

6 files changed

+54
-26
lines changed

6 files changed

+54
-26
lines changed

HISTORY.md

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

3+
## v11.3.1 2023 December 28
4+
5+
- Fixed a regression in v11.2.0 where `packageData` would always be fetched remotely, now if it is probided, it is respected once again
6+
- 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)
7+
38
## v11.3.0 2023 December 28
49

510
- Default cents thresholds to `100` in the API, rather than just the CLI

README.md

Lines changed: 4 additions & 4 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.3.0/edition-deno/index.ts'
59+
import pkg from 'https://unpkg.com/@bevry/github-api@^11.3.1/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.3.0'
65+
import pkg from '//cdn.skypack.dev/@bevry/github-api@^11.3.1'
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.3.0'
72+
import pkg from '//unpkg.com/@bevry/github-api@^11.3.1'
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/[email protected].0'
79+
import pkg from '//dev.jspm.io/@bevry/[email protected].1'
8080
</script>
8181
```
8282
### [Editions](https://editions.bevry.me "Editions are the best way to produce and consume packages you care about.")

package-lock.json

Lines changed: 5 additions & 5 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,13 +1,13 @@
11
{
22
"name": "@bevry/github-api",
3-
"version": "11.3.0",
3+
"version": "11.3.1",
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",
77
"funding": "https://bevry.me/fund",
88
"repository": {
99
"type": "git",
10-
"url": "https://github.com/bevry/github-api.git"
10+
"url": "git+https://github.com/bevry/github-api.git"
1111
},
1212
"bugs": {
1313
"url": "https://github.com/bevry/github-api/issues"

source/bin.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import writeFile from '@bevry/fs-write'
99

1010
// local
1111
import {
12+
shouldAutomate,
1213
Backers,
1314
getBackers,
1415
renderBackers,
@@ -88,17 +89,14 @@ const queryOptions: CliBackersQueryOptions = {
8889
sponsorCentsThreshold: null,
8990
donorCentsThreshold: null,
9091
}
91-
function auto(value: any) {
92-
return value == null || value === true
93-
}
9492
async function action() {
9593
// query
96-
if (auto(queryOptions.githubSlug)) {
94+
if (shouldAutomate(queryOptions.githubSlug)) {
9795
queryOptions.githubSlug =
9896
getGitHubSlugFromUrl(execSync('git remote get-url origin').toString()) ||
9997
null
10098
}
101-
if (auto(queryOptions.packagePath)) {
99+
if (shouldAutomate(queryOptions.packagePath)) {
102100
if (await isReadable('package.json')) {
103101
queryOptions.packagePath = 'package.json'
104102
queryOptions.packageData = (await readJSON(
@@ -113,7 +111,7 @@ async function action() {
113111
}
114112
}
115113
if (
116-
auto(queryOptions.githubSlug) &&
114+
shouldAutomate(queryOptions.githubSlug) &&
117115
queryOptions.packageData &&
118116
typeof queryOptions.packageData === 'object'
119117
) {
@@ -124,7 +122,7 @@ async function action() {
124122
// fetch
125123
if (!result) result = await getBackers(queryOptions)
126124
// write
127-
if (auto(renderOptions.writePath)) {
125+
if (shouldAutomate(renderOptions.writePath)) {
128126
renderOptions.writePath = queryOptions.packagePath || 'package.json'
129127
}
130128
if (
@@ -133,7 +131,7 @@ async function action() {
133131
) {
134132
renderOptions.packageData = queryOptions.packageData
135133
}
136-
if (auto(renderOptions.format)) {
134+
if (shouldAutomate(renderOptions.format)) {
137135
if (typeof renderOptions.writePath === 'string') {
138136
if (renderOptions.writePath.endsWith('package.json'))
139137
renderOptions.format = BackersRenderFormat.package
@@ -151,7 +149,7 @@ async function action() {
151149
else if (renderOptions.writePath.endsWith('.html'))
152150
renderOptions.format = BackersRenderFormat.html
153151
}
154-
if (auto(renderOptions.format))
152+
if (shouldAutomate(renderOptions.format))
155153
renderOptions.format = BackersRenderFormat.string // @todo add a raw mode
156154
}
157155
// output

source/index.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ export { Fellow, PromisePool, Errlop }
1515
import { env } from 'node:process'
1616
const envCredentials = env as GitHubCredentials
1717

18+
export function shouldAutomate(value: any): boolean {
19+
return value == null || value === true
20+
}
21+
22+
export function getFallback(value: any, fallback: any) {
23+
return shouldAutomate(value) ? fallback : value
24+
}
25+
1826
// ====================================
1927
// Our Types
2028

@@ -513,8 +521,13 @@ export async function getBackersFromThanksDev(
513521
username: string,
514522
opts: BackersQueryOptions = {},
515523
): Promise<ThanksDevBackers> {
516-
const sponsorCentsThreshold = opts.sponsorCentsThreshold ?? 100
517-
const donorCentsThreshold = opts.donorCentsThreshold ?? 100
524+
// defaults
525+
const sponsorCentsThreshold: number = getFallback(
526+
opts.sponsorCentsThreshold,
527+
100,
528+
)
529+
const donorCentsThreshold: number = getFallback(opts.donorCentsThreshold, 100)
530+
// prepare
518531
let sponsors: Array<ThanksDevDonor> = [],
519532
donors: Array<ThanksDevDonor> = []
520533
// monthly
@@ -618,8 +631,16 @@ export async function getBackersFromOpenCollective(
618631
opts: BackersQueryOptions = {},
619632
): Promise<OpenCollectiveBackers> {
620633
try {
621-
const sponsorCentsThreshold = opts.sponsorCentsThreshold ?? 100
622-
const donorCentsThreshold = opts.donorCentsThreshold ?? 100
634+
// defaults
635+
const sponsorCentsThreshold: number = getFallback(
636+
opts.sponsorCentsThreshold,
637+
100,
638+
)
639+
const donorCentsThreshold: number = getFallback(
640+
opts.donorCentsThreshold,
641+
100,
642+
)
643+
// fetch
623644
const url = `https://opencollective.com/${username}/members.json`
624645
const resp = await fetch(url, {})
625646
const profiles: OpenCollectiveResponse = await resp.json()
@@ -1899,11 +1920,15 @@ export async function getBackers(
18991920
{}
19001921
try {
19011922
// if auto-detect package data, fetch from slug if not offline
1902-
if (githubSlug && opts.packageData !== false && opts.offline !== true) {
1923+
if (
1924+
githubSlug &&
1925+
shouldAutomate(opts.packageData) &&
1926+
opts.offline !== true
1927+
) {
19031928
packageData = await getPackageData(githubSlug, {})
19041929
}
19051930
// if auto-detect slug, fetch from package data
1906-
if (opts.githubSlug !== false && packageData) {
1931+
if (shouldAutomate(opts.githubSlug) && packageData) {
19071932
githubSlug = getGitHubSlugFromPackageData(packageData) || ''
19081933
}
19091934

0 commit comments

Comments
 (0)