Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'hosted-git-info' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
// set this up first, so we can use 127.0.0.1 as our "hosted git" service
const httpPort = 18000 + (+process.env.TAP_CHILD_ID || 0)
const hostedUrl = `http://localhost:${httpPort}`
const ghi = require('hosted-git-info/git-host-info.js')
const gitPort = 12345 + (+process.env.TAP_CHILD_ID || 0)
ghi.localhost = {
protocols: [ 'git+https', 'git+ssh' ],
domain: `127.0.0.1:${gitPort}`,
httpstemplate: 'git://{domain}/{user}{#committish}',
treepath: 'not-implemented',
tarballtemplate: `${hostedUrl}/repo-HEAD.tgz`,
// shortcut MUST have a user and project, at least
shortcuttemplate: '{type}:{user}/x{#committish}',
pathtemplate: '/{user}{#committish}',
pathmatch: /^\/(repo|submodule-repo)/,
hashformat: h => h,
protocols_re: /^(git):$/
}
ghi.localhostssh = {
protocols: [ 'git+ssh' ],
domain: `localhostssh:${gitPort}`,
sshtemplate: `git://127.0.0.1:${gitPort}/{user}{#committish}`,
const ghi = require('hosted-git-info/git-host-info.js')
const gitPort = 12345 + (+process.env.TAP_CHILD_ID || 0)
ghi.localhost = {
protocols: [ 'git+https', 'git+ssh' ],
domain: `127.0.0.1:${gitPort}`,
httpstemplate: 'git://{domain}/{user}{#committish}',
treepath: 'not-implemented',
tarballtemplate: `${hostedUrl}/repo-HEAD.tgz`,
// shortcut MUST have a user and project, at least
shortcuttemplate: '{type}:{user}/x{#committish}',
pathtemplate: '/{user}{#committish}',
pathmatch: /^\/(repo|submodule-repo)/,
hashformat: h => h,
protocols_re: /^(git):$/
}
ghi.localhostssh = {
protocols: [ 'git+ssh' ],
domain: `localhostssh:${gitPort}`,
sshtemplate: `git://127.0.0.1:${gitPort}/{user}{#committish}`,
sshurltemplate: `git://127.0.0.1:${gitPort}/{user}{#committish}`,
treepath: 'not-implemented',
tarballtemplate: `${hostedUrl}/repo-HEAD.tgz`,
// shortcut MUST have a user and project, at least
shortcuttemplate: '{type}:{user}/x{#committish}',
pathtemplate: '/{user}{#committish}',
pathmatch: /^\/(repo|submodule-repo)/,
hashformat: h => h,
protocols_re: /^(git):$/
}
const remote = `git://localhost:${gitPort}/repo`
}
// TODO: Remove sometime far in the future
if (options.skipCleanup) {
options.cleanup = false;
}
const pkg = util.readPkg();
const runTests = options.tests && !options.yolo;
const runCleanup = options.cleanup && !options.yolo;
const runPublish = options.publish && !pkg.private;
const pkgManager = options.yarn === true ? 'yarn' : 'npm';
const pkgManagerName = options.yarn === true ? 'Yarn' : 'npm';
const rootDir = pkgDir.sync();
const hasLockFile = fs.existsSync(path.resolve(rootDir, options.yarn ? 'yarn.lock' : 'package-lock.json')) || fs.existsSync(path.resolve(rootDir, 'npm-shrinkwrap.json'));
const isOnGitHub = options.repoUrl && (hostedGitInfo.fromUrl(options.repoUrl) || {}).type === 'github';
let publishStatus = 'UNKNOWN';
const rollback = onetime(async () => {
console.log('\nPublish failed. Rolling back to the previous state…');
const tagVersionPrefix = await util.getTagVersionPrefix(options);
const latestTag = await git.latestTag();
const versionInLatestTag = latestTag.slice(tagVersionPrefix.length);
try {
if (versionInLatestTag === util.readPkg().version &&
versionInLatestTag !== pkg.version) { // Verify that the package's version has been bumped before deleting the last tag and commit.
await git.deleteTag(latestTag);
await git.removeLastCommit();
// reformat uri before parsing with hosted-git-info. Allows for further syntax support.
Object.keys(REPLACEMENTS).forEach(replacement => {
if(uri.indexOf(replacement) === 0) uri = uri.replace(replacement, REPLACEMENTS[replacement]);
});
hgi = hostedGitInfo.fromUrl(uri);
if (!hgi || hgi.user.includes('#')) {
let templateAndBranch = uri.split('#');
if (templateAndBranch.length === 1) {
fallback = true;
embarkVersion = semver(require(embarkPath('package.json')).version);
templateAndBranch.push(`${embarkVersion.major}.${embarkVersion.minor}`);
}
templateAndBranch[0] = `embark-framework/embark-${templateAndBranch[0]}-template`;
hgi = hostedGitInfo.fromUrl(templateAndBranch.join('#'));
if (fallback) {
hgi_fallback = hostedGitInfo.fromUrl(templateAndBranch[0]);
}
}
if(!hgi) { throw new Error('Unsupported template name or git host URL'); }
url = hgi.tarball();
if (fallback) {
url_fallback = hgi_fallback.tarball();
folder_fallback = `${hgi_fallback.user}/${hgi_fallback.project}/master`;
}
const returnObject = {
url,
browse: decodeURIComponent(hgi.browse()),
url_fallback,
filePath_fallback: fallback && joinPath(".embark/templates/", folder_fallback, "archive.zip"),
browse_fallback: fallback && decodeURIComponent(hgi_fallback.browse()),
embarkVersion
};
npm.load(conf, function (er) {
if (er)
throw er;
var parsed = hostedFromURL(package);
if (parsed) {
console.log("Installing dependency", parsed.path());
git = require('npm/lib/utils/git');
var install_path = 'fuse_modules/' + parsed.path();
var stats;
try {
stats = fs.statSync(install_path);
}
catch (e) {
}
if (stats && stats.isDirectory()) {
return postInstall(package, fn, install_path);
}
cloneRemote(parsed.path(), parsed.toString(), install_path, function (error) {
if (error) throw error;
postInstall(package, fn, install_path);
, fixBugsField: function(data) {
if (!data.bugs && data.repository && data.repository.url) {
var hosted = hostedGitInfo.fromUrl(data.repository.url)
if(hosted && hosted.bugs()) {
data.bugs = {url: hosted.bugs()}
}
}
else if(data.bugs) {
var emailRe = /^.+@.*\..+$/
if(typeof data.bugs == "string") {
if(emailRe.test(data.bugs))
data.bugs = {email:data.bugs}
else if(url.parse(data.bugs).protocol)
data.bugs = {url: data.bugs}
else
this.warn("nonEmailUrlBugsString")
}
else {
bugsTypos(data.bugs, this.warn)
, fixBugsField: function(data) {
if (!data.bugs && data.repository && data.repository.url) {
var hosted = hostedGitInfo.fromUrl(data.repository.url)
if(hosted && hosted.bugs()) {
data.bugs = {url: hosted.bugs()}
}
}
else if(data.bugs) {
var emailRe = /^.+@.*\..+$/
if(typeof data.bugs == "string") {
if(emailRe.test(data.bugs))
data.bugs = {email:data.bugs}
else if(url.parse(data.bugs).protocol)
data.bugs = {url: data.bugs}
else
this.warn("nonEmailUrlBugsString")
}
else {
bugsTypos(data.bugs, this.warn)
config(env, baseConfig) {
let pkg = this.parent.pkg;
if (this._documentingAddonAt()) {
pkg = require(path.join(this._documentingAddonAt(), 'package.json'));
}
let repo = pkg.repository;
let info = require('hosted-git-info').fromUrl(repo.url || repo);
let userConfig = this._readUserConfig();
let docsAppPathInRepo = path.relative(
this._getRepoRoot(),
path.join(
path.resolve(path.dirname(this.project.configPath()), '..'),
'app'
)
);
let addonPathInRepo = this._documentingAddonAt()
? path.relative(this._getRepoRoot(), path.join(this._documentingAddonAt(), 'addon'))
: path.relative(this._getRepoRoot(), path.join(this.project.root, 'addon'));
let config = {
'ember-cli-addon-docs': {
function getGitRepoInfoFromPackage(pkg) {
normalize(pkg);
if (pkg.repository && pkg.repository.type === "git") {
return hostedGitInfo.fromUrl(pkg.repository.url);
}
return null;
}
export async function createPublisher(packager: Packager, options: BuildOptions): Promise {
const repo = packager.devMetadata.repository || packager.metadata.repository
let info: Info = null
if (repo == null) {
let url = process.env.TRAVIS_REPO_SLUG || process.env.APPVEYOR_PROJECT_SLUG
if (url == null) {
url = await getGitUrlFromGitConfig()
}
if (url != null) {
info = parseRepositoryUrl(url)
}
if (info == null) {
log("Cannot detect repository by .git/config")
throw new Error("Please specify 'repository' in the dev package.json ('" + packager.devPackageFile + "')")
}
}
else {
info = parseRepositoryUrl(typeof repo === "string" ? repo : repo.url)
}
return new GitHubPublisher(info.user, info.project, packager.metadata.version, options.githubToken)
}