Skip to content
Closed
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
24 changes: 24 additions & 0 deletions src/Commands/SharedIssueTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,30 @@ public SharedIssueTracker(string repo)
return rs;
}

public async Task<bool> HasAnyAsync()
{
if (!File.Exists(_file))
return false;

Args = $"config -f {_file.Quoted()} -l";

var output = await ReadToEndAsync().ConfigureAwait(false);

if (output.IsSuccess)
foreach (var line in output.StdOut.Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries))
{
var parts = line.Split('=', 2);

if (parts.Length < 2)
continue;

if (parts[0].StartsWith("issuetracker.", StringComparison.Ordinal))
return true;
}

return false;
}

public async Task<bool> AddAsync(Models.IssueTrackerRule rule)
{
Args = $"config -f {_file.Quoted()} issuetracker.{rule.Name.Quoted()}.regex {rule.RegexString.Quoted()}";
Expand Down
19 changes: 17 additions & 2 deletions src/ViewModels/RepositoryConfigure.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;

using Avalonia.Collections;
Expand Down Expand Up @@ -305,10 +306,24 @@ public async Task ChangeIssueTrackerShareModeAsync()
if (_selectedIssueTrackerRule is not { } rule)
return;

var sharedTracker = new Commands.SharedIssueTracker(_repo.FullPath);

if (rule.IsShared)
await new Commands.SharedIssueTracker(_repo.FullPath).AddAsync(rule);
await sharedTracker.AddAsync(rule);
else
await new Commands.SharedIssueTracker(_repo.FullPath).RemoveAsync(rule);
{
await sharedTracker.RemoveAsync(rule);

if (await sharedTracker.HasAnyAsync())
return;

var filePath = Path.Combine(_repo.FullPath, ".issuetracker");

if (!File.Exists(filePath) || !string.IsNullOrEmpty(await File.ReadAllTextAsync(filePath)))
return;

File.Delete(filePath);
}
}

public void AddNewCustomAction()
Expand Down
Loading