Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Centralize all configuration strings into settingKeys.ts #4577

Merged
merged 3 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { GitErrorCodes } from './api/api1';
import { CommentReply, resolveCommentHandler } from './commentHandlerResolver';
import { IComment } from './common/comment';
import Logger from './common/logger';
import { FILE_LIST_LAYOUT, PR_SETTINGS_NAMESPACE } from './common/settingKeys';
import { ITelemetry } from './common/telemetry';
import { asImageDataURI, fromReviewUri, Schemes } from './common/uri';
import { formatError } from './common/utils';
Expand Down Expand Up @@ -1043,13 +1044,13 @@ ${contents}

context.subscriptions.push(
vscode.commands.registerCommand('pr.setFileListLayoutAsTree', _ => {
vscode.workspace.getConfiguration('githubPullRequests').update('fileListLayout', 'tree', true);
vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).update(FILE_LIST_LAYOUT, 'tree', true);
}),
);

context.subscriptions.push(
vscode.commands.registerCommand('pr.setFileListLayoutAsFlat', _ => {
vscode.workspace.getConfiguration('githubPullRequests').update('fileListLayout', 'flat', true);
vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).update(FILE_LIST_LAYOUT, 'flat', true);
}),
);

Expand Down
38 changes: 38 additions & 0 deletions src/common/settingKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,46 @@ export const QUICK_DIFF_EXP = 'experimental.quickDiff';
export const QUICK_DIFF = 'quickDiff';
export const SET_AUTO_MERGE = 'setAutoMerge';
export const SHOW_PULL_REQUEST_NUMBER_IN_TREE = 'showPullRequestNumberInTree';
export const DEFAULT_MERGE_METHOD = 'defaultMergeMethod';
export const DEFAULT_DELETION_METHOD = 'defaultDeletionMethod';
export const SELECT_LOCAL_BRANCH = 'selectLocalBranch';
export const SELECT_REMOTE = 'selectRemote';
export const REMOTES = 'remotes';

export const ISSUES_SETTINGS_NAMESPACE = 'githubIssues';
export const ASSIGN_WHEN_WORKING = 'assignWhenWorking';
export const ISSUE_COMPLETIONS = 'issueCompletions';
export const USER_COMPLETIONS = 'userCompletions';
export const ENABLED = 'enabled';
export const IGNORE_USER_COMPLETION_TRIGGER = 'ignoreUserCompletionTrigger';
export const CREATE_INSERT_FORMAT = 'createInsertFormat';
export const ISSUE_BRANCH_TITLE = 'issueBranchTitle';
export const USE_BRANCH_FOR_ISSUES = 'useBranchForIssues';
export const WORKING_ISSUE_FORMAT_SCM = 'workingIssueFormatScm';
export const IGNORE_COMPLETION_TRIGGER = 'ignoreCompletionTrigger';
export const ISSUE_COMPLETION_FORMAT_SCM = 'issueCompletionFormatScm';
export const CREATE_ISSUE_TRIGGERS = 'createIssueTriggers';
export const DEFAULT = 'default';
export const IGNORE_MILESTONES = 'ignoreMilestones';

// git
export const GIT = 'git';
export const PULL_BEFORE_CHECKOUT = 'pullBeforeCheckout';
export const OPEN_DIFF_ON_CLICK = 'openDiffOnClick';
export const AUTO_STASH = 'autoStash';

// GitHub Enterprise
export const GITHUB_ENTERPRISE = 'github-enterprise';
export const URI = 'uri';

// Editor
export const EDITOR = 'editor';
export const WORD_WRAP = 'wordWrap';

// Comments
export const COMMENTS = 'comments';
export const OPEN_VIEW = 'openView';

// Explorer
export const EXPLORER = 'explorer';
export const AUTO_REVEAL = 'autoReveal';
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { Schemes, handler as uriHandler } from './common/uri';
import { EXTENSION_ID, FOCUS_REVIEW_MODE } from './constants';
import { createExperimentationService, ExperimentationTelemetry } from './experimentationService';
import { CredentialStore } from './github/credentials';
import { FolderRepositoryManager, SETTINGS_NAMESPACE } from './github/folderRepositoryManager';
import { FolderRepositoryManager } from './github/folderRepositoryManager';
import { RepositoriesManager } from './github/repositoriesManager';
import { registerBuiltinGitProvider, registerLiveShareGitProvider } from './gitProviders/api';
import { GitHubContactServiceProvider } from './gitProviders/GitHubContactServiceProvider';
Expand Down Expand Up @@ -206,7 +206,7 @@ async function init(

registerCommands(context, reposManager, reviewManagers, telemetry, tree);

const layout = vscode.workspace.getConfiguration(SETTINGS_NAMESPACE).get<string>(FILE_LIST_LAYOUT);
const layout = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<string>(FILE_LIST_LAYOUT);
await vscode.commands.executeCommand('setContext', 'fileListLayout:flat', layout === 'flat');

const issuesFeatures = new IssueFeatureRegistrar(git, reposManager, reviewManagers, context, telemetry);
Expand Down
29 changes: 20 additions & 9 deletions src/github/createPRViewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@ import { commands, contexts } from '../common/executeCommands';
import Logger from '../common/logger';
import { Protocol } from '../common/protocol';
import { GitHubRemote } from '../common/remote';
import { ASSIGN_TO, CREATE_DRAFT, PULL_REQUEST_DESCRIPTION, PUSH_BRANCH, SET_AUTO_MERGE } from '../common/settingKeys';
import {
ASSIGN_TO,
CREATE_DRAFT,
PR_SETTINGS_NAMESPACE,
PULL_REQUEST_DESCRIPTION,
PUSH_BRANCH,
SET_AUTO_MERGE,
} from '../common/settingKeys';
import { getNonce, IRequestMessage, WebviewViewBase } from '../common/webview';
import {
byRemoteName,
DetachedHeadError,
FolderRepositoryManager,
PullRequestDefaults,
SETTINGS_NAMESPACE,
titleAndBodyFrom,
} from './folderRepositoryManager';
import { GitHubRepository } from './githubRepository';
Expand Down Expand Up @@ -136,7 +142,9 @@ export class CreatePullRequestViewProvider extends WebviewViewBase implements vs
// By default, the base branch we use for comparison is the base branch of origin. Compare this to the
// compare branch if it has a GitHub remote.
const origin = await this._folderRepositoryManager.getOrigin(compareBranch);
const useTemplate = vscode.workspace.getConfiguration(SETTINGS_NAMESPACE).get<string>(PULL_REQUEST_DESCRIPTION) === 'template';
const useTemplate =
vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<string>(PULL_REQUEST_DESCRIPTION) ===
'template';

let useBranchName = this._pullRequestDefaults.base === compareBranch.name;
Logger.debug(`Compare branch name: ${compareBranch.name}, Base branch name: ${this._pullRequestDefaults.base}`, CreatePullRequestViewProvider.ID);
Expand Down Expand Up @@ -326,10 +334,10 @@ export class CreatePullRequestViewProvider extends WebviewViewBase implements vs
defaultMergeMethod: getDefaultMergeMethod(mergeConfiguration.mergeMethodsAvailability),
allowAutoMerge: mergeConfiguration.viewerCanAutoMerge,
mergeMethodsAvailability: mergeConfiguration.mergeMethodsAvailability,
autoMergeDefault: mergeConfiguration.viewerCanAutoMerge && (vscode.workspace.getConfiguration(SETTINGS_NAMESPACE).get<boolean>(SET_AUTO_MERGE, false) === true),
autoMergeDefault: mergeConfiguration.viewerCanAutoMerge && (vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<boolean>(SET_AUTO_MERGE, false) === true),
createError: '',
labels: this.labels,
isDraftDefault: vscode.workspace.getConfiguration(SETTINGS_NAMESPACE).get(CREATE_DRAFT, false),
isDraftDefault: vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get(CREATE_DRAFT, false),
isDarkTheme: vscode.window.activeColorTheme.kind === vscode.ColorThemeKind.Dark
};

Expand Down Expand Up @@ -387,7 +395,7 @@ export class CreatePullRequestViewProvider extends WebviewViewBase implements vs
defaultMergeMethod: getDefaultMergeMethod(mergeConfiguration.mergeMethodsAvailability),
allowAutoMerge: mergeConfiguration.viewerCanAutoMerge,
mergeMethodsAvailability: mergeConfiguration.mergeMethodsAvailability,
autoMergeDefault: mergeConfiguration.viewerCanAutoMerge && (vscode.workspace.getConfiguration(SETTINGS_NAMESPACE).get<boolean>(SET_AUTO_MERGE, false) === true)
autoMergeDefault: mergeConfiguration.viewerCanAutoMerge && (vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<boolean>(SET_AUTO_MERGE, false) === true)
};
} else {
if (this.defaultCompareBranch?.name) {
Expand All @@ -401,7 +409,7 @@ export class CreatePullRequestViewProvider extends WebviewViewBase implements vs
}

private async autoAssign(pr: PullRequestModel): Promise<void> {
const configuration = vscode.workspace.getConfiguration(SETTINGS_NAMESPACE).get<string | undefined>(ASSIGN_TO);
const configuration = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<string | undefined>(ASSIGN_TO);
if (!configuration) {
return;
}
Expand Down Expand Up @@ -508,15 +516,18 @@ export class CreatePullRequestViewProvider extends WebviewViewBase implements vs
// We assume this happens only when the compare branch is based on the current branch.
const alwaysPublish = vscode.l10n.t('Always Publish Branch');
const publish = vscode.l10n.t('Publish Branch');
const pushBranchSetting = vscode.workspace.getConfiguration(SETTINGS_NAMESPACE).get(PUSH_BRANCH) === 'always';
const pushBranchSetting =
vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get(PUSH_BRANCH) === 'always';
const messageResult = !pushBranchSetting ? await vscode.window.showInformationMessage(
vscode.l10n.t('There is no upstream branch for \'{0}\'.\n\nDo you want to publish it and then create the pull request?', compareBranchName),
{ modal: true },
publish,
alwaysPublish)
: publish;
if (messageResult === alwaysPublish) {
await vscode.workspace.getConfiguration(SETTINGS_NAMESPACE).update(PUSH_BRANCH, 'always', vscode.ConfigurationTarget.Global);
await vscode.workspace
.getConfiguration(PR_SETTINGS_NAMESPACE)
.update(PUSH_BRANCH, 'always', vscode.ConfigurationTarget.Global);
}
if ((messageResult === alwaysPublish) || (messageResult === publish)) {
progress.report({ message: vscode.l10n.t('Pushing branch'), increment: 10 });
Expand Down
35 changes: 19 additions & 16 deletions src/github/folderRepositoryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ import { commands, contexts } from '../common/executeCommands';
import Logger from '../common/logger';
import { Protocol, ProtocolType } from '../common/protocol';
import { GitHubRemote, parseRepositoryRemotes, Remote } from '../common/remote';
import { GIT, PULL_BEFORE_CHECKOUT, PULL_BRANCH } from '../common/settingKeys';
import {
AUTO_STASH,
DEFAULT_MERGE_METHOD,
GIT,
PR_SETTINGS_NAMESPACE,
PULL_BEFORE_CHECKOUT,
PULL_BRANCH,
REMOTES,
} from '../common/settingKeys';
import { ITelemetry } from '../common/telemetry';
import { EventType, TimelineEvent } from '../common/timelineEvent';
import { fromPRUri, Schemes } from '../common/uri';
Expand Down Expand Up @@ -90,9 +98,6 @@ export class BadUpstreamError extends Error {
}
}

export const SETTINGS_NAMESPACE = 'githubPullRequests';
export const REMOTES_SETTING = 'remotes';

export const ReposManagerStateContext: string = 'ReposManagerStateContext';

export enum ReposManagerState {
Expand Down Expand Up @@ -167,7 +172,7 @@ export class FolderRepositoryManager implements vscode.Disposable {

this._subs.push(
vscode.workspace.onDidChangeConfiguration(async e => {
if (e.affectsConfiguration(`${SETTINGS_NAMESPACE}.${REMOTES_SETTING}`)) {
if (e.affectsConfiguration(`${PR_SETTINGS_NAMESPACE}.${REMOTES}`)) {
await this.updateRepositories();
}
}),
Expand Down Expand Up @@ -245,7 +250,7 @@ export class FolderRepositoryManager implements vscode.Disposable {
}

public async getActiveGitHubRemotes(allGitHubRemotes: GitHubRemote[]): Promise<GitHubRemote[]> {
const remotesSetting = vscode.workspace.getConfiguration(SETTINGS_NAMESPACE).get<string[]>(REMOTES_SETTING);
const remotesSetting = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<string[]>(REMOTES);

if (!remotesSetting) {
Logger.error(`Unable to read remotes setting`);
Expand Down Expand Up @@ -1372,8 +1377,8 @@ export class FolderRepositoryManager implements vscode.Disposable {

const origin = await this.getOrigin(branch);
const meta = await origin.getMetadata();
const remotesSettingDefault = vscode.workspace.getConfiguration(SETTINGS_NAMESPACE).inspect<string[]>(REMOTES_SETTING)?.defaultValue;
const remotesSettingSetValue = vscode.workspace.getConfiguration(SETTINGS_NAMESPACE).get<string[]>(REMOTES_SETTING);
const remotesSettingDefault = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).inspect<string[]>(REMOTES)?.defaultValue;
const remotesSettingSetValue = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<string[]>(REMOTES);
const settingsEqual = (!remotesSettingSetValue || remotesSettingDefault?.every((value, index) => remotesSettingSetValue[index] === value));
const parent = (meta.fork && meta.parent && settingsEqual)
? meta.parent
Expand Down Expand Up @@ -1672,9 +1677,7 @@ export class FolderRepositoryManager implements vscode.Disposable {
commit_title: title,
merge_method:
method ||
vscode.workspace
.getConfiguration('githubPullRequests')
.get<'merge' | 'squash' | 'rebase'>('defaultMergeMethod'),
vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<'merge' | 'squash' | 'rebase'>(DEFAULT_MERGE_METHOD),
owner: remote.owner,
repo: remote.repositoryName,
pull_number: pullRequest.number,
Expand Down Expand Up @@ -2215,9 +2218,9 @@ export class FolderRepositoryManager implements vscode.Disposable {
const neverShowPullNotification = this.context.globalState.get<boolean>(NEVER_SHOW_PULL_NOTIFICATION, false);
if (neverShowPullNotification) {
this.context.globalState.update(NEVER_SHOW_PULL_NOTIFICATION, false);
await vscode.workspace.getConfiguration(SETTINGS_NAMESPACE).update(PULL_BRANCH, 'never', vscode.ConfigurationTarget.Global);
await vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).update(PULL_BRANCH, 'never', vscode.ConfigurationTarget.Global);
}
return vscode.workspace.getConfiguration(SETTINGS_NAMESPACE).get<'never' | 'prompt' | 'always'>(PULL_BRANCH, 'prompt');
return vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<'never' | 'prompt' | 'always'>(PULL_BRANCH, 'prompt');
}

private async pullBranch(branch: Branch) {
Expand Down Expand Up @@ -2246,9 +2249,9 @@ export class FolderRepositoryManager implements vscode.Disposable {
await this.pullBranch(branch);
this._updateMessageShown = false;
} else if (never) {
await vscode.workspace.getConfiguration(SETTINGS_NAMESPACE).update(PULL_BRANCH, 'never', vscode.ConfigurationTarget.Global);
await vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).update(PULL_BRANCH, 'never', vscode.ConfigurationTarget.Global);
} else if (always) {
await vscode.workspace.getConfiguration(SETTINGS_NAMESPACE).update(PULL_BRANCH, 'always', vscode.ConfigurationTarget.Global);
await vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).update(PULL_BRANCH, 'always', vscode.ConfigurationTarget.Global);
await this.pullBranch(branch);
}
}
Expand Down Expand Up @@ -2282,7 +2285,7 @@ export class FolderRepositoryManager implements vscode.Disposable {
if (branch.behind !== undefined && branch.behind > 0) {
switch (pullBranchConfiguration) {
case 'always': {
const autoStash = vscode.workspace.getConfiguration('git').get<boolean>('autoStash', false);
const autoStash = vscode.workspace.getConfiguration(GIT).get<boolean>(AUTO_STASH, false);
if (autoStash) {
return this.promptPullBrach(pr, branch, autoStash);
} else {
Expand Down
10 changes: 6 additions & 4 deletions src/github/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import { OctokitResponse } from '@octokit/types';
import * as vscode from 'vscode';
import { AuthProvider } from '../common/authentication';
import Logger from '../common/logger';
import { NOTIFICATION_SETTING } from '../common/settingKeys';
import { NOTIFICATION_SETTING, PR_SETTINGS_NAMESPACE } from '../common/settingKeys';
import { createPRNodeUri } from '../common/uri';
import { PullRequestsTreeDataProvider } from '../view/prsTreeDataProvider';
import { CategoryTreeNode } from '../view/treeNodes/categoryNode';
import { PRNode } from '../view/treeNodes/pullRequestNode';
import { TreeNode } from '../view/treeNodes/treeNode';
import { CredentialStore, GitHub } from './credentials';
import { SETTINGS_NAMESPACE } from './folderRepositoryManager';
import { GitHubRepository } from './githubRepository';
import { PullRequestState } from './graphql';
import { PullRequestModel } from './pullRequestModel';
Expand Down Expand Up @@ -99,15 +98,18 @@ export class NotificationProvider implements vscode.Disposable {

this.disposables.push(
vscode.workspace.onDidChangeConfiguration((e) => {
if (e.affectsConfiguration(`${SETTINGS_NAMESPACE}.${NOTIFICATION_SETTING}`)) {
if (e.affectsConfiguration(`${PR_SETTINGS_NAMESPACE}.${NOTIFICATION_SETTING}`)) {
this.checkNotificationSetting();
}
})
);
}

private static isPRNotificationsOn() {
return vscode.workspace.getConfiguration(SETTINGS_NAMESPACE).get<string>(NOTIFICATION_SETTING) === 'pullRequests';
return (
vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<string>(NOTIFICATION_SETTING) ===
'pullRequests'
);
}

private registerAuthProvider(credentialStore: CredentialStore) {
Expand Down
3 changes: 2 additions & 1 deletion src/github/pullRequestOverview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as vscode from 'vscode';
import { onDidUpdatePR, openPullRequestOnGitHub } from '../commands';
import { IComment } from '../common/comment';
import Logger from '../common/logger';
import { DEFAULT_MERGE_METHOD, PR_SETTINGS_NAMESPACE } from '../common/settingKeys';
import { ReviewEvent as CommonReviewEvent } from '../common/timelineEvent';
import { asPromise, dispose, formatError } from '../common/utils';
import { IRequestMessage, PULL_REQUEST_OVERVIEW_VIEW_TYPE } from '../common/webview';
Expand Down Expand Up @@ -1011,7 +1012,7 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode
export function getDefaultMergeMethod(
methodsAvailability: MergeMethodsAvailability,
): MergeMethod {
const userPreferred = vscode.workspace.getConfiguration('githubPullRequests').get<MergeMethod>('defaultMergeMethod');
const userPreferred = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<MergeMethod>(DEFAULT_MERGE_METHOD);
// Use default merge method specified by user if it is available
if (userPreferred && methodsAvailability.hasOwnProperty(userPreferred) && methodsAvailability[userPreferred]) {
return userPreferred;
Expand Down
14 changes: 10 additions & 4 deletions src/github/pullRequestOverviewCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
'use strict';

import * as vscode from 'vscode';
import {
DEFAULT_DELETION_METHOD,
PR_SETTINGS_NAMESPACE,
SELECT_LOCAL_BRANCH,
SELECT_REMOTE,
} from '../common/settingKeys';
import { Schemes } from '../common/uri';
import { FolderRepositoryManager } from './folderRepositoryManager';
import { PullRequestModel } from './pullRequestModel';
Expand All @@ -31,17 +37,17 @@ export namespace PullRequestView {

if (branchInfo) {
const preferredLocalBranchDeletionMethod = vscode.workspace
.getConfiguration('githubPullRequests')
.get<boolean>('defaultDeletionMethod.selectLocalBranch');
.getConfiguration(PR_SETTINGS_NAMESPACE)
.get<boolean>(`${DEFAULT_DELETION_METHOD}.${SELECT_LOCAL_BRANCH}`);
actions.push({
label: vscode.l10n.t('Delete local branch {0}', branchInfo.branch),
type: 'local',
picked: !!preferredLocalBranchDeletionMethod,
});

const preferredRemoteDeletionMethod = vscode.workspace
.getConfiguration('githubPullRequests')
.get<boolean>('defaultDeletionMethod.selectRemote');
.getConfiguration(PR_SETTINGS_NAMESPACE)
.get<boolean>(`${DEFAULT_DELETION_METHOD}.${SELECT_REMOTE}`);

if (branchInfo.remote && branchInfo.createdForPullRequest && !branchInfo.remoteInUse) {
actions.push({
Expand Down
Loading