Skip to content

Commit

Permalink
[Refactor] Remove git dependency by utilizing parse-git-config
Browse files Browse the repository at this point in the history
  • Loading branch information
Green-Ranger11 authored and ljharb committed Dec 8, 2021
1 parent 1762a20 commit b164213
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"chalk": "^4.1.2",
"dotenv": "^10.0.0",
"git-repo-info": "^2.1.1",
"parse-git-config": "^3.0.0",
"yargs": "^17.3.0"
},
"engines": {
Expand Down
9 changes: 5 additions & 4 deletions utils/getRepo.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
'use strict';

const { execSync } = require('child_process');
const isGitRepo = require('git-repo-info');
const parse = require('parse-git-config');

module.exports = function getRepo(remote = 'origin') {
if (isGitRepo().sha) {
const getRepos = String(execSync(`git ls-remote --get-url ${remote}`)).trim();
if (isGitRepo().commonGitDir) {
const config = parse.sync({ path: `${isGitRepo().commonGitDir}/config` });
const remoteUrl = parse.expandKeys(config)?.remote?.[remote]?.url;
const pushRepoRegex = /(?<=github\.com(?:\/|:))(?:.*)(?=\.git*)/gm;
return getRepos.match(pushRepoRegex)?.[0];
return remoteUrl?.match(pushRepoRegex)?.[0];
}
return null;
};

0 comments on commit b164213

Please sign in to comment.