Skip to content

Commit

Permalink
feat: add "Publish to GitHub/Git" command
Browse files Browse the repository at this point in the history
  • Loading branch information
senyai committed Apr 22, 2024
1 parent 95ea578 commit 0ff3b3e
Show file tree
Hide file tree
Showing 10 changed files with 1,171 additions and 33 deletions.
711 changes: 698 additions & 13 deletions package-lock.json

Large diffs are not rendered by default.

23 changes: 22 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,16 @@
"command": "fossil.praise",
"title": "Praise (blame)",
"category": "Fossil"
},
{
"command": "fossil.gitPublish",
"title": "Publish to GitHub/Git",
"category": "Fossil"
},
{
"command": "fossil.gitExport",
"title": "Export git",
"category": "Fossil"
}
],
"menus": {
Expand Down Expand Up @@ -1049,6 +1059,16 @@
],
"description": "%config.username%",
"default": null
},
"fossil.confirmGitExport": {
"type": "string",
"enum": [
"Automatically",
"Never",
"Ask"
],
"default": "Ask",
"description": "When repository was exported to git, ask to run `fossil export` after every commit"
}
}
},
Expand Down Expand Up @@ -1127,7 +1147,8 @@
"@typescript-eslint/eslint-plugin": "^7.6.0",
"@typescript-eslint/parser": "^7.6.0",
"@vscode/test-electron": "~2.3.9",
"@vscode/vsce": "~2.25.0",
"@vscode/vsce": "~2.26.0",
"@octokit/rest": "~20.1.0",
"c8": "^8.0.1",
"esbuild": "~0.20.2",
"eslint": "^8.52.0",
Expand Down
34 changes: 32 additions & 2 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import { FossilExecutable, FossilCWD } from './fossilExecutable';

import { localize } from './main';
import { PraiseAnnotator } from './praise';
import { Credentials, exportGit, inputExportOptions } from './gitExport';

type CommandKey =
| 'add'
Expand All @@ -72,6 +73,8 @@ type CommandKey =
| 'deleteFiles'
| 'fileLog'
| 'forget'
| 'gitExport'
| 'gitPublish'
| 'ignore'
| 'init'
| 'integrate'
Expand Down Expand Up @@ -152,6 +155,7 @@ function command(id: CommandId, options: { repository?: boolean } = {}) {
export class CommandCenter {
private readonly disposables: Disposable[];
private readonly previewManager: FossilPreviewManager;
private readonly credentials = new Credentials();

constructor(
private readonly executable: FossilExecutable,
Expand Down Expand Up @@ -904,9 +908,19 @@ export class CommandCenter {
}

const result = await repository.commit(message, scope, newBranch);

if (!result.exitCode) {
const config = await repository.config('last-git-export-repo');
if (config.get('last-git-export-repo')) {
if (await interaction.confirmGitExport()) {
repository.gitExport();
}
}
}
return !result.exitCode;
}

// ToDo: rename/rethink this function
private async commitWithAnyInput(
repository: Repository,
opts: CommitOptions
Expand All @@ -921,7 +935,6 @@ export class CommandCenter {
: interaction.inputCommitMessage(),
opts
);

if (message && didCommit) {
inputBox.value = '';
}
Expand Down Expand Up @@ -1261,7 +1274,7 @@ export class CommandCenter {
name: 'Fossil UI',
cwd: repository.root,
});
terminal.sendText('fossil ui', true);
terminal.sendText('fossil ui');
// await commands.executeCommand<void>(
// 'simpleBrowser.show',
// 'http://127.0.0.1:8000'
Expand Down Expand Up @@ -1386,6 +1399,23 @@ export class CommandCenter {
const praises = await repository.praise(uri.fsPath);
await PraiseAnnotator.create(repository, editor, praises);
}

@command('fossil.gitPublish', { repository: true })
async gitPublish(repository: Repository): Promise<void> {
const options = await inputExportOptions(
this.credentials,
repository,
this.disposables
);
if (options) {
await exportGit(options, repository);
}
}
@command('fossil.gitExport', { repository: true })
async gitExport(repository: Repository): Promise<void> {
await repository.gitExport();
}

private async diff(
repository: Repository,
checkin: FossilCheckin,
Expand Down
9 changes: 9 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface ConfigScheme {
username: FossilUsername | null;
autoRefresh: boolean;
enableRenaming: boolean;
confirmGitExport: 'Automatically' | 'Never' | null;
}

class Config {
Expand Down Expand Up @@ -67,6 +68,14 @@ class Config {
disableRenaming() {
this.config.update('enableRenaming', false, false);
}

setGitExport(how: NonNullable<ConfigScheme['confirmGitExport']>) {
this.config.update('confirmGitExport', how, false);
}

get gitExport() {
return this.get('confirmGitExport');
}
}

const typedConfig = new Config();
Expand Down
2 changes: 2 additions & 0 deletions src/fossilExecutable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ type FossilCommand =
| 'diff'
// | 'extras' - we get it from `fossil status --differ`
| 'forget'
| 'git'
| 'info'
| 'init'
| 'ls'
Expand All @@ -112,6 +113,7 @@ type FossilCommand =
| 'rename'
| 'revert'
| 'settings'
| 'sqlite'
| 'stash'
| 'status'
| 'tag'
Expand Down
Loading

0 comments on commit 0ff3b3e

Please sign in to comment.