mirror of
https://github.com/turt2live/matrix-dimension.git
synced 2024-10-01 01:05:53 -04:00
Experiment with /repositories
endpoint
This commit is contained in:
parent
256ac0ac9e
commit
bea3850c94
@ -27,7 +27,7 @@ export class DimensionHookshotGithubService {
|
||||
@GET
|
||||
@Path("auth")
|
||||
@Security(ROLE_USER)
|
||||
public async getAuthUrl(): Promise<HookshotGithubAuthUrls> {
|
||||
public async getAuthUrls(): Promise<HookshotGithubAuthUrls> {
|
||||
const userId = this.context.request.user.userId;
|
||||
|
||||
try {
|
||||
@ -41,37 +41,15 @@ export class DimensionHookshotGithubService {
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("orgs")
|
||||
@Path("repos")
|
||||
@Security(ROLE_USER)
|
||||
public async getOrgs(): Promise<{ orgs: HookshotGithubOrg[] }> {
|
||||
public async getUserRepos(): Promise<{ repos: HookshotGithubRepo[] }> {
|
||||
const userId = this.context.request.user.userId;
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("org/:orgId/repos")
|
||||
@Security(ROLE_USER)
|
||||
public async getRepos(@PathParam("orgId") orgId: string): Promise<{ repos: HookshotGithubRepo[] }> {
|
||||
const userId = this.context.request.user.userId;
|
||||
|
||||
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)};
|
||||
return {repos};
|
||||
} catch (e) {
|
||||
LogService.error("DimensionHookshotGithubService", e);
|
||||
throw new ApiError(400, "Error getting repo information", "T2B_MISSING_AUTH");
|
||||
|
@ -33,6 +33,11 @@
|
||||
<div *ngIf="!isBridged && !authUrl && !orgAuthUrl">
|
||||
<label class="label-block">
|
||||
{{'Organization' | translate}}
|
||||
<small *ngIf="orgAddAuthUrl" style="padding-left: 16px">
|
||||
<a [href]="orgAddAuthUrl" rel="noopener" target="_blank">
|
||||
{{'Add to another GitHub organization' | translate}}
|
||||
</a>
|
||||
</small>
|
||||
<select class="form-control form-control-sm" [(ngModel)]="orgId"
|
||||
(change)="loadRepos()" [disabled]="isBusy">
|
||||
<option *ngFor="let org of orgs" [ngValue]="org">
|
||||
|
@ -3,7 +3,7 @@ import { BridgeComponent } from "../bridge.component";
|
||||
import { ScalarClientApiService } from "../../../shared/services/scalar/scalar-client-api.service";
|
||||
import { DomSanitizer, SafeUrl } from "@angular/platform-browser";
|
||||
import { TranslateService } from "@ngx-translate/core";
|
||||
import { FE_HookshotGithubConnection } from "../../../shared/models/hookshot_github";
|
||||
import { FE_HookshotGithubConnection, FE_HookshotGithubRepo } from "../../../shared/models/hookshot_github";
|
||||
import { HookshotGithubApiService } from "../../../shared/services/integrations/hookshot-github-api.service";
|
||||
|
||||
interface HookshotConfig {
|
||||
@ -22,14 +22,18 @@ export class HookshotGithubBridgeConfigComponent extends BridgeComponent<Hooksho
|
||||
public orgAuthUrl: SafeUrl;
|
||||
public loadingConnections = true;
|
||||
public bridgedRepoSlug: string;
|
||||
public orgEditAuthUrl: SafeUrl;
|
||||
public orgAddAuthUrl: SafeUrl;
|
||||
|
||||
public orgs: string[] = [];
|
||||
public orgId: string;
|
||||
|
||||
public repos: string[] = []; // for org
|
||||
public repos: string[] = [];
|
||||
public repoId: string;
|
||||
|
||||
private timerId: any;
|
||||
private orgToRepoMap: Record<string, FE_HookshotGithubRepo[]> = {};
|
||||
private limitedOrgs: string[] = [];
|
||||
|
||||
constructor(private hookshot: HookshotGithubApiService, private scalar: ScalarClientApiService, private sanitizer: DomSanitizer, public translate: TranslateService) {
|
||||
super("hookshot_github", translate);
|
||||
@ -41,6 +45,10 @@ export class HookshotGithubBridgeConfigComponent extends BridgeComponent<Hooksho
|
||||
|
||||
this.loadingConnections = true;
|
||||
this.tryLoadOrgs();
|
||||
|
||||
this.hookshot.getAuthUrls().then(urls => {
|
||||
this.orgAddAuthUrl = this.sanitizer.bypassSecurityTrustResourceUrl(urls.orgUrl);
|
||||
});
|
||||
}
|
||||
|
||||
private tryOrgAuth() {
|
||||
@ -54,7 +62,7 @@ export class HookshotGithubBridgeConfigComponent extends BridgeComponent<Hooksho
|
||||
}
|
||||
|
||||
private tryLoadOrgs() {
|
||||
this.hookshot.getOrgs().then(r => {
|
||||
this.hookshot.getKnownRepos().then(r => {
|
||||
this.authUrl = null;
|
||||
|
||||
if (r.length <= 0) {
|
||||
@ -62,7 +70,16 @@ export class HookshotGithubBridgeConfigComponent extends BridgeComponent<Hooksho
|
||||
return;
|
||||
}
|
||||
|
||||
this.orgs = r.map(o => o.name);
|
||||
this.orgToRepoMap = {};
|
||||
for (const repo of r) {
|
||||
if (!this.orgToRepoMap[repo.owner]) {
|
||||
this.orgToRepoMap[repo.owner] = [];
|
||||
}
|
||||
this.orgToRepoMap[repo.owner].push(repo);
|
||||
console.log(repo);
|
||||
}
|
||||
|
||||
this.orgs = Object.keys(this.orgToRepoMap);
|
||||
this.orgId = this.orgs[0];
|
||||
this.orgAuthUrl = null;
|
||||
this.loadRepos();
|
||||
@ -92,24 +109,16 @@ export class HookshotGithubBridgeConfigComponent extends BridgeComponent<Hooksho
|
||||
|
||||
public loadRepos() {
|
||||
this.isBusy = true;
|
||||
this.hookshot.getRepos(this.orgId).then(repos => {
|
||||
this.repos = repos.map(r => r.name);
|
||||
this.repoId = this.repos[0];
|
||||
this.repos = this.orgToRepoMap[this.orgId].map(r => r.name);
|
||||
this.repoId = this.repos[0];
|
||||
|
||||
if (this.isBridged) {
|
||||
const conn = this.bridge.config.connections[0].config;
|
||||
this.bridgedRepoSlug = `${conn.org}/${conn.repo}`;
|
||||
}
|
||||
if (this.isBridged) {
|
||||
const conn = this.bridge.config.connections[0].config;
|
||||
this.bridgedRepoSlug = `${conn.org}/${conn.repo}`;
|
||||
}
|
||||
|
||||
this.isBusy = false;
|
||||
this.loadingConnections = false;
|
||||
}).catch(e => {
|
||||
console.error(e);
|
||||
this.isBusy = false;
|
||||
this.translate.get('Error getting Github information').subscribe((res: string) => {
|
||||
this.toaster.pop("error", res);
|
||||
});
|
||||
});
|
||||
this.isBusy = false;
|
||||
this.loadingConnections = false;
|
||||
}
|
||||
|
||||
public get isBridged(): boolean {
|
||||
@ -132,6 +141,8 @@ export class HookshotGithubBridgeConfigComponent extends BridgeComponent<Hooksho
|
||||
}
|
||||
}
|
||||
|
||||
await this.scalar.setUserPowerLevel(this.roomId, this.bridge.config.botUserId, 50);
|
||||
|
||||
this.hookshot.bridgeRoom(this.roomId, this.orgId, this.repoId).then(conn => {
|
||||
this.bridge.config.connections.push(conn);
|
||||
this.isBusy = false;
|
||||
|
@ -14,11 +14,6 @@ export interface FE_HookshotGithubConnection {
|
||||
};
|
||||
}
|
||||
|
||||
export interface FE_HookshotGithubOrg {
|
||||
name: string;
|
||||
avatarUrl: string;
|
||||
}
|
||||
|
||||
export interface FE_HookshotGithubRepo {
|
||||
name: string;
|
||||
owner: string;
|
||||
|
@ -4,7 +4,6 @@ import { HttpClient } from "@angular/common/http";
|
||||
import {
|
||||
FE_HookshotGithubAuthUrls,
|
||||
FE_HookshotGithubConnection,
|
||||
FE_HookshotGithubOrg,
|
||||
FE_HookshotGithubRepo
|
||||
} from "../../models/hookshot_github";
|
||||
|
||||
@ -29,11 +28,7 @@ export class HookshotGithubApiService extends AuthedApi {
|
||||
return this.authedGet<FE_HookshotGithubAuthUrls>("/api/v1/dimension/hookshot/github/auth").toPromise();
|
||||
}
|
||||
|
||||
public getOrgs(): Promise<FE_HookshotGithubOrg[]> {
|
||||
return this.authedGet("/api/v1/dimension/hookshot/github/orgs").toPromise().then(r => r['orgs']);
|
||||
}
|
||||
|
||||
public getRepos(orgId: string): Promise<FE_HookshotGithubRepo[]> {
|
||||
return this.authedGet("/api/v1/dimension/hookshot/github/org/" + orgId + "/repos").toPromise().then(r => r['repos']);
|
||||
public getKnownRepos(): Promise<FE_HookshotGithubRepo[]> {
|
||||
return this.authedGet("/api/v1/dimension/hookshot/github/repos").toPromise().then(r => r['repos']);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user