Skip to content
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

wip #20

Merged

wip #20

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ namespace Octokit.Reactive;

public interface IObservableAuditOrganizationsClient
{
IObservable<DateTime?> GetUserLastActivityDate(string organization, string repository, string user);
IObservable<DateTime?> GetUserLastActivityDate(string organization, AuditLogPhraseOptions phraseOptions);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public ObservableAuditOrganizationsClient(IGitHubClient client)
_client = client.AuditLog.Organizations;
}

public IObservable<DateTime?> GetUserLastActivityDate(string organization, string repository, string user)
public IObservable<DateTime?> GetUserLastActivityDate(string organization, AuditLogPhraseOptions phraseOptions)
{
return _client.GetUserLastActivityDate(organization, repository, user).ToObservable();
return _client.GetUserLastActivityDate(organization, phraseOptions).ToObservable();
}
}
13 changes: 8 additions & 5 deletions Octokit/Clients/AuditOrganizationsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,23 @@ public AuditOrganizationsClient(IApiConnection apiConnection) : base(apiConnecti
{
}

[ManualRoute("GET", "/organizations/{org}/audit-log?phrase=actor:{user}+repo:{org}/{repo}")]
public async Task<DateTime?> GetUserLastActivityDate(string organization, string repository, string user)
[ManualRoute("GET", "/organizations/{org}/audit-log?phrase={phrase}")]
public async Task<DateTime?> GetUserLastActivityDate(string organization, AuditLogPhraseOptions auditLogPhraseOptions)
{
Ensure.ArgumentNotNullOrEmptyString(organization, nameof(organization));
Ensure.ArgumentNotNullOrEmptyString(repository, nameof(repository));
Ensure.ArgumentNotNullOrEmptyString(user, nameof(user));
Ensure.ArgumentNotNull(auditLogPhraseOptions, nameof(auditLogPhraseOptions));
Ensure.ArgumentNotNullOrEmptyString(auditLogPhraseOptions.Repository, nameof(AuditLogPhraseOptions.Repository));
Ensure.ArgumentNotNullOrEmptyString(auditLogPhraseOptions.User, nameof(AuditLogPhraseOptions.User));

var options = new ApiOptions()
{
PageSize = 1
};
IDictionary<string, string> parameters = new Dictionary<string, string>();
Pagination.Setup(parameters, options);
var auditLogs = await ApiConnection.Get<List<AuditLogEvent>>(ApiUrls.AuditLog(organization, repository, user), parameters);

var phrase = auditLogPhraseOptions.BuildPhrase(organization);
var auditLogs = await ApiConnection.Get<List<AuditLogEvent>>(ApiUrls.AuditLog(organization, phrase), parameters);

if (!auditLogs.Any())
{
Expand Down
5 changes: 2 additions & 3 deletions Octokit/Clients/IAuditOrganizationsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ public interface IAuditOrganizationsClient
/// http://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository
/// </remarks>
/// <param name="organization">The organization</param>
/// <param name="repository">The organization</param>
/// <param name="user">The user</param>
Task<DateTime?> GetUserLastActivityDate(string organization, string repository, string user);
/// <param name="auditLogPhraseOptions">The query phrase options</param>
Task<DateTime?> GetUserLastActivityDate(string organization, AuditLogPhraseOptions auditLogPhraseOptions);
}
}
8 changes: 3 additions & 5 deletions Octokit/Helpers/ApiUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5213,13 +5213,11 @@ public static Uri ActionsListWorkflowRuns(string owner, string repo, string work
/// Creates the relative <see cref="Uri"/> for getting the contents of the specified repository and path
/// </summary>
/// <param name="organization">The organization</param>
/// <param name="user">The user</param>
/// <param name="repository">The repository</param>
/// <param name="phrase">The query phrase to filter results</param>
/// <returns>The <see cref="Uri"/> for getting the contents of the specified repository and path</returns>
public static Uri AuditLog(string organization, string repository, string user)
public static Uri AuditLog(string organization, string phrase)
{
return "organizations/{0}/audit-log?phrase=actor:{1} repo:{2}/{3}"
.FormatUri(organization, user, organization, repository);
return "organizations/{0}/audit-log?phrase={1}".FormatUri(organization, phrase);
}
}
}
33 changes: 33 additions & 0 deletions Octokit/Models/Request/AuditLogPhraseOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Text;

namespace Octokit
{
public class AuditLogPhraseOptions
{
public string User { get; set; }
public string Repository { get; set; }
public DateTime? Created { get; set; }

public string BuildPhrase(string organization)
{
var sb = new StringBuilder();
if (!string.IsNullOrWhiteSpace(User))
{
sb.Append($"actor:{User} ");
}

if (!string.IsNullOrWhiteSpace(Repository))
{
sb.Append($"repo:{organization}/{Repository} ");
}

if (Created.HasValue)
{
sb.Append($"created:>={Created.Value:yyyy-MM-dd}");
}

return sb.ToString();
}
}
}
2 changes: 1 addition & 1 deletion Octokit/Octokit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Description>An async-based GitHub API client library for .NET and .NET Core</Description>
<AssemblyTitle>Octokit</AssemblyTitle>
<Authors>GitHub</Authors>
<Version>1.0.16</Version>
<Version>1.0.17</Version>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>Octokit</AssemblyName>
<PackageId>Apiiro.Octokit</PackageId>
Expand Down