• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

bpatrik / pigallery2 / 19182681002

07 Nov 2025 10:15PM UTC coverage: 68.691% (+0.2%) from 68.447%
19182681002

push

github

bpatrik
Adding minimal Test for repository.md #1047

1407 of 2301 branches covered (61.15%)

Branch coverage included in aggregate %.

2 of 4 new or added lines in 1 file covered. (50.0%)

5177 of 7284 relevant lines covered (71.07%)

4232.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

68.29
/src/backend/model/extension/ExtensionRepository.ts
1
import {Config} from '../../../common/config/private/Config';
1✔
2
import {ExtensionListItem} from '../../../common/entities/extension/ExtensionListItem';
3

4
export class ExtensionRepository {
1✔
5

6
  extensionsList: ExtensionListItem[];
7
  lastUpdate = 0;
256✔
8
  private UPDATE_FREQUENCY_MS = 30 * 1000;
256✔
9

10
  public async getExtensionList(): Promise<ExtensionListItem[]> {
11
    if (this.lastUpdate < Date.now() - this.UPDATE_FREQUENCY_MS) {
×
12
      await this.fetchList();
×
13
    }
14

15
    return this.extensionsList;
×
16
  }
17

18
  private getUrlFromMDLink(text: string) {
19
    if (!text) {
9!
20
      return text;
×
21
    }
22
    text = ('' + text).trim();
9✔
23
    /* Match full links and relative paths */
24
    // source: https://davidwells.io/snippets/regex-match-markdown-links
25
    const regex = /^\[.*]\(((?:\/|https?:\/\/)[\S./?=#]+)\)$/;
9✔
26

27
    if (text.match(regex).length > 0) {
9✔
28
      return text.match(regex)[0].match(/https?:\/\/[\S./?=#]+/)[0].slice(0, -1);
9✔
29
    }
30
    return text;
×
31
  }
32

33
  public repoMD(text: string): ExtensionListItem[] {
34
    const lines = text.split('\n');
1✔
35
    lines.forEach(line => line.trim());
13✔
36
    const tableStartLine = lines.findIndex(l => l.startsWith('|     **Name**     |'));
7✔
37
    const tableHeaderLines = 2;
1✔
38
    const table = lines.slice(tableStartLine + tableHeaderLines);
1✔
39
    const extensions: ExtensionListItem[] = [];
1✔
40
    const getUniqueID = (name: string) => {
1✔
41
      let id = name;
3✔
42
      let i = 2;
3✔
43
      while (extensions.findIndex(e => e.id === id) !== -1) {
3✔
44
        id = name + '-' + i;
×
45
        ++i;
×
46
      }
47
      return id;
3✔
48
    };
49
    table.forEach(l => {
1✔
50
      const entries = l.split('|').map((l) => l.trim()).filter(e => !!e);
29✔
51
      if (entries.length == 0) {
5✔
52
        return;
2✔
53
      }
54

55
      extensions.push({
3✔
56
        id: getUniqueID(entries[0].toLowerCase().replace(/\s+/g, '-')),
57
        name: entries[0],
58
        url: this.getUrlFromMDLink(entries[1]),
59
        readme: this.getUrlFromMDLink(entries[2]),
60
        zipUrl: this.getUrlFromMDLink(entries[3])
61
      });
62
    });
63
    return extensions;
1✔
64
  }
65

66
  public async fetchList(): Promise<ExtensionListItem[]> {
NEW
67
    const res = await (await fetch(Config.Extensions.repositoryUrl)).text();
×
NEW
68
    this.extensionsList = this.repoMD(res);
×
69
    this.lastUpdate = new Date().getTime();
×
70
    return this.extensionsList;
×
71
  }
72
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc