Browse Source

Adds better co-author support

Adds "Add Co-authors" command to scm title
Changes co-authors to be a selectable list -- pre-pop with existing
main
Eric Amodio 4 years ago
parent
commit
5891ebd8e2
8 changed files with 75 additions and 8 deletions
  1. +16
    -0
      package.json
  2. +1
    -0
      src/commands.ts
  3. +25
    -0
      src/commands/addAuthors.ts
  4. +3
    -0
      src/commands/common.ts
  5. +17
    -6
      src/commands/git/coauthors.ts
  6. +8
    -2
      src/commands/gitCommands.ts
  7. +1
    -0
      src/commands/quickCommand.ts
  8. +4
    -0
      src/git/models/contributor.ts

+ 16
- 0
package.json View File

@ -2391,6 +2391,15 @@
"category": "GitLens"
},
{
"command": "gitlens.addAuthors",
"title": "Add Co-authors",
"category": "GitLens",
"icon": {
"dark": "images/dark/icon-person-add.svg",
"light": "images/light/icon-person-add.svg"
}
},
{
"command": "gitlens.connectRemoteProvider",
"title": "Connect to Remote",
"category": "GitLens",
@ -4422,6 +4431,13 @@
"group": "6_copypath@100"
}
],
"scm/title": [
{
"command": "gitlens.addAuthors",
"when": "gitlens:enabled && !gitlens:readonly",
"group": "navigation@-99"
}
],
"scm/resourceGroup/context": [
{
"command": "gitlens.stashSave",

+ 1
- 0
src/commands.ts View File

@ -1,5 +1,6 @@
'use strict';
export * from './commands/addAuthors';
export * from './commands/annotations';
export * from './commands/closeUnchangedFiles';
export * from './commands/common';

+ 25
- 0
src/commands/addAuthors.ts View File

@ -0,0 +1,25 @@
'use strict';
import { commands, SourceControl } from 'vscode';
import { command, Command, Commands } from './common';
import { GitCommandsCommandArgs } from './gitCommands';
import { Container } from '../container';
@command()
export class AddAuthorsCommand extends Command {
constructor() {
super(Commands.AddAuthors);
}
async execute(sourceControl: SourceControl) {
let repo;
if (sourceControl?.rootUri != null) {
repo = await Container.git.getRepository(sourceControl.rootUri);
}
const args: GitCommandsCommandArgs = {
command: 'co-authors',
state: { repo: repo, contributors: undefined },
};
return commands.executeCommand(Commands.GitCommands, args);
}
}

+ 3
- 0
src/commands/common.ts View File

@ -4,6 +4,7 @@ import {
commands,
Disposable,
ExtensionContext,
SourceControl,
SourceControlResourceGroup,
SourceControlResourceState,
TextDocumentShowOptions,
@ -23,6 +24,7 @@ import { CommandQuickPickItem, RepositoriesQuickPick } from '../quickpicks';
import { ViewNode, ViewRefNode } from '../views/nodes';
export enum Commands {
AddAuthors = 'gitlens.addAuthors',
ClearFileAnnotations = 'gitlens.clearFileAnnotations',
CloseUnchangedFiles = 'gitlens.closeUnchangedFiles',
ComputingFileAnnotations = 'gitlens.computingFileAnnotations',
@ -345,6 +347,7 @@ function isScmResourceGroup(group: any): group is SourceControlResourceGroup {
if (group == null) return false;
return (
(group as SourceControl).inputBox === undefined &&
(group as SourceControlResourceGroup).id !== undefined &&
(group.handle !== undefined ||
(group as SourceControlResourceGroup).label !== undefined ||

+ 17
- 6
src/commands/git/coauthors.ts View File

@ -1,5 +1,6 @@
/* eslint-disable no-loop-func */
'use strict';
import { commands } from 'vscode';
import { Container } from '../../container';
import { GitContributor, GitService, Repository } from '../../git/gitService';
import { QuickCommandBase, StepAsyncGenerator, StepSelection, StepState } from '../quickCommand';
@ -56,12 +57,14 @@ export class CoAuthorsGitCommand extends QuickCommandBase {
const repo = gitApi.repositories.find(r => Strings.normalizePath(r.rootUri.fsPath) === state.repo.path);
if (repo === undefined) return;
for (const c of state.contributors) {
const coauthor = `${c.name}${c.email ? ` <${c.email}>` : ''}`;
let message = repo.inputBox.value;
const message = repo.inputBox.value;
if (message.includes(coauthor)) continue;
const index = message.indexOf('Co-authored-by: ');
if (index !== -1) {
message = message.substring(0, index - 1).trimRight();
}
for (const c of state.contributors) {
let newlines;
if (message.includes('Co-authored-by: ')) {
newlines = '\n';
@ -71,8 +74,11 @@ export class CoAuthorsGitCommand extends QuickCommandBase {
newlines = '\n\n\n';
}
repo.inputBox.value = `${message}${newlines}Co-authored-by: ${coauthor}`;
message += `${newlines}Co-authored-by: ${c.toCoauthor()}`;
}
repo.inputBox.value = message;
void (await commands.executeCommand('workbench.view.scm'));
}
protected async *steps(): StepAsyncGenerator {
@ -137,13 +143,18 @@ export class CoAuthorsGitCommand extends QuickCommandBase {
}
if (state.contributors === undefined || state.counter < 2) {
const message = (await GitService.getBuiltInGitApi())?.repositories.find(
r => Strings.normalizePath(r.rootUri.fsPath) === state.repo!.path,
)?.inputBox.value;
const step = this.createPickStep<ContributorQuickPickItem>({
title: `${this.title} to ${state.repo.formattedName}`,
allowEmpty: true,
multiselect: true,
placeholder: 'Choose contributors to add as co-authors',
matchOnDescription: true,
items: (await Container.git.getContributors(state.repo.path)).map(c =>
ContributorQuickPickItem.create(c),
ContributorQuickPickItem.create(c, message?.includes(c.toCoauthor())),
),
});
const selection: StepSelection<typeof step> = yield step;

+ 8
- 2
src/commands/gitCommands.ts View File

@ -405,9 +405,15 @@ export class GitCommandsCommand extends Command {
if (items.length === 0) {
if (!quickpick.canSelectMany || quickpick.activeItems.length === 0) {
const value = quickpick.value.trim();
if (value.length === 0) return;
if (value.length === 0 && !step.allowEmpty) return;
if (step.onDidAccept === undefined) return;
if (step.onDidAccept === undefined) {
if (step.allowEmpty) {
resolve(await this.nextStep(quickpick, commandsStep.command!, []));
}
return;
}
quickpick.busy = true;

+ 1
- 0
src/commands/quickCommand.ts View File

@ -75,6 +75,7 @@ export function isQuickInputStep(item: QuickPickStep | QuickInputStep): item is
export interface QuickPickStep<T extends QuickPickItem = any> {
additionalButtons?: QuickInputButton[];
allowEmpty?: boolean;
buttons?: QuickInputButton[];
items: (DirectiveQuickPickItem | T)[] | DirectiveQuickPickItem[];
keys?: StepNavigationKeys[];

+ 4
- 0
src/git/models/contributor.ts View File

@ -23,4 +23,8 @@ export class GitContributor {
getAvatarUri(fallback: GravatarDefaultStyle, size: number = 16): Uri {
return getAvatarUri(this.email, fallback, size);
}
toCoauthor(): string {
return `${this.name}${this.email ? ` <${this.email}>` : ''}`;
}
}

Loading…
Cancel
Save