import { Injectable } from '@angular/core' ; import { AngularFirestore } from '@angular/fire/firestore' ; import { AngularFireFunctions } from '@angular/fire/functions' ; import { of , Observable } from 'rxjs' ; import { map , switchMap } from 'rxjs/operators' ; import { IRepository , RepositoryModel } from '@shared/models/index.model' ; import { ActivityService } from './activity.service' ; import { AuthenticationService } from './authentication.service' ; /**
 * Repository service
 */ @ Injectable ( { providedIn : 'root' , } ) export class RepositoryService { param afs param fns param authService param activityService constructor ( private afs , private fns , private authService , private activityService ) { } /**
     * Forces refresh of users repositories
     */ public refresh ( ) { const callable = this . fns . httpsCallable ( 'findAllUserRepositories' ) ; return callable ( { token : this . authService . profile . oauth . githubToken } ) ; } param uid public findOneById ( uid ) { return this . activityService . start ( ) . pipe ( switchMap ( ( ) => this . afs . collection < IRepository > ( 'repositories' ) . doc < IRepository > ( uid ) . valueChanges ( ) ) , map ( ( repository ) => new RepositoryModel ( repository ) ) ) ; } /**
     * Loads all the available repositories
     */ public loadRepository ( repo ) { const callable = this . fns . httpsCallable ( 'findRepositoryInfo' ) ; return callable ( { repository : repo , token : this . authService . profile . oauth . githubToken } ) ; } param repo public createGitWebhook ( repo ) { const callable = this . fns . httpsCallable ( 'createGitWebhookRepository' ) ; return of ( new RepositoryModel ( callable ( { repositoryUid : repo . uid , token : this . authService . profile . oauth . githubToken } ) ) ) ; } param repo public deleteGitWebhook ( repo ) { const callable = this . fns . httpsCallable ( 'deleteGitWebhookRepository' ) ; return of ( new RepositoryModel ( callable ( { data : { uid : repo . uid , id : repo . id } , token : this . authService . profile . oauth . githubToken } ) ) ) ; } param uri public getStatusesUrlResponse ( fullName , ref ) { const callable = this . fns . httpsCallable ( 'findPullRequestStatus' ) ; return callable ( { token : this . authService . profile . oauth . githubToken , repository : { fullName : fullName , ref : ref } } ) ; } }