Skip to content

Commit

Permalink
[Refactor] Use git-repo-info to return sha, and get the repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Green-Ranger11 authored and ljharb committed Nov 18, 2021
1 parent 4e0a3d6 commit a7da80b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@octokit/graphql": "^4.8.0",
"chalk": "^4.1.2",
"dotenv": "^10.0.0",
"git-repo-info": "^2.1.1",
"yargs": "^17.3.0"
},
"engines": {
Expand Down
10 changes: 7 additions & 3 deletions utils/getRepo.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
'use strict';

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

module.exports = function getRepo() {
const getRepos = String(execSync('git ls-remote --get-url'));
const pushRepoRegex = /(?<=github\.com(?:\/|:))(?:.*)(?=\.git*)/gm;
return getRepos.match(pushRepoRegex)[0];
if (isGitRepo().sha) {
const getRepos = String(execSync('git ls-remote --get-url'));
const pushRepoRegex = /(?<=github\.com(?:\/|:))(?:.*)(?=\.git*)/gm;
return getRepos.match(pushRepoRegex)?.[0];
}
return null;
};
5 changes: 3 additions & 2 deletions utils/getSHA.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

const { execSync } = require('child_process');
const getRepoInfo = require('git-repo-info');

module.exports = function getSHA(short = false) {
return String(execSync(`git rev-parse${short ? ' --short' : ''} HEAD`)).trim();
const { sha, abbreviatedSha } = getRepoInfo();
return sha ? short ? abbreviatedSha : sha : null;
};

0 comments on commit a7da80b

Please sign in to comment.