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[] }> {
|
public async getOrgs(): Promise<{ orgs: HookshotGithubOrg[] }> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
|
|
||||||
|
try {
|
||||||
const hookshot = new HookshotGithubBridge(userId);
|
const hookshot = new HookshotGithubBridge(userId);
|
||||||
const userInfo = await hookshot.getLoggedInUserInfo();
|
const userInfo = await hookshot.getLoggedInUserInfo();
|
||||||
if (!userInfo.loggedIn) {
|
if (!userInfo.loggedIn) {
|
||||||
throw new ApiError(403, "Not logged in", "T2B_NOT_LOGGED_IN");
|
throw new ApiError(403, "Not logged in", "T2B_NOT_LOGGED_IN");
|
||||||
}
|
}
|
||||||
return {orgs: userInfo.organisations};
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@ -60,9 +67,15 @@ export class DimensionHookshotGithubService {
|
|||||||
public async getRepos(@PathParam("orgId") orgId: string): Promise<{ repos: HookshotGithubRepo[] }> {
|
public async getRepos(@PathParam("orgId") orgId: string): Promise<{ repos: HookshotGithubRepo[] }> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
|
|
||||||
|
try {
|
||||||
const hookshot = new HookshotGithubBridge(userId);
|
const hookshot = new HookshotGithubBridge(userId);
|
||||||
const repos = await hookshot.getRepos(orgId);
|
// const repos = await hookshot.getRepos(orgId);
|
||||||
return {repos};
|
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
|
@POST
|
||||||
|
@ -53,9 +53,28 @@ export class HookshotGithubBridge extends HookshotBridge {
|
|||||||
const res = await this.doProvisionRequest<HookshotGithubRepo[]>(bridge, "GET", `/v1/github/orgs/${orgId}/repositories`, {
|
const res = await this.doProvisionRequest<HookshotGithubRepo[]>(bridge, "GET", `/v1/github/orgs/${orgId}/repositories`, {
|
||||||
page,
|
page,
|
||||||
perPage,
|
perPage,
|
||||||
});
|
}).then(r => r['repositories']);
|
||||||
results.push(...res);
|
results.push(...res);
|
||||||
if (res.length < perPage) more = false;
|
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);
|
} while(more);
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
@ -43,19 +43,22 @@ export class HookshotGithubBridgeConfigComponent extends BridgeComponent<Hooksho
|
|||||||
this.tryLoadOrgs();
|
this.tryLoadOrgs();
|
||||||
}
|
}
|
||||||
|
|
||||||
private tryLoadOrgs() {
|
private tryOrgAuth() {
|
||||||
this.hookshot.getOrgs().then(r => {
|
|
||||||
this.authUrl = null;
|
|
||||||
|
|
||||||
if (r.length <= 0) {
|
|
||||||
this.hookshot.getAuthUrls().then(urls => {
|
this.hookshot.getAuthUrls().then(urls => {
|
||||||
console.log(urls);
|
|
||||||
this.orgAuthUrl = this.sanitizer.bypassSecurityTrustResourceUrl(urls.orgUrl);
|
this.orgAuthUrl = this.sanitizer.bypassSecurityTrustResourceUrl(urls.orgUrl);
|
||||||
this.loadingConnections = false;
|
this.loadingConnections = false;
|
||||||
this.timerId = setTimeout(() => {
|
this.timerId = setTimeout(() => {
|
||||||
this.tryLoadOrgs();
|
this.tryLoadOrgs();
|
||||||
}, 1000);
|
}, 1000);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private tryLoadOrgs() {
|
||||||
|
this.hookshot.getOrgs().then(r => {
|
||||||
|
this.authUrl = null;
|
||||||
|
|
||||||
|
if (r.length <= 0) {
|
||||||
|
this.tryOrgAuth();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,6 +79,8 @@ export class HookshotGithubBridgeConfigComponent extends BridgeComponent<Hooksho
|
|||||||
this.tryLoadOrgs();
|
this.tryLoadOrgs();
|
||||||
}, 1000);
|
}, 1000);
|
||||||
});
|
});
|
||||||
|
} else if (e.status === 400 && e.error.dim_errcode === "T2B_MISSING_AUTH") {
|
||||||
|
this.tryOrgAuth();
|
||||||
} else {
|
} else {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
this.translate.get('Error getting Github information').subscribe((res: string) => {
|
this.translate.get('Error getting Github information').subscribe((res: string) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user