Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
schpet committed Apr 2, 2024
1 parent ff05ec2 commit c3aefd0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ node_modules
oclif.lock
oclif.manifest.json
.env
testing.db
3 changes: 1 addition & 2 deletions src/commands/dump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export default class Dump extends Command {
migrate(db, {migrationsFolder: 'drizzle'}) // can this be done without migration files? need to make sure this works when run from a different directory

const api = trackerApi(config)

// steps:
// - projects
// - epics
Expand All @@ -77,8 +76,8 @@ export default class Dump extends Command {
`https://www.pivotaltracker.com/services/v5/projects/${projectId}/stories`,
async (page) => {
db.insert(tracker.storyTable).values(page)
console.log(`adding ${page.length} stories`)

console.log('xyx', page)
for (const story of page) {
api.page<Array<tracker.Comment>>(
`https://www.pivotaltracker.com/services/v5/projects/${projectId}/stories/${story.id}/comments`,
Expand Down
26 changes: 20 additions & 6 deletions src/tracker.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
import {pRateLimit} from 'p-ratelimit'

// chatgpt tells me the rate limit is '200 per minute per user'
// 3 per second comes out at 180 per minute
const limit = pRateLimit({
interval: 1000,
rate: 3,
concurrency: 5,
})

export function trackerApi(config: {apiKey: string}) {
async function request<TData>(url: string): Promise<TData> {
const response = await fetch(url, {
headers: {
'X-TrackerToken': config.apiKey,
accept: 'application/json',
},
})
const response = await limit(() =>
fetch(url, {
headers: {
'X-TrackerToken': config.apiKey,
accept: 'application/json',
},
}),
)

if (!response.ok) {
try {
console.error(await response.text())
console.error("headers:")
console.error(Object.fromEntries(response.headers.entries()))
} catch (er) {}
throw new Error(`request failed with status ${response.status}`)
}
Expand Down

0 comments on commit c3aefd0

Please sign in to comment.