Skip to content

Commit

Permalink
Release/2.0.2 (#78)
Browse files Browse the repository at this point in the history
* Hotfix/create project and team (#74)

Changes:
- move nluId and nluVisibility to parent object
- create team error namespace
- switch team error
- add/remove member to team

* Update cmd pull with revision (#76)

* Add versionType (major|minor|patch) when create-deployment (#75)

* Bump version to 2.0.2

* Modify CHANGELOGS

* Fix date in changelog
  • Loading branch information
prakashdivyy authored Dec 13, 2018
1 parent 1fd3c62 commit c5cb1df
Show file tree
Hide file tree
Showing 14 changed files with 228 additions and 107 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ coverage
typings
.nyc_output
*.map
.env
.env
*.yml
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# CHANGELOG
## [2.0.2] - 2018/12/13
### Fixed :
- Switch team error
- Create team error namespace
- Add or remove member to team

### Added :
- Pull with revision
- Version type when create-deployment

## [2.0.1] - 2018/12/05
### Fixed :
- Fix .gitignore
Expand Down
74 changes: 47 additions & 27 deletions components/bots/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,38 +380,58 @@ export default class Bot extends Component {
throw new Error("Sync only accept promises");
}

public async pull(name: string, version: string, options: JsonObject) {
let isGettingBot = false;
public async pull(revision: string, options: JsonObject) {

let projectId;
let bots;
let botDesc;

try {
const { data, response } = await this.helper.toPromise(this.api.botApi, this.api.botApi.botsGet, {});
let found = false;
let selectedBot: any;
for (const bot of data.items) {
const botName = bot.name;
if (botName === name) {
found = true;
selectedBot = bot;
break;
}
}
if (found) {
// Get specific bot version
isGettingBot = true;
const botId = selectedBot.id + ":" + version;
const getBot = await this.helper.toPromise(this.api.botApi, this.api.botApi.botsBotIdGet, botId);
const botDesc = getBot.data;
this.helper.dumpYaml("./bot.yml", botDesc);
console.log(`SUCCESS PULL BOT ${name} WITH VERSION ${version}`);
} else {
console.log(`BOT NOT FOUND`);
projectId = this.getProject();
} catch (e) {
console.log(this.helper.wrapError(e));
return;
}
try {
const { response: { body } } = await this.helper.toPromise(
this.api.botApi, this.api.botApi.projectsProjectIdBotRevisionsGet, projectId);
bots = body.data;

} catch (e) {
console.log("INVALID PROJECT");
return;
}
try {
if (!revision) {
revision = bots[0].revision;
}
const { response: { body } } = await this.helper.toPromise(
this.api.botApi, this.api.botApi.projectsProjectIdBotRevisionsRevisionGet, projectId, revision);
botDesc = body;

} catch (e) {
if (isGettingBot) {
console.log(`CANNOT PULL BOT ${name} WITH VERSION ${version}`);
} else {
console.log(this.helper.wrapError(e));
console.log("INVALID PROJECT REVISION");
return;
}

// remove data
delete botDesc.id;
delete botDesc.revision;
delete botDesc.changelog;
for (const flow in botDesc.flows) {
if (botDesc.flows[flow]) {
for (const state in botDesc.flows[flow].states) {
if (botDesc.flows[flow].states[state]) {
delete botDesc.flows[flow].states[state].style;
}
}
}
}

console.log(`Pull bot revision ${revision.substring(0, 6)} to bot.yml`);
this.helper.dumpYaml("./bot.yml", botDesc);

return;
}

private getProject() {
Expand Down
22 changes: 17 additions & 5 deletions components/bots/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ export default class Deployment {
constructor(private helper: IHelper, private api: any) {
}

public async create() {
public async create(versionType?: string) {
const projectId = this.helper.getProjectId();
const { response: { body: project } } = await this.helper.toPromise(
this.api.projectApi, this.api.projectApi.projectsProjectIdGet,
projectId
);

// TODO: {page:1, limit:1}
let botRevision: string;
let nluRevision: string;
Expand Down Expand Up @@ -53,13 +52,26 @@ export default class Deployment {
}

let targetVersion;

try {
// get previous deployment version
const { response: { body: latestDeployment } } = await this.helper.toPromise(this.api.projectApi,
this.api.projectApi.projectsProjectIdDeploymentGet, projectId);
const prevVersion = latestDeployment.version;
const [major, minor, patch] = prevVersion.split(".");
const updatedPatch = Number(patch) + 1;
targetVersion = `${major}.${minor}.${updatedPatch}`;
let [major, minor, patch] = prevVersion.split(".");

if (versionType === "major") {
major = Number(major) + 1;
minor = 0;
patch = 0;
} else if (versionType === "minor") {
minor = Number(minor) + 1;
patch = 0;
} else {
patch = Number(patch) + 1;
}
targetVersion = `${major}.${minor}.${patch}`;

} catch (e) {
targetVersion = "0.0.1";
}
Expand Down
2 changes: 1 addition & 1 deletion components/projects/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default class Project {
delete nluOptions.privateNlu;
}

const requestBody = { ...projectData, options: { ...options, nluOptions } };
const requestBody = { ...projectData, options: { ...options, ...nluOptions } };

try {
const { response } = await this.helper.toPromise(
Expand Down
51 changes: 38 additions & 13 deletions components/users/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ export default class Team extends Component {
if (this.checkUser(userInfo.id, teamMember)) {
throw new Error(`User ${username} already on this team`);
}

const { response } = await this.helper.toPromise(this.api.teamApi, this.api.teamApi.teamsTeamIdUsersUserIdPost, teamInfo.data.id, userInfo.id, { roleId: role } );
const { response } = await this.helper.toPromise(this.api.teamApi, this.api.teamApi.teamsTeamIdUsersUserIdPost, teamInfo.id, userInfo.id, { roleId: role } );
if (!response.body) {
throw new Error("Error adding user to team: invalid roleId");
}
Expand All @@ -31,7 +30,7 @@ export default class Team extends Component {
}
}

public async removeMember(username : string) {
public async removeMember(username: string) {
const answer = await this.helper.inquirerPrompt([
{
type: "confirm",
Expand All @@ -52,7 +51,7 @@ export default class Team extends Component {
throw new Error(`User ${username} not a member of this team`);
}

const { response } = await this.helper.toPromise(this.api.teamApi, this.api.teamApi.teamsTeamIdUsersUserIdDelete, teamInfo.data.id, userInfo.id);
const { response } = await this.helper.toPromise(this.api.teamApi, this.api.teamApi.teamsTeamIdUsersUserIdDelete, teamInfo.id, userInfo.id);

console.log(`Success remove ${username} from ${currentLogin}`);
} else {
Expand All @@ -64,28 +63,54 @@ export default class Team extends Component {
}
}

private async getInfo(username : string) {
private async getInfo(username: string) {
const currentLogin = this.helper.getProp("current_login") as string;
const currentUserType = this.helper.getProp("current_user_type") as string;

if (currentUserType !== "team") {
throw new Error("Must be on team to do this operation");
}

const requestTeamData =
await this.helper.toPromise(this.api.userApi, this.api.userApi.usersUserIdGet, currentLogin);

let teamInfo: any;
if (requestTeamData.response && requestTeamData.response.body) {
teamInfo = requestTeamData.response.body;
} else {
throw new Error("Cannot add user to team");
}

const team = await this.helper.toPromise(this.api.userApi, this.api.userApi.usersUserIdGet, currentLogin);
const { data } = await this.helper.toPromise(this.api.userApi, this.api.userApi.usersUserIdGet, username);
const member = await this.helper.toPromise(this.api.teamApi, this.api.teamApi.teamsTeamIdUsersGet, team.data.id);
const requestUserData =
await this.helper.toPromise(this.api.userApi, this.api.userApi.usersUserIdGet, username);

let userInfo: any;
if (requestUserData && requestUserData.response) {
userInfo = requestUserData.response.body;
} else {
throw new Error("Cannot add user to team");
}

const requestTeamMember =
await this.helper.toPromise(this.api.teamApi, this.api.teamApi.teamsTeamIdUsersGet, teamInfo.id);

let teamMember: any[];
if (requestTeamMember && requestTeamMember.response) {
teamMember = requestTeamMember.response.body;
} else {
throw new Error("Cannot add user to team");
}

return {
teamInfo: team,
userInfo: data,
teamMember: member,
teamInfo,
userInfo,
teamMember,
currentLogin
};
}

private checkUser(userId : string, member : any) : boolean {
const teamMember = member.response.body.map((x : JsonObject) => x.userId);
private checkUser(userId: string, member: any[]): boolean {
const teamMember = member.map((x: JsonObject) => x.userId);
if (teamMember.indexOf(userId) > -1) {
return true;
}
Expand Down
19 changes: 12 additions & 7 deletions components/users/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,22 @@ export default class User extends Component {
try {
const firstLogin = this.helper.getProp("first_login") as JsonObject;
const currentType = this.helper.getProp("current_user_type");
const currentLogin = this.helper.getProp("current_login");
const username = name ? name : currentLogin;

if (currentType === type) {
throw new Error(`Unable to switch : already on ${type}`);
if (currentType === type && username === currentLogin) {
throw new Error(`Unable to switch : already on ${currentLogin} ${type}`);
}


if (type === "team") {
const info = await this.helper.toPromise(this.api.userApi, this.api.userApi.usersUserIdGet, firstLogin.id);
const teams = info ? info.data.teams.filter((team: any) => team.username === name) : [];
const { response } = await this.helper.toPromise(this.api.userApi, this.api.userApi.usersUserIdGet, firstLogin.id);

if (!response) {
throw new Error("Unable to switch team");
}

const teams = response && response.body ? response.body.teams.filter((team: any) => team.username === name) : [];
if (teams.length > 0) {
const result = await this.helper.toPromise(this.api.authApi, this.api.authApi.tokensPost, { type: "team", teamId: teams[0].teamId });
const token = result.data.id;
Expand Down Expand Up @@ -187,9 +195,6 @@ export default class User extends Component {
const { response } = await this.helper.toPromise(this.api.teamApi, this.api.teamApi.teamsPost, { username: name, password: "", roleId: "teamAdmin" });

if (response && response.body.id) {
const { data } = await this.helper.toPromise(this.api.userApi, this.api.userApi.usersUserIdGet, currentLogin);
const result = await this.helper.toPromise(this.api.teamApi, this.api.teamApi.teamsTeamIdUsersUserIdPost, response.body.id, data.id, { roleId: "teamAdmin" });

console.log(`Team ${name} created !`);
} else {
console.log(`Team ${name} exist !`);
Expand Down
69 changes: 40 additions & 29 deletions lib/components/bots/bot.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c5cb1df

Please sign in to comment.