-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathgetAllWorklogs.ts
43 lines (33 loc) · 1.16 KB
/
getAllWorklogs.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { Version3Client } from 'jira.js';
import { addWorklog, createIssue } from './utils';
import { apiToken, email, host } from './credentials';
async function getAllWorklogs() {
const client = new Version3Client({
host,
authentication: {
basic: { email, apiToken },
},
});
// Used to reduce the amount of code that is not directly related to getting a worklogs
const issue = await createIssue(client);
// Let's add some worklogs
await addWorklog(client, issue);
await addWorklog(client, issue);
await addWorklog(client, issue);
// The main part responsible for getting the worklogs
const worklogs = [];
let offset = 0;
let total = 0;
do {
// eslint-disable-next-line no-await-in-loop
const worklogsPaginated = await client.issueWorklogs.getIssueWorklog({ issueIdOrKey: issue.key, startAt: offset });
offset += worklogsPaginated.worklogs.length;
total = worklogsPaginated.total;
worklogs.push(...worklogsPaginated.worklogs);
} while (offset < total);
console.log(`Received ${worklogs.length} worklogs.`);
}
getAllWorklogs().catch(e => {
console.error(e);
throw new Error(e.errorMessages.join(' '));
});