web/src/utils/fetch-changelog.ts
89 lines · 2187 bytes
10 symbols in this file
1import { error } from './logger';
2import { safeFetch } from './safe-fetch';
3
4const changelogUrl =
5 'https://raw.githubusercontent.com/Lissy93/awesome-privacy/main/.github/changelog.json';
6// 'https://gist.githubusercontent.com/Lissy93/ddae176f3f21a0d3c0251f5f6cbd3b09/raw/9e62d21ea8866709520331dd2ec6a67494460707/changelog.json';
7
8export interface ChangelogPr {
9 number: number;
10 url: string;
11 author?: string;
12 authorAvatar?: string;
13}
14
15export interface ServiceChange {
16 name: string;
17 category: string;
18 section: string;
19 fields?: string[];
20}
21
22export interface ServiceMoved {
23 name: string;
24 from: { category: string; section: string };
25 to: { category: string; section: string };
26}
27
28export interface SectionMoved {
29 from: { category: string; section: string };
30 to: { category: string; section: string };
31}
32
33export interface ServiceRenamed {
34 previousName: string;
35 name: string;
36 from: { category: string; section: string };
37 to: { category: string; section: string };
38}
39
40export interface ChangelogEntry {
41 date: string;
42 sha: string;
43 pr?: ChangelogPr | null;
44 changes: {
45 services?: {
46 added?: ServiceChange[];
47 removed?: ServiceChange[];
48 modified?: ServiceChange[];
49 moved?: ServiceMoved[];
50 renamed?: ServiceRenamed[];
51 };
52 sections?: {
53 added?: { name: string; category: string }[];
54 removed?: { name: string; category: string }[];
55 moved?: SectionMoved[];
56 };
57 categories?: {
58 added?: string[];
59 removed?: string[];
60 };
61 };
62}
63
64export interface Rejection {
65 date: string;
66 title: string;
67 pr: ChangelogPr;
68}
69
70export interface Changelog {
71 generatedAt: string;
72 entries: ChangelogEntry[];
73 rejections?: Rejection[];
74}
75
76export const fetchChangelog = async (): Promise<Changelog> => {
77 try {
78 const res = await safeFetch(changelogUrl);
79 if (!res.ok) {
80 error('Changelog', `HTTP ${res.status} fetching changelog.json`);
81 return { generatedAt: '', entries: [] };
82 }
83 const data: Changelog = await res.json();
84 return data;
85 } catch (err) {
86 error('Changelog', `Failed to fetch changelog.json: ${err}`);
87 return { generatedAt: '', entries: [] };
88 }
89};