Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
64897e8e0b | |||
530fc59880 | |||
82cf0c2257 | |||
ea16521ca3 | |||
15889699b4 | |||
765e56076d | |||
273821b732 | |||
057cca6f0e |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@mojoio/ora",
|
"name": "@mojoio/ora",
|
||||||
"version": "1.0.5",
|
"version": "1.0.9",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@mojoio/ora",
|
"name": "@mojoio/ora",
|
||||||
"version": "1.0.5",
|
"version": "1.0.9",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "an api abstraction package for ora.pm",
|
"description": "an api abstraction package for ora.pm",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
|
68
test/test.ts
68
test/test.ts
@ -20,8 +20,72 @@ tap.test('should get all projects of an organization', async () => {
|
|||||||
const losslessOrganization = organizations.find(orgArg => {
|
const losslessOrganization = organizations.find(orgArg => {
|
||||||
return orgArg.name.startsWith('Lossless');
|
return orgArg.name.startsWith('Lossless');
|
||||||
});
|
});
|
||||||
const projectsInLosslessOrg = await losslessOrganization.getAllProjects();
|
const projectsInLosslessOrg = await losslessOrganization.getProjects();
|
||||||
console.log(projectsInLosslessOrg);
|
});
|
||||||
|
|
||||||
|
tap.test('should get all lists for a project', async () => {
|
||||||
|
const organizations = await oraInstance.getOrganizations();
|
||||||
|
const losslessOrganization = organizations.find(orgArg => {
|
||||||
|
return orgArg.name.startsWith('Lossless');
|
||||||
|
});
|
||||||
|
const projectsInLosslessOrg = await losslessOrganization.getProjects();
|
||||||
|
const featureProjects = projectsInLosslessOrg.filter(oraProjectArg => {
|
||||||
|
return oraProjectArg.title.includes('Feature');
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log('The following Feature Boards are available:');
|
||||||
|
featureProjects.forEach(oraProjectArg => console.log(oraProjectArg.title));
|
||||||
|
const layerIoProject = featureProjects.find(oraProjectArg =>
|
||||||
|
oraProjectArg.title.includes('layer.io')
|
||||||
|
);
|
||||||
|
|
||||||
|
const lists = await layerIoProject.getLists();
|
||||||
|
console.log('\nThe following lists are available');
|
||||||
|
lists.forEach(listArg => console.log(listArg.title));
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should get all tasks for a project', async () => {
|
||||||
|
const organizations = await oraInstance.getOrganizations();
|
||||||
|
const losslessOrganization = organizations.find(orgArg => {
|
||||||
|
return orgArg.name.startsWith('Lossless');
|
||||||
|
});
|
||||||
|
const projectsInLosslessOrg = await losslessOrganization.getProjects();
|
||||||
|
const featureProjects = projectsInLosslessOrg.filter(oraProjectArg => {
|
||||||
|
return oraProjectArg.title.includes('Feature');
|
||||||
|
});
|
||||||
|
const layerIoProject = featureProjects.find(oraProjectArg =>
|
||||||
|
oraProjectArg.title.includes('layer.io')
|
||||||
|
);
|
||||||
|
const lists = await layerIoProject.getLists();
|
||||||
|
let tasks: ora.OraTask[] = [];
|
||||||
|
for (const list of lists) {
|
||||||
|
tasks = tasks.concat(await list.getTasks());
|
||||||
|
}
|
||||||
|
console.log('the following tasks are available:');
|
||||||
|
tasks.forEach(taskArg => console.log(taskArg.title));
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should get a milestone', async () => {
|
||||||
|
const organizations = await oraInstance.getOrganizations();
|
||||||
|
const losslessOrganization = organizations.find(orgArg => {
|
||||||
|
return orgArg.name.startsWith('Lossless');
|
||||||
|
});
|
||||||
|
const projectsInLosslessOrg = await losslessOrganization.getProjects();
|
||||||
|
const featureProjects = projectsInLosslessOrg.filter(oraProjectArg => {
|
||||||
|
return oraProjectArg.title.includes('Feature');
|
||||||
|
});
|
||||||
|
const layerIoProject = featureProjects.find(oraProjectArg =>
|
||||||
|
oraProjectArg.title.includes('layer.io')
|
||||||
|
);
|
||||||
|
const lists = await layerIoProject.getLists();
|
||||||
|
let tasks: ora.OraTask[] = [];
|
||||||
|
for (const list of lists) {
|
||||||
|
tasks = tasks.concat(await list.getTasks());
|
||||||
|
}
|
||||||
|
console.log('the following tasks are available:');
|
||||||
|
const milestone = await tasks[0].getMilestone();
|
||||||
|
expect(milestone).to.be.instanceOf(ora.OraMilestone);
|
||||||
|
console.log(`Task with title "${tasks[0].title}" is part of milestone "${milestone.title}"`);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -1,2 +1,6 @@
|
|||||||
export * from './ora.classes.ora';
|
export * from './ora.classes.ora';
|
||||||
export * from './ora.classes.organization';
|
export * from './ora.classes.organization';
|
||||||
|
export * from './ora.classes.project';
|
||||||
|
export * from './ora.classes.list';
|
||||||
|
export * from './ora.classes.task';
|
||||||
|
export * from './ora.classes.milestone';
|
||||||
|
@ -1,5 +1,63 @@
|
|||||||
import * as plugins from './ora.plugins';
|
import * as plugins from './ora.plugins';
|
||||||
|
import { OraProject } from './ora.classes.project';
|
||||||
|
import { OraTask } from './ora.classes.task';
|
||||||
|
|
||||||
export class OraList {
|
/**
|
||||||
|
* the interface for an ora list
|
||||||
}
|
*/
|
||||||
|
export interface IOraList {
|
||||||
|
actions: number;
|
||||||
|
archived: false;
|
||||||
|
color: string;
|
||||||
|
id: number;
|
||||||
|
list_type: number;
|
||||||
|
position: number;
|
||||||
|
project_id: number;
|
||||||
|
public: boolean;
|
||||||
|
title: string;
|
||||||
|
updated_at: string;
|
||||||
|
view_id: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class OraList implements IOraList {
|
||||||
|
// ======
|
||||||
|
// STATIC
|
||||||
|
// ======
|
||||||
|
public static async getAllLists(oraProjectRef: OraProject) {
|
||||||
|
const response = await oraProjectRef.oraOrganizationRef.oraRef.request(
|
||||||
|
`/projects/${oraProjectRef.id}/lists`,
|
||||||
|
'GET'
|
||||||
|
);
|
||||||
|
const oraLists: OraList[] = [];
|
||||||
|
for (const dataObject of response.data) {
|
||||||
|
oraLists.push(new OraList(oraProjectRef, dataObject));
|
||||||
|
}
|
||||||
|
return oraLists;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========
|
||||||
|
// INSTANCE
|
||||||
|
// ========
|
||||||
|
public actions: number;
|
||||||
|
public archived: false;
|
||||||
|
public color: string;
|
||||||
|
public id: number;
|
||||||
|
public list_type: number;
|
||||||
|
public position: number;
|
||||||
|
public project_id: number;
|
||||||
|
public public: boolean;
|
||||||
|
public title: string;
|
||||||
|
public updated_at: string;
|
||||||
|
public view_id: number;
|
||||||
|
|
||||||
|
public oraProjectObjectRef: OraProject;
|
||||||
|
|
||||||
|
constructor(oraProjectRefArg: OraProject, creationObjectArg) {
|
||||||
|
this.oraProjectObjectRef = oraProjectRefArg;
|
||||||
|
Object.assign(this, creationObjectArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getTasks() {
|
||||||
|
return OraTask.getAllOraTasks(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
47
ts/ora.classes.milestone.ts
Normal file
47
ts/ora.classes.milestone.ts
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import * as plugins from './ora.plugins';
|
||||||
|
import { OraProject } from './ora.classes.project';
|
||||||
|
|
||||||
|
export interface IOraMilestone {
|
||||||
|
id: number;
|
||||||
|
title: string;
|
||||||
|
created_at: string;
|
||||||
|
updated_at: string;
|
||||||
|
archived: boolean;
|
||||||
|
complete: boolean;
|
||||||
|
deadline: string;
|
||||||
|
color: string;
|
||||||
|
position: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class OraMilestone implements IOraMilestone {
|
||||||
|
// ======
|
||||||
|
// STATIC
|
||||||
|
// ======
|
||||||
|
public static async getAllMilestonesForProject(oraProjectArg: OraProject) {
|
||||||
|
const response = await oraProjectArg.oraOrganizationRef.oraRef.request(`/projects/${oraProjectArg.id}/milestones`, 'GET');
|
||||||
|
const milestones: OraMilestone[] = [];
|
||||||
|
for (const dataObject of response.data) {
|
||||||
|
milestones.push(new OraMilestone(oraProjectArg, dataObject));
|
||||||
|
}
|
||||||
|
return milestones;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========
|
||||||
|
// INSTANCE
|
||||||
|
// ========
|
||||||
|
public id: number;
|
||||||
|
public title: string;
|
||||||
|
public created_at: string;
|
||||||
|
public updated_at: string;
|
||||||
|
public archived: boolean;
|
||||||
|
public complete: boolean;
|
||||||
|
public deadline: string;
|
||||||
|
public color: string;
|
||||||
|
public position: number;
|
||||||
|
|
||||||
|
public oraProjectRef: OraProject;
|
||||||
|
constructor(oraProjectRef: OraProject, creationObjectArg: IOraMilestone) {
|
||||||
|
this.oraProjectRef = oraProjectRef;
|
||||||
|
Object.assign(this, creationObjectArg);
|
||||||
|
}
|
||||||
|
}
|
@ -9,25 +9,25 @@ export class Ora {
|
|||||||
this.apiToken = apiTokenArg;
|
this.apiToken = apiTokenArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getOrganizations () {
|
public async getOrganizations() {
|
||||||
return await OraOrganization.getAllOrganizations(this);
|
return await OraOrganization.getAllOrganizations(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* make a request
|
* make a request
|
||||||
* @param routeArg
|
* @param routeArg
|
||||||
* @param methodArg
|
* @param methodArg
|
||||||
* @param payloadArg
|
* @param payloadArg
|
||||||
*/
|
*/
|
||||||
public async request (routeArg: string, methodArg: string, payloadArg?: string) {
|
public async request(routeArg: string, methodArg: string, payloadArg?: string) {
|
||||||
const response = await plugins.smartrequest.request(this.apiBase + routeArg, {
|
const response = await plugins.smartrequest.request(this.apiBase + routeArg, {
|
||||||
method: methodArg,
|
method: methodArg,
|
||||||
requestBody: payloadArg,
|
requestBody: payloadArg,
|
||||||
headers: {
|
headers: {
|
||||||
accept: "application/json",
|
accept: 'application/json',
|
||||||
authorization: `Bearer ${this.apiToken}`
|
authorization: `Bearer ${this.apiToken}`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return response.body;
|
return response.body;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,18 @@ export interface IOraOrganization {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class OraOrganization implements IOraOrganization {
|
export class OraOrganization implements IOraOrganization {
|
||||||
|
// ======
|
||||||
|
// STATIC
|
||||||
|
// ======
|
||||||
|
public static async getAllOrganizations(oraRef: Ora): Promise<OraOrganization[]> {
|
||||||
|
const response = await oraRef.request('/organizations', 'GET');
|
||||||
|
const organizations: OraOrganization[] = [];
|
||||||
|
for (const orgData of response.data) {
|
||||||
|
organizations.push(new OraOrganization(oraRef, orgData));
|
||||||
|
}
|
||||||
|
return organizations;
|
||||||
|
}
|
||||||
|
|
||||||
public created_at: string;
|
public created_at: string;
|
||||||
public description: string;
|
public description: string;
|
||||||
public id: number;
|
public id: number;
|
||||||
@ -31,15 +43,6 @@ export class OraOrganization implements IOraOrganization {
|
|||||||
public updated_at: string;
|
public updated_at: string;
|
||||||
public web: string;
|
public web: string;
|
||||||
|
|
||||||
public static async getAllOrganizations(oraRef: Ora): Promise<OraOrganization[]> {
|
|
||||||
const response = await oraRef.request('/organizations', 'GET');
|
|
||||||
const organizations: OraOrganization[] = [];
|
|
||||||
for (const orgData of response.data) {
|
|
||||||
organizations.push(new OraOrganization(oraRef, orgData));
|
|
||||||
}
|
|
||||||
return organizations;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ========
|
// ========
|
||||||
// INSTANCE
|
// INSTANCE
|
||||||
// ========
|
// ========
|
||||||
@ -50,7 +53,7 @@ export class OraOrganization implements IOraOrganization {
|
|||||||
Object.assign(this, creationObjectArg);
|
Object.assign(this, creationObjectArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getAllProjects(): Promise<OraProject[]> {
|
public async getProjects(): Promise<OraProject[]> {
|
||||||
return OraProject.getAllProjectsForOrganization(this);
|
return OraProject.getAllProjectsForOrganization(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import * as plugins from './ora.plugins';
|
import * as plugins from './ora.plugins';
|
||||||
import { Ora } from './ora.classes.ora';
|
import { Ora } from './ora.classes.ora';
|
||||||
import { OraOrganization } from './ora.classes.organization';
|
import { OraOrganization } from './ora.classes.organization';
|
||||||
|
import { OraList } from './ora.classes.list';
|
||||||
|
import { OraMilestone } from './ora.classes.milestone';
|
||||||
|
|
||||||
export interface IOraProject {
|
export interface IOraProject {
|
||||||
archived: boolean;
|
archived: boolean;
|
||||||
@ -29,6 +31,24 @@ export interface IOraProject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class OraProject implements IOraProject {
|
export class OraProject implements IOraProject {
|
||||||
|
// ======
|
||||||
|
// STATIC
|
||||||
|
// ======
|
||||||
|
public static async getAllProjectsForOrganization(oraOrganizationRef: OraOrganization) {
|
||||||
|
const response = await oraOrganizationRef.oraRef.request('/projects', 'GET');
|
||||||
|
const projects: OraProject[] = [];
|
||||||
|
for (const projectData of response.data) {
|
||||||
|
const oraProject = new OraProject(oraOrganizationRef, projectData);
|
||||||
|
if (oraProject.organization_id === oraOrganizationRef.id) {
|
||||||
|
projects.push(oraProject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return projects;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========
|
||||||
|
// INSTANCE
|
||||||
|
// ========
|
||||||
public archived: boolean;
|
public archived: boolean;
|
||||||
public comment_all: number;
|
public comment_all: number;
|
||||||
public commits_visibility: number;
|
public commits_visibility: number;
|
||||||
@ -53,22 +73,17 @@ export class OraProject implements IOraProject {
|
|||||||
public view_title: 'Backlog';
|
public view_title: 'Backlog';
|
||||||
public web: string;
|
public web: string;
|
||||||
|
|
||||||
|
|
||||||
public oraOrganizationRef: OraOrganization;
|
public oraOrganizationRef: OraOrganization;
|
||||||
constructor(oraOrganiazionRefArg: OraOrganization, creationObjectArg: IOraProject) {
|
constructor(oraOrganiazionRefArg: OraOrganization, creationObjectArg: IOraProject) {
|
||||||
this.oraOrganizationRef = oraOrganiazionRefArg;
|
this.oraOrganizationRef = oraOrganiazionRefArg;
|
||||||
Object.assign(this, creationObjectArg);
|
Object.assign(this, creationObjectArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async getAllProjectsForOrganization(oraOrganizationRef: OraOrganization) {
|
public async getLists(): Promise<OraList[]> {
|
||||||
const response = await oraOrganizationRef.oraRef.request('/projects', 'GET');
|
return OraList.getAllLists(this);
|
||||||
const projects: OraProject[] = [];
|
}
|
||||||
for (const projectData of response.data) {
|
|
||||||
const oraProject = new OraProject(oraOrganizationRef, projectData);
|
public async getMileStones(): Promise<OraMilestone[]> {
|
||||||
if (oraProject.organization_id === oraOrganizationRef.id) {
|
return OraMilestone.getAllMilestonesForProject(this);
|
||||||
projects.push(oraProject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return projects;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
100
ts/ora.classes.task.ts
Normal file
100
ts/ora.classes.task.ts
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
import * as plugins from './ora.plugins';
|
||||||
|
import { OraList } from './ora.classes.list';
|
||||||
|
import { OraMilestone } from './ora.classes.milestone';
|
||||||
|
|
||||||
|
export interface IOraTask {
|
||||||
|
milestone_id: number;
|
||||||
|
task_type: number;
|
||||||
|
creator: number;
|
||||||
|
second_id: number;
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
last_picture: string;
|
||||||
|
last_picture_external_url: string;
|
||||||
|
created_at: string;
|
||||||
|
updated_at: string;
|
||||||
|
deadline: string;
|
||||||
|
archived: boolean;
|
||||||
|
color: string;
|
||||||
|
estimated: string;
|
||||||
|
time_tracked: string;
|
||||||
|
public: boolean;
|
||||||
|
state: string;
|
||||||
|
cover_width: number;
|
||||||
|
cover_height: number;
|
||||||
|
checklist: string;
|
||||||
|
comments: number;
|
||||||
|
public_comments: number;
|
||||||
|
likes: number;
|
||||||
|
attachments: number;
|
||||||
|
commits: number;
|
||||||
|
support_tickets: number;
|
||||||
|
value: number;
|
||||||
|
points: number;
|
||||||
|
points_done: number;
|
||||||
|
sprint_id: number;
|
||||||
|
position: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class OraTask implements IOraTask {
|
||||||
|
// ======
|
||||||
|
// STATIC
|
||||||
|
// ======
|
||||||
|
public static async getAllOraTasks(oraListArg: OraList): Promise<OraTask[]> {
|
||||||
|
const response = await oraListArg.oraProjectObjectRef.oraOrganizationRef.oraRef.request(
|
||||||
|
`/projects/${oraListArg.oraProjectObjectRef.id}/lists/${oraListArg.id}/tasks`,
|
||||||
|
'GET'
|
||||||
|
);
|
||||||
|
const oraTasks: OraTask[] = [];
|
||||||
|
for (const dataObject of response.data) {
|
||||||
|
oraTasks.push(new OraTask(oraListArg, dataObject));
|
||||||
|
}
|
||||||
|
return oraTasks;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========
|
||||||
|
// INSTANCE
|
||||||
|
// ========
|
||||||
|
public milestone_id: number;
|
||||||
|
public task_type: number;
|
||||||
|
public creator: number;
|
||||||
|
public second_id: number;
|
||||||
|
public title: string;
|
||||||
|
public description: string;
|
||||||
|
public last_picture: string;
|
||||||
|
public last_picture_external_url: string;
|
||||||
|
public created_at: string;
|
||||||
|
public updated_at: string;
|
||||||
|
public deadline: string;
|
||||||
|
public archived: boolean;
|
||||||
|
public color: string;
|
||||||
|
public estimated: string;
|
||||||
|
public time_tracked: string;
|
||||||
|
public public: boolean;
|
||||||
|
public state: string;
|
||||||
|
public cover_width: number;
|
||||||
|
public cover_height: number;
|
||||||
|
public checklist: string;
|
||||||
|
public comments: number;
|
||||||
|
public public_comments: number;
|
||||||
|
public likes: number;
|
||||||
|
public attachments: number;
|
||||||
|
public commits: number;
|
||||||
|
public support_tickets: number;
|
||||||
|
public value: number;
|
||||||
|
public points: number;
|
||||||
|
public points_done: number;
|
||||||
|
public sprint_id: number;
|
||||||
|
public position: number;
|
||||||
|
|
||||||
|
public oraListRef: OraList;
|
||||||
|
|
||||||
|
constructor(oraListRefArg: OraList, creationObjectArg: IOraTask) {
|
||||||
|
this.oraListRef = oraListRefArg;
|
||||||
|
Object.assign(this, creationObjectArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getMilestone (): Promise<OraMilestone> {
|
||||||
|
return (await this.oraListRef.oraProjectObjectRef.getMileStones()).find(milestoneArg => milestoneArg.id === this.milestone_id);
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,4 @@
|
|||||||
// pushrocks scope
|
// pushrocks scope
|
||||||
import * as smartrequest from '@pushrocks/smartrequest';
|
import * as smartrequest from '@pushrocks/smartrequest';
|
||||||
|
|
||||||
export {
|
export { smartrequest };
|
||||||
smartrequest
|
|
||||||
};
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user