Skip to content

Commit

Permalink
Tidy GitHubSettings.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
thomhurst committed Jun 27, 2024
1 parent d69c927 commit b8bcd49
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 39 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ jobs:
GitHub__Repository__Id: ${{ github.repository_id }}
GitHub__StandardToken: ${{ secrets.DOTNET_FORMAT_PUSH_TOKEN }}
GitHub__AdminToken: ${{ secrets.ADMIN_TOKEN }}
GitHub__PullRequest__Number: ${{ github.event.number }}
GitHub__PullRequest__Branch: ${{ github.event.pull_request.head.ref }}
GitHub__PullRequest__Sha: ${{ github.event.pull_request.head.sha }}
GitHub__PullRequest__Author: ${{ github.event.pull_request.user.login }}
Publish__ShouldPublish: ${{ github.event.inputs.publish-packages || false}}
Publish__IsAlpha: ${{ github.event.inputs.is-alpha || true}}
Codacy__ApiKey: ${{ secrets.CODACY_APIKEY }}
Expand Down
5 changes: 3 additions & 2 deletions src/ModularPipelines.Build/GitHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using ModularPipelines.Context;
using ModularPipelines.Git.Extensions;
using ModularPipelines.Git.Options;
using ModularPipelines.GitHub.Extensions;

namespace ModularPipelines.Build;

Expand Down Expand Up @@ -71,8 +72,8 @@ await context.Git().Commands.Commit(new GitCommitOptions
{
Message = message,
}, token: cancellationToken);

var author = context.Get<IOptions<GitHubSettings>>()?.Value?.PullRequest?.Author ?? "thomhurst";
var author = context.GitHub().EnvironmentVariables.Actor ?? "thomhurst";

var arguments = new List<string> { $"https://x-access-token:{token}@github.com/{author}/ModularPipelines.git" };

Expand Down
19 changes: 18 additions & 1 deletion src/ModularPipelines.Build/Modules/CodeFormattedNicelyModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
using ModularPipelines.Context;
using ModularPipelines.DotNet.Extensions;
using ModularPipelines.DotNet.Options;
using ModularPipelines.Extensions;
using ModularPipelines.Git.Extensions;
using ModularPipelines.GitHub.Attributes;
using ModularPipelines.GitHub.Extensions;
using ModularPipelines.Models;
using ModularPipelines.Modules;

Expand All @@ -29,6 +31,21 @@ public CodeFormattedNicelyModule(IOptions<GitHubSettings> githubSettings)
_githubSettings = githubSettings;
}

protected override Task<SkipDecision> ShouldSkip(IPipelineContext context)
{
if (context.GitHub().EnvironmentVariables.EventName != "pull_request")
{
return SkipDecision.Skip("Not a pull request").AsTask();
}

if (string.IsNullOrEmpty(_githubSettings.Value.StandardToken))
{
return SkipDecision.Skip("No authentication token for git").AsTask();
}

return SkipDecision.DoNotSkip.AsTask();
}

/// <inheritdoc/>
protected override async Task<CommandResult?> ExecuteAsync(IPipelineContext context, CancellationToken cancellationToken)
{
Expand Down Expand Up @@ -80,7 +97,7 @@ await context.DotNet().Format(new DotNetFormatOptions
Severity = "info",
}, cancellationToken);

var branchTriggeringPullRequest = _githubSettings.Value.PullRequest?.Branch!;
var branchTriggeringPullRequest = context.GitHub().EnvironmentVariables.RefName!;

await GitHelpers.SetUserCommitInformation(context, cancellationToken);

Expand Down
5 changes: 3 additions & 2 deletions src/ModularPipelines.Build/Modules/FormatMarkdownModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using ModularPipelines.Extensions;
using ModularPipelines.Git.Extensions;
using ModularPipelines.GitHub.Attributes;
using ModularPipelines.GitHub.Extensions;
using ModularPipelines.Models;
using ModularPipelines.Modules;
using ModularPipelines.Node.Extensions;
Expand All @@ -32,7 +33,7 @@ public FormatMarkdownModule(IOptions<GitHubSettings> gitHubSettings)
/// <inheritdoc/>
protected override Task<SkipDecision> ShouldSkip(IPipelineContext context)
{
if (string.IsNullOrEmpty(_gitHubSettings.Value.PullRequest?.Branch))
if (context.GitHub().EnvironmentVariables.EventName != "pull_request")
{
return SkipDecision.Skip("Not a pull request").AsTask();
}
Expand Down Expand Up @@ -88,7 +89,7 @@ await context.Node().Npx.ExecuteAsync(new NpxOptions
return await NothingAsync();
}

var branchTriggeringPullRequest = _gitHubSettings.Value.PullRequest!.Branch!;
var branchTriggeringPullRequest = context.GitHub().EnvironmentVariables.RefName!;

await GitHelpers.SetUserCommitInformation(context, cancellationToken);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using ModularPipelines.Git.Attributes;
using ModularPipelines.Git.Extensions;
using ModularPipelines.GitHub.Attributes;
using ModularPipelines.GitHub.Extensions;
using ModularPipelines.Models;
using ModularPipelines.Modules;
using Octokit;
Expand Down Expand Up @@ -69,7 +70,7 @@ protected override async Task<SkipDecision> ShouldSkip(IPipelineContext context)

if (!string.IsNullOrWhiteSpace(releaseNotesContents.Trim()))
{
await _gitHubClient.Repository.Release.Create(_githubSettings.Value.Repository!.Id!.Value,
await _gitHubClient.Repository.Release.Create(long.Parse(context.GitHub().EnvironmentVariables.RepositoryId!),
new NewRelease(versionInfoResult.Value)
{
Name = versionInfoResult.Value,
Expand All @@ -86,7 +87,7 @@ private async Task<string> GetReleaseNotesContents(CancellationToken cancellatio
{
var customNotes = await releaseNotesFile.ReadAsync(cancellationToken);

if (string.Equals("null", customNotes, StringComparison.OrdinalIgnoreCase))
if (string.Equals("null", customNotes.Trim(), StringComparison.OrdinalIgnoreCase))
{
customNotes = string.Empty;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@ namespace ModularPipelines.Build.Modules;
[DependsOn<PackProjectsModule>]
public class WaitForOtherOperatingSystemBuilds : Module<List<WorkflowRun>>
{
private readonly IOptions<GitHubSettings> _gitHubSettings;
private readonly IGitHubClient _gitHubClient;

public WaitForOtherOperatingSystemBuilds(IOptions<GitHubSettings> gitHubSettings,
IGitHubClient gitHubClient)
public WaitForOtherOperatingSystemBuilds(IGitHubClient gitHubClient)
{
_gitHubSettings = gitHubSettings;
_gitHubClient = gitHubClient;
}

Expand Down
12 changes: 0 additions & 12 deletions src/ModularPipelines.Build/Settings/GitHubPullRequest.cs

This file was deleted.

6 changes: 0 additions & 6 deletions src/ModularPipelines.Build/Settings/GitHubRepository.cs

This file was deleted.

6 changes: 0 additions & 6 deletions src/ModularPipelines.Build/Settings/GitHubSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,4 @@ public record GitHubSettings

[SecretValue]
public string? AdminToken { get; init; }

public string? Actor { get; init; }

public GitHubPullRequest? PullRequest { get; init; }

public GitHubRepository? Repository { get; init; }
}

0 comments on commit b8bcd49

Please sign in to comment.