-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Made GitHub New Pull Request a category. This allows the user to select the compare branch from the app. * Localization.
- Loading branch information
Showing
16 changed files
with
190 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
using Octokit; | ||
using Tql.Abstractions; | ||
using Tql.Abstractions; | ||
|
||
namespace Tql.Plugins.GitHub.Categories; | ||
|
||
|
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,38 @@ | ||
using System.Windows.Forms; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Tql.Abstractions; | ||
using Tql.Utilities; | ||
|
||
namespace Tql.Plugins.GitHub.Categories; | ||
|
||
// This class is not serializable because instances of this class | ||
// are transient by definition. The moment the user creates the pull | ||
// request, the instance in the history becomes invalid. Because of | ||
// this, there also isn't a MatchType class for this match. We do | ||
// still need the TypeId though! | ||
internal class NewPullRequestMatch(NewPullRequestDto dto) : IRunnableMatch, ICopyableMatch | ||
{ | ||
public string Text => dto.CompareBranch; | ||
public ImageSource Icon => Images.PullRequest; | ||
public MatchTypeId TypeId => TypeIds.NewPullRequest; | ||
|
||
public Task Run(IServiceProvider serviceProvider, IWin32Window owner) | ||
{ | ||
serviceProvider.GetRequiredService<IUI>().OpenUrl(dto.GetUrl()); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
public Task Copy(IServiceProvider serviceProvider) | ||
{ | ||
serviceProvider.GetRequiredService<IClipboard>().CopyUri(Text, dto.GetUrl()); | ||
|
||
return Task.CompletedTask; | ||
} | ||
} | ||
|
||
internal record NewPullRequestDto(Guid Id, string Owner, string Repository, string CompareBranch) | ||
{ | ||
public string GetUrl() => | ||
$"https://github.com/{Uri.EscapeDataString(Owner)}/{Uri.EscapeDataString(Repository)}/compare/{Uri.EscapeDataString(CompareBranch)}?expand=1"; | ||
} |
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,94 @@ | ||
using Octokit.GraphQL; | ||
using Octokit.GraphQL.Model; | ||
using Tql.Abstractions; | ||
using Tql.Plugins.GitHub.Services; | ||
using Tql.Utilities; | ||
|
||
namespace Tql.Plugins.GitHub.Categories; | ||
|
||
internal class NewPullRequestsMatch( | ||
NewMatchDto dto, | ||
GitHubApi api, | ||
IMatchFactory<NewPullRequestMatch, NewPullRequestDto> factory | ||
) : NewMatch(dto), ISearchableMatch | ||
{ | ||
public override MatchTypeId TypeId => TypeIds.NewPullRequests; | ||
public string SearchHint => Labels.NewPullRequestsMatch_SearchHint; | ||
|
||
public async Task<IEnumerable<IMatch>> Search( | ||
ISearchContext context, | ||
string text, | ||
CancellationToken cancellationToken | ||
) | ||
{ | ||
var task = context.GetDataCached($"{GetType()}|{Dto.Id}", _ => GetMatches()); | ||
|
||
if (!task.IsCompleted) | ||
await context.DebounceDelay(cancellationToken); | ||
|
||
return context.Filter(await task); | ||
} | ||
|
||
private async Task<ImmutableArray<NewPullRequestMatch>> GetMatches() | ||
{ | ||
var graphQlConnection = await api.GetConnection(Dto.Id!.Value); | ||
|
||
var query = new Query() | ||
.Repository(Dto.Repository, Dto.Owner) | ||
.Refs("refs/heads/", first: 100) | ||
.Edges.Select( | ||
refEdge => | ||
new | ||
{ | ||
Refs = refEdge | ||
.Node.Select( | ||
@ref => | ||
new | ||
{ | ||
@ref.Name, | ||
AssociatedPullRequests = @ref.AssociatedPullRequests( | ||
1, | ||
null, | ||
null, | ||
null, | ||
null, | ||
null, | ||
null, | ||
null, | ||
new[] { PullRequestState.Open } | ||
) | ||
.Edges.Select( | ||
pullRequest => | ||
new | ||
{ | ||
Id = pullRequest | ||
.Select(p4 => p4.Node.Id) | ||
.SingleOrDefault() | ||
} | ||
) | ||
.ToList() | ||
} | ||
) | ||
.SingleOrDefault() | ||
} | ||
) | ||
.Compile(); | ||
|
||
var items = await graphQlConnection.Run(query); | ||
|
||
return items | ||
.Where(p => p.Refs.AssociatedPullRequests.Count == 0) | ||
.Select( | ||
p => | ||
factory.Create( | ||
new NewPullRequestDto( | ||
Dto.Id!.Value, | ||
Dto.Owner!, | ||
Dto.Repository!, | ||
p.Refs.Name | ||
) | ||
) | ||
) | ||
.ToImmutableArray(); | ||
} | ||
} |
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,16 @@ | ||
using Tql.Abstractions; | ||
using Tql.Plugins.GitHub.Services; | ||
using Tql.Utilities; | ||
|
||
namespace Tql.Plugins.GitHub.Categories; | ||
|
||
internal class NewPullRequestsType( | ||
IMatchFactory<NewPullRequestsMatch, NewMatchDto> factory, | ||
ConfigurationManager configurationManager | ||
) : MatchType<NewPullRequestsMatch, NewMatchDto>(factory) | ||
{ | ||
public override Guid Id => TypeIds.NewPullRequests.Id; | ||
|
||
protected override bool IsValid(NewMatchDto dto) => | ||
!dto.Id.HasValue || configurationManager.Configuration.HasConnection(dto.Id.Value); | ||
} |
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
using Octokit; | ||
using Tql.Abstractions; | ||
using Tql.Abstractions; | ||
|
||
namespace Tql.Plugins.GitHub.Categories; | ||
|
||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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