Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,6 @@ $RECYCLE.BIN/
_NCrunch*
.idea

launchSettings.json
launchSettings.json

.vs
14 changes: 11 additions & 3 deletions src/Nullinside.Cicd.GitHub/Nullinside.Cicd.GitHub.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,20 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="log4net" Version="3.0.4"/>
<PackageReference Include="Octokit" Version="14.0.0"/>
<PackageReference Include="log4net" Version="3.0.4" />
<PackageReference Include="log4net.Ext.Json" Version="3.0.3" />
<PackageReference Include="Octokit" Version="14.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\octokit.graphql.net\src\Octokit.GraphQL\Octokit.GraphQL.csproj"/>
<ProjectReference Include="..\octokit.graphql.net\src\Octokit.GraphQL\Octokit.GraphQL.csproj" />
</ItemGroup>

<ItemGroup>
<None Remove="log4net.config" />
<Content Include="log4net.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

</Project>
9 changes: 8 additions & 1 deletion src/Nullinside.Cicd.GitHub/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// See https://aka.ms/new-console-template for more information

using log4net;
using log4net.Config;
using log4net.Core;

using Nullinside.Cicd.GitHub;
using Nullinside.Cicd.GitHub.Rule;

Expand All @@ -11,6 +15,9 @@
using ProductHeaderValue = Octokit.ProductHeaderValue;
using Query = Octokit.GraphQL.Query;

XmlConfigurator.Configure(new FileInfo("log4net.config"));
var log = LogManager.GetLogger(typeof(Program));

IRepoRule?[] rules = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(a => a.GetTypes())
.Where(t => typeof(IRepoRule).IsAssignableFrom(t) && !t.IsAbstract && !t.IsInterface)
Expand Down Expand Up @@ -42,6 +49,6 @@
}
}

Console.WriteLine("Waiting for next execution time...");
log.Info("Waiting for next execution time...");
Task.WaitAll(Task.Delay(TimeSpan.FromMinutes(5)));
}
11 changes: 9 additions & 2 deletions src/Nullinside.Cicd.GitHub/Rule/AssociateIssuesWithProject.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Octokit;
using log4net;

using Octokit;
using Octokit.GraphQL;
using Octokit.GraphQL.Core;
using Octokit.GraphQL.Model;
Expand All @@ -12,6 +14,11 @@ namespace Nullinside.Cicd.GitHub.Rule;
/// Handles associating issues with the project automatically.
/// </summary>
public class AssociateIssuesWithProject : IRepoRule {
/// <summary>
/// The logger
/// </summary>
private ILog _log = LogManager.GetLogger(typeof(AssociateIssuesWithProject));

/// <inheritdoc />
public async Task Handle(GitHubClient client, Connection graphQl, ID projectId, Repository repo) {
if (!repo.HasIssues) {
Expand All @@ -36,7 +43,7 @@ public async Task Handle(GitHubClient client, Connection graphQl, ID projectId,
continue;
}

Console.WriteLine($"{repo.Name}: Associating issue #{issue.Number}");
_log.Info($"{repo.Name}: Associating issue #{issue.Number}");
await graphQl.Run(new Mutation()
.AddProjectV2ItemById(new Arg<AddProjectV2ItemByIdInput>(new AddProjectV2ItemByIdInput {
ProjectId = projectId,
Expand Down
11 changes: 9 additions & 2 deletions src/Nullinside.Cicd.GitHub/Rule/CreateRulesets.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Octokit;
using log4net;

using Octokit;
using Octokit.GraphQL;
using Octokit.GraphQL.Core;
using Octokit.GraphQL.Model;
Expand All @@ -12,6 +14,11 @@ namespace Nullinside.Cicd.GitHub.Rule;
/// Creates the branch merging rules based on the code bases' language.
/// </summary>
public class CreateRulesets : IRepoRule {
/// <summary>
/// The logger
/// </summary>
private ILog _log = LogManager.GetLogger(typeof(CreateRulesets));

/// <inheritdoc />
public async Task Handle(GitHubClient client, Connection graphQl, ID projectId, Repository repo) {
// This currently doesn't run properly. You get an error about not specifying multiple Parameters on the status
Expand All @@ -33,7 +40,7 @@ public async Task Handle(GitHubClient client, Connection graphQl, ID projectId,
.Repository(repo.Name, Constants.GITHUB_ORG)
.Select(i => i.Id));

Console.WriteLine($"{repo.Name}: Creating default ruleset");
_log.Info($"{repo.Name}: Creating default ruleset");
StatusCheckConfigurationInput[]? statusChecks = null;
if ("Typescript".Equals(repo.Language, StringComparison.InvariantCultureIgnoreCase)) {
statusChecks = new[] {
Expand Down
16 changes: 16 additions & 0 deletions src/Nullinside.Cicd.GitHub/log4net.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<log4net>
<appender name="ConsoleAppenderJson" type="log4net.Appender.ConsoleAppender">
<layout type='log4net.Layout.SerializedLayout, log4net.Ext.Json'>
<decorator type='log4net.Layout.Decorators.StandardTypesDecorator, log4net.Ext.Json'/>
<default/> <!--explicit default members-->
<remove value='message'/> <!--remove the default preformatted message member-->
<member value='message:messageobject'/> <!--add raw message-->
</layout>

</appender>

<root>
<level value="INFO"/>
<appender-ref ref="ConsoleAppenderJson"/>
</root>
</log4net>
Loading