GitHubApps 1.2.1
dotnet add package GitHubApps --version 1.2.1
NuGet\Install-Package GitHubApps -Version 1.2.1
<PackageReference Include="GitHubApps" Version="1.2.1" />
paket add GitHubApps --version 1.2.1
#r "nuget: GitHubApps, 1.2.1"
// Install GitHubApps as a Cake Addin #addin nuget:?package=GitHubApps&version=1.2.1 // Install GitHubApps as a Cake Tool #tool nuget:?package=GitHubApps&version=1.2.1
GitHub Apps .NET (Core)
The GitHub Apps Core is a component that allows the creation of GitHub Apps using .NET.
A GitHub App is a service that receives a post request from GitHub when certain actions are executed.
This component exposes a GitHubAppBase
class that must be extended to implement your own Git Hub App.
Refer to the API Documentation to have a better understanding of each class and how to use it.
In this repository
Usage
Add the nuget package GitHubApps into your project. This package is compatible with netstandard1.0
, netstandard1.3
, netstandard2.0
, net45
, net46
, net461
, and net6.0
. If your project target any framework higher than those, it will work fine.
If you are planning to implement a ASP.NET Core Web Application using this component, install the GitHubApps.AspNetCore package instead. This package offers a MVC
Controller
that handles thePOST
request made by GitHub.
Creating your own GitHub App
In order to create your own GitHub App, create a class and extend from the GitHubAppBase
class.
using GitHubApps;
public class MyGitHubApp: GitHubAppBase
{
//TODO: Override the virtual methods for each event
}
This class contains several virtual methods that can be overwritten to handle the proper event and action. For example, to handle the GitHub event installation
with action created
, you can override the OnEventInstallationCreated()
method.
using GitHubApps;
public class MyGitHubApp: GitHubAppBase
{
public override EventResult OnEventInstallationCreated(GitHubDelivery<GitHubEventInstallation> payload)
{
// Your code goes here...
}
}
The method should always return an EventResult
object.
If an event/action that is not handled yet is called, it will call the method OnEventActionUnhandled()
.
If an event without action that is not handled yet is called, it will call the method OnEventUnhandled()
.
When implementing the GitHubApps
package only, it is necessary to manually implement the ProcessRequest()
call. This function is going to route the event to the proper method, which has to be overwritten.
Current Events
This list contains the events that are currently implemented by this component.
Event | Description | Package Version |
---|---|---|
create |
This event occurs when a Git branch or tag is created | v1.0.0 |
delete |
This event occurs when a Git branch or tag is deleted | v1.0.0 |
fork |
This event occurs when someone forks a repository | v1.0.0 |
installation |
This even toccurs when there activity relating to a GitHub App installation | v1.0.0 |
issue_comment |
This event occurs when there is activity relating to a comment on an issue or pull request | v1.0.0 |
issues |
This event occurs when there is activity relating to an issue | v1.0.0 |
label |
This event occurs when there is activity relating to labels | v1.0.0 |
pull_request |
This event occurs when there is activity on a pull request | v1.0.0 |
push |
This event occurs when there is a push to a repository branch | v1.0.0 |
release |
This event occurs when there is activity relating to releases | v1.0.0 |
repository |
This event occurs when there is activity relating to repositories | v1.0.0 |
If you need to handle an event that is not implement yet, you can do it by overwriting the method
OnEventUnhandled()
orOnEventActionUnhandled()
.
All of the GitHub events that are not in this list are going to be implemented at some point. Check the Project Roadmap on the Links section to see when it is likely to be delivered. Feel free to place an issue with your request in order to expedite its delivery.
Communicating with the GitHub API
When your GitHub App is called, it is very likely that you will want to perform any action in GitHub.
For example, every time a new Issue is created, you may want to, automatically, add a comment to it. In order to add a comment to an issue, you will need to use the GitHub REST API, and your GitHub App will need to have access to perform that.
There are different ways to communicate with the GitHub REST API. You can use the following methods:
- Use the GitHubAuth Nuget Package
- Use the Octokit Nuget Package
The GitHubAuth Nuget Package has the basic resources you need to access the API. It is also integrated with this library for projects targeting net6.0
and beyond. Refer to the GitHubAuth Repository to obtain more information on how to use it.
The Octokit Nuget Package has more resources to facilitate the communication with the API.
In the example below, we will use the GitHubAuth
library to respond to a event.
using GitHubApps;
public class MyGitHubApp: GitHubAppBase
{
public MyGitHubApp()
{
// Ideally, the Authenticator object comes from Dependency Injection
Authenticator = new GitHubAuth.AppAuthenticator("path_to_pem_file/pem_file.pem", 123456); // assuming 123456 is the GitHub App ID
// Implement the function to retrieve the HttpClient
Authenticator.GetClient = () => {
return new HttpClient();
}
}
public override EventResult OnEventInstallationCreated(GitHubDelivery<GitHubEventInstallation> payload)
{
// Retrieve the token to communicate with the API on behalf of the application installation id
var authData = Authenticator.GetToken<long>(payload.HookInstallationTargetID);
// Your code goes here...
// Use the token inside authData.Token to call the API.
}
}
Links
This section contains links that are relevant to this repository.
Link | Description |
---|---|
GitHub Webhook Events and Payloads | The specification of webhooks events and payloads |
Project Roadmap | The project roadmap and expected delivery dates |
Project Board | The project board containing the tasks and its status |
API Documentation | The API Documentation |
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard1.0 is compatible. netstandard1.1 was computed. netstandard1.2 was computed. netstandard1.3 is compatible. netstandard1.4 was computed. netstandard1.5 was computed. netstandard1.6 was computed. netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net45 is compatible. net451 was computed. net452 was computed. net46 is compatible. net461 is compatible. net462 is compatible. net463 was computed. net47 is compatible. net471 is compatible. net472 is compatible. net48 is compatible. net481 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
Universal Windows Platform | uap was computed. uap10.0 was computed. |
Windows Phone | wp8 was computed. wp81 was computed. wpa81 was computed. |
Windows Store | netcore was computed. netcore45 was computed. netcore451 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.5
- Newtonsoft.Json (>= 13.0.3)
-
.NETFramework 4.6
- Newtonsoft.Json (>= 13.0.3)
-
.NETFramework 4.6.1
- Newtonsoft.Json (>= 13.0.3)
-
.NETFramework 4.6.2
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.1)
- Newtonsoft.Json (>= 13.0.3)
-
.NETFramework 4.7
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.1)
- Newtonsoft.Json (>= 13.0.3)
-
.NETFramework 4.7.1
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.1)
- Newtonsoft.Json (>= 13.0.3)
-
.NETFramework 4.7.2
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.1)
- Newtonsoft.Json (>= 13.0.3)
-
.NETFramework 4.8
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.1)
- Newtonsoft.Json (>= 13.0.3)
-
.NETFramework 4.8.1
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.1)
- Newtonsoft.Json (>= 13.0.3)
-
.NETStandard 1.0
- NETStandard.Library (>= 1.6.1)
- Newtonsoft.Json (>= 13.0.3)
-
.NETStandard 1.3
- NETStandard.Library (>= 1.6.1)
- Newtonsoft.Json (>= 13.0.3)
-
.NETStandard 2.0
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.1)
- Newtonsoft.Json (>= 13.0.3)
-
net6.0
- GitHubAuth (>= 1.0.2)
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.1)
- Newtonsoft.Json (>= 13.0.3)
-
net7.0
- GitHubAuth (>= 1.0.2)
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.1)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on GitHubApps:
Package | Downloads |
---|---|
GitHubApps.AspNetCore.Mvc
A framework to facilitate the creation of GitHub Apps using Asp.NET Core |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.2.1 | 225 | 11/10/2023 |
1.2.1-preview.4 | 69 | 11/10/2023 |
1.2.1-preview.3 | 68 | 11/10/2023 |
1.2.1-preview.2 | 83 | 11/6/2023 |
1.2.1-preview.1 | 82 | 11/5/2023 |
1.2.0 | 119 | 10/30/2023 |
1.1.0 | 104 | 9/26/2023 |
1.0.1 | 114 | 9/23/2023 |
1.0.0 | 105 | 9/19/2023 |