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;
Context = repo;
if (useFakeSignersFile)
Args = $"-c gpg.ssh.allowedSignersFile=/dev/null show --no-show-signature --pretty=format:\"%G? %GK\" -s {sha}";
else
Args = $"show --no-show-signature --pretty=format:\"%G? %GK\" -s {sha}";
const string baseArgs = "show --no-show-signature --pretty=format:\"%G?%n%GS%n%GK\" -s";
const string fakeSignersFileArg = "-c gpg.ssh.allowedSignersFile=/dev/null";
Args = $"{(useFakeSignersFile ? fakeSignersFileArg : string.Empty)} {baseArgs} {sha}";
}
public Models.CommitSignInfo Result()
@ -20,10 +19,17 @@
return null;
var raw = rs.StdOut.Trim();
if (raw.Length > 1)
return new Models.CommitSignInfo() { VerifyResult = raw[0], Key = raw.Substring(2) };
if (raw.Length <= 1)
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 string Key { get; set; } = string.Empty;
public char VerifyResult { get; set; } = 'N';
public char VerifyResult { get; init; } = 'N';
public string Signer { get; init; } = string.Empty;
public string Key { get; init; } = string.Empty;
public IBrush Brush
{
@ -36,19 +37,19 @@ namespace SourceGit.Models
switch (VerifyResult)
{
case 'G':
return $"Good signature.\n\nKey: {Key}";
return $"Good signature.\n\nSigner: {Signer}\n\nKey: {Key}";
case 'B':
return $"Bad signature.\n\nKey: {Key}";
return $"Bad signature.\n\nSigner: {Signer}\n\nKey: {Key}";
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':
return $"Good signature but has expired.\n\nKey: {Key}";
return $"Good signature but has expired.\n\nSigner: {Signer}\n\nKey: {Key}";
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':
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':
return $"Signature cannot be checked.\n\nKey: {Key}";
return $"Signature cannot be checked.\n\nSigner: {Signer}\n\nKey: {Key}";
default:
return "No signature.";
}