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

samsmithnz / RepoAutomation / 3895898324

pending completion
3895898324

push

github

GitHub
Merge pull request #212 from samsmithnz/FixToLanguageTest

333 of 474 branches covered (70.25%)

Branch coverage included in aggregate %.

795 of 893 relevant lines covered (89.03%)

6.27 hits per line

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

67.83
/src/RepoAutomation/Program.cs
1
using CommandLine;
2
using Microsoft.Extensions.Configuration;
3
using RepoAutomation.Core.APIAccess;
4
using RepoAutomation.Core.Helpers;
5
using RepoAutomation.Core.Models;
6

7
namespace RepoAutomation;
8

9
public class Program
10
{
11
    public async static Task Main(string[] args)
12
    {
2✔
13
        //Load the appsettings.json configuration file
14
        IConfigurationBuilder? builder = new ConfigurationBuilder()
2✔
15
             .SetBasePath(Directory.GetCurrentDirectory())
2✔
16
             .AddJsonFile("appsettings.json", optional: false)
2✔
17
             .AddUserSecrets<Program>(true);
2✔
18
        IConfigurationRoot configuration = builder.Build();
2✔
19

20
        //Parse arguments
21
        string workingDirectory = Environment.CurrentDirectory;
2✔
22
        string workingTempDirectory = workingDirectory + "\\temp";
2✔
23
        string owner = "";
2✔
24
        string repository = "";
2✔
25
        string projectTypes = "";
2✔
26
        bool isPrivate = true;
2✔
27
        Parser.Default.ParseArguments<Options>(args).WithParsed<Options>(o =>
2✔
28
        {
2✔
29
            if (!string.IsNullOrEmpty(o.Directory))
2✔
30
            {
1✔
31
                workingDirectory = o.Directory;
1✔
32
            }
1✔
33
            if (!string.IsNullOrEmpty(o.Owner))
2✔
34
            {
2✔
35
                owner = o.Owner;
2✔
36
            }
2✔
37
            if (!string.IsNullOrEmpty(o.Repo))
2✔
38
            {
2✔
39
                repository = o.Repo;
2✔
40
            }
2✔
41
            if (!string.IsNullOrEmpty(o.Visibility))
2!
42
            {
×
43
                if (o.Visibility.ToLower() == "public")
×
44
                {
×
45
                    isPrivate = false;
×
46
                }
×
47
                else if (o.Visibility.ToLower() == "private")
×
48
                {
×
49
                    isPrivate = true;
×
50
                }
×
51
            }
×
52
            else
2✔
53
            {
2✔
54
                isPrivate = true;
2✔
55
            }
2✔
56
            if (!string.IsNullOrEmpty(o.ProjectTypes))
2!
57
            {
×
58
                projectTypes = o.ProjectTypes;
×
59
            }
×
60
        });
4✔
61

62
        //Do the work
63
        if (!string.IsNullOrEmpty(workingDirectory) &&
2!
64
            !string.IsNullOrEmpty(owner) &&
2✔
65
            !string.IsNullOrEmpty(repository))
2✔
66
        {
2✔
67
            string id = configuration["AppSettings:GitHubClientId"];
2✔
68
            string secret = configuration["AppSettings:GitHubClientSecret"];
2✔
69
            string repoURL = $"https://github.com/{owner}/{repository}";
2✔
70

71
            //1. Create the repo (if it doesn't exist)
72
            Repo? repo = await GitHubApiAccess.GetRepo(id, secret, owner, repository);
2✔
73
            if (repo == null)
2!
74
            {
×
75
                Console.WriteLine("Creating repo: " + repository);
×
76
                await GitHubApiAccess.CreateRepo(id,
×
77
                    secret,
×
78
                    repository,
×
79
                    true,
×
80
                    true,
×
81
                    false,
×
82
                    isPrivate);
×
83
            }
×
84

85
            //2. Clone the repo
86
            DotNet.CloneRepo(repoURL, repository, workingDirectory);
2✔
87

88
            //3. create the .NET projects
89
            if (!string.IsNullOrEmpty(projectTypes))
2!
90
            {
×
91
                DotNet.SetupDotnetProjects(repository, workingDirectory,
×
92
                    projectTypes);
×
93
            }
×
94

95
            //4. Create the GitHub Action
96
            Console.WriteLine("Creating GitHub Action");
2✔
97
            GitHubActions.SetupAction(workingDirectory + "\\" + repository,
2✔
98
                repository,
2✔
99
                projectTypes);
2✔
100

101
            //5. Create the Dependabot file
102
            Console.WriteLine("Create Dependabot configuration");
2✔
103
            GitHubDependabot.SetupDependabotFile(workingDirectory + "\\" + repository, owner);
2✔
104

105
            //6. Customize the README.md file
106
            Console.WriteLine("Adding GitHub Actions status badge to README.md file");
2✔
107
            GitHubReadme.AddStatusBadge(workingDirectory + "\\" + repository, repository);
2✔
108

109
            //7. Add GitVersion file
110
            Console.WriteLine("Adding GitVersion.yml file");
2✔
111
            GitVersion.AddGitVersionFile(workingDirectory + "\\" + repository, "0.1.0");
2✔
112

113
            //8. Push back to main         
114
            Console.WriteLine(Core.Helpers.CommandLine.RunCommand("git", "add .", workingDirectory + "\\" + repository));
2✔
115
            Console.WriteLine(Core.Helpers.CommandLine.RunCommand("git", @"commit -m""Created .NET projects, setup action, and created dependabot configuration""", workingDirectory + "\\" + repository));
2✔
116
            Console.WriteLine(Core.Helpers.CommandLine.RunCommand("git", "push", workingDirectory + "\\" + repository));
2✔
117

118
            //9. Set the branch policy
119
            //TODO: Set the branch policy
120
        }
2✔
121
    }
2✔
122

123

124
    //private static async Task<Asset[]?> GetReleaseAssets(string id, string secret, string owner, string repoName)
125
    //{
126
    //    Asset[]? assets = null;
127
    //    Release? release = await GitHubAPIAccess.GetReleaseLatest(id, secret, owner, repoName);
128
    //    if (release != null && release.assets != null && release.assets.Length > 0)
129
    //    {
130
    //        assets = release.assets;
131
    //    }
132
    //    return assets;
133
    //}
134

135
    public class Options
136
    {
137
        [Option('d', "directory", Required = false, HelpText = "set working directory")]
138
        public string? Directory { get; set; }
4✔
139

140
        [Option('o', "owner", Required = false, HelpText = "GitHub owner")]
141
        public string? Owner { get; set; }
6✔
142

143
        [Option('r', "repo", Required = false, HelpText = "new repo name")]
144
        public string? Repo { get; set; }
6✔
145

146
        [Option('v', "visibility", Required = false, HelpText = "new repo visibility. Can be set to private or public")]
147
        public string? Visibility { get; set; }
2✔
148

149
        [Option('p', "projecttypes", Required = false, HelpText = "dotnet project types, comma delimited, to create. See dotnet new docs for details: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-new#arguments")]
150
        public string? ProjectTypes { get; set; }
2✔
151

152
    }
153
}
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

© 2025 Coveralls, Inc