31 Commits
v0.0.2 ... main

Author SHA1 Message Date
a2e3cd60ed bump version to v0.2.2 2023-07-19 10:27:50 +03:00
aa870623ff Merge pull request #1 from maksim77/dependabot/npm_and_yarn/word-wrap-1.2.4
Bump word-wrap from 1.2.3 to 1.2.4
2023-07-19 10:18:04 +03:00
dependabot[bot]
5937f8c918 Bump word-wrap from 1.2.3 to 1.2.4
Bumps [word-wrap](https://github.com/jonschlinkert/word-wrap) from 1.2.3 to 1.2.4.
- [Release notes](https://github.com/jonschlinkert/word-wrap/releases)
- [Commits](https://github.com/jonschlinkert/word-wrap/compare/1.2.3...1.2.4)

---
updated-dependencies:
- dependency-name: word-wrap
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-19 06:20:54 +00:00
b9031579d6 Revert "try self-hosted runner"
This reverts commit cccd31016e.
2023-02-07 13:59:10 +03:00
cccd31016e try self-hosted runner 2023-02-07 13:54:08 +03:00
6d09eeaf99 bump version 2022-12-27 10:02:49 +03:00
caa05f26f6 update deps 2022-12-27 10:02:07 +03:00
7ef5b154ea bump version 2021-12-10 13:22:38 +03:00
75260016c8 fix async work with repository state 2021-12-10 13:19:37 +03:00
93ed637537 bump version 2021-12-09 16:09:17 +03:00
19d8a93f3f update changelog 2021-12-09 16:08:08 +03:00
d000c7b0ee add icon 2021-12-09 16:06:30 +03:00
6fd42bea39 small changelog fix formating 2021-12-07 19:01:53 +03:00
7d70129495 add new version to changelog 2021-12-07 19:01:27 +03:00
99bc7cb73e bump version 2021-12-07 15:25:06 +03:00
d4c2614d8e remove vsce from npm deps 2021-12-07 15:24:31 +03:00
98873d8be2 simplify gh actions 2021-12-07 15:23:27 +03:00
50f4015f30 rename error message 2021-12-07 15:17:55 +03:00
cb3ccbb4f6 Add overwrite button 2021-12-07 15:17:19 +03:00
5e776f686b Change error message 2021-12-07 15:03:15 +03:00
3c9a3f8168 remove unused log from switch 2021-12-07 15:02:56 +03:00
fdd72009b9 add some logs 2021-12-07 15:02:14 +03:00
3560e9f93b Fix gh actions 2021-12-07 14:24:55 +03:00
5e70f0da6b bump version 2021-12-07 11:56:16 +03:00
bf14a00b38 Change creation method for vscode.git api object 2021-12-07 11:53:13 +03:00
3b1a55ea0a add publish step to gh actions 2021-12-07 11:47:19 +03:00
926b050a63 add package step to gh actions 2021-12-07 11:35:44 +03:00
7e8621f6b2 remove matrix.os from gh actions 2021-12-07 11:35:33 +03:00
e1b1b4a16a Add Github Actions 2021-12-07 11:18:51 +03:00
ec9ab4174b Update .gitignore && package-lock.json 2021-12-07 11:17:18 +03:00
90cdb968bc fix typo in README 2021-12-06 22:47:35 +03:00
8 changed files with 910 additions and 645 deletions

97
.github/workflows/main.yml vendored Normal file
View File

@@ -0,0 +1,97 @@
name: "Main"
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
name: Lint
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: "14"
- run: /usr/bin/Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 & echo "Started xvfb"
shell: bash
- run: npm install
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- run: npm run lint
env:
DISPLAY: ":99.0"
package:
runs-on: ubuntu-latest
needs: lint
name: Package
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: "14"
- run: npm install
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- run: npm install -g vsce
- run: vsce package
- run: echo "VSIX_PATH=$(find . -maxdepth 1 -type f -iname "*.vsix" | head -1)" >> $GITHUB_ENV
- run: echo "VSIX_NAME=$(basename $(find . -maxdepth 1 -type f -iname "*.vsix" | head -1))" >> $GITHUB_ENV
- uses: actions/upload-artifact@v2
with:
path: ${{ env.VSIX_PATH }}
name: ${{ env.VSIX_NAME }}
release:
runs-on: ubuntu-latest
needs: package
if: startsWith(github.ref, 'refs/tags/v')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VSCE_PAT: ${{ secrets.VSCE_PAT }}
DISPLAY: ":99.0"
name: Release
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: "14"
- run: /usr/bin/Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 & echo "Started xvfb"
shell: bash
- run: npm install
- run: npm install -g vsce
- run: vsce package
- run: echo "VSIX_PATH=$(find . -maxdepth 1 -type f -iname "*.vsix" | head -1)" >> $GITHUB_ENV
- run: echo "VSIX_NAME=$(basename $(find . -maxdepth 1 -type f -iname "*.vsix" | head -1))" >> $GITHUB_ENV
- uses: actions/create-release@v1
id: create_release
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
body: See [CHANGE LOG](https://github.com/maksim77/gitcheck/blob/main/CHANGELOG.md) for details.
draft: false
prerelease: false
- uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ env.VSIX_PATH }}
asset_name: ${{ env.VSIX_NAME }}
asset_content_type: application/zip
- run: vsce publish

1
.gitignore vendored
View File

@@ -1 +1,2 @@
out out
.vscode-test/

View File

@@ -3,11 +3,26 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 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). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.0.2] - 2021-12-06
## [v0.2.0] - 2021-12-10
### Fixed
-Fix async work with repository state
## [v0.1.1] - 2021-12-09
### Added
- icon
## [v0.1.0] - 2021-12-07
### Added
- Overwrite button in error message
## [v0.0.3] - 2021-12-07
### Fixed
- Small fixes
## [v0.0.2] - 2021-12-06
### Added ### Added
- README 😂 - README 😂
### Changed ### Changed
- Rename `user` => `name` in settings options - Rename `user` => `name` in settings options
## [0.0.1] - 2021-12-06 ## [v0.0.1] - 2021-12-06
- Initial release - Initial release

View File

@@ -4,6 +4,6 @@ Sometimes, after cloning a repository from a corporate server and having already
This extension is written to avoid this. This extension is written to avoid this.
## Configuration ## 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.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.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`. * `gitcheck.email` This value will be checked against the value of the git parameter `user.email`.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

1212
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -2,8 +2,8 @@
"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.2", "version": "0.2.2",
"preview": true, "preview": false,
"engines": { "engines": {
"vscode": "^1.62.0" "vscode": "^1.62.0"
}, },
@@ -19,6 +19,7 @@
"type": "git", "type": "git",
"url": "https://github.com/maksim77/gitcheck.git" "url": "https://github.com/maksim77/gitcheck.git"
}, },
"icon": "media/folder-green-git-icon.png",
"activationEvents": [ "activationEvents": [
"workspaceContains:.git/" "workspaceContains:.git/"
], ],
@@ -27,7 +28,7 @@
], ],
"main": "./out/extension.js", "main": "./out/extension.js",
"contributes": { "contributes": {
"configuration":[ "configuration": [
{ {
"title": "Git User Check", "title": "Git User Check",
"properties": { "properties": {
@@ -36,11 +37,11 @@
"description": "Remote domain for check" "description": "Remote domain for check"
}, },
"gitcheck.name": { "gitcheck.name": {
"type":"string", "type": "string",
"description": "user.name for gitcheck domain" "description": "user.name for gitcheck domain"
}, },
"gitcheck.email": { "gitcheck.email": {
"type":"string", "type": "string",
"description": "user.email for gitcheck domain" "description": "user.email for gitcheck domain"
} }
} }
@@ -56,16 +57,16 @@
"test": "node ./out/test/runTest.js" "test": "node ./out/test/runTest.js"
}, },
"devDependencies": { "devDependencies": {
"@types/vscode": "^1.62.0",
"@types/glob": "^7.1.4", "@types/glob": "^7.1.4",
"@types/mocha": "^9.0.0", "@types/mocha": "^9.0.0",
"@types/node": "14.17.27", "@types/node": "14.17.27",
"@types/vscode": "^1.62.0",
"@typescript-eslint/eslint-plugin": "^5.1.0", "@typescript-eslint/eslint-plugin": "^5.1.0",
"@typescript-eslint/parser": "^5.1.0", "@typescript-eslint/parser": "^5.1.0",
"@vscode/test-electron": "^1.6.2",
"eslint": "^8.1.0", "eslint": "^8.1.0",
"glob": "^7.1.7", "glob": "^7.1.7",
"mocha": "^9.1.3", "mocha": "^9.1.3",
"typescript": "^4.4.4", "typescript": "^4.4.4"
"@vscode/test-electron": "^1.6.2"
} }
} }

View File

@@ -1,39 +1,85 @@
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import { GitExtension } from './git'; import { GitExtension, Repository } from './git';
class UserConf {
domain: string = "";
name: string = "";
email:string = "";
valid: boolean = false;
constructor() {
var conf = vscode.workspace.getConfiguration("gitcheck");
const _domain = conf.get<string>("domain");
const _name = conf.get<string>("name");
const _email = conf.get<string>("email");
if (!(_domain && _name && _email)) {
console.log("Missing config params");
this.valid = false;
} else {
this.domain = _domain;
this.name = _name;
this.email = _email;
this.valid = true;
}
}
}
export async function activate() { export async function activate() {
var conf = vscode.workspace.getConfiguration("gitcheck"); const userConf = new UserConf();
const domain = conf.get<string>("domain"); if (!userConf.valid) {
const name = conf.get<string>("name"); return;
const email = conf.get<string>("email"); }
if (!vscode.workspace.workspaceFolders) { if (!vscode.workspace.workspaceFolders) {
console.log("No opened workspace");
return; return;
} }
if (!(domain && name && email)) {
console.log("Missing config params"); const gitExt = vscode.extensions.getExtension<GitExtension>('vscode.git')!;
const git = gitExt.exports.getAPI(1);
if (!git) {
console.log("Git extension disabled");
return; return;
} }
const git = vscode.extensions.getExtension<GitExtension>('vscode.git')!.exports.getAPI(1)!;
const repository = await git.openRepository(vscode.workspace.workspaceFolders[0].uri); const repository = await git.openRepository(vscode.workspace.workspaceFolders[0].uri);
if (!repository) { if (!repository) {
console.error("Cannot open git repository");
return; return;
} }
repository.state.remotes.forEach(async remote => { let remotesLen:number = 0;
repository.state.onDidChange(() => {
if (remotesLen > 0) {
return;
}
remotesLen = repository.state.remotes.length;
if (remotesLen > 0) {
gitCheck(repository, userConf);
}
});
}
function gitCheck(repo:Repository, conf:UserConf) {
repo.state.remotes.forEach(async remote => {
const pushUrl = remote.pushUrl; const pushUrl = remote.pushUrl;
if (pushUrl && pushUrl.includes(domain)) { if (pushUrl && pushUrl.includes(conf.domain)) {
var gitConfig = await repository.getConfigs(); var gitConfig = await repo.getConfigs();
var gitName:string = ""; var gitName:string = "";
var gitEmail:string = ""; var gitEmail:string = "";
gitConfig = gitConfig.filter( elem => { gitConfig = gitConfig.filter( elem => {
return elem.key === "user.name" || elem.key === "user.email"; return elem.key === "user.name" || elem.key === "user.email";
}); });
if (gitConfig.length === 0) { if (gitConfig.length === 0) {
vscode.window.showErrorMessage("Missing user creds in git"); console.error("Missing user creds in git");
const option = await vscode.window.showErrorMessage("Missing user settings in git", "Overwrite");
if (option && option === "Overwrite") {
await repo.setConfig("user.name", conf.name);
await repo.setConfig("user.email", conf.email);
}
return; return;
} }
gitConfig.forEach(c => { gitConfig.forEach(c => {
@@ -47,11 +93,16 @@ export async function activate() {
break; break;
default: default:
console.log(c.key); break;
} }
}); });
if (gitName !== name || gitEmail !== email) { if (gitName !== conf.name || gitEmail !== conf.email) {
vscode.window.showErrorMessage("Wrong user creds in git"); console.error("Wrong user settings in git");
const option = await vscode.window.showErrorMessage("Wrong user settings in git", "Overwrite");
if (option && option === "Overwrite") {
await repo.setConfig("user.name", conf.name);
await repo.setConfig("user.email", conf.email);
}
} }
} }
}); });