mirror of
https://github.com/turt2live/matrix-dimension.git
synced 2024-10-01 01:05:53 -04:00
Hacky re-wire to /repositories
to test bridge theory
This commit is contained in:
parent
9ab6c8f3f2
commit
256ac0ac9e
@ -46,12 +46,19 @@ export class DimensionHookshotGithubService {
|
||||
public async getOrgs(): Promise<{ orgs: HookshotGithubOrg[] }> {
|
||||
const userId = this.context.request.user.userId;
|
||||
|
||||
const hookshot = new HookshotGithubBridge(userId);
|
||||
const userInfo = await hookshot.getLoggedInUserInfo();
|
||||
if (!userInfo.loggedIn) {
|
||||
throw new ApiError(403, "Not logged in", "T2B_NOT_LOGGED_IN");
|
||||
try {
|
||||
const hookshot = new HookshotGithubBridge(userId);
|
||||
const userInfo = await hookshot.getLoggedInUserInfo();
|
||||
if (!userInfo.loggedIn) {
|
||||
throw new ApiError(403, "Not logged in", "T2B_NOT_LOGGED_IN");
|
||||
}
|
||||
const repos = await hookshot.getInstalledRepos();
|
||||
const orgs = Array.from(new Set(repos.map(r => r.owner))).map(o => ({ name: o, avatarUrl: null }));
|
||||
return { orgs: orgs }; // was from userInfo
|
||||
} catch (e) {
|
||||
LogService.error("DimensionHookshotGithubService", e);
|
||||
throw new ApiError(400, "Error getting org information", "T2B_MISSING_AUTH");
|
||||
}
|
||||
return {orgs: userInfo.organisations};
|
||||
}
|
||||
|
||||
@GET
|
||||
@ -60,9 +67,15 @@ export class DimensionHookshotGithubService {
|
||||
public async getRepos(@PathParam("orgId") orgId: string): Promise<{ repos: HookshotGithubRepo[] }> {
|
||||
const userId = this.context.request.user.userId;
|
||||
|
||||
const hookshot = new HookshotGithubBridge(userId);
|
||||
const repos = await hookshot.getRepos(orgId);
|
||||
return {repos};
|
||||
try {
|
||||
const hookshot = new HookshotGithubBridge(userId);
|
||||
// const repos = await hookshot.getRepos(orgId);
|
||||
const repos = await hookshot.getInstalledRepos();
|
||||
return {repos: repos.filter(r => r.owner === orgId)};
|
||||
} catch (e) {
|
||||
LogService.error("DimensionHookshotGithubService", e);
|
||||
throw new ApiError(400, "Error getting repo information", "T2B_MISSING_AUTH");
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
|
@ -53,9 +53,28 @@ export class HookshotGithubBridge extends HookshotBridge {
|
||||
const res = await this.doProvisionRequest<HookshotGithubRepo[]>(bridge, "GET", `/v1/github/orgs/${orgId}/repositories`, {
|
||||
page,
|
||||
perPage,
|
||||
});
|
||||
}).then(r => r['repositories']);
|
||||
results.push(...res);
|
||||
if (res.length < perPage) more = false;
|
||||
page++;
|
||||
} while(more);
|
||||
return results;
|
||||
}
|
||||
|
||||
public async getInstalledRepos(): Promise<HookshotGithubRepo[]> {
|
||||
const bridge = await this.getDefaultBridge();
|
||||
const results: HookshotGithubRepo[] = [];
|
||||
let more = true;
|
||||
let page = 1;
|
||||
let perPage = 10;
|
||||
do {
|
||||
const res = await this.doProvisionRequest<HookshotGithubRepo[]>(bridge, "GET", `/v1/github/repositories`, {
|
||||
page,
|
||||
perPage,
|
||||
}).then(r => r['repositories']);
|
||||
results.push(...res);
|
||||
if (res.length < perPage) more = false;
|
||||
page++;
|
||||
} while(more);
|
||||
return results;
|
||||
}
|
||||
|
@ -43,19 +43,22 @@ export class HookshotGithubBridgeConfigComponent extends BridgeComponent<Hooksho
|
||||
this.tryLoadOrgs();
|
||||
}
|
||||
|
||||
private tryOrgAuth() {
|
||||
this.hookshot.getAuthUrls().then(urls => {
|
||||
this.orgAuthUrl = this.sanitizer.bypassSecurityTrustResourceUrl(urls.orgUrl);
|
||||
this.loadingConnections = false;
|
||||
this.timerId = setTimeout(() => {
|
||||
this.tryLoadOrgs();
|
||||
}, 1000);
|
||||
});
|
||||
}
|
||||
|
||||
private tryLoadOrgs() {
|
||||
this.hookshot.getOrgs().then(r => {
|
||||
this.authUrl = null;
|
||||
|
||||
if (r.length <= 0) {
|
||||
this.hookshot.getAuthUrls().then(urls => {
|
||||
console.log(urls);
|
||||
this.orgAuthUrl = this.sanitizer.bypassSecurityTrustResourceUrl(urls.orgUrl);
|
||||
this.loadingConnections = false;
|
||||
this.timerId = setTimeout(() => {
|
||||
this.tryLoadOrgs();
|
||||
}, 1000);
|
||||
});
|
||||
this.tryOrgAuth();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -76,6 +79,8 @@ export class HookshotGithubBridgeConfigComponent extends BridgeComponent<Hooksho
|
||||
this.tryLoadOrgs();
|
||||
}, 1000);
|
||||
});
|
||||
} else if (e.status === 400 && e.error.dim_errcode === "T2B_MISSING_AUTH") {
|
||||
this.tryOrgAuth();
|
||||
} else {
|
||||
console.error(e);
|
||||
this.translate.get('Error getting Github information').subscribe((res: string) => {
|
||||
|
Loading…
Reference in New Issue
Block a user