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
|
# 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
|
- 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",
|
"name": "gitcheck",
|
||||||
"displayName": "Git User Check",
|
"displayName": "Git User Check",
|
||||||
"description": "Checking the user's compliance with the repository",
|
"description": "Checking the user's compliance with the repository",
|
||||||
"version": "0.0.1",
|
"version": "0.0.2",
|
||||||
"preview": true,
|
"preview": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"vscode": "^1.62.0"
|
"vscode": "^1.62.0"
|
||||||
@@ -33,15 +33,15 @@
|
|||||||
"properties": {
|
"properties": {
|
||||||
"gitcheck.domain": {
|
"gitcheck.domain": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "remote domain for check"
|
"description": "Remote domain for check"
|
||||||
},
|
},
|
||||||
"gitcheck.user": {
|
"gitcheck.name": {
|
||||||
"type":"string",
|
"type":"string",
|
||||||
"description": "Username for gitcheck domain"
|
"description": "user.name for gitcheck domain"
|
||||||
},
|
},
|
||||||
"gitcheck.email": {
|
"gitcheck.email": {
|
||||||
"type":"string",
|
"type":"string",
|
||||||
"description": "Email for gitcheck domain"
|
"description": "user.email for gitcheck domain"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,51 +1,60 @@
|
|||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import { GitExtension } from './git';
|
import { GitExtension } from './git';
|
||||||
|
|
||||||
export function activate() {
|
export async function activate() {
|
||||||
var conf = vscode.workspace.getConfiguration("gitcheck");
|
var conf = vscode.workspace.getConfiguration("gitcheck");
|
||||||
const domain = conf.get<string>("domain");
|
const domain = conf.get<string>("domain");
|
||||||
const user = conf.get<string>("user");
|
const name = conf.get<string>("name");
|
||||||
const email = conf.get<string>("email");
|
const email = conf.get<string>("email");
|
||||||
|
|
||||||
if (!(domain && user && email)) {
|
if (!vscode.workspace.workspaceFolders) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(domain && name && email)) {
|
||||||
console.log("Missing config params");
|
console.log("Missing config params");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const git = vscode.extensions.getExtension<GitExtension>('vscode.git')!.exports.getAPI(1)!;
|
const git = vscode.extensions.getExtension<GitExtension>('vscode.git')!.exports.getAPI(1)!;
|
||||||
const repository = git.repositories[0];
|
const repository = await git.openRepository(vscode.workspace.workspaceFolders[0].uri);
|
||||||
repository.state.remotes.forEach(async remote => {
|
|
||||||
const pushUrl = remote.pushUrl;
|
if (!repository) {
|
||||||
if (pushUrl && pushUrl.includes(domain)) {
|
return;
|
||||||
var gitConfig = await repository.getConfigs();
|
}
|
||||||
var gitUser:string = "";
|
|
||||||
var gitEmail:string = "";
|
repository.state.remotes.forEach(async remote => {
|
||||||
gitConfig = gitConfig.filter( elem => {
|
const pushUrl = remote.pushUrl;
|
||||||
return elem.key === "user.name" || elem.key === "user.email";
|
if (pushUrl && pushUrl.includes(domain)) {
|
||||||
});
|
var gitConfig = await repository.getConfigs();
|
||||||
if (gitConfig.length === 0) {
|
var gitName:string = "";
|
||||||
vscode.window.showErrorMessage("Missing user creds in git");
|
var gitEmail:string = "";
|
||||||
return;
|
gitConfig = gitConfig.filter( elem => {
|
||||||
}
|
return elem.key === "user.name" || elem.key === "user.email";
|
||||||
gitConfig.forEach(c => {
|
});
|
||||||
switch (c.key) {
|
if (gitConfig.length === 0) {
|
||||||
case "user.name":
|
vscode.window.showErrorMessage("Missing user creds in git");
|
||||||
gitUser = c.value;
|
return;
|
||||||
break;
|
|
||||||
|
|
||||||
case "user.email":
|
|
||||||
gitEmail = c.value;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
console.log(c.key);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (gitUser !== user || gitEmail !== email) {
|
|
||||||
vscode.window.showErrorMessage("Wrong user creds in git");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
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() {}
|
export function deactivate() {}
|
||||||
|
|||||||
Reference in New Issue
Block a user