Skip to content

Commit

Permalink
Merge pull request #6995 from ever-co/fix/#6823-github-2-way-sync
Browse files Browse the repository at this point in the history
Fix :: #6823 Project Setting (DTO & Migrations)
  • Loading branch information
evereq authored Oct 14, 2023
2 parents 03258ab + d620425 commit 923e7ea
Show file tree
Hide file tree
Showing 32 changed files with 375 additions and 204 deletions.
6 changes: 2 additions & 4 deletions .scripts/configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ if (!env.IS_DOCKER) {
JITSU_BROWSER_WRITE_KEY: '${env.JITSU_BROWSER_WRITE_KEY}',
GAUZY_GITHUB_APP_NAME: '${env.GAUZY_GITHUB_APP_NAME}',
GAUZY_GITHUB_APP_ID: '${env.GAUZY_GITHUB_APP_ID}',
GAUZY_GITHUB_CLIENT_ID: '${env.GAUZY_GITHUB_CLIENT_ID}',
GAUZY_GITHUB_REDIRECT_URL: '${env.GAUZY_GITHUB_REDIRECT_URL}',
GAUZY_GITHUB_POST_INSTALL_URL: '${env.GAUZY_GITHUB_POST_INSTALL_URL}',
Expand Down Expand Up @@ -260,7 +259,6 @@ if (!env.IS_DOCKER) {
JITSU_BROWSER_WRITE_KEY: 'DOCKER_JITSU_BROWSER_WRITE_KEY',
GAUZY_GITHUB_APP_NAME: 'DOCKER_GAUZY_GITHUB_APP_NAME',
GAUZY_GITHUB_APP_ID: 'DOCKER_GAUZY_GITHUB_APP_ID',
GAUZY_GITHUB_CLIENT_ID: 'DOCKER_GAUZY_GITHUB_CLIENT_ID',
GAUZY_GITHUB_REDIRECT_URL: 'DOCKER_GAUZY_GITHUB_REDIRECT_URL',
GAUZY_GITHUB_POST_INSTALL_URL: 'DOCKER_GAUZY_GITHUB_POST_INSTALL_URL',
Expand Down Expand Up @@ -290,10 +288,10 @@ if (!isProd) {
// we always want first to remove old generated files (one of them is not needed for current build)
try {
unlinkSync(`./apps/gauzy/src/environments/environment.ts`);
} catch {}
} catch { }
try {
unlinkSync(`./apps/gauzy/src/environments/environment.prod.ts`);
} catch {}
} catch { }

const envFileDest: string = isProd ? 'environment.prod.ts' : 'environment.ts';
const envFileDestOther: string = !isProd
Expand Down
2 changes: 0 additions & 2 deletions .scripts/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ export type Env = Readonly<{
JITSU_BROWSER_WRITE_KEY: string;

GAUZY_GITHUB_APP_NAME: string;
GAUZY_GITHUB_APP_ID: string;
GAUZY_GITHUB_CLIENT_ID: string;
GAUZY_GITHUB_REDIRECT_URL: string;
GAUZY_GITHUB_POST_INSTALL_URL: string;
Expand Down Expand Up @@ -145,7 +144,6 @@ export const env: Env = cleanEnv(
JITSU_BROWSER_WRITE_KEY: str({ default: '' }),

GAUZY_GITHUB_APP_NAME: str({ default: '' }),
GAUZY_GITHUB_APP_ID: str({ default: '' }),
GAUZY_GITHUB_CLIENT_ID: str({ default: '' }),
GAUZY_GITHUB_REDIRECT_URL: str({ default: '' }),
GAUZY_GITHUB_POST_INSTALL_URL: str({ default: '' }),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/internal/Observable';
import { IIntegrationMap, IIntegrationMapSyncRepository, IIntegrationSyncedRepositoryFindInput } from '@gauzy/contracts';
import { toParams } from '@gauzy/common-angular';
import { API_PREFIX } from '../../constants';

@Injectable({
providedIn: 'root'
Expand All @@ -13,27 +9,4 @@ export class IntegrationMapService {
constructor(
private readonly _http: HttpClient
) { }

/**
* Synchronize a GitHub repository.
* @param input The synchronization input data.
* @returns An Observable of the synchronized IntegrationMap.
*/
syncGithubRepository(input: IIntegrationMapSyncRepository): Observable<IIntegrationMap> {
const url = `${API_PREFIX}/integration-map/github/repository-sync`;
return this._http.post<IIntegrationMap>(url, input);
}

/**
* Get synced GitHub repositories based on input parameters
*
* @param input - Input parameters for the query
* @returns An Observable of type IIntegrationMap
*/
getSyncedGithubRepository(input: IIntegrationSyncedRepositoryFindInput): Observable<IIntegrationMap> {
const url = `${API_PREFIX}/integration-map/github/repository-sync`;
return this._http.get<IIntegrationMap>(url, {
params: toParams(input)
});
}
}
41 changes: 29 additions & 12 deletions apps/gauzy/src/app/@core/services/organization-projects.service.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, firstValueFrom, take } from 'rxjs';
import {
IOrganizationProjectCreateInput,
IOrganizationProject,
IOrganizationProjectsFindInput,
IEditEntityByMemberInput,
IPagination,
IEmployee,
IOrganizationProjectUpdateInput
IOrganizationProjectUpdateInput,
IOrganizationProjectSetting
} from '@gauzy/contracts';
import { Observable, firstValueFrom, take } from 'rxjs';
import { toParams } from '@gauzy/common-angular';
import { API_PREFIX } from '../constants/app.constants';

Expand All @@ -20,22 +21,22 @@ export class OrganizationProjectsService {
private readonly API_URL = `${API_PREFIX}/organization-projects`;

constructor(
private readonly http: HttpClient
private readonly _http: HttpClient
) { }

create(
body: IOrganizationProjectCreateInput
): Promise<IOrganizationProject> {
return firstValueFrom(
this.http.post<IOrganizationProject>(this.API_URL, body)
this._http.post<IOrganizationProject>(this.API_URL, body)
);
}

edit(
body: Partial<IOrganizationProjectUpdateInput>
): Promise<IOrganizationProject> {
return firstValueFrom(
this.http.put<IOrganizationProject>(`${this.API_URL}/${body.id}`, body)
this._http.put<IOrganizationProject>(`${this.API_URL}/${body.id}`, body)
);
}

Expand All @@ -44,7 +45,7 @@ export class OrganizationProjectsService {
where?: IOrganizationProjectsFindInput
): Promise<IOrganizationProject[]> {
return firstValueFrom(
this.http.get<IOrganizationProject[]>(`${this.API_URL}/employee/${id}`, {
this._http.get<IOrganizationProject[]>(`${this.API_URL}/employee/${id}`, {
params: toParams({ ...where })
})
);
Expand All @@ -55,14 +56,14 @@ export class OrganizationProjectsService {
where?: IOrganizationProjectsFindInput
): Promise<IPagination<IOrganizationProject>> {
return firstValueFrom(
this.http.get<IPagination<IOrganizationProject>>(`${this.API_URL}`, {
this._http.get<IPagination<IOrganizationProject>>(`${this.API_URL}`, {
params: toParams({ where, relations })
})
);
}

getById(id: IOrganizationProject['id'], relations: string[] = [],): Observable<IOrganizationProject> {
return this.http.get<IOrganizationProject>(`${this.API_URL}/${id}`, {
return this._http.get<IOrganizationProject>(`${this.API_URL}/${id}`, {
params: toParams({ relations })
});
}
Expand All @@ -71,15 +72,15 @@ export class OrganizationProjectsService {
request: IOrganizationProjectsFindInput
): Promise<number> {
return firstValueFrom(
this.http.get<number>(`${this.API_URL}/count`, {
this._http.get<number>(`${this.API_URL}/count`, {
params: toParams({ ...request })
})
);
}

updateByEmployee(updateInput: IEditEntityByMemberInput): Promise<any> {
return firstValueFrom(
this.http
this._http
.put(`${this.API_URL}/employee`, updateInput)
);
}
Expand All @@ -89,13 +90,29 @@ export class OrganizationProjectsService {
body: IOrganizationProjectUpdateInput
): Promise<IOrganizationProject> {
return firstValueFrom(
this.http.put<IOrganizationProject>(`${this.API_URL}/task-view/${id}`, body).pipe(take(1))
this._http.put<IOrganizationProject>(`${this.API_URL}/task-view/${id}`, body).pipe(take(1))
);
}

delete(id: IOrganizationProject['id']): Promise<any> {
return firstValueFrom(
this.http.delete(`${this.API_URL}/${id}`)
this._http.delete(`${this.API_URL}/${id}`)
);
}

/**
* Updates the settings for an organization project.
*
* @param id - The unique identifier (ID) of the organization project to update.
* @param input - The updated project settings to apply.
*
* @returns An Observable of type `IOrganizationProject` representing the updated organization project.
*/
updateProjectSetting(
id: IOrganizationProject['id'],
input: IOrganizationProjectSetting
): Observable<IOrganizationProjectSetting> {
const url = `${this.API_URL}/setting/${id}`;
return this._http.put<IOrganizationProject>(url, input);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@
<div class="col-4">
<div class="h-12 w-12 flex-shrink-0">
<ngx-github-repository-selector
[sourceId]="parsedInt(integrationMap?.sourceId)"
[sourceId]="project?.externalRepositoryId"
[integration]="integration"
(onChanged)="selectRepository($event)"
></ngx-github-repository-selector>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,24 @@ import {
PermissionsEnum,
IIntegrationTenant,
IGithubRepository,
IIntegrationMapSyncRepository,
IntegrationEntity,
IIntegrationMap
IOrganizationProjectSetting,
HttpStatus
} from '@gauzy/contracts';
import { TranslateService } from '@ngx-translate/core';
import { Router } from '@angular/router';
import { uniq } from 'underscore';
import { EMPTY } from 'rxjs';
import { catchError, debounceTime, filter, finalize, tap } from 'rxjs/operators';
import { distinctUntilChange, parsedInt } from '@gauzy/common-angular';
import { distinctUntilChange } from '@gauzy/common-angular';
import { CKEditor4 } from 'ckeditor4-angular/ckeditor';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { TranslationBaseComponent } from '../../language-base/translation-base.component';
import { patterns } from '../../regex/regex-patterns.const';
import { environment as ENV } from '../../../../environments/environment';
import {
ErrorHandlingService,
IntegrationMapService,
OrganizationContactService,
OrganizationProjectsService,
OrganizationTeamsService,
Store,
ToastrService
Expand All @@ -54,8 +53,6 @@ import { ckEditorConfig } from "../../ckeditor.config";
export class ProjectMutationComponent extends TranslationBaseComponent
implements OnInit {

public parsedInt = parsedInt;

public FormHelpers: typeof FormHelpers = FormHelpers;
public OrganizationProjectBudgetTypeEnum = OrganizationProjectBudgetTypeEnum;
public TaskListTypeEnum = TaskListTypeEnum;
Expand Down Expand Up @@ -115,17 +112,6 @@ export class ProjectMutationComponent extends TranslationBaseComponent
return form;
}

/**
* Represents an integration map or a boolean value.
*/
private _integrationMap: IIntegrationMap | boolean;
get integrationMap(): IIntegrationMap | boolean {
return this._integrationMap;
}
@Input() set integrationMap(value: IIntegrationMap | boolean) {
this._integrationMap = value;
}

/**
* Represents an integration tenant or a boolean value.
*/
Expand Down Expand Up @@ -163,7 +149,7 @@ export class ProjectMutationComponent extends TranslationBaseComponent
private readonly _errorHandler: ErrorHandlingService,
private readonly _organizationTeamService: OrganizationTeamsService,
private readonly _organizationContactService: OrganizationContactService,
private readonly _integrationMapService: IntegrationMapService
private readonly _organizationProjectsService: OrganizationProjectsService,
) {
super(translateService);
}
Expand Down Expand Up @@ -496,30 +482,33 @@ export class ProjectMutationComponent extends TranslationBaseComponent

const { id: organizationId, tenantId } = this.organization;
const { id: projectId } = this.project;
const integrationId = this.integration['id'];
const externalRepositoryId = repository.id;

/** */
const request: IIntegrationMapSyncRepository = {
const request: IOrganizationProjectSetting = {
organizationId,
tenantId,
gauzyId: projectId,
integrationId,
repository,
entity: IntegrationEntity.PROJECT
externalRepositoryId
}

// Fetch entity settings by integration ID and handle the result as an observable
this._integrationMapService.syncGithubRepository(request).pipe(
this._organizationProjectsService.updateProjectSetting(projectId, request).pipe(
tap((response: any) => {
if (response['status'] == HttpStatus.BAD_REQUEST) {
throw new Error(`${response['message']}`);
}
}),
tap(() => {
this._toastrService.success('NOTES.ORGANIZATIONS.EDIT_ORGANIZATIONS_PROJECTS.SYNC_REPOSITORY', {
repository: repository.full_name,
project: this.project.name
});
}),
catchError((error) => {
this._errorHandler.handleError(error);
return EMPTY;
}),
// Execute the following code block when the observable completes or errors
finalize(() => {
this._toastrService.success('NOTES.ORGANIZATIONS.EDIT_ORGANIZATIONS_PROJECTS.SYNC_REPOSITORY', {
repository: repository.full_name,
project: this.project.name
});
// Set the 'loading' flag to false to indicate that data loading is complete
this.loading = false;
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ <h5>{{ 'INTEGRATIONS.GITHUB_PAGE.NAME' | translate }}</h5>
</div>
<div class="issues-container">
<ngx-github-repository-selector
[sourceId]="parsedInt((integrationMap$ | async)?.sourceId)"
[sourceId]="(project$ | async)?.externalRepositoryId"
[integration]="integration"
(onChanged)="selectRepository($event)"
[selected]="true"
Expand Down
Loading

0 comments on commit 923e7ea

Please sign in to comment.