Path: blob/main/src/vs/sessions/contrib/changes/browser/checksViewModel.ts
13401 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { Disposable } from '../../../../base/common/lifecycle.js';6import { derived, derivedOpts, IObservable } from '../../../../base/common/observable.js';7import { URI } from '../../../../base/common/uri.js';8import { IGitHubService } from '../../github/browser/githubService.js';9import { GitHubPullRequestCIModel } from '../../github/browser/models/githubPullRequestCIModel.js';10import { ISessionsManagementService } from '../../../services/sessions/common/sessionsManagement.js';11import { structuralEquals } from '../../../../base/common/equals.js';1213export class ChecksViewModel extends Disposable {14readonly activeSessionResourceObs: IObservable<URI | undefined>;15readonly checksObs: IObservable<GitHubPullRequestCIModel | undefined>;1617constructor(18@IGitHubService gitHubService: IGitHubService,19@ISessionsManagementService sessionManagementService: ISessionsManagementService,20) {21super();2223this.activeSessionResourceObs = derived<URI | undefined>(this, reader => {24const session = sessionManagementService.activeSession.read(reader);25return session?.resource;26});2728const pullRequestInfoObs = derivedOpts<{ owner: string; repo: string; prNumber: number; headSha: string } | undefined>({29equalsFn: structuralEquals30}, reader => {31const session = sessionManagementService.activeSession.read(reader);32if (!session) {33return undefined;34}3536const gitHubInfo = session.gitHubInfo.read(reader);37if (!gitHubInfo?.pullRequest) {38return undefined;39}4041const prModel = gitHubService.getPullRequest(gitHubInfo.owner, gitHubInfo.repo, gitHubInfo.pullRequest.number);42const pr = prModel.pullRequest.read(reader);43if (!pr) {44return undefined;45}4647return {48owner: gitHubInfo.owner,49repo: gitHubInfo.repo,50prNumber: gitHubInfo.pullRequest.number,51headSha: pr.headSha52};53});5455this.checksObs = derived(this, reader => {56const pullRequestInfo = pullRequestInfoObs.read(reader);57if (!pullRequestInfo) {58return undefined;59}6061// Use the PR's headSha (commit SHA) rather than the branch62// name so CI checks can still be fetched after branch deletion63// (e.g. after the PR is merged).64const ciModel = gitHubService.getPullRequestCI(pullRequestInfo.owner, pullRequestInfo.repo, pullRequestInfo.prNumber, pullRequestInfo.headSha);65ciModel.refresh();66reader.store.add(ciModel.startPolling());6768return ciModel;69});70}71}727374