Skip to content

Commit 44fa24b

Browse files
v2.15.11 (#238)
* Examples improved. addWorklog, getAllWorklogs examples added * 2.15.11
1 parent e0dd32e commit 44fa24b

20 files changed

+546
-356
lines changed

.github/FUNDING.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.

CHANGELOG.md

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

3+
### 2.15.11
4+
5+
- All properties in `PageOfWorklogs` marked as required.
6+
- Examples improved.
7+
38
### 2.15.10
49

510
- `newErrorHandling` console message removed.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ const client = new Version3Client({
213213

214214
1. Example
215215

216-
You can find out [example project here](https://github.com/MrRefactoring/jira.js/tree/master/example) or perform the following actions:
216+
You can find out [examples project here](https://github.com/MrRefactoring/jira.js/tree/master/examples) or perform the following actions:
217217

218218
- Change the `host`, `email` and `apiToken` to your data
219219
- Run script

example/README.md

Lines changed: 0 additions & 23 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.

examples/README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Jira.js usage examples
2+
3+
## Table of contents
4+
5+
1. [Initial steps](#initial-steps)
6+
2. Examples
7+
1. [Basic example](#basic-example)
8+
2. [Add worklog example](#add-worklog-example)
9+
3. [Get all worklogs example](#get-all-worklogs-example)
10+
11+
## Initial steps
12+
13+
1. Install dependencies
14+
15+
```shell
16+
npm i
17+
```
18+
19+
2. Specify `host`, `email` and `apiToken` variables in `src/credentials.ts` file
20+
21+
```ts
22+
const host = 'https://your-domain.atlassian.net';
23+
const email = 'YOUR_EMAIL';
24+
const apiToken = 'YOUR_API_TOKEN';
25+
```
26+
27+
## Examples
28+
29+
### Basic example
30+
31+
> ⚠️ Attention, the following behavior is performed:
32+
> 1. If you don't have any projects yet, then a new project is created with the `PROJECT` key, called `My Project`
33+
> 2. If you already have a project, it will create a new `task` named `My first issue` in the first project that comes along
34+
35+
To run the basic example, just run the `basic` script:
36+
37+
```shell
38+
npm run basic
39+
```
40+
41+
---
42+
43+
### Add worklog example
44+
45+
> ⚠️ Attention, the following behavior is performed:
46+
>
47+
> In the first project that comes along, a new task is created, and one new Workflow is added to it
48+
49+
> If you haven't created a project yet, follow the [basic example](#basic-example)
50+
51+
To add a `worklog` run the `addWorklog` script:
52+
53+
```shell
54+
npm run addWorklog
55+
```
56+
57+
---
58+
59+
### Get all worklogs example
60+
61+
> ⚠️ Attention, the following behavior is performed:
62+
>
63+
> The same as in [Add worklog example](#add-worklog-example), and will also get all the worklogs that have been added
64+
65+
> If you haven't created a project yet, follow the [basic example](#basic-example)
66+
67+
To get all worklogs run the `getAllWorklogs` script:
68+
69+
```shell
70+
npm run getAllWorklogs
71+
```

example/package-lock.json renamed to examples/package-lock.json

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

example/package.json renamed to examples/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
{
2-
"name": "example",
2+
"name": "jira.js-examples",
33
"private": true,
44
"version": "1.0.0",
55
"description": "",
66
"author": "Vladislav Tupikin <[email protected]>",
77
"scripts": {
8-
"start": "ts-node src/index.ts"
8+
"basic": "ts-node src/basic.ts",
9+
"addWorklog": "ts-node src/addWorklog.ts",
10+
"getAllWorklogs": "ts-node src/getAllWorklogs.ts"
911
},
1012
"license": "MIT",
1113
"devDependencies": {
12-
"@types/node": "^18.7.18",
14+
"@types/node": "^18.7.22",
1315
"ts-node": "^10.9.1",
1416
"typescript": "^4.8.3"
1517
},

examples/src/addWorklog.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { createIssue } from "./utils";
2+
import { Version3Client } from "jira.js";
3+
import { apiToken, email, host } from "./credentials";
4+
5+
async function addWorklog() {
6+
const client = new Version3Client({
7+
host,
8+
authentication: {
9+
basic: { email, apiToken },
10+
},
11+
newErrorHandling: true,
12+
});
13+
14+
// Used to reduce the amount of code that is not directly related to creating a worklog
15+
const { id: issueIdOrKey } = await createIssue(client);
16+
17+
// The main part responsible for creating the worklog
18+
const worklog = await client.issueWorklogs.addWorklog({
19+
issueIdOrKey, // Required
20+
comment: 'My first worklog', // Not requited
21+
timeSpentSeconds: 60, // Required one of `timeSpentSeconds` or `timeSpent`
22+
});
23+
24+
console.log(`Worklog successfully added for Issue Id: ${worklog.issueId}`)
25+
}
26+
27+
addWorklog().catch(e => {
28+
console.error(e);
29+
30+
throw new Error(e.errorMessages.join(' '));
31+
});

0 commit comments

Comments
 (0)