From 7bf342844d4b3d462b054495ea109ad34951bbcd Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Tue, 17 Apr 2018 10:51:52 -0400 Subject: [PATCH] Repository interface --- .../Models/Internal/RepositorySettings.cs | 6 ++ src/Tgstation.Server.Api/Models/Repository.cs | 6 ++ .../Models/TestMergeParameters.cs | 5 + .../Components/IRepository.cs | 98 +++++++++++++++++++ 4 files changed, 115 insertions(+) create mode 100644 src/Tgstation.Server.Host/Components/IRepository.cs diff --git a/src/Tgstation.Server.Api/Models/Internal/RepositorySettings.cs b/src/Tgstation.Server.Api/Models/Internal/RepositorySettings.cs index 11917d2f81..35a560f7da 100644 --- a/src/Tgstation.Server.Api/Models/Internal/RepositorySettings.cs +++ b/src/Tgstation.Server.Api/Models/Internal/RepositorySettings.cs @@ -41,6 +41,12 @@ namespace Tgstation.Server.Api.Models.Internal [Permissions(WriteRight = RepositoryRights.ChangeTestMergeCommits)] public bool PushTestMergeCommits { get; set; } + /// + /// If test merge commits are signed with the username of the person who merged it. Note this only affects future commits + /// + [Permissions(WriteRight = RepositoryRights.ChangeTestMergeCommits)] + public bool ShowTestMergeCommitters { get; set; } + /// /// How often the automatically updates in minutes /// diff --git a/src/Tgstation.Server.Api/Models/Repository.cs b/src/Tgstation.Server.Api/Models/Repository.cs index 96ca42c58c..db3ed5b303 100644 --- a/src/Tgstation.Server.Api/Models/Repository.cs +++ b/src/Tgstation.Server.Api/Models/Repository.cs @@ -26,6 +26,12 @@ namespace Tgstation.Server.Api.Models [Permissions(DenyWrite = true)] public RevisionInformation RevisionInformation { get; set; } + /// + /// If the repository was cloned from GitHub.com. If this enables test merge functionality + /// + [Permissions(DenyWrite = true)] + public bool IsGitHub { get; set; } + /// /// The branch or tag HEAD points to /// diff --git a/src/Tgstation.Server.Api/Models/TestMergeParameters.cs b/src/Tgstation.Server.Api/Models/TestMergeParameters.cs index 2c3ba33f02..ed27e6bb08 100644 --- a/src/Tgstation.Server.Api/Models/TestMergeParameters.cs +++ b/src/Tgstation.Server.Api/Models/TestMergeParameters.cs @@ -17,5 +17,10 @@ namespace Tgstation.Server.Api.Models /// [Required] public string PullRequestRevision { get; set; } + + /// + /// Optional comment about the test + /// + public string Comment { get; set; } } } \ No newline at end of file diff --git a/src/Tgstation.Server.Host/Components/IRepository.cs b/src/Tgstation.Server.Host/Components/IRepository.cs new file mode 100644 index 0000000000..90dce08440 --- /dev/null +++ b/src/Tgstation.Server.Host/Components/IRepository.cs @@ -0,0 +1,98 @@ +using System.Threading; +using System.Threading.Tasks; + +namespace Tgstation.Server.Host.Components +{ + /// + /// Represents an on-disk git repository + /// + interface IRepository + { + /// + /// Check if the is in a working state + /// + /// The for the operation + /// A resulting in if the is in a working state, otherwise + Task Exists(CancellationToken cancellationToken); + + /// + /// Check if the was cloned from GitHub.com + /// + /// The for the operation + /// A resulting in if the was cloned from GitHub.com, otherwise + Task IsGitHubRepository(CancellationToken cancellationToken); + + /// + /// Get the SHA of the HEAD + /// + /// The for the operation + /// A resulting in the SHA of the HEAD + Task GetHead(CancellationToken cancellationToken); + + /// + /// Get the current reference the HEAD is using. This can be a branch or tag + /// + /// The for the operation + /// A resulting in the current reference the HEAD is using. Will be if not on a branch or tag + Task GetReference(CancellationToken cancellationToken); + + /// + /// Get the current origin remote the is using + /// + /// The for the operation + /// A resulting in the current origin remote the is using + Task GetOrigin(CancellationToken cancellationToken); + + /// + /// Deletes the and clones a using an if provided + /// + /// The new remote url + /// The access string to clone the repository + /// The for the operation + /// A representing the running operation + Task SetOrigin(string newOrigin, string accessString, CancellationToken cancellationToken); + + /// + /// Checks out a given + /// + /// The sha or reference to checkout + /// The for the operation + /// A representing the running operation + Task CheckoutObject(string committish, CancellationToken cancellationToken); + + /// + /// Attempt to merge a GitHub pull request into HEAD + /// + /// The pull request number on the remote repository + /// The commit in the pull request to merge + /// The name of the merge committer + /// The e-mail of the merge committer + /// The body of the commit message + /// The access string to fetch from the origin repository + /// The for the operation + /// A resulting in the SHA of the new HEAD on success, on merge conflict + Task AddTestMerge(int pullRequestNumber, string targetCommit, string committerName, string committerEmail, string commitBody, string accessToken, CancellationToken cancellationToken); + + /// + /// Fetch commits from the origin repository + /// + /// The access string to fetch from the origin repository + /// The for the operation + /// A representing the running operation + Task FetchOrigin(string accessString, CancellationToken cancellationToken); + + /// + /// Requires the current HEAD to be a tracked reference. Hard resets the reference to what it tracks on the origin repository + /// + /// The for the operation + /// A resulting in the SHA of the new HEAD + Task ResetToOrigin(CancellationToken cancellationToken); + + /// + /// Push the current repository HEAD to a temporary GitHub branch and then delete it + /// + /// The for the operation + /// A representing the running operation + Task PushHeadToTemporaryBranch(CancellationToken cancellationToken); + } +}