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

AJGranowski / preceding-tag-action / 17814434032

18 Sep 2025 12:38AM UTC coverage: 80.903% (-1.7%) from 82.624%
17814434032

Pull #33

github

AJGranowski
Fix eslint errors
Pull Request #33: Add fuzz testing

59 of 68 branches covered (86.76%)

Branch coverage included in aggregate %.

0 of 6 new or added lines in 1 file covered. (0.0%)

174 of 220 relevant lines covered (79.09%)

19.45 hits per line

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

54.55
/src/GitHubAPI.ts
1
import type { Octokit } from "@octokit/rest";
2

3
import type { CommitDate } from "./types/CommitDate";
4
import type { GitRef } from "./types/GitRef";
5
import type { Repository } from "./types/Repository";
6

7
class GitHubAPI {
1✔
8
    private readonly octokit: Octokit;
1✔
9
    private readonly repo: Repository;
2✔
10
    constructor(octokit: Octokit, repo: Repository) {
1✔
11
        this.octokit = octokit;
2✔
12
        this.repo = repo;
2✔
13
    }
2✔
14

15
    /**
16
     * Get and return every tag in this repo matching the filter.
17
     *
18
     * Will reject if the API is unavailable.
19
     */
20
    async fetchAllTags(filter: RegExp): Promise<string[]> {
1✔
21
        // https://docs.github.com/en/rest/git/refs?apiVersion=2022-11-28#list-matching-references
22
        return this.octokit.rest.git.listMatchingRefs({
1✔
23
            owner: this.repo.owner,
1✔
24
            repo: this.repo.repo,
1✔
25
            ref: "tags"
1✔
26
        }).then((response) => {
1✔
27
            return response.data
×
28
                .map((object) => object.ref.substring("refs/tags/".length))
×
29
                .filter((tag: string) => filter.test(tag));
×
30
        });
1✔
31

32
        /*
33
         * If the above endpoint doesn't return all tags for some reason, switch to iterating over listTags
34
         * https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#list-repository-tags
35
         */
36
    }
1✔
37

38
    /**
39
     * Returns the commit difference between two references.
40
     * If the head ref matches the base ref, the result is zero.
41
     * If the head ref is a descendant of the base ref, the result is positive.
42
     * If the head ref is an ancestor of the base ref, the result is negative.
43
     * If the head ref is diverged from the base ref, the result is NaN.
44
     *
45
     * Will reject if the API is unavailable, or if the two references cannot be compared.
46
     */
47
    async fetchCommitDifference(base: GitRef, head: GitRef): Promise<number> {
1✔
48
        // https://docs.github.com/en/rest/commits/commits?apiVersion=2022-11-28#compare-two-commits
49
        return this.octokit.rest.repos.compareCommitsWithBasehead({
×
50
            owner: this.repo.owner,
×
51
            repo: this.repo.repo,
×
52
            basehead: `${base}...${head}`,
×
53
            page: 1,
×
54
            per_page: 1
×
55
        }).then((response) => {
×
56
            switch (response.data.status) {
×
57
                case "ahead":
×
NEW
58
                    if (response.data.ahead_by < 0) {
×
NEW
59
                        throw new Error(`ahead_by property is negative: ${response.data.ahead_by}`);
×
NEW
60
                    }
×
61

62
                    return response.data.ahead_by;
×
63
                case "behind":
×
NEW
64
                    if (response.data.behind_by < 0) {
×
NEW
65
                        throw new Error(`behind_by property is negative: ${response.data.behind_by}`);
×
NEW
66
                    }
×
67

68
                    return -response.data.behind_by;
×
69
                case "identical":
×
70
                    return 0;
×
71
                case "diverged":
×
72
                    return NaN;
×
73
                default:
×
74
                    throw new Error(`Unknown compare status: ${response.data.status}`);
×
75
            }
×
76
        });
×
77
    }
×
78

79
    /**
80
     * Get the author and committer dates of a commit.
81
     *
82
     * Will reject if the API is unavailable, or if the reference does not exist.
83
     */
84
    async fetchCommitDate(ref: GitRef): Promise<CommitDate> {
1✔
85
        // https://docs.github.com/en/rest/commits/commits?apiVersion=2022-11-28#get-a-commit
86
        return this.octokit.rest.repos.getCommit({
1✔
87
            owner: this.repo.owner,
1✔
88
            repo: this.repo.repo,
1✔
89
            ref: ref,
1✔
90
            page: 1,
1✔
91
            per_page: 1
1✔
92
        }).then((response) => {
1✔
93
            return {
1✔
94
                author: response.data.commit.author?.date,
1✔
95
                committer: response.data.commit.committer?.date
1✔
96
            };
1✔
97
        });
1✔
98
    }
1✔
99
}
1✔
100

101
export { GitHubAPI };
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