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

Up to 3.11.1 #1998

Merged
merged 2 commits into from
Mar 22, 2024
Merged
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
2 changes: 1 addition & 1 deletion application/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chipmunk",
"version": "3.11.0",
"version": "3.11.1",
"description": "Logs analyzer tool",
"author": "Dmitry Astafyev",
"scripts": {
Expand Down
159 changes: 95 additions & 64 deletions application/client/src/app/service/session/dependencies/teamwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,32 +67,62 @@ export class TeamWork extends Subscriber {
comments: comments,
});
}
protected async load(): Promise<void> {
try {
const repos = await Requests.IpcRequest.send(
Requests.GitHub.GetRepos.Response,
new Requests.GitHub.GetRepos.Request(),
);
const active = await Requests.IpcRequest.send(
Requests.GitHub.GetActive.Response,
new Requests.GitHub.GetActive.Request(),
);
this.repos.clear();
repos.repos.forEach((repo: GitHubRepo) => {
this.repos.set(repo.uuid, repo);
});
if (active.uuid !== undefined) {
this.active.repo = this.repos.get(active.uuid);
}
if (this.active.repo !== undefined) {
this.user().reload();
}
this.subjects.get().loaded.emit();
this.subjects.get().active.emit(this.active.repo);
this.file().check();
} catch (err) {
this.error().add(`Fail to load available GitHub references: ${utils.error(err)}`);
}
protected loading(): {
repos(): Promise<void>;
active(): Promise<void>;
} {
return {
repos: async (): Promise<void> => {
try {
const repos = await Requests.IpcRequest.send(
Requests.GitHub.GetRepos.Response,
new Requests.GitHub.GetRepos.Request(),
);
const active = await Requests.IpcRequest.send(
Requests.GitHub.GetActive.Response,
new Requests.GitHub.GetActive.Request(),
);
this.repos.clear();
repos.repos.forEach((repo: GitHubRepo) => {
this.repos.set(repo.uuid, repo);
});
if (active.uuid !== undefined) {
this.active.repo = this.repos.get(active.uuid);
}
await this.loading().active();
} catch (err) {
this.error().add(
`Fail to load available GitHub references: ${utils.error(err)}`,
);
}
},
active: (): Promise<void> => {
return new Promise((resolve) => {
const active = this.active.repo;
if (active === undefined) {
this.active.username = undefined;
this.subjects.get().loaded.emit();
this.subjects.get().username.emit(this.active.username);
this.subjects.get().active.emit(active);
return resolve();
}
this.user()
.reload()
.catch((err: Error) => {
this.log().error(`Fail to reload user: ${err}`);
this.error().add(`Fail to reload user: ${err}`);
})
.then(() => {
this.file().check();
})
.finally(() => {
this.subjects.get().loaded.emit();
this.subjects.get().active.emit(active);
resolve();
});
});
},
};
}

protected metadata(): {
Expand Down Expand Up @@ -295,9 +325,11 @@ export class TeamWork extends Subscriber {
public init(session: Session) {
this.setLoggerName(`TeamWork: ${cutUuid(session.uuid())}`);
this.session = session;
this.load().catch((err: Error) => {
this.error().add(`Loading error: ${err.message}`);
});
this.loading()
.repos()
.catch((err: Error) => {
this.error().add(`Loading error: ${err.message}`);
});

this.register(
Events.IpcEvent.subscribe(
Expand Down Expand Up @@ -411,9 +443,7 @@ export class TeamWork extends Subscriber {
this.error().add(`Fail to save active: ${response.error}`);
} else {
this.active.repo = repo;
this.subjects.get().active.emit(repo);
this.file().check();
this.user().reload();
this.loading().active();
}
})
.catch((err: Error) => {
Expand All @@ -424,29 +454,29 @@ export class TeamWork extends Subscriber {
return this.active.repo;
},
create: (repo: GitHubRepo): Promise<void> => {
return Requests.IpcRequest.send(
Requests.GitHub.AddRepo.Response,
new Requests.GitHub.AddRepo.Request(repo),
)
.then((response: Requests.GitHub.AddRepo.Response) => {
if (response.error !== undefined) {
this.error().add(`Fail to add new repo: ${response.error}`);
return Promise.reject(new Error(response.error));
}
if (response.uuid === undefined) {
return Promise.reject(new Error(`No uuid for added repo`));
}
repo.uuid = response.uuid;
this.active.repo = repo;
this.repos.set(repo.uuid, repo);
this.subjects.get().loaded.emit();
this.subjects.get().active.emit(this.active.repo);
this.file().check();
return Promise.resolve();
})
.catch((err: Error) => {
this.error().add(`Fail to add new GitHub references: ${err.message}`);
});
return new Promise((resolve, reject) => {
Requests.IpcRequest.send(
Requests.GitHub.AddRepo.Response,
new Requests.GitHub.AddRepo.Request(repo),
)
.then((response: Requests.GitHub.AddRepo.Response) => {
if (response.error !== undefined) {
this.error().add(`Fail to add new repo: ${response.error}`);
return reject(new Error(response.error));
}
if (response.uuid === undefined) {
return reject(new Error(`No uuid for added repo`));
}
repo.uuid = response.uuid;
this.active.repo = repo;
this.repos.set(repo.uuid, repo);
this.loading().active().finally(resolve);
})
.catch((err: Error) => {
this.error().add(`Fail to add new GitHub references: ${err.message}`);
reject(err);
});
});
},
update: (repo: GitHubRepo): Promise<void> => {
if (!this.repos.has(repo.uuid)) {
Expand All @@ -464,10 +494,11 @@ export class TeamWork extends Subscriber {
this.repos.set(repo.uuid, repo);
if (this.active.repo !== undefined && this.active.repo.uuid !== undefined) {
this.active.repo = repo;
this.user().reload();
return this.loading().active();
} else {
this.subjects.get().loaded.emit();
return Promise.resolve();
}
this.subjects.get().loaded.emit();
return Promise.resolve();
})
.catch((err: Error) => {
this.error().add(`Fail to update GitHub references: ${err.message}`);
Expand All @@ -489,28 +520,28 @@ export class TeamWork extends Subscriber {
this.error().add(`Fail to remove new repo: ${response.error}`);
return Promise.reject(new Error(response.error));
}
return this.load();
return this.loading().repos();
})
.catch((err: Error) => {
this.error().add(`Fail to update GitHub references: ${err.message}`);
});
},
reload: (): Promise<void> => {
return this.load();
return this.loading().repos();
},
};
}

public user(): {
reload(): void;
reload(): Promise<void>;
get(): string | undefined;
} {
return {
reload: (): void => {
reload: (): Promise<void> => {
if (this.active.repo === undefined || this.destroyed) {
return;
return Promise.reject(new Error(`No active repo selected`));
}
Requests.IpcRequest.send(
return Requests.IpcRequest.send(
Requests.GitHub.GetUserName.Response,
new Requests.GitHub.GetUserName.Request(),
)
Expand Down
2 changes: 1 addition & 1 deletion application/holder/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chipmunk",
"version": "3.11.0",
"version": "3.11.1",
"chipmunk": {
"versions": {}
},
Expand Down
6 changes: 4 additions & 2 deletions application/holder/src/service/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,15 +436,17 @@ export class Service extends Implementation {
);
} else {
const uuid = unique();
this.repos.set(uuid, {
const repo = {
uuid,
repo: request.repo,
owner: request.owner,
token: request.token,
branch: request.branch,
settings: request.settings,
});
};
this.repos.set(uuid, repo);
this.storage().save();
this.active = repo;
resolve(new Requests.GitHub.AddRepo.Response({ uuid }));
}
});
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 3.11.1 (22.03.2024)

## Fixes
- Fix create/update/change repo issue in context of Teamwork feature

# 3.11.0 (22.03.2024)

## Fixes
Expand Down
Loading