Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions scripts/__fixtures__/types-bundle-exports.snapshot.txt
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ root UpdateWorkItemPropertyContext UpdateWorkItemPropertyContext b19d5a82a8ce76e
root UpdateWorkItemPropertyOption UpdateWorkItemPropertyOption$1 6d23dbf98435bcec
root UpdateWorkItemPropertyValue UpdateWorkItemPropertyValue 23b58c453ef01ec9
root UpdateWorkItemRelationDefinition UpdateWorkItemRelationDefinition$1 dad02a1ef882b7c4
root UpdateWorkItemSubscribers UpdateWorkItemSubscribers f72fe68c309b90d2
root UpdateWorkItemTemplate UpdateWorkItemTemplate$1 856cdfea975105b7
root UpdateWorkItemType UpdateWorkItemType$1 7db0326070f3a59e
root UpdateWorkItemWorklog UpdateWorkItemWorklog a5682731a39d9298
Expand Down Expand Up @@ -937,7 +938,7 @@ root WorkItemLink WorkItemLink 19a1c8cc227f3eaf
root WorkItemLinkField WorkItemLinkField 1f060447b94fe3cc
root WorkItemLinkFieldsParams WorkItemLinkFieldsParams 7e5edc5f75f3fc58
root WorkItemLinkOrderBy WorkItemLinkOrderBy c76aba0c76a92eb5
root WorkItemNavigation WorkItemNavigation 261d5447a5473a70
root WorkItemNavigation WorkItemNavigation 60976416b59244f7
root WorkItemOrderBy WorkItemOrderBy 2e5db248118b1c9a
root WorkItemPage WorkItemPage 70e819a503f44a9c
root WorkItemPageLite WorkItemPageLite 622ee1ba3ab9149e
Expand Down Expand Up @@ -981,6 +982,7 @@ root WorkItems WorkItems$1 69ead42d2e6929e5
root WorkItemSearch WorkItemSearch 974da631fd7583d2
root WorkItemSearchItem WorkItemSearchItem a666d687bce31d3d
root WorkItemShapeParams WorkItemShapeParams a18e52e3529faf8d
root WorkItemSubscribers WorkItemSubscribers 493e5f02076c4114
root WorkItemTemplate WorkItemTemplate$1 2245da839e698489
root WorkItemTemplateData WorkItemTemplateData fb644987980a439b
root WorkItemTemplateField WorkItemTemplateField b0fcbb132ca82025
Expand Down Expand Up @@ -1484,7 +1486,7 @@ v2 WorkItemIds WorkItemIds 17b1a84f473ed6c6
v2 WorkItemLinkField WorkItemLinkField 1f060447b94fe3cc
v2 WorkItemLinkOrderBy WorkItemLinkOrderBy c76aba0c76a92eb5
v2 WorkItemLinks Links e64a91fed57267eb
v2 WorkItemNavigation WorkItemNavigation 261d5447a5473a70
v2 WorkItemNavigation WorkItemNavigation 60976416b59244f7
v2 WorkItemOrderBy WorkItemOrderBy 2e5db248118b1c9a
v2 WorkItemProperties WorkItemProperties 84d5b6c057fb50e2
v2 WorkItemPropertyContextOrderBy WorkItemPropertyContextOrderBy 576846614cee13f5
Expand All @@ -1501,7 +1503,8 @@ v2 WorkItemRelationDefinitionField WorkItemRelationDefinitionField 1739d027f8b00
v2 WorkItemRelationDefinitionFieldsParams WorkItemRelationDefinitionFieldsParams 467fbf17dad2cc92
v2 WorkItemRelationDefinitions WorkItemRelationDefinitions a9eb573da708f378
v2 WorkItemRelations Relations f2555a064c57ffdd
v2 WorkItems WorkItems 397d2b053d80d030
v2 WorkItems WorkItems 4a0d6f7e983c5212
v2 WorkItemSubscribersResource Subscribers 0003bd40110bdee1
v2 WorkItemTemplateField WorkItemTemplateField b0fcbb132ca82025
v2 WorkItemTemplateOrderBy WorkItemTemplateOrderBy 391d22d3b2f31757
v2 WorkItemTemplates WorkItemTemplates 4e0936894bdb2873
Expand Down Expand Up @@ -1567,7 +1570,7 @@ v2 WorkspaceWorkItemPropertyOptionOrderBy WorkspaceWorkItemPropertyOptionOrderBy
v2 WorkspaceWorkItemPropertyOptions WorkspaceWorkItemPropertyOptions 5b5eb658230e9226
v2 WorkspaceWorkItemPropertyOrderBy WorkspaceWorkItemPropertyOrderBy dcb582a7109e424a
v2 WorkspaceWorkItemPropertyShapeParams WorkspaceWorkItemPropertyShapeParams a5d16f942a12070f
v2 WorkspaceWorkItems WorkspaceWorkItems 48f33b3a3b2545b1
v2 WorkspaceWorkItems WorkspaceWorkItems 42abb594e8506152
v2 WorkspaceWorkItemShapeParams WorkspaceWorkItemShapeParams e26772ac16cdf87e
v2 WorkspaceWorkItemTemplateField WorkspaceWorkItemTemplateField ebccf9986a66dcd6
v2 WorkspaceWorkItemTemplateOrderBy WorkspaceWorkItemTemplateOrderBy 96cf8171f05f86e8
Expand Down Expand Up @@ -1776,6 +1779,7 @@ v2models UpdateWorkItemProperty UpdateWorkItemProperty 8e153af041482f4a
v2models UpdateWorkItemPropertyContext UpdateWorkItemPropertyContext b19d5a82a8ce76ef
v2models UpdateWorkItemPropertyOption UpdateWorkItemPropertyOption 2101d5a2cd79e7a3
v2models UpdateWorkItemRelationDefinition UpdateWorkItemRelationDefinition 3dfeb24782588c6d
v2models UpdateWorkItemSubscribers UpdateWorkItemSubscribers f72fe68c309b90d2
v2models UpdateWorkItemTemplate UpdateWorkItemTemplate d0b70c45fd61c1ae
v2models UpdateWorkItemType UpdateWorkItemType f8a49123a0320ccf
v2models UpdateWorkItemWorklog UpdateWorkItemWorklog a5682731a39d9298
Expand Down Expand Up @@ -1832,6 +1836,7 @@ v2models WorkItemPropertyType WorkItemPropertyType e60994cc895bf11c
v2models WorkItemRelationCreateRequest WorkItemRelationCreateRequest 4b7dad64fafb3e86
v2models WorkItemRelationDefinition WorkItemRelationDefinition b82ddab4e7b520fe
v2models WorkItemRelationList WorkItemRelationList 6d5e946713382898
v2models WorkItemSubscribers WorkItemSubscribers 493e5f02076c4114
v2models WorkItemTemplate WorkItemTemplate 4331780b7911b0dc
v2models WorkItemTemplateData WorkItemTemplateData fb644987980a439b
v2models WorkItemTemplateUseRequest WorkItemTemplateUseRequest 6537904f31cda000
Expand Down
34 changes: 34 additions & 0 deletions src/api/v2/WorkItems/Subscribers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { UpdateWorkItemSubscribers, WorkItemSubscribers } from "../../../models/v2/WorkItemSubscriber";
import { AnyOperationId, V2Resource } from "../kernel/resource";

/**
* Who is subscribed to a work item — a singleton list on the work item, read with
* `retrieve` and changed with `update` (`{add, remove}`), which answers the resulting list.
* To address the work item by its key (`ENG-12`) without its project, use
* `WorkspaceWorkItems.retrieveSubscribersByIdentifier`/`updateSubscribersByIdentifier`.
*/
export class Subscribers extends V2Resource<WorkItemSubscribers, never, UpdateWorkItemSubscribers> {
/** Exported from the v2 barrel as `WorkItemSubscribersResource`; `exported-names.test.ts` pins the two together. */
static readonly publicName = "WorkItemSubscribersResource";

protected path = "/workspaces/{slug}/projects/{project_id}/work-items/{work_item_id}/subscribers/";
protected operations: Record<string, AnyOperationId> = {
retrieve: "work_items_subscribers_retrieve",
update: "work_items_subscribers_partial_update",
};

/** The users subscribed to this work item. */
retrieve(slug: string, project: string, workItem: string): Promise<WorkItemSubscribers> {
return this.doRetrieveSingleton({ slug, project_id: project, work_item_id: workItem });
}

/** Subscribe `data.add` and unsubscribe `data.remove`; answers the resulting list. */
update(
slug: string,
project: string,
workItem: string,
data: UpdateWorkItemSubscribers
): Promise<WorkItemSubscribers> {
return this.doUpdateSingleton(data, { slug, project_id: project, work_item_id: workItem });
}
}
5 changes: 5 additions & 0 deletions src/api/v2/WorkItems/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Comments } from "./Comments";
import { Dependencies } from "./Dependencies";
import { Links } from "./Links";
import { Relations } from "./Relations";
import { Subscribers } from "./Subscribers";
import { WorkLogs } from "./WorkLogs";

export interface ListWorkItemsParams {
Expand Down Expand Up @@ -105,6 +106,7 @@ export class WorkItems extends LoadsNavigableRows<WorkItem, CreateWorkItem, Upda
public activities: Activities;
public relations: Relations;
public dependencies: Dependencies;
public subscribers: Subscribers;

constructor(transport: V2Transport) {
super(transport);
Expand All @@ -115,6 +117,7 @@ export class WorkItems extends LoadsNavigableRows<WorkItem, CreateWorkItem, Upda
this.activities = new Activities(transport);
this.relations = new Relations(transport);
this.dependencies = new Dependencies(transport);
this.subscribers = new Subscribers(transport);
}

protected navigationOf(meta: LoadedMeta): NavigationFactories<WorkItemNavigation> {
Expand All @@ -127,6 +130,7 @@ export class WorkItems extends LoadsNavigableRows<WorkItem, CreateWorkItem, Upda
activities: () => owned(this.activities, ids, meta.idNames),
relations: () => owned(this.relations, ids, meta.idNames),
dependencies: () => owned(this.dependencies, ids, meta.idNames),
subscribers: () => owned(this.subscribers, ids, meta.idNames),
};
}

Expand Down Expand Up @@ -328,6 +332,7 @@ export { Comments } from "./Comments";
export { Dependencies } from "./Dependencies";
export { Links } from "./Links";
export { Relations } from "./Relations";
export { Subscribers } from "./Subscribers";
export { WorkLogs } from "./WorkLogs";
export type {
ListWorkItemActivitiesParams,
Expand Down
25 changes: 23 additions & 2 deletions src/api/v2/WorkspaceWorkItems.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Page } from "../../models/v2/common";
import { WorkItem } from "../../models/v2/WorkItem";
import { UpdateWorkItemSubscribers, WorkItemSubscribers } from "../../models/v2/WorkItemSubscriber";
import { WorkItemExpand, WorkItemField } from "./generated/constants";
import { AnyOperationId, V2Resource } from "./kernel/resource";
import { ListWorkItemsParams } from "./WorkItems";
Expand All @@ -10,15 +11,21 @@ export interface WorkspaceWorkItemShapeParams {
expand?: readonly WorkItemExpand[];
}

/** Every work item across every project the caller can see; `list`/`retrieveByIdentifier` only — everything else stays on `Project.workItems`. */
/** Every work item across every project the caller can see; `list` and the by-identifier reads/writes only — everything else stays on `Project.workItems`. */
export class WorkspaceWorkItems extends V2Resource<WorkItem, never, never> {
protected path = "/workspaces/{slug}/work-items/";
// The readable-key route is a template of its own, not `{pk}` on the collection: the
// key is composite (`ENG-12`) and the server resolves it, so `urlFor` builds this one.
protected extraPaths = { retrieveByIdentifier: "/workspaces/{slug}/work-items/{identifier}/" };
protected extraPaths = {
retrieveByIdentifier: "/workspaces/{slug}/work-items/{identifier}/",
retrieveSubscribersByIdentifier: "/workspaces/{slug}/work-items/{identifier}/subscribers/",
updateSubscribersByIdentifier: "/workspaces/{slug}/work-items/{identifier}/subscribers/",
};
protected operations: Record<string, AnyOperationId> = {
list: "workspace_work_items_list",
retrieveByIdentifier: "work_items_retrieve_by_identifier",
retrieveSubscribersByIdentifier: "work_items_subscribers_retrieve_by_identifier",
updateSubscribersByIdentifier: "work_items_subscribers_partial_update_by_identifier",
};

/**
Expand Down Expand Up @@ -62,4 +69,18 @@ export class WorkspaceWorkItems extends V2Resource<WorkItem, never, never> {
params as Record<string, unknown>
);
}

/** `WorkItemSubscribersResource.retrieve` for a work item addressed by its key (`ENG-12`) or id. */
retrieveSubscribersByIdentifier(slug: string, identifier: string): Promise<WorkItemSubscribers> {
return this.doRetrieveSingleton({ slug, identifier }, "retrieveSubscribersByIdentifier");
}

/** `WorkItemSubscribersResource.update` for a work item addressed by its key (`ENG-12`) or id. */
updateSubscribersByIdentifier(
slug: string,
identifier: string,
data: UpdateWorkItemSubscribers
): Promise<WorkItemSubscribers> {
return this.doUpdateSingleton(data, { slug, identifier }, "updateSubscribersByIdentifier");
}
}
4 changes: 4 additions & 0 deletions src/api/v2/generated/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@ export const OPERATION_IDS = [
"work_items_partial_update",
"work_items_retrieve",
"work_items_retrieve_by_identifier",
"work_items_subscribers_partial_update",
"work_items_subscribers_partial_update_by_identifier",
"work_items_subscribers_retrieve",
"work_items_subscribers_retrieve_by_identifier",
"work_items_unarchive",
"work_items_upsert",
"work_items_use",
Expand Down
3 changes: 2 additions & 1 deletion src/api/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export { States } from "./States";
export { Workspaces } from "./Workspaces";
export type { WorkspaceField, WorkspaceFieldsParams } from "./Workspaces";
export { Wiki } from "./Wiki";
// The seven work-item children are exported under their qualified names, matching the
// The eight work-item children are exported under their qualified names, matching the
// Python SDK and the `Comments as ReleaseComments` precedent further down. Bare
// `Comments`/`Links`/`Activities` say nothing about which resource they belong to, and
// two of those names are already claimed by `Releases`.
Expand All @@ -55,6 +55,7 @@ export {
Dependencies as WorkItemDependencies,
Links as WorkItemLinks,
Relations as WorkItemRelations,
Subscribers as WorkItemSubscribersResource,
WorkItems,
// `Worklogs`, not `WorkLogs`: the API spells it one word, and `ProjectWorklogs` in this
// same barrel already does.
Expand Down
9 changes: 9 additions & 0 deletions src/api/v2/loaded/WorkItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { Comments } from "../WorkItems/Comments";
import type { Dependencies } from "../WorkItems/Dependencies";
import type { Links } from "../WorkItems/Links";
import type { Relations } from "../WorkItems/Relations";
import type { Subscribers } from "../WorkItems/Subscribers";
import type { WorkLogs } from "../WorkItems/WorkLogs";

/**
Expand Down Expand Up @@ -81,6 +82,14 @@ export interface WorkItemNavigation {
* call answers the full row. Call the resource flat for the narrowed one.
*/
readonly dependencies: Owned<Dependencies, WorkItemIds>;
/**
* Subscribers with this row's ids already supplied.
*
* `fields` is accepted here and does **not** narrow the return type: TypeScript erases a
* method's type parameter when it infers through `Owned`'s conditional, so a navigated
* call answers the full row. Call the resource flat for the narrowed one.
*/
readonly subscribers: Owned<Subscribers, WorkItemIds>;
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/models/v2/WorkItemSubscriber.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** The users subscribed to a work item. A singleton list, not a page of rows. */
export interface WorkItemSubscribers {
subscriber_ids: string[];
}

/** PATCH body: subscribe `add`, unsubscribe `remove`. Both optional, at most 100 ids each, never the same id in both. */
export interface UpdateWorkItemSubscribers {
add?: string[];
remove?: string[];
}
1 change: 1 addition & 0 deletions src/models/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export * from "./WorkItemPropertyContext";
export * from "./WorkItemPropertyOption";
export * from "./WorkItemRelation";
export * from "./WorkItemRelationDefinition";
export * from "./WorkItemSubscriber";
export * from "./WorkItemTemplate";
export * from "./WorkItemType";
export * from "./WorkItemWorklog";
Expand Down
41 changes: 41 additions & 0 deletions tests/unit/v2/work-item-subscribers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Subscribers is a singleton list on a work item: GET reads it, PATCH `{add, remove}` answers the new list.
*/
import nock from "nock";
import { Configuration } from "../../../src/Configuration";
import { Subscribers } from "../../../src/api/v2/WorkItems";
import { V2Transport } from "../../../src/api/v2/kernel/transport";

const BASE = "https://api.example.com";
const SLUG = "acme";
const PROJECT = "ENG";
const WORK_ITEM = "wi-1";

const makeTransport = () => new V2Transport(new Configuration({ baseUrl: BASE, apiKey: "secret" }));

afterEach(() => nock.cleanAll());

describe("WorkItems.subscribers (v2)", () => {
const collection = `/api/v2/workspaces/${SLUG}/projects/${PROJECT}/work-items/${WORK_ITEM}/subscribers/`;
const make = () => new Subscribers(makeTransport());

it("retrieves the list, with no pk segment", async () => {
nock(BASE)
.get(collection)
.reply(200, { subscriber_ids: ["u1", "u2"] });

expect(await make().retrieve(SLUG, PROJECT, WORK_ITEM)).toEqual({ subscriber_ids: ["u1", "u2"] });
});

it("updates with add/remove and answers the resulting list", async () => {
const body = { add: ["u3"], remove: ["u1"] };
const scope = nock(BASE)
.patch(collection, body)
.reply(200, { subscriber_ids: ["u2", "u3"] });

const result = await make().update(SLUG, PROJECT, WORK_ITEM, body);

expect(result.subscriber_ids).toEqual(["u2", "u3"]);
expect(scope.isDone()).toBe(true);
});
});
17 changes: 17 additions & 0 deletions tests/unit/v2/workspace-work-items.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,21 @@ describe("WorkspaceWorkItems (v2)", () => {
expect(identifierScope.isDone()).toBe(true);
expect(listScope.isDone()).toBe(true);
});

it("reads and changes a work item's subscribers by identifier, without its project", async () => {
const path = "/api/v2/workspaces/acme/work-items/ENG-12/subscribers/";
nock(BASE)
.get(path)
.reply(200, { subscriber_ids: ["u1"] });
const scope = nock(BASE)
.patch(path, { add: ["u2"] })
.reply(200, { subscriber_ids: ["u1", "u2"] });

const workItems = makeWorkspaceWorkItems();
expect(await workItems.retrieveSubscribersByIdentifier("acme", "ENG-12")).toEqual({ subscriber_ids: ["u1"] });
expect(await workItems.updateSubscribersByIdentifier("acme", "ENG-12", { add: ["u2"] })).toEqual({
subscriber_ids: ["u1", "u2"],
});
expect(scope.isDone()).toBe(true);
});
});