-
Notifications
You must be signed in to change notification settings - Fork 12
Обновление под новую версию Аудитора #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zetroot
wants to merge
10
commits into
DotNetRu:master
Choose a base branch
from
zetroot:feature/new-auditor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e4535ef
github directory implementation
zetroot 52a0637
added github file, extracted base abstraction for file and directory
zetroot ddd8c05
added github file implementation, added exist method implementation, …
zetroot 901e9cc
renaming Github to GitHub
zetroot 5c793f6
added radzen blazor framework
zetroot 6df2daf
updated wasm application to show community list
zetroot 068ff5d
nuget updates
zetroot c74777c
fixing community loading
zetroot 5df734a
added factory method for authenticated clients
zetroot 2841d73
using base database directory for auditor store
zetroot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,42 @@ | ||
| using Octokit; | ||
| using Octokit.Internal; | ||
|
|
||
| namespace DotNetRu.Commune.GithubFileSystem | ||
| { | ||
| /// <summary> | ||
| /// Factoy for building clients | ||
| /// </summary> | ||
| public class ClientFactory | ||
| { | ||
| private const string ProductName = "DotNetRuCommune"; | ||
|
|
||
| /// <summary> | ||
| /// Build anonymous client - no credentials needed | ||
| /// </summary> | ||
| /// <returns>Github client with anonymous credentials</returns> | ||
| public GitHubClient Anonymous() | ||
| { | ||
| var credStore = new InMemoryCredentialStore(Credentials.Anonymous); | ||
| var client = new GitHubClient(new Connection(new ProductHeaderValue(ProductName), | ||
| GitHubClient.GitHubApiUrl, credStore, | ||
| new HttpClientAdapter(Net5HttpMessageHandlerFactory.CreateDefault), | ||
| new SimpleJsonSerializer())); | ||
| return client; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Get an authenticated client with specific token | ||
| /// </summary> | ||
| /// <param name="token">personal access token for github</param> | ||
| /// <returns>GitHUb client with injeccted personal access token</returns> | ||
| public GitHubClient WithToken(string token) | ||
| { | ||
| var credStore = new InMemoryCredentialStore(new (token, AuthenticationType.Bearer)); | ||
| var client = new GitHubClient(new Connection(new ProductHeaderValue(ProductName), | ||
| GitHubClient.GitHubApiUrl, credStore, | ||
| new HttpClientAdapter(Net5HttpMessageHandlerFactory.CreateDefault), | ||
| new SimpleJsonSerializer())); | ||
| return client; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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,86 @@ | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using DotNetRu.Auditor.Storage.FileSystem; | ||
| using Octokit; | ||
|
|
||
| namespace DotNetRu.Commune.GithubFileSystem | ||
| { | ||
| /// <summary> | ||
| /// Virtual directory in github repository. Implements <see cref="IDirectory"/> | ||
| /// </summary> | ||
| public class GitHubDirectory : GitHubFilesystemEntry, IDirectory | ||
| { | ||
| private GitHubDirectory(IGitHubClient gitHubClient, Repository repository, Reference branch, string name, string fullName) : | ||
| base(gitHubClient, repository, branch, name, fullName) | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Factory method for building root directory | ||
| /// </summary> | ||
| /// <param name="gitHubClient">Github client for this directory, stores authentication data in it</param> | ||
| /// <param name="repository">repository, contents are accessed to</param> | ||
| /// <param name="branch">branch in the reposiroty, to work with</param> | ||
| /// <returns>new directory instance pointing to the root of content of this branch in this repository</returns> | ||
| public static IDirectory ForRoot(IGitHubClient gitHubClient, Repository repository, Reference branch) | ||
| { | ||
| return new GitHubDirectory(gitHubClient, repository, branch, string.Empty, "/"); | ||
| } | ||
|
|
||
| private string GetChildFullName(string childDirectoryName) => | ||
| FullName switch | ||
| { | ||
| null => childDirectoryName, | ||
| "" => childDirectoryName, | ||
| {} s when s.EndsWith("/") => $"{FullName}{childDirectoryName}", | ||
| _ => $"{FullName}/{childDirectoryName}" | ||
| }; | ||
|
|
||
| /// <inheritdoc /> | ||
| public IDirectory GetDirectory(string childDirectoryName) | ||
| { | ||
| var childFullName = GetChildFullName(childDirectoryName); | ||
| return new GitHubDirectory(GitHubClient, Repository, Branch, childDirectoryName, childFullName); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public IFile GetFile(string childFileName) | ||
| { | ||
| var childFullName = GetChildFullName(childFileName); | ||
| return new GitHubFile(GitHubClient, Repository, Branch, childFileName, childFullName); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async IAsyncEnumerable<IDirectory> EnumerateDirectoriesAsync() | ||
| { | ||
| var contents = await ContentsClient.GetAllContentsByRef(Repository.Id, FullName, Branch.Ref) | ||
| .ConfigureAwait(false); | ||
| foreach (var content in contents.Where(x => x.Type.Value == ContentType.Dir)) | ||
| { | ||
| yield return new GitHubDirectory(GitHubClient, Repository, Branch, content.Name, content.Path); | ||
| } | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async IAsyncEnumerable<IFile> EnumerateFilesAsync() | ||
| { | ||
| var contents = await ContentsClient.GetAllContentsByRef(Repository.Id, FullName, Branch.Ref) | ||
| .ConfigureAwait(false); | ||
| foreach (var content in contents.Where(x => x.Type.Value == ContentType.File)) | ||
| { | ||
| yield return new GitHubFile(GitHubClient, Repository, Branch, content.Name, content.Path); | ||
| } | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public override async ValueTask<bool> ExistsAsync() | ||
| { | ||
| var parentDirectory = GetParentDirectory(); | ||
| var contents = await ContentsClient.GetAllContentsByRef(Repository.Id, parentDirectory, Branch.Ref) | ||
| .ConfigureAwait(false); | ||
|
|
||
| return contents.Any(x => x.Name == Name && x.Type.Value == ContentType.File); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,50 @@ | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using DotNetRu.Auditor.Storage.FileSystem; | ||
| using Octokit; | ||
|
|
||
| namespace DotNetRu.Commune.GithubFileSystem | ||
| { | ||
| /// <summary> | ||
| /// Files from github repository | ||
| /// </summary> | ||
| public class GitHubFile : GitHubFilesystemEntry, IFile | ||
| { | ||
| /// <summary> | ||
| /// ctor | ||
| /// </summary> | ||
| /// <param name="gitHubClient">github client</param> | ||
| /// <param name="repository">github repository</param> | ||
| /// <param name="branch">branch in this repository</param> | ||
| /// <param name="name">file name</param> | ||
| /// <param name="fullName">file full path in repository</param> | ||
| public GitHubFile(IGitHubClient gitHubClient, Repository repository, Reference branch, string name, string fullName) : | ||
| base(gitHubClient, repository, branch, name, fullName) | ||
| { | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public override async ValueTask<bool> ExistsAsync() | ||
| { | ||
| var parentDirectory = GetParentDirectory(); | ||
| var contents = await ContentsClient.GetAllContentsByRef(Repository.Id, parentDirectory, Branch.Ref) | ||
| .ConfigureAwait(false); | ||
|
|
||
| return contents.Any(x => x.Name == Name && x.Type.Value == ContentType.File); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<Stream> OpenForReadAsync() | ||
| { | ||
| var contents = await ContentsClient | ||
| .GetRawContentByRef(Repository.Owner.Login, Repository.Name, FullName, Branch.Ref) | ||
| .ConfigureAwait(false); | ||
| return new MemoryStream(contents, false); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public Task<IWritableFile?> RequestWriteAccessAsync() => throw new System.NotImplementedException(); | ||
|
|
||
| } | ||
| } |
69 changes: 69 additions & 0 deletions
69
DotNetRu.Commune.GithubFilesystem/GitHubFilesystemEntry.cs
This file contains hidden or 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,69 @@ | ||
| using System.Threading.Tasks; | ||
| using DotNetRu.Auditor.Storage.FileSystem; | ||
| using Octokit; | ||
|
|
||
| namespace DotNetRu.Commune.GithubFileSystem | ||
| { | ||
| /// <summary> | ||
| /// base class for all filesystem objects - directories and files | ||
| /// </summary> | ||
| public abstract class GitHubFilesystemEntry : IFileSystemEntry | ||
| { | ||
| /// <summary> | ||
| /// Github client, used to access github data | ||
| /// </summary> | ||
| protected readonly IGitHubClient GitHubClient; | ||
|
|
||
| /// <summary> | ||
| /// repository in github where data contents are stored | ||
| /// </summary> | ||
| protected readonly Repository Repository; | ||
|
|
||
| /// <summary> | ||
| /// repository branch wich contents are browsed or modified | ||
| /// </summary> | ||
| protected readonly Reference Branch; | ||
|
|
||
| /// <summary> | ||
| /// helper property to access contents client. Contents client is a wrapper over contents endpoint, it is used for manipulating data in repository | ||
| /// </summary> | ||
| protected IRepositoryContentsClient ContentsClient => GitHubClient.Repository.Content; | ||
|
|
||
| /// <summary> | ||
| /// ctor | ||
| /// </summary> | ||
| /// <param name="gitHubClient">github client</param> | ||
| /// <param name="repository">github repository</param> | ||
| /// <param name="branch">branch in repository</param> | ||
| /// <param name="name">name of this entry</param> | ||
| /// <param name="fullName">full name, aka path of this entry</param> | ||
| protected GitHubFilesystemEntry(IGitHubClient gitHubClient, Repository repository, Reference branch, string name, string fullName) | ||
| { | ||
| GitHubClient = gitHubClient; | ||
| Repository = repository; | ||
| Branch = branch; | ||
| Name = name; | ||
| FullName = fullName; | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public string Name { get; } | ||
|
|
||
| /// <inheritdoc /> | ||
| public string FullName { get; } | ||
|
|
||
| /// <inheritdoc /> | ||
| public abstract ValueTask<bool> ExistsAsync(); | ||
|
|
||
| /// <summary> | ||
| /// Get parent directory name containing this entry | ||
| /// </summary> | ||
| /// <returns>path of the parent directory</returns> | ||
| protected string GetParentDirectory() => | ||
| FullName.Remove(FullName.Length - Name.Length) switch | ||
| { | ||
| "/" => string.Empty, | ||
| {} s => s | ||
| }; | ||
| } | ||
| } |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.