Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/sessions/contrib/changes/browser/checksViewModel.ts
13401 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { Disposable } from '../../../../base/common/lifecycle.js';
7
import { derived, derivedOpts, IObservable } from '../../../../base/common/observable.js';
8
import { URI } from '../../../../base/common/uri.js';
9
import { IGitHubService } from '../../github/browser/githubService.js';
10
import { GitHubPullRequestCIModel } from '../../github/browser/models/githubPullRequestCIModel.js';
11
import { ISessionsManagementService } from '../../../services/sessions/common/sessionsManagement.js';
12
import { structuralEquals } from '../../../../base/common/equals.js';
13
14
export class ChecksViewModel extends Disposable {
15
readonly activeSessionResourceObs: IObservable<URI | undefined>;
16
readonly checksObs: IObservable<GitHubPullRequestCIModel | undefined>;
17
18
constructor(
19
@IGitHubService gitHubService: IGitHubService,
20
@ISessionsManagementService sessionManagementService: ISessionsManagementService,
21
) {
22
super();
23
24
this.activeSessionResourceObs = derived<URI | undefined>(this, reader => {
25
const session = sessionManagementService.activeSession.read(reader);
26
return session?.resource;
27
});
28
29
const pullRequestInfoObs = derivedOpts<{ owner: string; repo: string; prNumber: number; headSha: string } | undefined>({
30
equalsFn: structuralEquals
31
}, reader => {
32
const session = sessionManagementService.activeSession.read(reader);
33
if (!session) {
34
return undefined;
35
}
36
37
const gitHubInfo = session.gitHubInfo.read(reader);
38
if (!gitHubInfo?.pullRequest) {
39
return undefined;
40
}
41
42
const prModel = gitHubService.getPullRequest(gitHubInfo.owner, gitHubInfo.repo, gitHubInfo.pullRequest.number);
43
const pr = prModel.pullRequest.read(reader);
44
if (!pr) {
45
return undefined;
46
}
47
48
return {
49
owner: gitHubInfo.owner,
50
repo: gitHubInfo.repo,
51
prNumber: gitHubInfo.pullRequest.number,
52
headSha: pr.headSha
53
};
54
});
55
56
this.checksObs = derived(this, reader => {
57
const pullRequestInfo = pullRequestInfoObs.read(reader);
58
if (!pullRequestInfo) {
59
return undefined;
60
}
61
62
// Use the PR's headSha (commit SHA) rather than the branch
63
// name so CI checks can still be fetched after branch deletion
64
// (e.g. after the PR is merged).
65
const ciModel = gitHubService.getPullRequestCI(pullRequestInfo.owner, pullRequestInfo.repo, pullRequestInfo.prNumber, pullRequestInfo.headSha);
66
ciModel.refresh();
67
reader.store.add(ciModel.startPolling());
68
69
return ciModel;
70
});
71
}
72
}
73
74