-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT]: Create a GitHub App from a manifest
* Create a GitHub App from a manifest * Add missing InstallationPermissions * observable and tests * Remove ManualRoute on Observable route --------- Co-authored-by: Nick Floyd <139819+nickfloyd@users.noreply.github.com>
- Loading branch information
1 parent
b208057
commit c2aee1a
Showing
11 changed files
with
282 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using Octokit.Internal; | ||
using Xunit; | ||
|
||
namespace Octokit.Tests.Models | ||
{ | ||
public class GitHubAppFromManifestTests | ||
{ | ||
[Fact] | ||
public void CanBeDeserialized() | ||
{ | ||
// from https://docs.github.com/rest/apps/apps#create-a-github-app-from-a-manifest | ||
const string json = @"{ | ||
""id"": 1, | ||
""slug"": ""octoapp"", | ||
""node_id"": ""MDxOkludGVncmF0aW9uMQ=="", | ||
""owner"": { | ||
""login"": ""github"", | ||
""id"": 1, | ||
""node_id"": ""MDEyOk9yZ2FuaXphdGlvbjE="", | ||
""url"": ""https://api.github.com/orgs/github"", | ||
""repos_url"": ""https://api.github.com/orgs/github/repos"", | ||
""events_url"": ""https://api.github.com/orgs/github/events"", | ||
""avatar_url"": ""https://github.com/images/error/octocat_happy.gif"", | ||
""gravatar_id"": """", | ||
""html_url"": ""https://github.com/octocat"", | ||
""followers_url"": ""https://api.github.com/users/octocat/followers"", | ||
""following_url"": ""https://api.github.com/users/octocat/following{/other_user}"", | ||
""gists_url"": ""https://api.github.com/users/octocat/gists{/gist_id}"", | ||
""starred_url"": ""https://api.github.com/users/octocat/starred{/owner}{/repo}"", | ||
""subscriptions_url"": ""https://api.github.com/users/octocat/subscriptions"", | ||
""organizations_url"": ""https://api.github.com/users/octocat/orgs"", | ||
""received_events_url"": ""https://api.github.com/users/octocat/received_events"", | ||
""type"": ""User"", | ||
""site_admin"": true | ||
}, | ||
""name"": ""Octocat App"", | ||
""description"": ""A short description of the app"", | ||
""external_url"": ""https://example.com"", | ||
""html_url"": ""https://github.com/apps/octoapp"", | ||
""created_at"": ""2017-07-08T16:18:44-04:00"", | ||
""updated_at"": ""2017-07-08T16:18:44-04:00"", | ||
""permissions"": { | ||
""metadata"": ""read"", | ||
""contents"": ""read"", | ||
""issues"": ""write"", | ||
""single_file"": ""write"" | ||
}, | ||
""events"": [ | ||
""push"", | ||
""pull_request"" | ||
], | ||
""client_id"": ""Iv1.8a61f9b3a7aba766"", | ||
""client_secret"": ""1726be1638095a19edd134c77bde3aa2ece1e5d8"", | ||
""webhook_secret"": ""e340154128314309424b7c8e90325147d99fdafa"", | ||
""pem"": ""-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEAuEPzOUE+kiEH1WLiMeBytTEF856j0hOVcSUSUkZxKvqczkWM\n9vo1gDyC7ZXhdH9fKh32aapba3RSsp4ke+giSmYTk2mGR538ShSDxh0OgpJmjiKP\nX0Bj4j5sFqfXuCtl9SkH4iueivv4R53ktqM+n6hk98l6hRwC39GVIblAh2lEM4L/\n6WvYwuQXPMM5OG2Ryh2tDZ1WS5RKfgq+9ksNJ5Q9UtqtqHkO+E63N5OK9sbzpUUm\noNaO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39RjrhJlYACRZNMbK+v/ckEQYdJSSKmGCVe0JrGYDuPtic\nI9+IGfSorf7KHPoMmMN6bPYQ7Gjh7a++tgRFTMEc8956Hnt4xGahy9NcglNtBpVN\n6G8jAoGBAMCh028pdzJa/xeBHLLaVB2sc0Fe7993WlsPmnVE779dAz7qMscOtXJK\nfgtriltLSSD6rTA9hUAsL/X62rY0wdXuNdijjBb/qvrx7CAV6i37NK1CjABNjsfG\nZM372Ac6zc1EqSrid2IjET1YqyIW2KGLI1R2xbQc98UGlt48OdWu\n-----END RSA PRIVATE KEY-----\n"" | ||
}"; | ||
|
||
var app = new SimpleJsonSerializer().Deserialize<GitHubAppFromManifest>(json); | ||
|
||
Assert.Equal(1, app.Id); | ||
Assert.Equal("octoapp", app.Slug); | ||
Assert.Equal("MDxOkludGVncmF0aW9uMQ==", app.NodeId); | ||
Assert.Equal("Octocat App", app.Name); | ||
Assert.Equal("A short description of the app", app.Description); | ||
Assert.Equal("https://example.com", app.ExternalUrl); | ||
Assert.Equal("https://github.com/apps/octoapp", app.HtmlUrl); | ||
Assert.Equal(InstallationReadWritePermissionLevel.Write, app.Permissions.SingleFile); | ||
Assert.Contains("push", app.Events); | ||
|
||
Assert.Equal("Iv1.8a61f9b3a7aba766", app.ClientId); | ||
Assert.Equal("1726be1638095a19edd134c77bde3aa2ece1e5d8", app.ClientSecret); | ||
Assert.Equal("e340154128314309424b7c8e90325147d99fdafa", app.WebhookSecret); | ||
Assert.Equal("-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEAuEPzOUE+kiEH1WLiMeBytTEF856j0hOVcSUSUkZxKvqczkWM\n9vo1gDyC7ZXhdH9fKh32aapba3RSsp4ke+giSmYTk2mGR538ShSDxh0OgpJmjiKP\nX0Bj4j5sFqfXuCtl9SkH4iueivv4R53ktqM+n6hk98l6hRwC39GVIblAh2lEM4L/\n6WvYwuQXPMM5OG2Ryh2tDZ1WS5RKfgq+9ksNJ5Q9UtqtqHkO+E63N5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5MX73maB/7yAX8pVO39RjrhJlYACRZNMbK+v/ckEQYdJSSKmGCVe0JrGYDuPtic\nI9+IGfSorf7KHPoMmMN6bPYQ7Gjh7a++tgRFTMEc8956Hnt4xGahy9NcglNtBpVN\n6G8jAoGBAMCh028pdzJa/xeBHLLaVB2sc0Fe7993WlsPmnVE779dAz7qMscOtXJK\nfgtriltLSSD6rTA9hUAsL/X62rY0wdXuNdijjBb/qvrx7CAV6i37NK1CjABNjsfG\nZM372Ac6zc1EqSrid2IjET1YqyIW2KGLI1R2xbQc98UGlt48OdWu\n-----END RSA PRIVATE KEY-----\n", app.Pem); | ||
|
||
Assert.Equal(1, app.Owner.Id); | ||
Assert.Equal("github", app.Owner.Login); | ||
Assert.Equal("https://api.github.com/orgs/github", app.Owner.Url); | ||
Assert.Equal(AccountType.User, app.Owner.Type); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
|
||
namespace Octokit | ||
{ | ||
/// <summary> | ||
/// Represents a GitHub application from a manifest. | ||
/// https://docs.github.com/rest/apps/apps#create-a-github-app-from-a-manifest | ||
/// </summary> | ||
[DebuggerDisplay("{DebuggerDisplay,nq}")] | ||
public class GitHubAppFromManifest : GitHubApp | ||
{ | ||
public GitHubAppFromManifest() { } | ||
|
||
public GitHubAppFromManifest(long id, string slug, string nodeId, string name, User owner, string description, string externalUrl, string htmlUrl, DateTimeOffset createdAt, DateTimeOffset updatedAt, InstallationPermissions permissions, IReadOnlyList<string> events, string clientId, string clientSecret, string webhookSecret, string pem) | ||
: base(id, slug, nodeId, name, owner, description, externalUrl, htmlUrl, createdAt, updatedAt, permissions, events) | ||
{ | ||
ClientId = clientId; | ||
ClientSecret = clientSecret; | ||
WebhookSecret = webhookSecret; | ||
Pem = pem; | ||
} | ||
|
||
/// <summary> | ||
/// The Client Id of the GitHub App. | ||
/// </summary> | ||
public string ClientId { get; private set; } | ||
|
||
/// <summary> | ||
/// The Client Secret of the GitHub App. | ||
/// </summary> | ||
public string ClientSecret { get; private set; } | ||
|
||
/// <summary> | ||
/// The Webhook Secret of the GitHub App. | ||
/// </summary> | ||
public string WebhookSecret { get; private set; } | ||
|
||
/// <summary> | ||
/// The PEM of the GitHub App. | ||
/// </summary> | ||
public string Pem { get; private set; } | ||
} | ||
} |
Oops, something went wrong.