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

Feature: Added support for pushing Git commits #12633

Merged
merged 29 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b61ca54
Feature: Support for pushing changes
ferrariofilippo Jun 8, 2023
0a69cc7
Tooltips
ferrariofilippo Jun 9, 2023
7812d9e
Update tooltip
ferrariofilippo Jun 9, 2023
ff2156e
Merge
ferrariofilippo Jun 14, 2023
44ef185
Handle Login
ferrariofilippo Jun 16, 2023
6042916
Merge branch 'main' into Git_Push
ferrariofilippo Jun 16, 2023
0e09857
Merge leftovers
ferrariofilippo Jun 16, 2023
58cc802
Requested Changes
ferrariofilippo Jun 17, 2023
034f86b
Requested Changes
ferrariofilippo Jun 18, 2023
ddb7b5a
Merge branch 'main' into Git_Push
yaira2 Jun 19, 2023
dc635a5
Build pipeline
yaira2 Jun 19, 2023
81e7b0c
Merge branch 'main' into Git_Push
yaira2 Jun 19, 2023
8348eaa
Fix requests
ferrariofilippo Jun 19, 2023
e3d90ff
Device Flow not working
ferrariofilippo Jun 20, 2023
0316d2e
Remove " from token
ferrariofilippo Jun 20, 2023
d1aa133
Bug Fix & Copy Button
ferrariofilippo Jun 20, 2023
cbde437
Copy Button
ferrariofilippo Jun 20, 2023
97189e4
Update Dialog
ferrariofilippo Jun 21, 2023
fe50c5d
Merge branch 'main' into Git_Push
ferrariofilippo Jun 21, 2023
900bffe
Update modal
ferrariofilippo Jun 22, 2023
1b4369b
Icons
yaira2 Jun 26, 2023
077243c
Update StatusBarControl.xaml
yaira2 Jun 26, 2023
2818605
Tweak path
yaira2 Jun 27, 2023
e8993a2
Update PathIcons.xaml
yaira2 Jun 27, 2023
02dab93
Update PathIcons.xaml
yaira2 Jun 27, 2023
e84ed91
Partial Requested Changes
ferrariofilippo Jun 27, 2023
efaba3e
Remaining Requested changes
ferrariofilippo Jun 27, 2023
90eb0be
Merge
ferrariofilippo Jun 27, 2023
09af69e
Update PathIcons.xaml
yaira2 Jun 27, 2023
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
39 changes: 39 additions & 0 deletions src/Files.App/Actions/Git/GitPushAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Files.App.Commands;
using Files.App.Contexts;

namespace Files.App.Actions
{
internal class GitPushAction : ObservableObject, IAction
{
private readonly IContentPageContext _context;

public string Label { get; } = "Push".GetLocalizedResource();
yaira2 marked this conversation as resolved.
Show resolved Hide resolved

public string Description { get; } = "GitPushDescription".GetLocalizedResource();

public RichGlyph Glyph { get; } = new("\uE74A");

public bool IsExecutable =>
_context.CanExecuteGitAction;

public GitPushAction()
{
_context = Ioc.Default.GetRequiredService<IContentPageContext>();

_context.PropertyChanged += Context_PropertyChanged;
}

public Task ExecuteAsync()
{
return GitHelpers.PushToOrigin(
_context.ShellPage?.InstanceViewModel.GitRepositoryPath,
_context.ShellPage?.InstanceViewModel.GitBranchName);
}

private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName is nameof(IContentPageContext.CanExecuteGitAction))
OnPropertyChanged(nameof(IsExecutable));
}
}
}
40 changes: 40 additions & 0 deletions src/Files.App/Actions/Git/GitSyncAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Files.App.Commands;
using Files.App.Contexts;

namespace Files.App.Actions
{
internal class GitSyncAction : ObservableObject, IAction
{
private readonly IContentPageContext _context;

public string Label { get; } = "GitSync".GetLocalizedResource();

public string Description { get; } = "GitSyncDescription".GetLocalizedResource();

public RichGlyph Glyph { get; } = new("\uEDAB");

public bool IsExecutable =>
_context.CanExecuteGitAction;

public GitSyncAction()
{
_context = Ioc.Default.GetRequiredService<IContentPageContext>();

_context.PropertyChanged += Context_PropertyChanged;
}

public Task ExecuteAsync()
{
GitHelpers.PullOrigin(_context.ShellPage?.InstanceViewModel.GitRepositoryPath);
return GitHelpers.PushToOrigin(
_context.ShellPage?.InstanceViewModel.GitRepositoryPath,
_context.ShellPage?.InstanceViewModel.GitBranchName);
}

private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName is nameof(IContentPageContext.CanExecuteGitAction))
OnPropertyChanged(nameof(IsExecutable));
}
}
}
2 changes: 2 additions & 0 deletions src/Files.App/Commands/CommandCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,7 @@ public enum CommandCodes
// Git
GitFetch,
GitPull,
GitPush,
GitSync,
}
}
4 changes: 4 additions & 0 deletions src/Files.App/Commands/Manager/CommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ public IRichCommand this[HotKey hotKey]
public IRichCommand PlayAll => commands[CommandCodes.PlayAll];
public IRichCommand GitFetch => commands[CommandCodes.GitFetch];
public IRichCommand GitPull => commands[CommandCodes.GitPull];
public IRichCommand GitPush => commands[CommandCodes.GitPush];
public IRichCommand GitSync => commands[CommandCodes.GitSync];

public CommandManager()
{
Expand Down Expand Up @@ -308,6 +310,8 @@ public CommandManager()
[CommandCodes.PlayAll] = new PlayAllAction(),
[CommandCodes.GitFetch] = new GitFetchAction(),
[CommandCodes.GitPull] = new GitPullAction(),
[CommandCodes.GitPush] = new GitPushAction(),
[CommandCodes.GitSync] = new GitSyncAction(),
};

private void UpdateHotKeys()
Expand Down
2 changes: 2 additions & 0 deletions src/Files.App/Commands/Manager/ICommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,7 @@ public interface ICommandManager : IEnumerable<IRichCommand>

IRichCommand GitFetch { get; }
IRichCommand GitPull { get; }
IRichCommand GitPush { get; }
IRichCommand GitSync { get; }
}
}
23 changes: 16 additions & 7 deletions src/Files.App/Data/Models/DirectoryPropertiesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,18 @@ public bool ShowLocals
}
}

private string _PullInfo = "0";
public string PullInfo
private string _StatusInfo = "0 / 0";
public string StatusInfo
{
get => _PullInfo;
set => SetProperty(ref _PullInfo, value);
get => _StatusInfo;
set => SetProperty(ref _StatusInfo, value);
}

private string _ExtendedStatusInfo = string.Format("CommitsNumber".GetLocalizedResource(), 0);
public string ExtendedStatusInfo
{
get => _ExtendedStatusInfo;
set => SetProperty(ref _ExtendedStatusInfo, value);
}

public ObservableCollection<string> BranchesNames => _ShowLocals
Expand All @@ -91,9 +98,11 @@ public void UpdateGitInfo(bool isGitRepository, string? repositoryPath, BranchIt
_gitRepositoryPath = repositoryPath;
ShowLocals = true;

PullInfo = branches.Any()
? branches[0].BehindBy.ToString() ?? "0"
: "0";
var behind = branches.Any() ? branches[0].BehindBy ?? 0 : 0;
var ahead = branches.Any() ? branches[0].AheadBy ?? 0 : 0;

ExtendedStatusInfo = string.Format("GitSyncStatusExtendedInfo".GetLocalizedResource(), ahead, behind);
StatusInfo = $"{ahead} / {behind}";

if (isGitRepository)
{
Expand Down
23 changes: 23 additions & 0 deletions src/Files.App/Data/Parameters/GitConfirmLoginParams.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Text.Json.Serialization;

namespace Files.App.Data.Parameters
{
internal class GitConfirmLoginParams
{
[JsonPropertyName("client_id")]
public string ClientId { get; init; }

[JsonPropertyName("device_code")]
public string DeviceCode { get; init; }

[JsonPropertyName("grant_type")]
public string GrantType { get; init; }

public GitConfirmLoginParams(string clientId = "", string deviceCode = "")
{
ClientId = clientId;
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
DeviceCode = deviceCode;
GrantType = "urn:ietf:params:oauth:grant-type:device_code";
}
}
}
19 changes: 19 additions & 0 deletions src/Files.App/Data/Parameters/GitRequireTokenParams.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Text.Json.Serialization;

namespace Files.App.Data.Parameters
{
internal class GitRequireTokenParams
{
[JsonPropertyName("client_id")]
public string ClientId { get; init; }

[JsonPropertyName("scope")]
public string Scope { get; init; }

public GitRequireTokenParams(string clientId = "", string scope = "repo")
{
ClientId = clientId;
Scope = scope;
}
}
}
34 changes: 34 additions & 0 deletions src/Files.App/Helpers/CredentialsHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Runtime.InteropServices;
using Windows.Security.Credentials;

namespace Files.App.Helpers
{
internal class CredentialsHelpers
{
public static void SavePassword(string resourceName, string username, string password)
{
var vault = new PasswordVault();
var credential = new PasswordCredential(resourceName, username, password);

vault.Add(credential);
}

public static string GetPassword(string resourceName, string username)
{
try
{
var vault = new PasswordVault();
var credential = vault.Retrieve(resourceName, username);

credential.RetrievePassword();

return credential.Password;
}
// Thrown if the resource does not exist
catch (COMException)
{
return string.Empty;
}
}
}
}
49 changes: 49 additions & 0 deletions src/Files.App/Helpers/DynamicDialogFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using Files.App.Dialogs;
using Files.App.ViewModels.Dialogs;
using Microsoft.UI.Text;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Data;
Expand Down Expand Up @@ -262,5 +263,53 @@ public static DynamicDialog GetFor_GitCheckoutConflicts(string checkoutBranchNam

return dialog;
}

public static DynamicDialog GetFor_GitLogin(string userCode)
{
var url = "https://github.com/login/device";

var redirectLink = new HyperlinkButton()
{
Content = url,
NavigateUri = new Uri(url),
HorizontalAlignment = HorizontalAlignment.Center
};
var userCodeTextBlock = new TextBlock()
{
Text = userCode,
FontWeight = FontWeights.Bold,
FontSize = 20.0d,
HorizontalAlignment = HorizontalAlignment.Center
};

return new DynamicDialog(new DynamicDialogViewModel()
{
TitleText = "ConnectGitHub".GetLocalizedResource(),
PrimaryButtonText = "Close".GetLocalizedResource(),
SubtitleText = "ConnectGitHubDescription".GetLocalizedResource(),
DisplayControl = new StackPanel()
{
MinWidth = 250d,
Children =
{
redirectLink,
userCodeTextBlock
}
},
DynamicButtons = DynamicDialogButtons.Primary,
});
}

public static DynamicDialog GetFor_GitHubConnectionError()
{
DynamicDialog dialog = new DynamicDialog(new DynamicDialogViewModel()
{
TitleText = "Error".GetLocalizedResource(),
SubtitleText = "CannotReachGitHubError".GetLocalizedResource(),
PrimaryButtonText = "Close".GetLocalizedResource(),
DynamicButtons = DynamicDialogButtons.Primary
});
return dialog;
}
}
}
Loading