diff --git a/types/node-redmine/index.d.ts b/types/node-redmine/index.d.ts new file mode 100644 index 0000000000..74c3c8effa --- /dev/null +++ b/types/node-redmine/index.d.ts @@ -0,0 +1,102 @@ +// Type definitions for node-redmine 0.2 +// Project: https://github.com/zanran/node-redmine#readme +// Definitions by: Roberto Rossetti +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +export interface IssueRecord { + id: number; + project: IssueRecordField; + tracker: IssueRecordField; + status: IssueRecordField; + priority: IssueRecordField; + author: IssueRecordField; + assigned_to: IssueRecordField; + parent?: IssueRecordField; + subject: string; + description: string; + start_date: string | null; + due_date: string | null; + done_ratio: number; + is_private: boolean; + total_estimated_hours: number | null; + created_at: string; + updated_at: string | null; + closed_on: string | null; +} + +export interface IssueRecordField { + id: number; + name?: string; +} + +export interface IssueParams { + project_id?: number; + tracker_id?: number; + priority_id?: number; + category_id?: number; + status_id?: number; + assigned_to_id?: number; + subject?: string; + description?: string; + parent_issue_id?: number; + notes?: string; + uploads?: UploadRecord[]; +} + +export interface UploadResult { + upload: UploadRecord; +} + +export interface UploadRecord { + token: string; + content_type?: string; + filename: string; +} + +export interface IssueData { + issue: IssueParams; +} + +export interface Issue { + issue: IssueRecord; +} + +export interface Issues { + issues: IssueRecord[]; +} + +export class Redmine { + constructor(host: string, config: any, port: number); + + /////////////////////////////////////// REST API for issues(Stable) /////////////////////////////////////// + + issues(params: any, callback: (err: any, data: any) => void): Issues; + + get_issue_by_id(id: number, params: any, callback: (err: any, data: any) => void): Issue; + + create_issue(issue: IssueData, callback: (err: any, data: any) => void): Issue; + + update_issue(id: number, issue: IssueData, callback: (err: any, data: any) => void): Issue; + + delete_issue(id: number, callback: (err: any, data: any) => void): void; + + add_watcher(id: number, params: any, callback: (err: any, data: any) => void): void; + + remove_watcher(id: number, params: any, callback: (err: any, data: any) => void): void; + + /////////////////////////////////////// REST API for Issue Relations(Alpha) /////////////////////////////////////// + + issue_relation_by_issue_id(id: number, callback: (err: any, data: any) => void): void; + + create_issue_relation(id: number, params: any, callback: (err: any, data: any) => void): void; + + issue_relation_by_id(id: number, callback: (err: any, data: any) => void): void; + + delete_issue_relation(id: number, callback: (err: any, data: any) => void): void; + + /////////////////////////////////////// REST API for Common(Alpha) /////////////////////////////////////// + + upload(content: any, callback: (err: any, data: any) => void): UploadResult; +} diff --git a/types/node-redmine/node-redmine-tests.ts b/types/node-redmine/node-redmine-tests.ts new file mode 100644 index 0000000000..edcb65050d --- /dev/null +++ b/types/node-redmine/node-redmine-tests.ts @@ -0,0 +1,18 @@ +import { Issue, Redmine } from 'node-redmine'; + +const redmine = new Redmine('http://localhost', { apiKey: 'QWERTYUIOP' }, 8080); + +const dump_issue = (issue: Issue) => { + console.log('Dumping issue:'); + for (const item in issue) { + console.log(`${JSON.stringify(issue)}: `); + } +}; +redmine.issues({ limit: 2 }, (err, data) => { + if (err) throw err; + + for (const issue of data.issues) { + dump_issue(issue); + } + console.log(`total count: ${data.total_count}`); +}); diff --git a/types/node-redmine/tsconfig.json b/types/node-redmine/tsconfig.json new file mode 100644 index 0000000000..c7648a4e8b --- /dev/null +++ b/types/node-redmine/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "node-redmine-tests.ts" + ] +} diff --git a/types/node-redmine/tslint.json b/types/node-redmine/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/node-redmine/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }