1.6.0 • Published 2 years ago
youtrack-rest-client v1.6.0
youtrack-rest-client
Client library for the youtrack rest api
Install
npm install youtrack-rest-client
yarn add youtrack-rest-client
Usage
Authentication
With your permanent token (see Manage-Permanent-Token):
import {Youtrack} from "youtrack-rest-client";
const config = {
baseUrl: "http://example.myjetbrains.com",
token: "perm:your-token"
};
const youtrack = new Youtrack(config);
With username/password
The current REST API does not support logging in with username/password anymore, if you require this you need to use the legacy REST API (youtrack-rest-client version 0.3.x).
Users
// get the current user
youtrack.users.current().then((user: User) => {
console.log({user});
});
// get all users
youtrack.users.all().then((users: ReducedUser[]) => {
console.log({users});
});
// get a user by id
youtrack.users.byId('1-1').then((user: User) => {
console.log({user});
});
Projects
// get all projects
youtrack.projects.all().then((projects: ReducedProject[]) => {
console.dir(projects);
});
// get a project by its id
youtrack.projects.byId('0-0').then((project: Project) => {
console.dir(project);
});
Issues
// search/list issues
youtrack.issues.search('project: T1').then((issues: ReducedIssue[]) => {
console.log({issues});
});
// get issue by id
youtrack.issues.byId('T1-2').then((issue: Issue) => {
console.log({issue});
});
// delete an issue
youtrack.issues.delete('2-2').then(() => {
console.log('issue deleted');
});
// create a new issue
youtrack.issues.create({
summary: 'lorem ipsum',
description: 'created using rest api',
project: {
id: '0-0'
}
}).then(issue => {
console.log({issue});
});
// update an issue
youtrack.issues.update({
id: 'T1-2',
summary: "updated summary"
}).then(issue => {
console.log({issue});
});
Commands
// execute command for issue(s) (internal id is used)
youtrack.issues.executeCommand({
query: 'for me',
issues: [
{
id: '2-6'
}
]
}).then(response => {
console.log({response});
});
// execute command for issue(s) and add a comment
youtrack.issues.executeCommand({
query: 'for me',
comment: 'gonna solve this real quick',
issues: [
{
id: '2-6'
}
]
}).then(response => {
console.log({response});
});
WorkItems (Time-Tracking)
// get the configured workitem types for the project
youtrack.projects.getWorkItemTypes('0-0').then((workItemTypes: WorkItemType[]) => {
console.log({workItemTypes});
});
// list the workitems of a project
youtrack.workItems.all('T1-2').then((workItems: WorkItem[]) => {
console.log({workItems});
});
// add new workitem to project
youtrack.workItems.create('T1-2', {
duration: {
presentation: '30m'
},
text: 'fixed bug',
type: {
name: 'Development',
id: '77-0'
}
}).then(workItem => {
console.log({workItem});
});
// update workitem
youtrack.workItems.update('T1-2', {
id: '116-3',
duration: {
presentation: '45m'
}
}).then(workItem => {
console.log({workItem});
});
// delete work item
youtrack.workItems.delete('T1-2', '116-3').then(() => {
console.log('workitem deleted.');
});
Issue Comments
// list comments of an issue
youtrack.comments.all('T1-2').then((comments: IssueComment[]) => {
console.log({comments});
});
// add comment to issue
youtrack.comments.create('T1-2', {
text: 'issue comment'
}).then(comment => {
console.log({comment});
});
// update comment
youtrack.comments.update('T1-2', {
id: '4-1',
text: 'updated issue comment'
}).then(comment => {
console.log({comment});
});
// delete a comment
youtrack.comments.delete('T1-2', '4-1').then(() => {
console.log('comment deleted.');
});
Issue Tags
// get all tags
youtrack.tags.all().then((tags: IssueTag[]) => {
console.log({tags});
});
// get tag by id
youtrack.tags.byId('6-0').then((tag: IssueTag) => {
console.log({tag});
});
Issue Links
// get issue links of issue
youtrack.issues.byId('P1-1').then((issue: Issue) => {
console.log({links: issue.links});
});
// update issue link(s)
youtrack.issues.update({
id: 'P1-1',
links: [
{
issues: [
{
id: '2-3'
}
],
id: '92-1s',
}
]
}).then((issue: Issue) => {
console.log({links: issue.links});
});
Agiles
// get all agile boards
youtrack.agiles.all().then((agiles: ReducedAgile[]) => {
console.log({agiles});
});
// get specific agile board by id
youtrack.agiles.byId('104-0').then((agile: Agile) => {
console.log({agile});
});
// create new agile board
youtrack.agiles.create({
name: '19-15',
projects: [{ id: '0-0' }]
}).then((agile: Agile) => {
console.log({agile});
});
// delete an agile board
youtrack.agiles.delete('104-1').then(() => {
console.log('agile deleted.');
});
// update an agile board
youtrack.agiles.update({ id: '104-0', projects: [{ id: '0-0' }] }).then((agile: Agile) => {
console.log({agile});
});
Sprints
const agileId = '104-0';
// get all sprints of an agile board
youtrack.sprints.all(agileId).then((sprints: ReducedSprint[]) => {
console.log({sprints});
});
// get agile sprint by id
youtrack.sprints.byId(agileId, '105-0').then((sprint: Sprint) => {
console.log({sprint});
});
// create new sprint
youtrack.sprints.create(agileId, { name: 'my sprint' }).then((sprint: Sprint) => {
console.log({sprint});
});
// update a sprint
youtrack.sprints.update(agileId, { id: '105-3', name: 'my sprint 3' }).then((sprint: Sprint) => {
console.log({sprint});
});
// delete a sprint
youtrack.sprints.delete(agileId, '105-2').then(() => {
console.log('sprint deleted.');
});
Contributing
If you encounter any missing features or bugs, you're welcome to open an Issue! PRs are welcome too ;-)
- Fork it ( https://github.com/shanehofstetter/youtrack-rest-client/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
1.6.0
2 years ago
1.5.0
2 years ago
1.4.0
4 years ago
1.3.2
5 years ago
1.3.1
5 years ago
1.3.0
5 years ago
1.2.1
6 years ago
1.2.0
6 years ago
1.1.0
6 years ago
1.0.0
6 years ago
0.3.2
6 years ago
0.3.1
6 years ago
0.3.0
6 years ago
0.2.4
6 years ago
0.2.3
6 years ago
0.2.2
6 years ago
0.2.1
6 years ago
0.2.0
6 years ago
0.1.2
6 years ago
0.1.1
6 years ago
0.1.0
6 years ago