|
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 * as vscode from 'vscode'; |
7 | | -import { TreeDecorationProvider } from './treeDecorationProviders'; |
8 | | -import { createCommitsNodeUri, fromCommitsNodeUri, Schemes } from '../common/uri'; |
9 | | -import { FolderRepositoryManager } from '../github/folderRepositoryManager'; |
10 | | -import { PullRequestModel } from '../github/pullRequestModel'; |
11 | | - |
12 | | -export class CommitsDecorationProvider extends TreeDecorationProvider { |
13 | | - |
14 | | - constructor() { |
15 | | - super(); |
16 | | - } |
17 | | - |
18 | | - registerPullRequestPropertyChangedListeners(_folderManager: FolderRepositoryManager, model: PullRequestModel): vscode.Disposable { |
19 | | - return model.onDidChange(e => { |
20 | | - if (e.timeline) { |
21 | | - // Timeline changed, which may include new commits, so update the decoration |
22 | | - const uri = createCommitsNodeUri(model.remote.owner, model.remote.repositoryName, model.number, model.item.commits.length); |
23 | | - this._onDidChangeFileDecorations.fire(uri); |
24 | | - } |
25 | | - }); |
26 | | - } |
27 | | - |
28 | | - provideFileDecoration( |
29 | | - uri: vscode.Uri, |
30 | | - _token: vscode.CancellationToken, |
31 | | - ): vscode.ProviderResult<vscode.FileDecoration> { |
32 | | - if (uri.scheme !== Schemes.CommitsNode) { |
33 | | - return undefined; |
34 | | - } |
35 | | - |
36 | | - const params = fromCommitsNodeUri(uri); |
37 | | - if (!params) { |
38 | | - return undefined; |
39 | | - } |
40 | | - |
41 | | - return { |
42 | | - badge: params.commitsCount.toString(), |
43 | | - tooltip: vscode.l10n.t('{0} commits', params.commitsCount) |
44 | | - }; |
45 | | - } |
46 | | - |
47 | | -} |
| 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 * as vscode from 'vscode'; |
| 7 | +import { TreeDecorationProvider } from './treeDecorationProviders'; |
| 8 | +import { createCommitsNodeUri, fromCommitsNodeUri, Schemes } from '../common/uri'; |
| 9 | +import { FolderRepositoryManager } from '../github/folderRepositoryManager'; |
| 10 | +import { PullRequestModel } from '../github/pullRequestModel'; |
| 11 | +import { RepositoriesManager } from '../github/repositoriesManager'; |
| 12 | + |
| 13 | +export class CommitsDecorationProvider extends TreeDecorationProvider { |
| 14 | + |
| 15 | + constructor(private readonly _repositoriesManager: RepositoriesManager) { |
| 16 | + super(); |
| 17 | + } |
| 18 | + |
| 19 | + registerPullRequestPropertyChangedListeners(_folderManager: FolderRepositoryManager, model: PullRequestModel): vscode.Disposable { |
| 20 | + return model.onDidChange(e => { |
| 21 | + if (e.timeline) { |
| 22 | + // Timeline changed, which may include new commits, so update the decoration |
| 23 | + const uri = createCommitsNodeUri(model.remote.owner, model.remote.repositoryName, model.number); |
| 24 | + this._onDidChangeFileDecorations.fire(uri); |
| 25 | + } |
| 26 | + }); |
| 27 | + } |
| 28 | + |
| 29 | + provideFileDecoration( |
| 30 | + uri: vscode.Uri, |
| 31 | + _token: vscode.CancellationToken, |
| 32 | + ): vscode.ProviderResult<vscode.FileDecoration> { |
| 33 | + if (uri.scheme !== Schemes.CommitsNode) { |
| 34 | + return undefined; |
| 35 | + } |
| 36 | + |
| 37 | + const params = fromCommitsNodeUri(uri); |
| 38 | + if (!params) { |
| 39 | + return undefined; |
| 40 | + } |
| 41 | + |
| 42 | + // Find the PR model to get the current commit count |
| 43 | + const folderManager = this._repositoriesManager.folderManagers.find(fm => |
| 44 | + fm.gitHubRepositories.some(repo => |
| 45 | + repo.remote.owner === params.owner && repo.remote.repositoryName === params.repo |
| 46 | + ) |
| 47 | + ); |
| 48 | + |
| 49 | + if (folderManager) { |
| 50 | + const repo = folderManager.gitHubRepositories.find(r => |
| 51 | + r.remote.owner === params.owner && r.remote.repositoryName === params.repo |
| 52 | + ); |
| 53 | + if (repo) { |
| 54 | + const pr = repo.getExistingPullRequestModel(params.prNumber); |
| 55 | + if (pr) { |
| 56 | + const commitsCount = pr.item.commits.length; |
| 57 | + return { |
| 58 | + badge: commitsCount.toString(), |
| 59 | + tooltip: vscode.l10n.t('{0} commits', commitsCount) |
| 60 | + }; |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + return undefined; |
| 66 | + } |
| 67 | + |
| 68 | +} |
0 commit comments