aboutsummaryrefslogtreecommitdiff
path: root/Program.cs
blob: 8c2e1bf3d0cd287e0658bc7dca326804f69bbc3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System.Collections;
using System.Diagnostics;
using dotenv.net;

DotEnv.Load();
var envVars = DotEnv.Read();
foreach (DictionaryEntry entry in Environment.GetEnvironmentVariables())
    envVars[entry.Key.ToString()!] = entry.Value!.ToString()!;

while (true)
{
    var repoPaths =
        Directory.GetDirectories(String.IsNullOrEmpty(envVars["GIT_DIRECTORY"])
            ? "./repos/"
            : envVars["GIT_DIRECTORY"]);
    foreach (var repoPath in repoPaths)
    {
        Console.WriteLine($"Fetching {repoPath}...");
        var fetchProcess = Process.Start(new ProcessStartInfo
        {
            WorkingDirectory = repoPath,
            FileName = "git",
            Arguments = "fetch origin master:master"
        });
        if (!fetchProcess!.HasExited) fetchProcess.WaitForExit();
        Console.WriteLine($"Fetched with exit code {fetchProcess.ExitCode}.");
    }

    if (envVars.ContainsKey("CGIT_CACHE_DIRECTORY"))
    {
        foreach (var cacheFile in Directory.GetFiles(envVars["CGIT_CACHE_DIRECTORY"]))
            File.Delete(cacheFile);
    }

    Task.Delay(3600000).Wait();
}