Comparing version 2.0.0 to 2.1.0
# Change Log | ||
# [Next](https://github.com/Mossop/bugzilla-ts/compare/v1.1.6...main) | ||
# [2.1.0](https://github.com/Mossop/bugzilla-ts/compare/v2.0.0...v2.1.0) | ||
- Added `getComment`, `getBugComments` and `createComment` API methods. | ||
# [2.0.0](https://github.com/Mossop/bugzilla-ts/compare/v1.1.6...v2.0.0) | ||
- Fixed date/time validation. | ||
@@ -6,0 +10,0 @@ - Added support for Red Hat Bugzilla. |
@@ -6,4 +6,5 @@ /// <reference types="node" /> | ||
import { FilteredQuery } from "./query"; | ||
import type { Bug, User, History } from "./types"; | ||
export type { Bug, User, History, Change, Flag } from "./types"; | ||
import type { Bug, User, History, Comment } from "./types"; | ||
import { CreateCommentContent } from "./types"; | ||
export type { Bug, User, History, Change, Flag, Comment } from "./types"; | ||
export default class BugzillaAPI { | ||
@@ -21,3 +22,6 @@ private readonly link; | ||
advancedSearch(query: string | URL | Record<string, string> | [string, string][] | URLSearchParams): FilteredQuery<Bug>; | ||
getComment(commentId: number): Promise<Comment | undefined>; | ||
getBugComments(bugId: number): Promise<Comment[] | undefined>; | ||
createComment(bugId: number, comment: string, options?: Partial<Omit<CreateCommentContent, "comment">>): Promise<number>; | ||
} | ||
//# sourceMappingURL=index.d.ts.map |
@@ -83,4 +83,31 @@ "use strict"; | ||
} | ||
async getComment(commentId) { | ||
let comment = await this.link.get(`bug/comment/${commentId}`, (0, validators_1.object)(types_1.CommentsSpec)); | ||
if (!comment) { | ||
throw new Error(`Failed to get comment #${commentId}.`); | ||
} | ||
return comment.comments.get(commentId); | ||
} | ||
async getBugComments(bugId) { | ||
var _a; | ||
let comments = await this.link.get(`bug/${bugId}/comment`, (0, validators_1.object)(types_1.CommentsSpec)); | ||
if (!comments) { | ||
throw new Error(`Failed to get comments of bug #${bugId}.`); | ||
} | ||
return (_a = comments.bugs.get(bugId)) === null || _a === void 0 ? void 0 : _a.comments; | ||
} | ||
async createComment(bugId, comment, options = {}) { | ||
var _a; | ||
const content = { | ||
comment, | ||
is_private: (_a = options.is_private) !== null && _a !== void 0 ? _a : false, | ||
}; | ||
let commentStatus = await this.link.post(`bug/${bugId}/comment`, (0, validators_1.object)(types_1.CreatedCommentSpec), content); | ||
if (!comment) { | ||
throw new Error("Failed to create comment."); | ||
} | ||
return commentStatus.id; | ||
} | ||
} | ||
exports.default = BugzillaAPI; | ||
//# sourceMappingURL=index.js.map |
@@ -95,3 +95,34 @@ import type { DateTime } from "luxon"; | ||
export declare const HistoryLookupSpec: ObjectSpec<HistoryLookup>; | ||
export interface Comment { | ||
attachment_id?: int | null; | ||
bug_id: int; | ||
count: int; | ||
creation_time: datetime; | ||
creator: string; | ||
id: int; | ||
is_private: boolean; | ||
tags: string[]; | ||
time: datetime; | ||
text: string; | ||
} | ||
export declare const CommentSpec: ObjectSpec<Comment>; | ||
export interface CommentsTemplate { | ||
comments: Comment[]; | ||
} | ||
export declare const CommentsTemplateSpec: ObjectSpec<CommentsTemplate>; | ||
export interface Comments { | ||
bugs: Map<number, CommentsTemplate>; | ||
comments: Map<number, Comment>; | ||
} | ||
export declare const CommentsSpec: ObjectSpec<Comments>; | ||
export interface CreateCommentContent { | ||
comment: string; | ||
is_private: boolean; | ||
} | ||
export declare const CreateCommentContentSpec: ObjectSpec<CreateCommentContent>; | ||
export interface CreatedComment { | ||
id: int; | ||
} | ||
export declare const CreatedCommentSpec: ObjectSpec<CreatedComment>; | ||
export {}; | ||
//# sourceMappingURL=types.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.HistoryLookupSpec = exports.BugHistorySpec = exports.HistorySpec = exports.ChangeSpec = exports.BugSpec = exports.FlagSpec = exports.UserSpec = exports.VersionSpec = exports.LoginResponseSpec = void 0; | ||
exports.CreatedCommentSpec = exports.CreateCommentContentSpec = exports.CommentsSpec = exports.CommentsTemplateSpec = exports.CommentSpec = exports.HistoryLookupSpec = exports.BugHistorySpec = exports.HistorySpec = exports.ChangeSpec = exports.BugSpec = exports.FlagSpec = exports.UserSpec = exports.VersionSpec = exports.LoginResponseSpec = void 0; | ||
const validators_1 = require("./validators"); | ||
@@ -86,2 +86,28 @@ exports.LoginResponseSpec = { | ||
}; | ||
exports.CommentSpec = { | ||
attachment_id: (0, validators_1.nullable)((0, validators_1.optional)(validators_1.int)), | ||
bug_id: validators_1.int, | ||
count: validators_1.int, | ||
creation_time: validators_1.datetime, | ||
creator: validators_1.string, | ||
id: validators_1.int, | ||
is_private: validators_1.boolean, | ||
tags: (0, validators_1.array)(validators_1.string), | ||
time: validators_1.datetime, | ||
text: validators_1.string, | ||
}; | ||
exports.CommentsTemplateSpec = { | ||
comments: (0, validators_1.array)((0, validators_1.object)(exports.CommentSpec)), | ||
}; | ||
exports.CommentsSpec = { | ||
bugs: (0, validators_1.map)(validators_1.intString, (0, validators_1.object)(exports.CommentsTemplateSpec)), | ||
comments: (0, validators_1.map)(validators_1.intString, (0, validators_1.object)(exports.CommentSpec)), | ||
}; | ||
exports.CreateCommentContentSpec = { | ||
comment: validators_1.string, | ||
is_private: validators_1.boolean, | ||
}; | ||
exports.CreatedCommentSpec = { | ||
id: validators_1.int, | ||
}; | ||
//# sourceMappingURL=types.js.map |
@@ -18,2 +18,4 @@ import { DateTime } from "luxon"; | ||
export declare function maybeArray<T>(validator: Validator<T>): Validator<T | T[]>; | ||
export declare function intString(val: any): number; | ||
export declare function map<K, V>(keyValidator: Validator<K>, valueValidator: Validator<V>): Validator<Map<K, V>>; | ||
//# sourceMappingURL=validators.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.maybeArray = exports.optional = exports.nullable = exports.string = exports.double = exports.int = exports.boolean = exports.datetime = exports.array = exports.object = void 0; | ||
exports.map = exports.intString = exports.maybeArray = exports.optional = exports.nullable = exports.string = exports.double = exports.int = exports.boolean = exports.datetime = exports.array = exports.object = void 0; | ||
const luxon_1 = require("luxon"); | ||
@@ -102,2 +102,26 @@ function repr(val) { | ||
exports.maybeArray = maybeArray; | ||
function intString(val) { | ||
if (typeof val != "string") { | ||
throw new Error(`Expected an integer as a string but received ${repr(val)}`); | ||
} | ||
let value = parseInt(val, 10); | ||
if (value.toString() != val) { | ||
throw new Error(`Expected an integer as a string but received ${repr(val)}`); | ||
} | ||
return value; | ||
} | ||
exports.intString = intString; | ||
function map(keyValidator, valueValidator) { | ||
return (val) => { | ||
if (!val || typeof val != "object") { | ||
throw new Error(`Expected an object but received ${repr(val)}`); | ||
} | ||
let result = new Map(); | ||
for (let [key, value] of Object.entries(val)) { | ||
result.set(keyValidator(key), valueValidator(value)); | ||
} | ||
return result; | ||
}; | ||
} | ||
exports.map = map; | ||
//# sourceMappingURL=validators.js.map |
{ | ||
"name": "bugzilla", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "A NodeJS module to access Bugzilla instances through the REST API.", | ||
@@ -14,3 +14,3 @@ "main": "dist/index.js", | ||
"prepack": "npm run build", | ||
"version": "node scripts/version.js", | ||
"version": "node scripts/version.js && git add CHANGELOG.md", | ||
"postversion": "node scripts/post-version.js && git add CHANGELOG.md && git commit -m 'Update CHANGELOG.md'" | ||
@@ -49,3 +49,3 @@ }, | ||
"jest": "^27.4.7", | ||
"msw": "^0.36.4", | ||
"msw": "^0.39.1", | ||
"prettier": "^2.5.1", | ||
@@ -52,0 +52,0 @@ "ts-jest": "^27.1.3", |
@@ -89,1 +89,31 @@ # Bugzilla | [![npm version](https://badgen.net/npm/v/bugzilla)](https://www.npmjs.com/package/bugzilla) [![Build](https://github.com/Mossop/bugzilla-ts/actions/workflows/build.yml/badge.svg)](https://github.com/Mossop/bugzilla-ts/actions/workflows/build.yml) [![codecov](https://codecov.io/gh/Mossop/bugzilla-ts/branch/main/graph/badge.svg)](https://codecov.io/gh/Mossop/bugzilla-ts) | ||
Custom fields are not currently returned. | ||
## Retrieving comments by ID | ||
```javascript | ||
// .getComment() accepts one parameter, ID of comment, as number | ||
let comment = await api.getComment(123456); | ||
``` | ||
Return value is Comment object. | ||
## Retrieving all comments of bug | ||
```javascript | ||
// .getComments() accepts one parameter, ID of bug, as number | ||
let comments = await api.getBugComments(123456); | ||
``` | ||
Return value is array of Comment objects. | ||
## Creating comments | ||
```javascript | ||
let comment = await api.createComment( | ||
123456, | ||
"This is new comment on bug #123456", | ||
{ is_private: false }, | ||
); | ||
``` | ||
Returned value is ID of the newly-created comment. |
@@ -8,7 +8,15 @@ import { URL, URLSearchParams } from "url"; | ||
import { FilteredQuery } from "./query"; | ||
import type { Bug, User, History } from "./types"; | ||
import { HistoryLookupSpec, BugSpec, UserSpec, VersionSpec } from "./types"; | ||
import type { Bug, User, History, Comment } from "./types"; | ||
import { | ||
HistoryLookupSpec, | ||
BugSpec, | ||
UserSpec, | ||
VersionSpec, | ||
CommentsSpec, | ||
CreatedCommentSpec, | ||
CreateCommentContent, | ||
} from "./types"; | ||
import { array, object } from "./validators"; | ||
export type { Bug, User, History, Change, Flag } from "./types"; | ||
export type { Bug, User, History, Change, Flag, Comment } from "./types"; | ||
@@ -141,2 +149,51 @@ export default class BugzillaAPI { | ||
} | ||
public async getComment(commentId: number): Promise<Comment | undefined> { | ||
let comment = await this.link.get( | ||
`bug/comment/${commentId}`, | ||
object(CommentsSpec), | ||
); | ||
if (!comment) { | ||
throw new Error(`Failed to get comment #${commentId}.`); | ||
} | ||
return comment.comments.get(commentId); | ||
} | ||
public async getBugComments(bugId: number): Promise<Comment[] | undefined> { | ||
let comments = await this.link.get( | ||
`bug/${bugId}/comment`, | ||
object(CommentsSpec), | ||
); | ||
if (!comments) { | ||
throw new Error(`Failed to get comments of bug #${bugId}.`); | ||
} | ||
return comments.bugs.get(bugId)?.comments; | ||
} | ||
public async createComment( | ||
bugId: number, | ||
comment: string, | ||
options: Partial<Omit<CreateCommentContent, "comment">> = {}, | ||
): Promise<number> { | ||
const content = { | ||
comment, | ||
is_private: options.is_private ?? false, | ||
}; | ||
let commentStatus = await this.link.post( | ||
`bug/${bugId}/comment`, | ||
object(CreatedCommentSpec), | ||
content, | ||
); | ||
if (!comment) { | ||
throw new Error("Failed to create comment."); | ||
} | ||
return commentStatus.id; | ||
} | ||
} |
@@ -16,2 +16,4 @@ /* eslint-disable @typescript-eslint/naming-convention */ | ||
ObjectSpec, | ||
intString, | ||
map, | ||
} from "./validators"; | ||
@@ -201,1 +203,63 @@ | ||
}; | ||
export interface Comment { | ||
attachment_id?: int | null; | ||
bug_id: int; | ||
count: int; | ||
creation_time: datetime; | ||
creator: string; | ||
id: int; | ||
is_private: boolean; | ||
tags: string[]; | ||
time: datetime; | ||
text: string; | ||
} | ||
export const CommentSpec: ObjectSpec<Comment> = { | ||
attachment_id: nullable(optional(int)), | ||
bug_id: int, | ||
count: int, | ||
creation_time: datetime, | ||
creator: string, | ||
id: int, | ||
is_private: boolean, | ||
tags: array(string), | ||
time: datetime, | ||
text: string, | ||
}; | ||
export interface CommentsTemplate { | ||
comments: Comment[]; | ||
} | ||
export const CommentsTemplateSpec: ObjectSpec<CommentsTemplate> = { | ||
comments: array(object(CommentSpec)), | ||
}; | ||
export interface Comments { | ||
bugs: Map<number, CommentsTemplate>; | ||
comments: Map<number, Comment>; | ||
} | ||
export const CommentsSpec: ObjectSpec<Comments> = { | ||
bugs: map(intString, object(CommentsTemplateSpec)), | ||
comments: map(intString, object(CommentSpec)), | ||
}; | ||
export interface CreateCommentContent { | ||
comment: string; | ||
is_private: boolean; | ||
} | ||
export const CreateCommentContentSpec: ObjectSpec<CreateCommentContent> = { | ||
comment: string, | ||
is_private: boolean, | ||
}; | ||
export interface CreatedComment { | ||
id: int; | ||
} | ||
export const CreatedCommentSpec: ObjectSpec<CreatedComment> = { | ||
id: int, | ||
}; |
@@ -132,1 +132,37 @@ import { DateTime } from "luxon"; | ||
} | ||
export function intString(val: any): number { | ||
if (typeof val != "string") { | ||
throw new Error( | ||
`Expected an integer as a string but received ${repr(val)}`, | ||
); | ||
} | ||
let value = parseInt(val, 10); | ||
if (value.toString() != val) { | ||
throw new Error( | ||
`Expected an integer as a string but received ${repr(val)}`, | ||
); | ||
} | ||
return value; | ||
} | ||
export function map<K, V>( | ||
keyValidator: Validator<K>, | ||
valueValidator: Validator<V>, | ||
): Validator<Map<K, V>> { | ||
return (val: any): Map<K, V> => { | ||
if (!val || typeof val != "object") { | ||
throw new Error(`Expected an object but received ${repr(val)}`); | ||
} | ||
let result = new Map<K, V>(); | ||
for (let [key, value] of Object.entries(val)) { | ||
result.set(keyValidator(key), valueValidator(value)); | ||
} | ||
return result; | ||
}; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
80670
1544
119
0