<commit_before>/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

'use strict';
import { CancellationToken, commands, Disposable, scm, SourceControl, SourceControlResourceGroup, SourceControlResourceState, Uri, window, workspace } from 'vscode';
import * as nls from 'vscode-nls';
import { IChangeStore } from './changeStore';
import { GitHubApi, CommitOperation } from './github/api';
import { getRelativePath } from './extension';

const localize = nls.loadMessageBundle();

interface ScmProvider {
	sourceControl: SourceControl,
	groups: SourceControlResourceGroup[]
}

export class VirtualSCM implements Disposable {
	private readonly providers: ScmProvider[] = [];

	private disposable: Disposable;

	constructor(
		private readonly originalScheme: string,
		private readonly github: GitHubApi,
		private readonly changeStore: IChangeStore,
	) {
		this.registerCommands();

		// TODO@eamodio listen for workspace folder changes
		for (const folder of workspace.workspaceFolders ?? []) {
			this.createScmProvider(folder.uri, folder.name);

			for (const operation of changeStore.getChanges(folder.uri)) {
				this.update(folder.uri, operation.uri);
			}
		}

		this.disposable = Disposable.from(
			changeStore.onDidChange(e => this.update(e.rootUri, e.uri)),
		);
	}

	dispose() {
		this.disposable.dispose();
	}

	private registerCommands() {
		commands.registerCommand('githubBrowser.commit', (...args: any[]) => this.commitChanges(args[0]));

		commands.registerCommand('githubBrowser.discardChanges', (resourceState: SourceControlResourceState) =>
			this.discardChanges(resourceState.resourceUri)
		);

		commands.registerCommand('githubBrowser.openChanges', (resourceState: SourceControlResourceState) =>
			this.openChanges(resourceState.resourceUri)
		);

		commands.registerCommand('githubBrowser.openFile', (resourceState: SourceControlResourceState) =>
			this.openFile(resourceState.resourceUri)
		);
	}

	async commitChanges(sourceControl: SourceControl): Promise<void> {<commit_msg>Makes ✔ commit button work<commit_after>/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

'use strict';
import { CancellationToken, commands, Disposable, scm, SourceControl, SourceControlResourceGroup, SourceControlResourceState, Uri, window, workspace } from 'vscode';
import * as nls from 'vscode-nls';
import { IChangeStore } from './changeStore';
import { GitHubApi, CommitOperation } from './github/api';
import { getRelativePath } from './extension';

const localize = nls.loadMessageBundle();

interface ScmProvider {
	sourceControl: SourceControl,
	groups: SourceControlResourceGroup[]
}

export class VirtualSCM implements Disposable {
	private readonly providers: ScmProvider[] = [];

	private disposable: Disposable;

	constructor(
		private readonly originalScheme: string,
		private readonly github: GitHubApi,
		private readonly changeStore: IChangeStore,
	) {
		this.registerCommands();

		// TODO@eamodio listen for workspace folder changes
		for (const folder of workspace.workspaceFolders ?? []) {
			this.createScmProvider(folder.uri, folder.name);

			for (const operation of changeStore.getChanges(folder.uri)) {
				this.update(folder.uri, operation.uri);
			}
		}

		this.disposable = Disposable.from(
			changeStore.onDidChange(e => this.update(e.rootUri, e.uri)),
		);
	}

	dispose() {
		this.disposable.dispose();
	}

	private registerCommands() {
		commands.registerCommand('githubBrowser.commit', (sourceControl: SourceControl | undefined) => {
			// TODO@eamodio remove this hack once I figure out why the args are missing
			if (sourceControl === undefined && this.providers.length === 1) {
				sourceControl = this.providers[0].sourceControl;
			}

			if (sourceControl === undefined) {
				return;
			}

			this.commitChanges(sourceControl);
		});

		commands.registerCommand('githubBrowser.discardChanges', (resourceState: SourceControlResourceState) =>
			this.discardChanges(resourceState.resourceUri)
		);

		commands.registerCommand('githubBrowser.openChanges', (resourceState: SourceControlResourceState) =>
			this.openChanges(resourceState.resourceUri)
		);

		commands.registerCommand('githubBrowser.openFile', (resourceState: SourceControlResourceState) =>
			this.openFile(resourceState.resourceUri)
		);
	}

	async commitChanges(sourceControl: SourceControl): Promise<void> {
{'fraction_non_alphanumeric': 0.18006496142915143, 'fraction_numerical': 0.0006090133982947625, 'mean_word_length': 3.487249544626594, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5814171', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1265, 'n_words': 307}