Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: gemstash compatibility added #7111

Closed
wants to merge 9 commits into from
71 changes: 54 additions & 17 deletions lib/datasource/rubygems/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const http = new Http(id);

const INFO_PATH = '/api/v1/gems';
const VERSIONS_PATH = '/api/v1/versions';
const DEPENDENCIES_PATH = 'api/v1/dependencies.json';

const getHeaders = (): OutgoingHttpHeaders => {
return { hostType: id };
Expand All @@ -32,6 +33,24 @@ export async function fetch(
return response.body;
}

export async function fetch_deps(
dependency: string,
registry: string,
path: string
): Promise<any> {
const headers = getHeaders();

const name = `${path}?gems=${dependency}`;
const baseUrl = ensureTrailingSlash(registry);

logger.trace({ dependency }, `RubyGems lookup request: ${baseUrl} ${name}`);
const response = (await http.getJson(name, { baseUrl, headers })) || {
body: undefined,
};

return response.body;
}

export async function getDependency(
dependency: string,
registry: string
Expand All @@ -51,23 +70,41 @@ export async function getDependency(
return null;
}

const versions = (await fetch(dependency, registry, VERSIONS_PATH)) || [];

const releases = versions.map(
({
number: version,
platform: rubyPlatform,
created_at: releaseTimestamp,
rubygems_version: rubygemsVersion,
ruby_version: rubyVersion,
}) => ({
version,
rubyPlatform,
releaseTimestamp,
rubygemsVersion,
rubyVersion,
})
);
const testendpoint = (await http.get(VERSIONS_PATH));
let releases;

if (testendpoint.statusCode === 404) {
logger.debug({ dependency }, '/api/v1/versions does not exist. Using /api/v1/dependencies.json');
const versions = (await fetch_deps(dependency, registry, DEPENDENCIES_PATH)) || [];

releases = versions.map(
({
number: version,
platform: rubyPlatform,
}) => ({
version,
rubyPlatform,
})
);
} else {
const versions = (await fetch(dependency, registry, VERSIONS_PATH)) || [];

releases = versions.map(
({
number: version,
platform: rubyPlatform,
created_at: releaseTimestamp,
rubygems_version: rubygemsVersion,
ruby_version: rubyVersion,
}) => ({
version,
rubyPlatform,
releaseTimestamp,
rubygemsVersion,
rubyVersion,
})
);
}

return {
releases,
Expand Down