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

suculent / thinx-device-api / #252646983

21 Mar 2022 12:58PM UTC coverage: 12.085% (+0.6%) from 11.517%
#252646983

push

suculent
submodule sync

111 of 2797 branches covered (3.97%)

Branch coverage included in aggregate %.

973 of 6173 relevant lines covered (15.76%)

0.39 hits per line

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

6.58
/lib/thinx/git.js
1
// Git Shell Manager
2

3
var Globals = require("./globals.js");
1✔
4
var app_config = Globals.app_config();
1✔
5
var fs = require("fs-extra");
1✔
6

7
const exec = require("child_process");
1✔
8

9
module.exports = class Git {
1✔
10

11
        checkResponse(rstring, local_path) {
12
                
13
                // default response is ''
14
                let success = false;
×
15
                if (rstring.indexOf("already exists and is not an empty") != -1) {
×
16
                        success = true;
×
17
                }
18
                if (rstring.indexOf("FETCH_HEAD") != -1) {
×
19
                        success = true;
×
20
                }
21
                if (rstring.indexOf("up-to-date") != -1) {
×
22
                        success = true;
×
23
                } 
24
                if (rstring.indexOf("Checking out files: 100%") != -1) {
×
25
                        success = true;
×
26
                }
27
                if (rstring.indexOf("done.") != -1) {
×
28
                        success = true;
×
29
                } 
30
                if (typeof(local_path) !== "undefined") {
×
31
                        success = fs.existsSync(local_path + "/basename.json"); // may throw! but does not work.
×
32
                }
33
                return success;
×
34
        }
35

36
        tryShellOp(cmd, local_path) {
37
                let success = false;
×
38
                let result;
39
                try {
×
40
                        result = exec.execSync(cmd).toString(); // lgtm [js/command-line-injection]                        
×
41
                        if (result) {
×
42
                                console.log("git fetch cmd result:", result);
×
43
                        }
44
                } catch (e) {
45
                        console.log("[git] git rsa clone error: " + e);
×
46
                }                
47
                if (typeof(result) !== "undefined") {
×
48
                        success = this.checkResponse(result, local_path);
×
49
                }
50
                return success;
×
51
        }
52

53
    fetch(owner, command, local_path) {
54
                let success = false;
×
55
                let RSAKey = require("./rsakey"); let rsa = new RSAKey();
×
56
                let key_paths = rsa.getKeyPathsForOwner(owner);
×
57
                if ((typeof(key_paths) === "undefined") || (key_paths.length < 1)) {
×
58
                        // TODO (16): should be done upstream (sources only) based on return value and pass to build log if needed
59
                        // https://github.com/suculent/thinx-device-api/issues/309
60
                        console.log("ℹ️ [info] [git] no_rsa_keys_found");
×
61
                        success = this.tryShellOp("cd " + local_path + ";" + command, local_path);
×
62
                } else {
63
                        for (var kindex in key_paths) {
×
64
                                var gfpfx = "ssh-agent bash -c 'ssh-add " + app_config.ssh_keys + "/" + key_paths[kindex] + "; ".replace("//", "/");
×
65
                                let prefixed_command = gfpfx + "cd " + local_path + ";" + command + "' 2>&1";
×
66
                                console.log("[git fetch] trying command", prefixed_command);
×
67
                                success = this.tryShellOp(prefixed_command, local_path);
×
68
                                if (success) return success;
×
69
                        }
70
                }
71
                return success;
×
72
        }
73

74
        prefetch(repo_path, sanitized_url, sanitized_branch, GIT_PREFETCH) {
75

76
                console.log(`🔨 [debug] git prefetch command:\n ${GIT_PREFETCH}`);
×
77

78
                var result;
79

80
                try {
×
81
                        result = exec.execSync(GIT_PREFETCH).toString().replace("\n", "");
×
82
                        if (result !== "Already up to date.") {
×
83
                                console.log(`ℹ️ [info] [builder] git prefetch result: ${result}`);
×
84
                        }
85
                } catch (e) {
86
                        console.log("⚠️ [warning] git prefetch not successful...");
×
87
                        if (typeof (result) === "undefined") {
×
88
                                result = "";
×
89
                        }
90
                }
91

92
                return result;
×
93
        }
94
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc