Skip to content
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
143f16e
fix: config would fail because no providers were configured (#129)
Dec 23, 2021
6cdf60d
chore: release 1.5.2 (#130)
github-actions[bot] Dec 23, 2021
44a0620
feat: async enumerable and lazy paging (#128)
Dec 24, 2021
20ebc69
chore: release 1.6.0 (#133)
github-actions[bot] Dec 24, 2021
b9caa76
feat: add sort keys to show help (#132)
Dec 26, 2021
8b782e5
chore: tests for some common model classes (#136)
Dec 31, 2021
9de2b55
feat: add initial filter impl (#137)
Dec 31, 2021
f90de83
chore: release 1.7.0 (#134)
github-actions[bot] Dec 31, 2021
fe138dd
fix: accept filter contents with embedded colons (like 'title:fix:') …
Dec 31, 2021
dbaf907
chore: release 1.7.1 (#140)
github-actions[bot] Dec 31, 2021
187f3d9
fix: during the changes to status fetching the rollup got lost along …
Jan 4, 2022
291ba6c
chore: release 1.7.2 (#142)
github-actions[bot] Jan 4, 2022
eb00ab0
fix: when a user is deleted the Author field isn't returned. replacin…
Jan 6, 2022
01f5d1f
chore: release 1.7.3 (#144)
github-actions[bot] Jan 6, 2022
8247867
fix: handle errors in show/watch (#147)
tshowers-bt Jan 26, 2022
15f65f2
feat: initial addition of loggers with some simple top level log stat…
Mar 30, 2022
f68e47b
chore: release 1.8.0 (#153)
github-actions[bot] Apr 8, 2022
6a8ee49
fix: Revert "feat: initial addition of loggers " (#154)
Insomniak47 Apr 8, 2022
650402d
chore: release 1.8.1 (#155)
github-actions[bot] Apr 8, 2022
60e923d
fix: registration was not living long enough to handle cancellation p…
Insomniak47 Apr 9, 2022
748d2f7
chore: release 1.8.2 (#157)
github-actions[bot] Apr 9, 2022
cdd9db4
feat: configurable show timeout (#160)
tshowers-bt May 6, 2022
84d884b
chore: release 1.9.0 (#162)
github-actions[bot] May 9, 2022
dd71f6f
fix: add docs for filter, cleanup sorting and other text (#164)
Insomniak47 Oct 8, 2022
4cb1d81
chore: release 1.9.1 (#165)
github-actions[bot] Oct 8, 2022
9d5f33b
feat: add config subcommands (and move to an app builder setup) (#166)
Insomniak47 Oct 23, 2022
c8e174a
chore: release 1.10.0 (#169)
github-actions[bot] Oct 23, 2022
8fea83b
feat: configurable configfile path (#171)
Insomniak47 Nov 1, 2022
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
76 changes: 76 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,81 @@
# Changelog

## [1.9.0](https://www.github.com/wareismymind/peer/compare/v1.8.2...v1.9.0) (2022-05-06)


### Features

* configurable show timeout ([#160](https://www.github.com/wareismymind/peer/issues/160)) ([cdd9db4](https://www.github.com/wareismymind/peer/commit/cdd9db4184e9226e6638059d6cd56862eb46cf14))

### [1.8.2](https://www.github.com/wareismymind/peer/compare/v1.8.1...v1.8.2) (2022-04-09)


### Bug Fixes

* registration was not living long enough to handle cancellation properly. Also flattened out some of the async enumerables ([#156](https://www.github.com/wareismymind/peer/issues/156)) ([60e923d](https://www.github.com/wareismymind/peer/commit/60e923d345b656f01381b9a8e288642513f4f145))

### [1.8.1](https://www.github.com/wareismymind/peer/compare/v1.8.0...v1.8.1) (2022-04-08)


### Bug Fixes

* Revert "feat: initial addition of loggers " ([#154](https://www.github.com/wareismymind/peer/issues/154)) ([6a8ee49](https://www.github.com/wareismymind/peer/commit/6a8ee49c58b911a86a218b98e228f841359b316e))

## [1.8.0](https://www.github.com/wareismymind/peer/compare/v1.7.3...v1.8.0) (2022-03-30)


### Features

* initial addition of loggers with some simple top level log statements (and one in show) until we figure out how we want to approach it ([#152](https://www.github.com/wareismymind/peer/issues/152)) ([15f65f2](https://www.github.com/wareismymind/peer/commit/15f65f231b72b06231aca7f937c0635e6ba95f91))


### Bug Fixes

* handle errors in show/watch ([#147](https://www.github.com/wareismymind/peer/issues/147)) ([8247867](https://www.github.com/wareismymind/peer/commit/824786781edf230f7e83032f59b0fe5aafcd567a))

### [1.7.3](https://www.github.com/wareismymind/peer/compare/v1.7.2...v1.7.3) (2022-01-06)


### Bug Fixes

* when a user is deleted the Author field isn't returned. replacing author with 'octoghost' in those cases ([#143](https://www.github.com/wareismymind/peer/issues/143)) ([eb00ab0](https://www.github.com/wareismymind/peer/commit/eb00ab0e3ea00411e973fc324b1d49a6445facfa))

### [1.7.2](https://www.github.com/wareismymind/peer/compare/v1.7.1...v1.7.2) (2022-01-04)


### Bug Fixes

* during the changes to status fetching the rollup got lost along the way ([#141](https://www.github.com/wareismymind/peer/issues/141)) ([187f3d9](https://www.github.com/wareismymind/peer/commit/187f3d9cf318aa49563370c65c1883cedc165975))

### [1.7.1](https://www.github.com/wareismymind/peer/compare/v1.7.0...v1.7.1) (2021-12-31)


### Bug Fixes

* accept filter contents with embedded colons (like 'title:fix:') ([#139](https://www.github.com/wareismymind/peer/issues/139)) ([fe138dd](https://www.github.com/wareismymind/peer/commit/fe138ddd22f259d4245e792e73dd3008583be47c))

## [1.7.0](https://www.github.com/wareismymind/peer/compare/v1.6.0...v1.7.0) (2021-12-31)


### Features

* add initial filter impl ([#137](https://www.github.com/wareismymind/peer/issues/137)) ([9de2b55](https://www.github.com/wareismymind/peer/commit/9de2b552cde8a412963008577f836c5b6df58ada))
* add sort keys to show help ([#132](https://www.github.com/wareismymind/peer/issues/132)) ([b9caa76](https://www.github.com/wareismymind/peer/commit/b9caa76108cf282d49ae3af7f546acd49fcc1c74))

## [1.6.0](https://www.github.com/wareismymind/peer/compare/v1.5.2...v1.6.0) (2021-12-24)


### Features

* async enumerable and lazy paging ([#128](https://www.github.com/wareismymind/peer/issues/128)) ([44a0620](https://www.github.com/wareismymind/peer/commit/44a062087bf98145fcc6b2221eaa34a89a26c430))

### [1.5.2](https://www.github.com/wareismymind/peer/compare/v1.5.1...v1.5.2) (2021-12-23)


### Bug Fixes

* config would fail because no providers were configured ([#129](https://www.github.com/wareismymind/peer/issues/129)) ([143f16e](https://www.github.com/wareismymind/peer/commit/143f16e9b49b752f425d0d1698ac0bf7fc865919))

### [1.5.1](https://www.github.com/wareismymind/peer/compare/v1.5.0...v1.5.1) (2021-12-19)


Expand Down
4 changes: 4 additions & 0 deletions Peer.Domain/Check.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Peer.Domain.Util;

namespace Peer.Domain
{
Expand All @@ -12,6 +13,9 @@ public class Check

public Check(string name, string? description, Uri url, CheckStatus status, CheckResult result)
{
Validators.ArgIsDefined(status);
Validators.ArgIsDefined(result);

Name = name ?? throw new ArgumentNullException(nameof(name));
Description = description;
Url = url ?? throw new ArgumentNullException(nameof(url));
Expand Down
31 changes: 18 additions & 13 deletions Peer.Domain/Commands/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,32 @@ public class Config
private const string _configHelp = @"
{
""Peer"": {
//optional: The amount of time between calls to providers when using the --watch flag
""WatchIntervalSeconds"": 30
// The amount of time to wait for the show command to fetch pull request info (default: 10)
""ShowTimeoutSeconds"": 30
// The amount of time between calls to providers when using the --watch flag (default: 30)
""WatchIntervalSeconds"": 15
},
// Pull request provider configurations organized by type (currently there's only github!)
""Providers"": {
//The type of the provider you're configuring (currently there's only github!)
// A list of GitHub pull request provider configurations
""github"": [{
//required: a friendly name for this provider
""Name"": ""required: a friendly name for this provider"",
// A friendly name for this provider (required)
""Name"": ""GitHub-Work"",
""Configuration"": {
//required: your API token
// An API token with permission to read issues (required)
// You will need to configure SSO on the PAT to see pull requests from organizations that require it
""AccessToken"": """",
//optional: the github username you're interested in investigating, alternatively we'll fetch yours from the api
// The GitHub username you're interested in investigating (optional)
// If not provided we'll fetch the username associated with the AccessToken from the API
""Username"": """",
//optional: Orgs can be either be traditional (github, wareismymind) or a username for user's repos
// if left empty we'll look at all orgs available to your user
// A list of organizations or other GitHub users whose repos to include pull requests from (default: [])
// If the list is empty then we'll include all visible requests regardless of the repo owner
""Orgs"": [""myorg"", ""wareismymind"", ""someuser""],
//optional: Orgs that you'd like to exclude from the output, only really makes sense if no orgs are set
// A list of organizations or other GitHub users whose repos will be excluded when searching for pull requests (default: [])
// Use this option as an alternative to `Orgs`
""ExcludedOrgs"": [],
//optional: indicates the number of pull requests that will be listed, should be number between 1 and 100.
// if not provided will default to 20.
""Count"": 20
// The number of pull requests to include in your search results (min: 1, max: 100, default: 20)
""Count"": 30
}
}]
}
Expand Down
2 changes: 1 addition & 1 deletion Peer.Domain/Commands/Details.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public Details(

public async Task<Result<None, FindError>> DetailsAsync(DetailsArguments args, CancellationToken token = default)
{
var findResult = await _prService.FindByPartial(args.Partial, token);
var findResult = await _prService.FindSingleByPartial(args.Partial, token);
var formatted = findResult.Map(pr => _formatter.Format(pr));

if (formatted.IsError)
Expand Down
13 changes: 10 additions & 3 deletions Peer.Domain/Commands/DetailsFormatter.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Peer.Domain.Util;
using wimm.Secundatives.Extensions;


namespace Peer.Domain.Commands
{
//TODO:CN -- Ansi term code support
Expand All @@ -20,6 +20,8 @@ public DetailsFormatter(ICheckSymbolProvider symbolProvider)

public IList<string> Format(PullRequest pullRequest)
{
Validators.ArgIsNotNull(pullRequest);

var lines = new List<string>
{
"---",
Expand All @@ -32,16 +34,21 @@ public IList<string> Format(PullRequest pullRequest)
lines.Add("Url:");
lines.Add($"{_pad}{pullRequest.Url}");
lines.Add(string.Empty);
lines.Add("Checks:");

if (!pullRequest.Checks.Any())
{
return lines;
}

lines.Add("Checks:");
var titleWidth = pullRequest.Checks.Max(x => x.Name.Length);

//Checks here
foreach (var check in pullRequest.Checks)
{
var symbol = _symbolProvider.GetSymbol(check.Status, check.Result)
.UnwrapOr("\u25EF\uFE0F"); //Large white circle

lines.Add($"{_pad}{symbol,4} {check.Name.PadRight(titleWidth)} -- {check.Url}");
}

Expand Down
4 changes: 2 additions & 2 deletions Peer.Domain/Commands/IPullRequestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Peer.Domain.Commands
{
public interface IPullRequestService
{
Task<IEnumerable<PullRequest>> FetchAllPullRequests(CancellationToken token = default);
Task<Result<PullRequest, FindError>> FindByPartial(PartialIdentifier partial, CancellationToken token = default);
IAsyncEnumerable<PullRequest> FetchAllPullRequests(CancellationToken token = default);
Task<Result<PullRequest, FindError>> FindSingleByPartial(PartialIdentifier partial, CancellationToken token = default);
}
}
2 changes: 1 addition & 1 deletion Peer.Domain/Commands/Open.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public Open(IPullRequestService prService, IOSInfoProvider infoProvider)

public async Task<Result<None, OpenError>> OpenAsync(OpenArguments openOptions, CancellationToken token = default)
{
var res = await _prService.FindByPartial(openOptions.Partial, token)
var res = await _prService.FindSingleByPartial(openOptions.Partial, token)
.MapError(err => err switch
{
FindError.AmbiguousMatch => OpenError.AmbiguousPattern,
Expand Down
69 changes: 55 additions & 14 deletions Peer.Domain/Commands/Show.cs
Original file line number Diff line number Diff line change
@@ -1,49 +1,90 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using System.Threading;
using System.Threading.Tasks;
using Peer.Domain.Configuration.CommandConfigs;
using Peer.Domain.Exceptions;
using Peer.Domain.Filters;
using wimm.Secundatives;

namespace Peer.Domain.Commands
{
public class Show
{
private readonly List<IPullRequestFetcher> _fetchers;
private readonly IPullRequestService _pullRequestService;
private readonly IListFormatter _formatter;
private readonly IConsoleWriter _writer;
private readonly ISorter<PullRequest>? _sorter;
private readonly List<IFilter> _filters;

public ShowConfig Config { get; }

public Show(
IEnumerable<IPullRequestFetcher> fetchers,
IPullRequestService prService,
IListFormatter formatter,
IConsoleWriter writer,
ISorter<PullRequest>? sorter = null)
ShowConfig config,
ISorter<PullRequest>? sorter = null,
IEnumerable<IFilter>? filters = null)
{
_fetchers = fetchers.ToList();
_pullRequestService = prService;
_formatter = formatter;
_writer = writer;
Config = config;
_sorter = sorter;
_filters = filters?.ToList() ?? new();
}

public async Task<Result<None, ShowError>> ShowAsync(ShowArguments _, CancellationToken token = default)
public async Task<Result<None, ShowError>> ShowAsync(ShowArguments args, CancellationToken token = default)
{
var prs = await FetchAllSources(token);
var sorted = _sorter?.Sort(prs) ?? prs;
_writer.Display(_formatter.FormatLines(sorted).ToList(), token);
using var cts = new CancellationTokenSource();
token.Register(() => cts.Cancel());
cts.CancelAfter(Config.TimeoutSeconds);

var prs = await GetPullRequests(args, cts.Token);
if (prs.IsError)
{
_writer.Clear();
_writer.Display(new List<string>
{
prs.Error switch
{
ShowError.Timeout => "error: timeout fetching pull request info; consider increasing the 'ShowTimeoutSeconds' in your peer config",
_ => "error: failed to fetch pull request info",
},
}, token);
return prs.Error;
}

var lines = _formatter.FormatLines(prs.Value).ToList();
_writer.Display(lines, token);
return Maybe.None;
}

private async Task<IEnumerable<PullRequest>> FetchAllSources(CancellationToken token)
private async Task<Result<IList<PullRequest>, ShowError>> GetPullRequests(ShowArguments args, CancellationToken token)
{
var tasks = _fetchers.Select(async x => await x.GetPullRequestsAsync(token));
var prs = await Task.WhenAll(tasks);
var combined = prs.SelectMany(x => x);
return combined;
try
{
var prs = _pullRequestService.FetchAllPullRequests(token);
prs = _filters.Aggregate(prs, (prs, filter) => filter.Filter(prs));
return await (_sorter?.Sort(prs) ?? prs).Take(args.Count).ToListAsync(token);
}
catch (OperationCanceledException)
{
return ShowError.Timeout;
}
catch (FetchException)
{
return ShowError.Fire;
}
}
}

public enum ShowError
{
Timeout,
Fire,
}
}
5 changes: 5 additions & 0 deletions Peer.Domain/Commands/ShowArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
{
public class ShowArguments
{
public int Count { get; }
public ShowArguments(int count)
{
Count = count;
}
}
}
14 changes: 0 additions & 14 deletions Peer.Domain/Commands/WatchArguments.cs

This file was deleted.

30 changes: 25 additions & 5 deletions Peer.Domain/Commands/WatchShow.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Threading;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using wimm.Secundatives;

Expand All @@ -15,20 +17,38 @@ public WatchShow(Show show, IConsoleWriter consoleWriter)
_consoleWriter = consoleWriter;
}

public async Task<Result<None, ShowError>> WatchAsync(WatchArguments watchConfig, ShowArguments args, CancellationToken token)
public async Task<Result<None, ShowError>> WatchAsync(ShowArguments args, CancellationToken token)
{
var consecutiveFailures = 0;
_consoleWriter.Clear();

while (!token.IsCancellationRequested)
{
var res = await _show.ShowAsync(args, token);

if (res.IsError)
consecutiveFailures = res.IsError
? consecutiveFailures + 1
: 0;

if (consecutiveFailures > _show.Config.WatchMaxConsecutiveShowFailures)
{
return res;
_consoleWriter.Clear();
_consoleWriter.Display(new List<string>
{
$"error: too many consecutive errors",
}, token);

return ShowError.Fire;
}

await Task.Delay(watchConfig.IntervalSeconds, token);
try
{
await Task.Delay(_show.Config.WatchIntervalSeconds, token);
}
catch (OperationCanceledException)
{
break;
}
}

return Maybe.None;
Expand Down
Loading