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

suculent / thinx-device-api / #252646907

11 Feb 2026 11:27AM UTC coverage: 8.606% (-63.1%) from 71.753%
#252646907

push

suculent
dependency update

28 of 2056 branches covered (1.36%)

Branch coverage included in aggregate %.

543 of 4579 relevant lines covered (11.86%)

0.13 hits per line

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

5.88
/lib/thinx/github.js
1
// GitHub APIs Implementation
2
const https = require('node:https');
1✔
3
const gitKeysURL = "https://api.github.com/user/keys";
1✔
4

5
module.exports = class GitHub {
1✔
6

7
    // check with GitHub if the added access token is valid 
8
    static validateAccessToken(token, callback) {
9

10
        let options = {
×
11
            headers: {
12
                "User-Agent": "THiNX API",
13
                "Authorization": "Bearer " + token,
14
                "Accept": "application/vnd.github+json",
15
                "Content-Type": "application/vnd.github+json",
16
                "X-GitHub-Api-Version": "2022-11-28"
17
            }
18
        };
19

20
        https.get(gitKeysURL, options, (res) => {
×
21
            let data = "";
×
22
            res.on('data', (d) => {
×
23
                data += d;
×
24
            });
25
            res.on('end', () => {
×
26
                let json_data = JSON.parse(data);
×
27
                if (res.statusCode == 200) {
×
28
                    callback(true, json_data);
×
29
                } else {
30
                    console.log("[DEBUG] GitHub Keys Error Response:", data.toString());
×
31
                    callback(false);
×
32
                }
33
            });
34
        }).on('error', (e) => {
35
            console.error(e);
×
36
            callback(false, e);
×
37
        });
38
    }
39

40
    static processPublicKeyRequest(res, callback) {
41
        console.log('statusCode:', res.statusCode);
×
42
        console.log('headers:', res.headers);
×
43

44
        let data = "";
×
45

46
        res.on('data', (d) => {
×
47
            data += d;
×
48
            console.log(d);
×
49
        });
50

51
        res.on('end', () => {
×
52
            let json_data = JSON.parse(data);
×
53
            let valid_state = false;
×
54
            if ((json_data.error) && (json_data.errors.message === "key is already in use")) valid_state = true;
×
55
            if (res.statusCode === 201) valid_state = true;
×
56
            if (res.statusCode === 422) valid_state = true;
×
57
            callback(valid_state, json_data); // should not respond directly but be parsed, validated and only enumerated errors should be  returned intentionally 
×
58
        });
59

60
        res.on('error', (e) => {
×
61
            console.log("error", e);
×
62
            callback(false, e);
×
63
        });
64
    }
65

66
    static addPublicKey(token, key, callback) {
67

68
        let options = {
×
69
            method: 'POST',
70
            hostname: 'api.github.com',
71
            port: 443,
72
            path: '/user/keys',
73
            headers: {
74
                "User-Agent": "THiNX API",
75
                "Authorization": "Bearer " + token,
76
                "Accept": "application/vnd.github+json",
77
                "Content-Type": "application/vnd.github+json",
78
                "X-GitHub-Api-Version": "2022-11-28"
79
            }
80
        };
81

82
        let body = JSON.stringify({
×
83
            title: "THiNX Key",
84
            key: key
85
        });
86

87
        console.log("[github] calling", options, body);
×
88

89
        let req = https.request(options, (res) => {
×
90
            GitHub.processPublicKeyRequest(res, callback);
×
91
        }).on('error', (e) => {
92
            console.error(e);
×
93
            callback(false, e);
×
94
        });
95

96
        req.write(body);
×
97
        req.end();
×
98
    }
99
};
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