Skip to content

Commit

Permalink
50: Add labels (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
JensAstrup authored Mar 30, 2024
1 parent 7d3fe0c commit 275bef5
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 17 deletions.
46 changes: 34 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,33 +51,55 @@ Full documentation for the Shortcut API can be found [here](https://shortcut.com

### Searching Stories

```javascript
const client = new Client()
const stories = await client.stories.search('team:engineering is:started')
```typescript
const client: Client = new Client()
const stories: Story[] = await client.stories.search('team:engineering is:started')
console.log(stories)
```

### Commenting on a Story

_Also available on epics_

```typescript
const client: Client = new Client()
const story: Story = await client.stories.get('story-id')
const comment = await story.comment('This is a comment')
````

### Listing Iterations

```javascript
const iterations = await client.iterations.list();
```typescript
const client: Client = new Client();
const iterations: Iteration[] = await client.iterations.list();
console.log(iterations);
```

### Creating an Iteration

```javascript
const iteration = await client.iterations.create({
name: 'Sprint 1',
start_date: '2022-01-01',
end_date: '2022-01-14',
```typescript
const client: Client = new Client();
const iteration: Iteration = await client.iterations.create({
name: 'Sprint 1',
start_date: '2022-01-01',
end_date: '2022-01-14',
});
````
### Delete a label
```typescript
const client: Client = new Client();
const label: Label = await client.labels.get('label-id');
await label.delete();
````

### Get a Team

```javascript
const team = await client.teams.get('team-id');
```typescript
const client: Client = new Client();
const team: Team = await client.teams.get('team-id');
console.log(team);
````
Expand Down
1 change: 0 additions & 1 deletion src/base-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export default class BaseService<T extends ShortcutResource> {
const instancesData: Record<string, unknown>[] = response.data ?? []
return instancesData.map((instance) => this.factory(convertApiFields(instance)))
}

}

export class BaseSearchableService<T extends ShortcutResource> extends BaseService<T> {
Expand Down
9 changes: 7 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,36 @@ import Team from '@sx/teams/team'
import Workflow from '@sx/workflows/workflow'
import Epic from '@sx/epics/epic'
import Objective from '@sx/objectives/objective'
import Label from '@sx/labels/label'

// Services
import BaseService from '@sx/base-service'
import StoriesService from '@sx/stories/stories-service'
import IterationsService from '@sx/iterations/iterations-service'
import TeamsService from '@sx/teams/teams-service'
import MembersService from '@sx/members/members-service'
import WorkflowsService from '@sx/workflows/workflows-service'
import EpicsService from '@sx/epics/epics-service'
import ObjectivesService from '@sx/objectives/objectives-service'
import LabelsService from '@sx/labels/labels-service'

// Interfaces
import ThreadedCommentInterface from '@sx/threaded-comments/contracts/threaded-comment-interface'
import ThreadedCommentCreateData from '@sx/threaded-comments/contracts/threaded-comment-create-data'
import {StoryComment} from '@sx/stories/comment/story-comment'

export default Client
export {Client, Iteration, Member, Story, Team, Workflow, Epic, Objective}
export {Client, Iteration, Member, Story, Team, Workflow, Epic, Objective, Label}
export {
BaseService,
StoriesService,
IterationsService,
TeamsService,
MembersService,
WorkflowsService,
EpicsService,
ObjectivesService
ObjectivesService,
LabelsService
}
export {ThreadedCommentInterface, ThreadedCommentCreateData, StoryComment}
export {ShortcutResource}
15 changes: 15 additions & 0 deletions src/labels/contracts/label-api-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import BaseData from '@sx/base-data'

export default interface LabelApiData extends BaseData {
app_url: string
archived: boolean
color: string | null
created_at: string | null
description: string | null
entity_type: string
external_id: string | null
id: number
name: string
stats: object[]
updated_at: string | null
}
8 changes: 8 additions & 0 deletions src/labels/contracts/label-create-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import BaseCreateData from '@sx/base-create-data'

export default interface LabelCreateData extends BaseCreateData {
color: string | null
description: string | null
externalId: string | null
name: string
}
15 changes: 15 additions & 0 deletions src/labels/contracts/label-interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import BaseInterface from '@sx/base-interface'

export default interface LabelInterface extends BaseInterface {
appUrl: string
archived: boolean
color: string | null
createdAt: string | null
description: string | null
entityType: string
externalId: string | null
id: number
name: string
stats: object[]
updatedAt: string | null
}
26 changes: 26 additions & 0 deletions src/labels/label.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import ShortcutResource from '@sx/base-resource'
import LabelInterface from '@sx/labels/contracts/label-interface'


export default class Label extends ShortcutResource {
public static baseUrl: string = 'https://api.shortcut.com/api/v3/labels'
public createFields = ['color', 'description', 'externalId', 'name']

constructor(init: LabelInterface | object) {
super()
Object.assign(this, init)
this.changedFields = []
}

appUrl!: string
archived!: boolean
color!: string | null
createdAt!: string | null
description!: string | null
entityType!: string
externalId!: string | null
id!: number
name!: string
stats!: object[]
updatedAt!: string | null
}
8 changes: 8 additions & 0 deletions src/labels/labels-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import BaseService from '@sx/base-service'
import Label from '@sx/labels/label'


export default class LabelsService extends BaseService<Label> {
public static baseUrl: string = 'https://api.shortcut.com/api/v3/labels'
protected factory = (data: object) => new Label(data)
}
4 changes: 2 additions & 2 deletions src/stories/story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import WorkflowService from '@sx/workflows/workflows-service'
import {
Branch,
Commit,
LabelSlim,
LinkedFile,
StoryCustomField,
StoryStats,
Expand All @@ -27,6 +26,7 @@ import TeamsService from '@sx/teams/teams-service'
import Member from '@sx/members/member'
import MembersService from '@sx/members/members-service'
import StoryInterface from '@sx/stories/contracts/story-interface'
import Label from '@sx/labels/label'


/**
Expand Down Expand Up @@ -165,7 +165,7 @@ export default class Story extends ShortcutResource {
id!: number
iterationId!: number | null
labelIds!: number[]
labels!: LabelSlim[]
labels!: Label[]

/* The lead time in seconds of this story */
leadTime!: number
Expand Down

0 comments on commit 275bef5

Please sign in to comment.