MCPcopy Create free account
hub / github.com/apache/camel-website / GitHubReleaseFetcher

Class GitHubReleaseFetcher

github-release-binary.js:72–165  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70 const { ZipFS, getLibzipPromise } = require('@yarnpkg/libzip');
71
72 class GitHubReleaseFetcher {
73
74 supports(locator, opts) {
75 return supports(locator.reference);
76 }
77
78 getLocalPath(locator, opts) {
79 return null;
80 }
81
82 async fetch(locator, opts) {
83 const expectedChecksum = opts.checksums.get(locator.locatorHash) || null;
84
85 const [packageFs, releaseFs, checksum] = await opts.cache.fetchPackageFromCache(locator, expectedChecksum, {
86 onHit: () => opts.report.reportCacheHit(locator),
87 onMiss: () => opts.report.reportCacheMiss(locator, `${structUtils.prettyLocator(opts.project.configuration, locator)} can't be found in the cache and will be fetched from the remote server`),
88 loader: () => this.fetchFromNetwork(locator, opts),
89 skipIntegrityCheck: opts.skipIntegrityCheck,
90 });
91
92 return {
93 packageFs,
94 releaseFs,
95 prefixPath: structUtils.getIdentVendorPath(locator),
96 checksum,
97 };
98 }
99
100 async fetchFromNetwork(locator, opts) {
101 // 1980-01-01, like Fedora
102 const defaultTime = 315532800;
103
104 const parts = parse(locator.reference);
105
106 const releaseBuffer = await httpUtils.get(`https://github.com/${parts.organization}/${parts.repository}/releases/download/${parts.version}/${parts.binary}`, {
107 configuration: opts.project.configuration,
108 });
109
110 const packageName = ppath.join(locator.scope !== null ? '@' + locator.scope : '', locator.name);
111
112 const tmpDir = xfs.mktempSync();
113
114 const zipFS = new ZipFS(ppath.join(tmpDir, 'release.zip'), { create: true, libzip: await getLibzipPromise() });
115
116 zipFS.writeFileSync('package.json', `{ "name": "${packageName}", "dependencies": { "@yarnpkg/fslib": "${YARN_FS_VERSION}" } }`);
117 zipFS.utimesSync('package.json', defaultTime, defaultTime);
118
119 const dir = ppath.join('node_modules', packageName);
120 zipFS.mkdirSync(dir, { recursive: true });
121
122 const stubFile = ppath.join(dir, 'exec.js');
123 zipFS.writeFileSync(stubFile, `const { xfs } = require('@yarnpkg/fslib');
124const fs = require('fs');
125const path = require('path');
126const os = require('os');
127const { spawn } = require('child_process');
128
129const execute = (path, args) => {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected