Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript conversion #9

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
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
20 changes: 20 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"extends": "eslint:recommended",

"env": {
"node": true
},

"rules": {
"indent": [ 2, 2 ],
"quotes": [ 2, "single" ],
"semi": [ 2, "always" ],
"object-curly-spacing": [2, "always"],
"array-bracket-spacing": [2, "never"],
"no-console": 1
}
}
22 changes: 0 additions & 22 deletions .jshintrc

This file was deleted.

5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
language: node_js
node_js:
- 0.10
branches:
only:
- master
- "5"
32 changes: 0 additions & 32 deletions gulpfile.js

This file was deleted.

26 changes: 15 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,30 @@
"Jeff Knaggs <[email protected]>"
],
"scripts": {
"test": "mocha --compilers coffee:coffee-script/register",
"test:w": "npm run test -- --watch",
"prepublish": "gulp build"
"build": "tsc",
"build:w": "tsc --watch --pretty",
"test": "tsc && ava",
"test:w": "ava --watch --color",
"clean": "rimraf lib",
"dev": "npm run clean && concurrently \"npm run build:w\" \"npm run test:w\"",
"prepublish": "npm run build"
},
"main": "lib/teamcity",
"keywords": [
"teamcity",
"api"
],
"ava": {
"files": "lib/test"
},
"dependencies": {
"request": "^2.34.0"
},
"devDependencies": {
"chai": "^1.9.1",
"coffee-script": "^1.7.1",
"gulp": "^3.9.1",
"gulp-coffee": "^2.1.1",
"gulp-load-plugins": "^0.5.3",
"gulp-mocha": "^0.5.1",
"mocha": "^1.20.1",
"rimraf": "^2.2.8"
"ava": "^0.13.0",
"concurrently": "^2.0.0",
"eslint": "^2.4.0",
"rimraf": "^2.5.2",
"typescript": "^1.8.9"
}
}
11 changes: 0 additions & 11 deletions src/build-queue.coffee

This file was deleted.

15 changes: 15 additions & 0 deletions src/build-queue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Locatable from './locatable';
import { IClientApi } from './client';
import { IBuildQueueLocator } from './locators/build-queue-locator';
import { IBuild } from './entities';

export default class BuildQueue extends Locatable<IBuildQueueLocator> {

constructor(client: IClientApi, parent?: Locatable<any>, path?: string) {
super(client, parent, path || '/app/rest/buildQueue');
}

triggerBuild(build: IBuild, cb?: (r: any) => void): Promise<any> {
return this.client._post(this.getPath(), build, cb);
}
}
5 changes: 5 additions & 0 deletions src/build-statistics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Locatable from './locatable';
import { IClientApi } from './client';

export default class BuildStatistics {
}
20 changes: 0 additions & 20 deletions src/build-type-builds.coffee

This file was deleted.

8 changes: 0 additions & 8 deletions src/build-types.coffee

This file was deleted.

10 changes: 10 additions & 0 deletions src/build-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Locatable from './locatable';
import { IClientApi } from './client';
import { IBuildTypeLocator } from './locators/build-type-locator';

export default class BuildTypes extends Locatable<IBuildTypeLocator> {

constructor(client: IClientApi, parent?: Locatable<any>, path?: string) {
super(client, parent, path || '/app/rest/buildTypes');
}
}
19 changes: 19 additions & 0 deletions src/builds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Locatable from './locatable';
import { IClientApi } from './client';
import { IBuildLocator } from './locators/build-locator';
import BuildStatistics from './build-statistics';

export default class Builds extends Locatable<IBuildLocator> {

statistics: BuildStatistics;

constructor(client: IClientApi, parent?: Locatable<any>, path?: string) {
super(client, parent, path || '/app/rest/builds');

this.statistics = new BuildStatistics();
}

buildLog(cb?: (r:any) => void) {
return this.client._get(this.getPath('downloadBuildLog.html'), cb);
}
}
26 changes: 0 additions & 26 deletions src/builds/builds.coffee

This file was deleted.

8 changes: 0 additions & 8 deletions src/changes.coffee

This file was deleted.

9 changes: 9 additions & 0 deletions src/changes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Locatable from './locatable';
import { IClientApi } from './client';
import { IChangesLocator } from './locators/changes-locator';

export default class Changes extends Locatable<IChangesLocator> {
constructor(client: IClientApi, parent?: Locatable<any>, path?: string) {
super(client, parent, path || '/app/rest/changes');
}
}
4 changes: 4 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface IClientApi {
_get: (path: string, params?: any, cb?: (result: any) => void) => Promise<any>
_post: (path: string, params?: any, cb?: (result: any) => void) => Promise<any>
}
13 changes: 13 additions & 0 deletions src/entities.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export interface IComment {
text: string;
}

export interface IBuild {
buildTypeId: number|string;
agentId: number|string;
comment: IComment
}

export interface IBuildType {

}
108 changes: 108 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import request from 'request';

import { IClientApi } from './client';
import Builds from './builds';
import BuildTypes from './build-types';
import BuildQueue from './build-queue';
import Changes from './changes';
import Projects from './projects';
import VcsRootInstances from './vcs-root-instances';

interface Options {
username?: string,
password?: string,

protocol?: string,
baseUrl?: string
}

export default class TeamCity {
private client: IClientApi

builds: Builds;
buildTypes: BuildTypes;
buildQueue: BuildQueue;
changes: Changes;
projects: Projects;
vcsRootInstances: VcsRootInstances;

constructor(options?: Options, client?: IClientApi) {
this.client = client || new Client(options);

this.builds = new Builds(this.client);
this.buildTypes = new BuildTypes(this.client);
this.buildQueue = new BuildQueue(this.client);
this.projects = new Projects(this.client);
this.vcsRootInstances = new VcsRootInstances(this.client);
}
}

function url(path, options) {
return `${options.protocol}://${options.baseUrl}${path}`;
}

class Client implements IClientApi {
private options: Options;

constructor(options: Options) {
this.options = options;
}

_call(options: any, cb?: (err: any, data?: any) => void): Promise<any> {
const opts = Object.assign(
{},
options,
{
auth: {
username: this.options.username,
password: this.options.password,
sendImmediately: true
}
}, {
headers: {
'Accept': 'application/json'
}
}
);

request(options, (err, response, body) => {
return new Promise((resolve, reject) => {
if (err) {
if (cb) { cb(err); }
reject(err);
return;
}

let data;

if (typeof body === 'string') {
try {
data = JSON.parse(body);
} catch (error) {
err = body;
}
} else {
data = body;
}

if (cb) {
cb(err, data);
}

if (err) {
reject(err);
} else {
resolve(data);
}
});
});
}

_get(path: string, params?: any, cb?: (result: any) => void): Promise<any> {

}

_post(path: string, params?: any, cb?: (result: any) => void): Promise<any> {

}
}
Loading