Skip to content

Commit 096c0c5

Browse files
committed
Fetch summary
1 parent ba96aed commit 096c0c5

File tree

5 files changed

+30
-27
lines changed

5 files changed

+30
-27
lines changed

src/core/api.ts

+21-16
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,38 @@
11
import { getCache } from "../cache";
2-
import { fetchLatestVersion } from "./pypi";
2+
import { fetchLibrary } from "./pypi";
33

44
const ONE_HOUR = 60 * 60 * 1000;
5+
const CACHE_PREFIX = "v1";
56

6-
export const getVersion = async (library: string) => {
7+
const getCacheKey = (library: string) => `${CACHE_PREFIX}-${library}`;
8+
9+
export const getInfo = async (
10+
library: string,
11+
): Promise<{ version: string; summary: string }> => {
712
const cache = getCache();
13+
const key = getCacheKey(library);
814

9-
const info = cache.get(library, null);
15+
let info = cache.get(key, null);
1016

1117
if (info) {
12-
const { version, date } = JSON.parse(info);
13-
const parsedDate = new Date(date);
18+
const data = JSON.parse(info);
19+
const parsedDate = new Date(data.date);
1420

1521
if (new Date().getTime() - parsedDate.getTime() < ONE_HOUR) {
16-
console.log("Not fetching new value for", library);
22+
console.info("Not fetching new value for", library);
1723

18-
return version;
24+
return data.info;
1925
}
2026
}
2127

22-
const version = await fetchLatestVersion(library);
28+
const data = await fetchLibrary(library);
29+
30+
info = {
31+
version: data.info.version as string,
32+
summary: data.info.summary as string,
33+
};
2334

24-
await cache.put(
25-
library,
26-
JSON.stringify({
27-
version,
28-
date: new Date(),
29-
}),
30-
);
35+
await cache.put(key, JSON.stringify({ info, date: new Date() }));
3136

32-
return version;
37+
return info;
3338
};

src/core/decorations.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@ import { MarkdownString, Position, Range, ThemeColor } from "vscode";
22
import { Dependency } from "../types";
33

44
export const getDecoration = (dep: Dependency) => {
5-
const message = new MarkdownString(
6-
`**this is a new update lololol**`,
7-
true,
8-
);
5+
const message = new MarkdownString(`**${dep.name}**`, true);
96
message.appendText("\n");
10-
message.appendMarkdown("$(globe)");
7+
message.appendMarkdown(dep.summary || "No information for this library");
118
message.isTrusted = true;
129

1310
const prefix = dep.version.latest === dep.version.installed ? "✅" : "⚠️";

src/core/listener.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { TextEditor, window, TextEditorDecorationType } from "vscode";
22
import { Dependency } from "../types";
33
import { findDependencies } from "../utils/parsing";
44
import { getInstalledVersions } from "./poetry";
5-
import { getVersion } from "./api";
5+
import { getInfo } from "./api";
66
import { getDecoration } from "./decorations";
77
import { dirname } from "path";
88

@@ -14,10 +14,11 @@ const updateVersions = (
1414
) => {
1515
return Promise.all(
1616
deps.map(async (dep) => {
17-
const version = await getVersion(dep.name);
17+
const info = await getInfo(dep.name);
1818

1919
dep.version.installed = installedVersions[dep.name];
20-
dep.version.latest = version;
20+
dep.version.latest = info.version;
21+
dep.summary = info.summary;
2122
}),
2223
);
2324
};

src/core/pypi.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import fetch from "node-fetch";
22

3-
export const fetchLatestVersion = async (library: string) => {
3+
export const fetchLibrary = async (library: string) => {
44
const x = await fetch(`https://pypi.org/pypi/${library}/json`);
5-
const data = await x.json();
65

7-
return (data.info?.version as string) ?? "unknown";
6+
return await x.json();
87
};

src/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export type Dependency = {
55
installed?: string;
66
latest?: string;
77
};
8+
summary?: string;
89
line: number;
910
rawText: string;
1011
};

0 commit comments

Comments
 (0)