TheNerdCollective.Integrations.GitHub
1.0.1
dotnet add package TheNerdCollective.Integrations.GitHub --version 1.0.1
NuGet\Install-Package TheNerdCollective.Integrations.GitHub -Version 1.0.1
<PackageReference Include="TheNerdCollective.Integrations.GitHub" Version="1.0.1" />
<PackageVersion Include="TheNerdCollective.Integrations.GitHub" Version="1.0.1" />
<PackageReference Include="TheNerdCollective.Integrations.GitHub" />
paket add TheNerdCollective.Integrations.GitHub --version 1.0.1
#r "nuget: TheNerdCollective.Integrations.GitHub, 1.0.1"
#:package TheNerdCollective.Integrations.GitHub@1.0.1
#addin nuget:?package=TheNerdCollective.Integrations.GitHub&version=1.0.1
#tool nuget:?package=TheNerdCollective.Integrations.GitHub&version=1.0.1
TheNerdCollective.Integrations.GitHub
A comprehensive .NET integration library for the GitHub API v3, providing seamless access to GitHub Actions workflow management and repository information.
Features
- Workflow Run Management: Retrieve, filter, and manage GitHub Actions workflow runs
- Status Filtering: Filter workflow runs by status, conclusion, actor, branch, and event
- Workflow Control: Cancel, rerun, rerun failed jobs, and delete workflow runs
- Attempt Tracking: Access workflow run attempts for debugging and analysis
- Async/Await Support: Fully asynchronous API for high-performance applications
- Configurable: Easy setup with dependency injection and configuration
Installation
dotnet add package TheNerdCollective.Integrations.GitHub
Quick Start
1. Configure in appsettings.json
{
"GitHub": {
"Token": "your_github_personal_access_token",
"Owner": "your-username-or-org",
"Repository": "your-repo-name"
}
}
2. Register in Dependency Injection (Program.cs)
builder.Services.Configure<GitHubOptions>(
builder.Configuration.GetSection("GitHub"));
builder.Services.AddHttpClient<GitHubService>();
3. Use the Service
public class MyService
{
private readonly GitHubService _gitHubService;
public MyService(GitHubService gitHubService)
{
_gitHubService = gitHubService;
}
public async Task CheckWorkflows()
{
// Get latest 10 workflow runs
var runs = await _gitHubService.GetLatestWorkflowRunsAsync(limit: 10);
foreach (var run in runs)
{
Console.WriteLine($"{run.Name}: {run.Status} - {run.Conclusion}");
}
}
public async Task GetFailedRuns()
{
// Get failed workflow runs
var failedRuns = await _gitHubService.GetWorkflowRunsAsync(
limit: 20,
conclusion: "failure"
);
return failedRuns;
}
public async Task RerunWorkflow(long runId)
{
var success = await _gitHubService.RerunWorkflowAsync(runId);
return success;
}
}
API Reference
GetLatestWorkflowRunsAsync(int limit, string? status, string? conclusion)
Retrieve the latest workflow runs with optional filtering.
Parameters:
limit(int, default: 10): Maximum runs to retrieve (max: 100)status(string, optional): Filter by status (completed, in_progress, queued, requested, waiting, etc.)conclusion(string, optional): Filter by conclusion (success, failure, neutral, cancelled, skipped, timed_out, action_required)
Returns: Task<List<WorkflowRun>>
GetWorkflowRunsAsync(int limit, string? status, string? conclusion, string? actor, string? branch, string? event, string? sort, string? direction)
Advanced filtering for workflow runs.
Parameters:
limit(int, default: 10): Maximum runs to retrievestatus,conclusion: Standard filtersactor(string, optional): Filter by actor (username)branch(string, optional): Filter by branch nameevent(string, optional): Filter by event type (push, pull_request, schedule, etc.)sort(string, default: "created"): Sort fielddirection(string, default: "desc"): Sort direction (asc/desc)
Returns: Task<List<WorkflowRun>>
GetWorkflowRunAsync(long runId)
Get details of a specific workflow run.
Parameters:
runId(long): The workflow run ID
Returns: Task<WorkflowRun?>
CancelWorkflowRunAsync(long runId)
Cancel a running workflow.
Parameters:
runId(long): The workflow run ID
Returns: Task<bool> (success status)
RerunWorkflowAsync(long runId)
Rerun a completed workflow.
Parameters:
runId(long): The workflow run ID
Returns: Task<bool> (success status)
RerunFailedJobsAsync(long runId)
Rerun only the failed jobs in a workflow.
Parameters:
runId(long): The workflow run ID
Returns: Task<bool> (success status)
DeleteWorkflowRunAsync(long runId)
Delete a workflow run from history.
Parameters:
runId(long): The workflow run ID
Returns: Task<bool> (success status)
GetWorkflowRunAttemptsAsync(long runId)
Get all attempts of a workflow run.
Parameters:
runId(long): The workflow run ID
Returns: Task<List<WorkflowRun>>
Configuration
GitHubOptions
Configure these settings in your appsettings.json:
{
"GitHub": {
"Token": "ghp_xxxxxxxxxxxx",
"Owner": "The-Nerd-Collective",
"Repository": "TheNerdCollective.Components"
}
}
GitHub Personal Access Token
- Go to https://github.com/settings/tokens
- Click "Generate new token"
- Select required scopes (recommend
actions,repofor full access) - Copy the token and store securely in your configuration
Models
WorkflowRun
Represents a GitHub Actions workflow execution with the following key properties:
Id: Unique workflow run identifierName: Workflow nameStatus: Current status (completed, in_progress, queued, etc.)Conclusion: Final result (success, failure, cancelled, etc.)Event: Triggering event typeHeadBranch: Branch where the workflow runsHeadSha: Commit SHACreatedAt: When the run was createdUpdatedAt: Last update timestampActor: User who triggered the workflowHtmlUrl: GitHub web URL for the run
Error Handling
The service catches exceptions and returns empty collections or null values:
var runs = await _gitHubService.GetLatestWorkflowRunsAsync();
if (!runs.Any())
{
// Handle empty result (no runs or API error)
}
For production use, consider implementing retry logic and logging for failed requests.
License
Licensed under the Apache License, Version 2.0. See LICENSE file for details.
Support
For issues or questions, visit the repository: https://github.com/The-Nerd-Collective/TheNerdCollective.Components
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.Configuration (>= 10.0.1)
- Microsoft.Extensions.DependencyInjection (>= 10.0.1)
- Microsoft.Extensions.Http (>= 10.0.1)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.1 | 77 | 1/26/2026 |