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

Feature: Auto Populate Labels #5679

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,15 @@
}
]
},
"githubPullRequests.pullRequestLabels": {
alexr00 marked this conversation as resolved.
Show resolved Hide resolved
"type": "array",
"items": {
"type": "string",
"description": "%githubPullRequests.pullRequestLabels.label.description%"
},
"default": [],
"description": "%githubPullRequests.pullRequestLabels.description%"
},
"githubPullRequests.defaultMergeMethod": {
"type": "string",
"enum": [
Expand Down
2 changes: 2 additions & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@
"githubIssues.assignWhenWorking.description": "Assigns the issue you're working on to you. Only applies when the issue you're working on is in a repo you currently have open.",
"githubPullRequests.focusedMode.description": "The layout to use when a pull request is checked out. Set to false to prevent layout changes.",
"githubPullRequests.showPullRequestNumberInTree.description": "Shows the pull request number in the tree view.",
"githubPullRequests.pullRequestLabels.description": "Group of labels that you want to add to the PR automatically",
alexr00 marked this conversation as resolved.
Show resolved Hide resolved
"githubPullRequests.pullRequestLabels.label.description": "Each string element is value of label that you want to add",
alexr00 marked this conversation as resolved.
Show resolved Hide resolved
"view.github.pull.request.name": "GitHub Pull Request",
"view.github.login.name": "Login",
"view.pr.github.name": "Pull Requests",
Expand Down
1 change: 1 addition & 0 deletions src/common/settingKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const PULL_REQUEST_DESCRIPTION = 'pullRequestDescription';
export const NOTIFICATION_SETTING = 'notifications';
export const POST_CREATE = 'postCreate';
export const QUERIES = 'queries';
export const PULL_REQUEST_LABELS = 'pullRequestLabels';
export const FOCUSED_MODE = 'focusedMode';
export const CREATE_DRAFT = 'createDraft';
export const QUICK_DIFF = 'quickDiff';
Expand Down
21 changes: 21 additions & 0 deletions src/github/createPRViewProviderNew.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
DEFAULT_CREATE_OPTION,
PR_SETTINGS_NAMESPACE,
PULL_REQUEST_DESCRIPTION,
PULL_REQUEST_LABELS,
PUSH_BRANCH
} from '../common/settingKeys';
import { ITelemetry } from '../common/telemetry';
Expand Down Expand Up @@ -158,6 +159,24 @@ export class CreatePullRequestViewProviderNew extends WebviewViewBase implements
return undefined;
}

private async getPullRequestDefaultLabels(defaultBaseRemote: RemoteInfo): Promise<ILabel[]> {

const defaultLabelValues = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get(PULL_REQUEST_LABELS) as Array<string>;
alexr00 marked this conversation as resolved.
Show resolved Hide resolved

// Return early if no config present
if (!defaultLabelValues || defaultLabelValues.length === 0) {
return [];
}

// Fetch labels from the repo and filter with case-sensitive comparison to be safe,
// dropping any labels that don't exist on the repo.
// TODO: @alexr00 - Add a cache for this.
const labels = await this._folderRepositoryManager.getLabels(undefined, { owner: defaultBaseRemote.owner, repo: defaultBaseRemote.repositoryName });
const defaultLabels = labels.filter(label => defaultLabelValues.includes(label.name));

return defaultLabels;
}

private async getTitleAndDescription(compareBranch: Branch, baseBranch: string): Promise<{ title: string, description: string }> {
let title: string = '';
let description: string = '';
Expand Down Expand Up @@ -347,6 +366,8 @@ export class CreatePullRequestViewProviderNew extends WebviewViewBase implements
this.telemetry.sendTelemetryEvent('pr.defaultTitleAndDescriptionProvider', { providerTitle: defaultTitleAndDescriptionProvider });
}

this.labels = await this.getPullRequestDefaultLabels(defaultBaseRemote);

const params: CreateParamsNew = {
defaultBaseRemote,
defaultBaseBranch,
Expand Down