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

VS Code vscode.git integration #18

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 1 addition & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Place your settings in this file to overwrite default and user settings.
{
"typescript.surveys.enabled": false,
"terminal.integrated.cwd": "C:\\Users\\Benjamin\\Desktop\\project\\emojis4git"
"typescript.surveys.enabled": false
}
15 changes: 4 additions & 11 deletions src/gitmojiCommit/composeCommit.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
const { workspace } = require('vscode')
const convertToEmoji = require('./convertToEmoji')
const convertToEmoji = require('./convertToEmoji');

module.exports = (commitType, commitText) => {
const multiline = workspace.getConfiguration().get('gitmoji.multilineCommit')
const emoji = convertToEmoji(commitType)

if (multiline) {
return `git commit -m $'${emoji} ${commitText}'`
} else {
return `git commit -m "${emoji} ${commitText}"`
}
}
const emoji = convertToEmoji(commitType);
return `${emoji} ${commitText}`;
};
5 changes: 0 additions & 5 deletions src/gitmojiCommit/doesTerminalExist.js

This file was deleted.

9 changes: 4 additions & 5 deletions src/gitmojiCommit/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const { commands, window } = require('vscode')
const getCommitType = require('./getCommitType')
const composeCommit = require('./composeCommit')
const sendMessageToTerminal = require('./sendMessageToTerminal')
const sendMessageToSourceControl = require("./sendMessageToSourceControl");

// register this function as gitmojiCommit
module.exports = () =>
commands.registerCommand('extension.gitmojiCommit', async function() {
commands.registerCommand('extension.gitmojiCommit', async function () {
// get the gitmoji commit type
const commitType = await getCommitType()
// if no type is selected exit and display warning message
Expand All @@ -25,7 +25,6 @@ module.exports = () =>
}

const commitMessage = composeCommit(commitType, commitText)

// send the composed message to integrated terminal
sendMessageToTerminal(commitMessage)
// send the composed message to Source Control
sendMessageToSourceControl(commitMessage);
})
51 changes: 51 additions & 0 deletions src/gitmojiCommit/sendMessageToSourceControl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const { workspace, window, extensions } = require('vscode');

module.exports = async (commitMessage) => {
// get boolean value of autoCommit setting
const autoCommit = workspace.getConfiguration().get('gitmoji.autoCommit')

// get built in vscode git extension api
const gitExtension = extensions.getExtension('vscode.git').exports;
const git = gitExtension.getAPI(1);

// list of workspace repositories
const repos = git.repositories;
// if no repositories show warning message
if (!repos || !repos.length) {
return window.showWarningMessage('You have no active repositories.');

// if one repository, just set the commit message
} else if (repos.length === 1) {
if (autoCommit) {
repos[0].commit(commitMessage).catch(e => window.showWarningMessage(e.stdout));
} else {
setCommit(repos[0], commitMessage)
}
} else {
// gather directory names of all repos
const directories = repos.map((el, i) => {
return el.rootUri.path.split('/').pop()
});
// allow user to chose directory they want commit to go to
const directory = await window.showQuickPick(directories, {
placeHolder: 'Which repositiory should commit be sent to?',
ignoreFocusOut: true
});

if (!directory) {
window.showWarningMessage('Gitmoji Commit: You did not pick a repository.');
}
// determine index of choice
const index = directories.indexOf(directory);
// Set the Commit Message
if (autoCommit) {
repos[index].commit(commitMessage).catch(e => window.showWarningMessage(e.stdout));
} else {
setCommit(repos[index], commitMessage);
}
}
};

function setCommit(repository, commit) {
repository.inputBox.value = commit;
}
70 changes: 0 additions & 70 deletions src/gitmojiCommit/sendMessageToTerminal.js

This file was deleted.