Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
461bd634a6
|
|||
|
533fe677de
|
|||
|
4788b5403b
|
|||
|
eee833f62e
|
|||
|
f305cdd7c3
|
|||
|
f38ef7dee3
|
10
CHANGELOG.md
10
CHANGELOG.md
@@ -1,5 +1,13 @@
|
||||
# Change Log
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [0.0.1]
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
## [0.0.2] - 2021-12-06
|
||||
### Added
|
||||
- README 😂
|
||||
### Changed
|
||||
- Rename `user` => `name` in settings options
|
||||
|
||||
## [0.0.1] - 2021-12-06
|
||||
- Initial release
|
||||
10
README.md
10
README.md
@@ -1 +1,9 @@
|
||||
# gitcheck
|
||||
# Git User Check
|
||||
|
||||
Sometimes, after cloning a repository from a corporate server and having already sent several commits there, you notice that you forgot to change the user settings in git.
|
||||
This extension is written to avoid this.
|
||||
|
||||
## Configuration
|
||||
* `gitcheck.domain` – The domain (or just a substring) for which the check will be performed (you can see in the output of the command `git remote -v`)&
|
||||
* `gitcheck.name` – This value will be checked against the value of the git parameter `user.name`.
|
||||
* `gitcheck.email` – This value will be checked against the value of the git parameter `user.email`.
|
||||
10
package.json
10
package.json
@@ -2,7 +2,7 @@
|
||||
"name": "gitcheck",
|
||||
"displayName": "Git User Check",
|
||||
"description": "Checking the user's compliance with the repository",
|
||||
"version": "0.0.1",
|
||||
"version": "0.0.2",
|
||||
"preview": true,
|
||||
"engines": {
|
||||
"vscode": "^1.62.0"
|
||||
@@ -33,15 +33,15 @@
|
||||
"properties": {
|
||||
"gitcheck.domain": {
|
||||
"type": "string",
|
||||
"description": "remote domain for check"
|
||||
"description": "Remote domain for check"
|
||||
},
|
||||
"gitcheck.user": {
|
||||
"gitcheck.name": {
|
||||
"type":"string",
|
||||
"description": "Username for gitcheck domain"
|
||||
"description": "user.name for gitcheck domain"
|
||||
},
|
||||
"gitcheck.email": {
|
||||
"type":"string",
|
||||
"description": "Email for gitcheck domain"
|
||||
"description": "user.email for gitcheck domain"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,51 +1,60 @@
|
||||
import * as vscode from 'vscode';
|
||||
import { GitExtension } from './git';
|
||||
|
||||
export function activate() {
|
||||
export async function activate() {
|
||||
var conf = vscode.workspace.getConfiguration("gitcheck");
|
||||
const domain = conf.get<string>("domain");
|
||||
const user = conf.get<string>("user");
|
||||
const name = conf.get<string>("name");
|
||||
const email = conf.get<string>("email");
|
||||
|
||||
if (!(domain && user && email)) {
|
||||
if (!vscode.workspace.workspaceFolders) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(domain && name && email)) {
|
||||
console.log("Missing config params");
|
||||
return;
|
||||
}
|
||||
|
||||
const git = vscode.extensions.getExtension<GitExtension>('vscode.git')!.exports.getAPI(1)!;
|
||||
const repository = git.repositories[0];
|
||||
repository.state.remotes.forEach(async remote => {
|
||||
const pushUrl = remote.pushUrl;
|
||||
if (pushUrl && pushUrl.includes(domain)) {
|
||||
var gitConfig = await repository.getConfigs();
|
||||
var gitUser:string = "";
|
||||
var gitEmail:string = "";
|
||||
gitConfig = gitConfig.filter( elem => {
|
||||
return elem.key === "user.name" || elem.key === "user.email";
|
||||
});
|
||||
if (gitConfig.length === 0) {
|
||||
vscode.window.showErrorMessage("Missing user creds in git");
|
||||
return;
|
||||
}
|
||||
gitConfig.forEach(c => {
|
||||
switch (c.key) {
|
||||
case "user.name":
|
||||
gitUser = c.value;
|
||||
break;
|
||||
const repository = await git.openRepository(vscode.workspace.workspaceFolders[0].uri);
|
||||
|
||||
case "user.email":
|
||||
gitEmail = c.value;
|
||||
break;
|
||||
if (!repository) {
|
||||
return;
|
||||
}
|
||||
|
||||
default:
|
||||
console.log(c.key);
|
||||
}
|
||||
});
|
||||
if (gitUser !== user || gitEmail !== email) {
|
||||
vscode.window.showErrorMessage("Wrong user creds in git");
|
||||
}
|
||||
repository.state.remotes.forEach(async remote => {
|
||||
const pushUrl = remote.pushUrl;
|
||||
if (pushUrl && pushUrl.includes(domain)) {
|
||||
var gitConfig = await repository.getConfigs();
|
||||
var gitName:string = "";
|
||||
var gitEmail:string = "";
|
||||
gitConfig = gitConfig.filter( elem => {
|
||||
return elem.key === "user.name" || elem.key === "user.email";
|
||||
});
|
||||
if (gitConfig.length === 0) {
|
||||
vscode.window.showErrorMessage("Missing user creds in git");
|
||||
return;
|
||||
}
|
||||
});
|
||||
gitConfig.forEach(c => {
|
||||
switch (c.key) {
|
||||
case "user.name":
|
||||
gitName = c.value;
|
||||
break;
|
||||
|
||||
case "user.email":
|
||||
gitEmail = c.value;
|
||||
break;
|
||||
|
||||
default:
|
||||
console.log(c.key);
|
||||
}
|
||||
});
|
||||
if (gitName !== name || gitEmail !== email) {
|
||||
vscode.window.showErrorMessage("Wrong user creds in git");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function deactivate() {}
|
||||
|
||||
Reference in New Issue
Block a user