Skip to content

Commit

Permalink
init repo and create template
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodman, Burton authored and Rodman, Burton committed Dec 17, 2018
1 parent 829a622 commit d199e93
Show file tree
Hide file tree
Showing 12 changed files with 336 additions and 19 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.vs/
.vscode/

bin/
obj/

nupkg/
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ A dotnet global tool to initialize (and update) Repositories, Builds and Release
Where feasible, both TFS 2017+ and Azure DevOps will be supported. If Azure DevOps adds a feature (like yml builds), this tool should use it's file formats and conventions as much as possible and poly-fill for older versions.

# Project goals:
1. [ ] create a dotnet global tool that...
2. [ ] if the current directory is not a git repo calls git init
3. [ ] if the current directory does not have a azdo-init template file creates one
1. [x] create a dotnet global tool that...
2. [x] if the current directory is not a git repo calls git init
3. [x] if the current directory does not have a azdo-init template file creates one
4. [ ] FUTURE: if the specified Team Project does not exist, create it
5. [ ] if the specified (remote) Repository does not exist in the specified Azure DevOps account URL, create it
6. [ ] if the specified (remote) Repository is not set as a remote for the local repo, add it
Expand Down
33 changes: 17 additions & 16 deletions sample/azdo-init.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
version: '1.0'

# [required] Your TFS or Azure DevOps instance URL
account: https://dev.azure.com/youraccount
account: ${AzureDevOpsCollectionUrl}

# [optional] Your Team Project name. Defaults to current directory name.
project: MyProject
# project: ${TeamProjectName}

# [optional] Repository Name. Defaults to current directory name.
repository: MyProject
# repository: ${RepositoryName}

# For branches, all values are optional and if not supplied are turned off.
# boolean like values interpreted per https://yaml.org/type/bool.html
# integer values interpreted per https://yaml.org/type/int.html

branches:
develop:
master:
minimum-reviewers: 2 # !!int = 0
approve-own-changes: true # !!bool = false
complete-if-not-approved: true # !!bool = false
reset-votes-on-new-change: true # !!bool = false
automatic-reviewers:
- burtonrodman # string, and identity that can be resolved in the account
linked-work-items: ignore|warn|required # string = ignore
comment-resolution: ignore|warn|required # string = ignore
merge-strategy: none|squash|no-fast-forward # string = none
build: TDB
external-services: TBD
- name: master
# minimum-reviewers: 2 # !!int = 0
# approve-own-changes: true # !!bool = false
# complete-if-not-approved: true # !!bool = false
# reset-votes-on-new-change: true # !!bool = false
# automatic-reviewers:
# - burtonrodman # string, and identity that can be resolved in the account
# linked-work-items: ignore|warn|required # string = ignore
# comment-resolution: ignore|warn|required # string = ignore
# merge-strategy: none|squash|no-fast-forward # string = none
# build: TDB
# external-services: TBD

- name: develop
39 changes: 39 additions & 0 deletions src/GitRepo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using static azdo_init.ProcessUtilities;
namespace azdo_init
{

public class GitRepo
{
private readonly ILogger logger;

public GitRepo(ILogger logger)
{
this.logger = logger;
}

public void EnsureExists()
{
if (!Exists())
{
Init();
logger.WriteAction("repo initialized.");
}
else
{
logger.WriteInformation("repo exists.");
}
}

public bool Exists()
{
return ExecuteProcess("git", "rev-parse", "--is-inside-work-tree").StartsWith("true");
}

public static void Init()
{
ExecuteProcess("git", "init");
}

}
}
27 changes: 27 additions & 0 deletions src/HelpCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace azdo_init
{
public class HelpCommand
{
public static bool IsHelpCommand(string arg)
{
switch (arg)
{
case "--help":
case "-help":
case "-h":
case "/help":
case "/h":
case "?":
case "/?":
return true;
default:
return false;
}

}

public static void ShowHelp() {

}
}
}
43 changes: 43 additions & 0 deletions src/ILogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;

namespace azdo_init
{

public interface ILogger
{
void Write(string message, LoggerSeverity severity);
}

public enum LoggerSeverity
{
Information,
Action,
Warning,
Error
}

public static class LoggerExtensions
{

public static void WriteInformation(this ILogger logger, string message)
{
logger.Write(message, LoggerSeverity.Information);
}

public static void WriteAction(this ILogger logger, string message)
{
logger.Write(message, LoggerSeverity.Action);
}

}

public class ConsoleLogger : ILogger
{

public void Write(string message, LoggerSeverity severity)
{
Console.WriteLine($"{severity}, {message}");
}

}
}
36 changes: 36 additions & 0 deletions src/InitFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.IO;

namespace azdo_init
{

public class InitFile
{
private readonly ILogger logger;

public InitFile(ILogger logger)
{
this.logger = logger;
}

public static RepositoryOptions Deserialize(string path)
{
return null;
}

public bool Exists()
{
return File.Exists("azdo-init.yml");
}

public void Create() {
var fullPath = Path.GetFullPath("azdo-init.yml");
using (var stream = typeof(InitFile).Assembly.GetManifestResourceStream("azdo_init.template.yml"))
using (var reader = new StreamReader(stream))
{
File.WriteAllText(fullPath, reader.ReadToEnd());
}
logger.WriteAction($"created {fullPath}");
}

}
}
24 changes: 24 additions & 0 deletions src/ProcessUtilities.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Diagnostics;

namespace azdo_init
{

public static class ProcessUtilities
{

public static string ExecuteProcess(string cmd, params string[] args)
{
var info = new ProcessStartInfo();
info.FileName = cmd;
info.Arguments = string.Join(' ', args);
info.UseShellExecute = false;
info.RedirectStandardOutput = true;

var process = Process.Start(info);
var output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
return output;
}

}
}
32 changes: 32 additions & 0 deletions src/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using static azdo_init.HelpCommand;

namespace azdo_init
{
class Program
{
static void Main(string[] args)
{
// if (IsHelpCommand(args.FirstOrDefault())) {
// ShowHelp();
// }

var logger = new ConsoleLogger();

var gitrepo = new GitRepo(logger);
gitrepo.EnsureExists();

var initfile = new InitFile(logger);
if (!initfile.Exists())
{
initfile.Create();
return;
}

}

}
}
59 changes: 59 additions & 0 deletions src/RepositoryOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System.Collections.Generic;
using YamlDotNet.Serialization;

namespace azdo_init
{
public class RepositoryOptions
{
[YamlMember(Alias = "account", ApplyNamingConventions = false)]
public string AzureDevOpsCollectionUrl { get; set; }


[YamlMember(Alias = "project", ApplyNamingConventions = false)]
public string TeamProjectName { get; set; }


[YamlMember(Alias = "repository", ApplyNamingConventions = false)]
public string RepositoryName { get; set; }

public string Version { get; set; }


public List<BranchOptions> Branches { get; set; }

}

public class BranchOptions
{
public string Name { get; set; }

[YamlMember(Alias = "minimum-reviewers", ApplyNamingConventions = false)]
public int MinimumReviewers { get; set; }

[YamlMember(Alias = "approve-own-changes", ApplyNamingConventions = false)]
public bool ApproveOwnChanges { get; set; }

[YamlMember(Alias = "complete-if-not-approved", ApplyNamingConventions = false)]
public bool CompleteIfNotApproved { get; set; }

[YamlMember(Alias = "reset-votes-on-new-change", ApplyNamingConventions = false)]
public bool ResetVotesOnNewChange { get; set; }

[YamlMember(Alias = "automatic-reviewers", ApplyNamingConventions = false)]
public string[] AutomaticReviewers { get; set; }

[YamlMember(Alias = "linked-work-items", ApplyNamingConventions = false)]
public string LinkedWorkItems { get; set; }

[YamlMember(Alias = "comment-resolution", ApplyNamingConventions = false)]
public string CommentResolution { get; set; }

[YamlMember(Alias = "merge-strategy", ApplyNamingConventions = false)]
public string MergeStrategy { get; set; }

// # build: TDB
// # external-services: TBD

}

}
19 changes: 19 additions & 0 deletions src/azdo-init.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<RootNamespace>azdo_init</RootNamespace>
<PackAsTool>true</PackAsTool>
<ToolCommandName>azdo-init</ToolCommandName>
<PackageOutputPath>./nupkg</PackageOutputPath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="YamlDotNet" Version="5.3.0" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="template.yml" />
</ItemGroup>
</Project>
30 changes: 30 additions & 0 deletions src/template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: '1.0'

# [required] Your TFS or Azure DevOps instance URL
account: ${AzureDevOpsCollectionUrl}

# [optional] Your Team Project name. Defaults to current directory name.
# project: ${TeamProjectName}

# [optional] Repository Name. Defaults to current directory name.
# repository: ${RepositoryName}

# For branches, all values are optional and if not supplied are turned off.
# boolean like values interpreted per https://yaml.org/type/bool.html
# integer values interpreted per https://yaml.org/type/int.html

branches:
- name: master
# minimum-reviewers: 2 # !!int = 0
# approve-own-changes: true # !!bool = false
# complete-if-not-approved: true # !!bool = false
# reset-votes-on-new-change: true # !!bool = false
# automatic-reviewers:
# - burtonrodman # string, and identity that can be resolved in the account
# linked-work-items: ignore|warn|required # string = ignore
# comment-resolution: ignore|warn|required # string = ignore
# merge-strategy: none|squash|no-fast-forward # string = none
# build: TDB
# external-services: TBD

- name: develop

0 comments on commit d199e93

Please sign in to comment.