enhance: show commit signer (#626)

Signed-off-by: Gadfly <gadfly@gadfly.vip>
This commit is contained in:
GadflyFang 2024-10-30 14:48:37 +08:00 committed by GitHub
parent e680f8477e
commit 4e87b25765
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 16 deletions

View file

@ -7,10 +7,9 @@
WorkingDirectory = repo; WorkingDirectory = repo;
Context = repo; Context = repo;
if (useFakeSignersFile) const string baseArgs = "show --no-show-signature --pretty=format:\"%G?%n%GS%n%GK\" -s";
Args = $"-c gpg.ssh.allowedSignersFile=/dev/null show --no-show-signature --pretty=format:\"%G? %GK\" -s {sha}"; const string fakeSignersFileArg = "-c gpg.ssh.allowedSignersFile=/dev/null";
else Args = $"{(useFakeSignersFile ? fakeSignersFileArg : string.Empty)} {baseArgs} {sha}";
Args = $"show --no-show-signature --pretty=format:\"%G? %GK\" -s {sha}";
} }
public Models.CommitSignInfo Result() public Models.CommitSignInfo Result()
@ -20,10 +19,17 @@
return null; return null;
var raw = rs.StdOut.Trim(); var raw = rs.StdOut.Trim();
if (raw.Length > 1) if (raw.Length <= 1)
return new Models.CommitSignInfo() { VerifyResult = raw[0], Key = raw.Substring(2) }; return null;
var lines = raw.Split('\n');
return new Models.CommitSignInfo()
{
VerifyResult = lines[0][0],
Signer = string.IsNullOrEmpty(lines[1]) ? "<UnKnown>" : lines[1],
Key = lines[2]
};
return null;
} }
} }
} }

View file

@ -4,8 +4,9 @@ namespace SourceGit.Models
{ {
public class CommitSignInfo public class CommitSignInfo
{ {
public string Key { get; set; } = string.Empty; public char VerifyResult { get; init; } = 'N';
public char VerifyResult { get; set; } = 'N'; public string Signer { get; init; } = string.Empty;
public string Key { get; init; } = string.Empty;
public IBrush Brush public IBrush Brush
{ {
@ -36,19 +37,19 @@ namespace SourceGit.Models
switch (VerifyResult) switch (VerifyResult)
{ {
case 'G': case 'G':
return $"Good signature.\n\nKey: {Key}"; return $"Good signature.\n\nSigner: {Signer}\n\nKey: {Key}";
case 'B': case 'B':
return $"Bad signature.\n\nKey: {Key}"; return $"Bad signature.\n\nSigner: {Signer}\n\nKey: {Key}";
case 'U': case 'U':
return $"Good signature with unknown validity.\n\nKey: {Key}"; return $"Good signature with unknown validity.\n\nSigner: {Signer}\n\nKey: {Key}";
case 'X': case 'X':
return $"Good signature but has expired.\n\nKey: {Key}"; return $"Good signature but has expired.\n\nSigner: {Signer}\n\nKey: {Key}";
case 'Y': case 'Y':
return $"Good signature made by expired key.\n\nKey: {Key}"; return $"Good signature made by expired key.\n\nSigner: {Signer}\n\nKey: {Key}";
case 'R': case 'R':
return $"Good signature made by a revoked key.\n\nKey: {Key}"; return $"Good signature made by a revoked key.\n\nSigner: {Signer}\n\nKey: {Key}";
case 'E': case 'E':
return $"Signature cannot be checked.\n\nKey: {Key}"; return $"Signature cannot be checked.\n\nSigner: {Signer}\n\nKey: {Key}";
default: default:
return "No signature."; return "No signature.";
} }