import * as request from 'request-promise' import * as config from 'config' import * as fs from 'fs' import * as path from 'path' import { DbCollection } from '../types' export class TeambitionCore { private cookies: string constructor (token: string, cookies) { this.cookies = cookies } importTasksToScrum(_taskflowId, body) { return request.post(`${config.TEAMBITION.CORE.URL}/taskflows/${_taskflowId}/tasks`, { headers: { cookie: this.cookies, 'request-server': config.APP.NAME }, timeout: 5000, strictSSL: false, json: true, body: body, }) } /** * @author jiangwei * @desc 导入测试用例 * @param {DbCollection.Testcase} body * @returns * @memberof TeambitionCore */ importTestcase(body: DbCollection.Testcase) { return request.post(`${config.TEAMBITION.CORE.URL}/testcases`, { headers: { cookie: this.cookies, 'request-server': config.APP.NAME }, timeout: 5000, strictSSL: false, json: true, body: body, }) } findTagsByProjectId (_projectId) { return request.get(`${config.TEAMBITION.CORE.URL}/projects/${_projectId}/tags`, { headers: { cookie: this.cookies, 'request-server': config.APP.NAME }, strictSSL: false, json: true }) } getCustomfieldLookupChoices(_projectId, _organizationId, _customfieldId) { return request.get(`${config.TEAMBITION.CORE.URL}/customfields/${_customfieldId}/popup`, { headers: { cookie: this.cookies, 'request-server': config.APP.NAME }, strictSSL: false, json: true, qs: { _projectId: `${_projectId}`, _organizationId: `${_organizationId}` } }) } getSprintList(_projectId, options? :Object) { return request.get(`${config.TEAMBITION.CORE.URL}/projects/${_projectId}/sprints`, { headers: { cookie: this.cookies, 'request-server': config.APP.NAME }, strictSSL: false, json: true, qs: options }) } getTestPlanByProjectId (_projectId: string) { return request.get(`${config.TEAMBITION.CORE.URL}/projects/${_projectId}/testplans`, { headers: { cookie: this.cookies, 'request-server': config.APP.NAME }, strictSSL: false, json: true }) } getTestPlanGroups (_testPlanId: string, needRoot: boolean) { return request.get(`${config.TEAMBITION.CORE.URL}/testplans/${_testPlanId}/commongroups`, { qs: {needRoot}, headers: { cookie: this.cookies, 'request-server': config.APP.NAME }, strictSSL: false, json: true }) } getOrganizationMemberByName(_organizationId, name) { return request.get(`${config.TEAMBITION.CORE.URL}/api/v2/organizations/${_organizationId}/members/search`, { headers: { cookie: this.cookies, 'request-server': config.APP.NAME }, strictSSL: false, json: true, qs: { q: name, _: Date.now() } }) } getCustomfieldsByProjectId (_projectId: string) { return request.get(`${config.TEAMBITION.CORE.URL}/api/customfields`, { headers: { cookie: this.cookies, 'request-server': config.APP.NAME }, strictSSL: false, json: true, qs: { _projectId: String(_projectId) } }) } getSfcByProjectId (_projectId: string, objectType: string) { return request.get(`${config.TEAMBITION.CORE.URL}/api/projects/${_projectId}/scenariofieldconfigs`, { headers: { cookie: this.cookies, 'request-server': config.APP.NAME }, strictSSL: false, json: true, qs: { objectType } }) } async getProjectCluster (_organizationId: string, selectBy: string, _projectTagId: string, customfieldIds: string [] = []) { const query = await fs.readFileSync( path.resolve(__dirname, '../../query/project-cluster.graphql'), { encoding: 'utf8' } ) return request.post(`${config.TEAMBITION.CORE.URL}/api/graphql`, { headers: { cookie: this.cookies, 'request-server': config.APP.NAME }, timeout: 5000, strictSSL: false, json: true, body: { query, variables: { organizationId: _organizationId, selectBy, projectTagId: _projectTagId, customfieldIds, pageSize: 1000 } }, }) } async getCustomfields (_organizationId: string, customfieldIds: string []) { const query = await fs.readFileSync( path.resolve(__dirname, '../../query/customfield.graphql'), { encoding: 'utf8' } ) return request.post(`${config.TEAMBITION.CORE.URL}/api/graphql`, { headers: { cookie: this.cookies, 'request-server': config.APP.NAME }, timeout: 5000, strictSSL: false, json: true, body: { query, variables: { organizationId: _organizationId, customfieldIds, pageSize: 1000 } }, }) } async getProjecttag (projectTagId: string) { const query = await fs.readFileSync( path.resolve(__dirname, '../../query/projecttag.graphql'), { encoding: 'utf8' } ) return request.post(`${config.TEAMBITION.CORE.URL}/api/graphql`, { headers: { cookie: this.cookies, 'request-server': config.APP.NAME }, timeout: 5000, strictSSL: false, json: true, body: { query, variables: { projectTagId } }, }) } }