From f10f365dc5d2885d4c8ef472e63ddb64d63fd614 Mon Sep 17 00:00:00 2001 From: Anh-Duc Le Date: Wed, 25 Apr 2018 14:49:39 +0200 Subject: [PATCH 01/12] Added Serilog nuget and upgraded the NET Framework from 4.0 => 4.5 --- ConsoleTests/ConsoleTests.csproj | 6 +++++- ConsoleTests/app.config | 3 +++ SharpBucket/Authentication/IAuthenticate.cs | 19 +++++++++++++++++++ SharpBucket/SharpBucket.csproj | 18 ++++++++++++------ SharpBucket/packages.config | 6 +++--- SharpBucketTests/SharpBucketTests.csproj | 21 ++++++++++----------- SharpBucketTests/packages.config | 5 ++--- 7 files changed, 54 insertions(+), 24 deletions(-) create mode 100644 ConsoleTests/app.config diff --git a/ConsoleTests/ConsoleTests.csproj b/ConsoleTests/ConsoleTests.csproj index bc64a762..324bcb4c 100644 --- a/ConsoleTests/ConsoleTests.csproj +++ b/ConsoleTests/ConsoleTests.csproj @@ -9,8 +9,9 @@ Properties ConsoleTests ConsoleTests - v4.0 + v4.5 512 + AnyCPU @@ -21,6 +22,7 @@ DEBUG;TRACE prompt 4 + false AnyCPU @@ -30,6 +32,7 @@ TRACE prompt 4 + false @@ -46,6 +49,7 @@ + diff --git a/ConsoleTests/app.config b/ConsoleTests/app.config new file mode 100644 index 00000000..51278a45 --- /dev/null +++ b/ConsoleTests/app.config @@ -0,0 +1,3 @@ + + + diff --git a/SharpBucket/Authentication/IAuthenticate.cs b/SharpBucket/Authentication/IAuthenticate.cs index cea2f5e4..7dc5244d 100644 --- a/SharpBucket/Authentication/IAuthenticate.cs +++ b/SharpBucket/Authentication/IAuthenticate.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using RestSharp; +using Serilog; namespace SharpBucket.Authentication { @@ -13,5 +14,23 @@ public virtual T GetResponse(string url, Method method, T body, IDictionary + /// With SeriLog logging + /// + /// + /// + /// + /// + /// + /// + /// + public virtual T GetResponse(ILogger logger, string url, Method method, T body, IDictionary requestParameters) + { + var executeMethod = typeof(RequestExecutor).GetMethod("ExecuteRequestWithLogging"); + var generic = executeMethod?.MakeGenericMethod(typeof(T)); + return (T)generic?.Invoke(this, new object[] { logger,url, method, body, client, requestParameters + }); + } } } \ No newline at end of file diff --git a/SharpBucket/SharpBucket.csproj b/SharpBucket/SharpBucket.csproj index c550d455..3da67654 100644 --- a/SharpBucket/SharpBucket.csproj +++ b/SharpBucket/SharpBucket.csproj @@ -9,8 +9,9 @@ Properties SharpBucket SharpBucket - v4.0 + v4.5 512 + true @@ -20,6 +21,7 @@ DEBUG;TRACE prompt 4 + false pdbonly @@ -29,16 +31,18 @@ prompt 4 bin\Release\SharpBucket.XML + false - ..\packages\Newtonsoft.Json.7.0.1\lib\net40\Newtonsoft.Json.dll - True + ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll - ..\packages\RestSharp.105.2.3\lib\net4\RestSharp.dll - True + ..\packages\RestSharp.105.2.3\lib\net45\RestSharp.dll + + + ..\packages\Serilog.2.6.0\lib\net45\Serilog.dll @@ -154,7 +158,9 @@ - + + Designer + Designer diff --git a/SharpBucket/packages.config b/SharpBucket/packages.config index d5dbdcff..37b13519 100644 --- a/SharpBucket/packages.config +++ b/SharpBucket/packages.config @@ -1,6 +1,6 @@  - - - + + + \ No newline at end of file diff --git a/SharpBucketTests/SharpBucketTests.csproj b/SharpBucketTests/SharpBucketTests.csproj index 9febdacb..57cf1a27 100644 --- a/SharpBucketTests/SharpBucketTests.csproj +++ b/SharpBucketTests/SharpBucketTests.csproj @@ -8,7 +8,7 @@ Properties SharBucketTests SharBucketTests - v4.0 + v4.5 512 {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 10.0 @@ -20,6 +20,9 @@ 4.0 + + + true @@ -29,6 +32,7 @@ DEBUG;TRACE prompt 4 + false pdbonly @@ -37,15 +41,14 @@ TRACE prompt 4 + false - ..\packages\NUnit.3.9.0\lib\net40\nunit.framework.dll - True + ..\packages\NUnit.3.9.0\lib\net45\nunit.framework.dll ..\packages\Shouldly.2.8.3\lib\net40\Shouldly.dll - True @@ -75,13 +78,9 @@ - - {f7c8fef8-4adb-4175-a4d8-2a0598b78786} - SharpBucket - - - - + + Designer + diff --git a/SharpBucketTests/packages.config b/SharpBucketTests/packages.config index d3a98c57..8df699ab 100644 --- a/SharpBucketTests/packages.config +++ b/SharpBucketTests/packages.config @@ -1,6 +1,5 @@  - - - + + \ No newline at end of file From bbe2e209b7043221518381f86ee1d0f2b5685cae Mon Sep 17 00:00:00 2001 From: Anh-Duc Le Date: Wed, 25 Apr 2018 14:52:11 +0200 Subject: [PATCH 02/12] SharpBucket/Authentication/RequestExecutor.cs => Added ExecuteRequestWithLogging() --- SharpBucket/Authentication/RequestExecutor.cs | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/SharpBucket/Authentication/RequestExecutor.cs b/SharpBucket/Authentication/RequestExecutor.cs index 85a269ad..9cc81e90 100644 --- a/SharpBucket/Authentication/RequestExecutor.cs +++ b/SharpBucket/Authentication/RequestExecutor.cs @@ -3,6 +3,8 @@ using System.Net; using RestSharp; using RestSharp.Deserializers; +using Serilog; +using SharpBucket.V2.Pocos; namespace SharpBucket.Authentication { @@ -87,5 +89,67 @@ private static bool RequestingSimpleType() { return typeof(T) == typeof(object); } + + + /// + /// With Logging + /// + /// + /// + /// + /// + /// + /// + /// + /// + public static T ExecuteRequestWithLogging(ILogger logger, string url, Method method, T body, RestClient client, IDictionary requestParameters) + where T : new() + { + var request = new RestRequest(url, method); + if (requestParameters != null) + { + foreach (var requestParameter in requestParameters) + { + request.AddParameter(requestParameter.Key, requestParameter.Value); + } + } + + if (ShouldAddBody(method)) + { + if (body.GetType() != typeof(Branch)) + { + request.RequestFormat = DataFormat.Json; + request.AddBody(body); + } + else + { + request.AddObject(body); + request.AddHeader("Content-Type", "multipart/form-data"); + } + } + + //Fixed bug that prevents RestClient for adding custom headers to the request + //https://stackoverflow.com/questions/22229393/why-is-restsharp-addheaderaccept-application-json-to-a-list-of-item + + client.ClearHandlers(); + + client.AddHandler("application/json", new JsonDeserializer()); + + var result = ExectueRequest(method, client, request); + + if (result.ErrorException != null) + { + throw new WebException("REST client encountered an error: " + result.ErrorMessage, result.ErrorException); + } + // This is a hack in order to allow this method to work for simple types as well + // one example of this is the GetRevisionRaw method + if (RequestingSimpleType()) + { + return result.Content as dynamic; + } + + logger.Debug($"{result.StatusCode}: {result.StatusDescription}"); + return result.Data; + } } } \ No newline at end of file From 06b508cf6950cf60bdd777234b5e6f72423733ad Mon Sep 17 00:00:00 2001 From: Anh-Duc Le Date: Wed, 25 Apr 2018 14:59:50 +0200 Subject: [PATCH 03/12] Added ILogger parameter to Sharpbucket.cs methods (Send/Get/Post/Put/Delete) --- SharpBucket/SharpBucket.cs | 82 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/SharpBucket/SharpBucket.cs b/SharpBucket/SharpBucket.cs index 7b5fbab4..46c8dd5c 100644 --- a/SharpBucket/SharpBucket.cs +++ b/SharpBucket/SharpBucket.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Net; using RestSharp; +using Serilog; using SharpBucket.Authentication; using SharpBucket.Utility; @@ -119,6 +120,32 @@ private T Send(T body, Method method, string overrideUrl = null, IDictionary< return response; } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + /// + /// + private T Send(ILogger logger, T body, Method method, string overrideUrl = null, IDictionary requestParameters = null) + { + var relativeUrl = overrideUrl; + T response; + try + { + response = authenticator.GetResponse(logger, relativeUrl, method, body, requestParameters); + } + catch (WebException ex) + { + Console.WriteLine(ex.Message); + response = default(T); + } + return response; + } + internal T Get(T body, string overrideUrl, object requestParameters = null) { //Convert to dictionary to avoid refactoring the Send method. @@ -126,19 +153,74 @@ internal T Get(T body, string overrideUrl, object requestParameters = null) return Send(body, Method.GET, overrideUrl, parameterDictionary); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + /// + internal T Get(ILogger logger, T body, string overrideUrl, object requestParameters = null) + { + //Convert to dictionary to avoid refactoring the Send method. + var parameterDictionary = requestParameters.ToDictionary(); + return Send(logger, body, Method.GET, overrideUrl, parameterDictionary); + } + internal T Post(T body, string overrideUrl) { return Send(body, Method.POST, overrideUrl); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + internal T Post(ILogger logger, T body, string overrideUrl) + { + return Send(logger, body, Method.POST, overrideUrl); + } + internal T Put(T body, string overrideUrl) { return Send(body, Method.PUT, overrideUrl); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + internal T Put(ILogger logger, T body, string overrideUrl) + { + return Send(logger, body, Method.PUT, overrideUrl); + } + internal T Delete(T body, string overrideUrl) { return Send(body, Method.DELETE, overrideUrl); } + + /// + /// With Logging + /// + /// + /// + /// + /// + /// + internal T Delete(ILogger logger, T body, string overrideUrl) + { + return Send(logger, body, Method.DELETE, overrideUrl); + } } } \ No newline at end of file From c6bf2768509d9b5f14f506abb44b226704e4d8c3 Mon Sep 17 00:00:00 2001 From: Anh-Duc Le Date: Wed, 25 Apr 2018 15:05:27 +0200 Subject: [PATCH 04/12] Added Serilog Logger to EndPoint --- SharpBucket/V2/EndPoints/EndPoint.cs | 81 ++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/SharpBucket/V2/EndPoints/EndPoint.cs b/SharpBucket/V2/EndPoints/EndPoint.cs index a088c107..94a1a69a 100644 --- a/SharpBucket/V2/EndPoints/EndPoint.cs +++ b/SharpBucket/V2/EndPoints/EndPoint.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Dynamic; +using Serilog; namespace SharpBucket.V2.EndPoints { @@ -57,6 +58,46 @@ private IEnumerable> IteratePages(string overrideUrl, int p while (!String.IsNullOrEmpty(response.next)); } + /// + /// Generator that allows lazy access to paginated resources. + /// With logging. + /// + /// + /// + /// + /// + /// + /// + private IEnumerable> IteratePages(ILogger logger, string overrideUrl, int pageLen = DEFAULT_PAGE_LEN, + IDictionary requestParameters = null) + { + Debug.Assert(!String.IsNullOrEmpty(overrideUrl)); + //Debug.Assert(!overrideUrl.Contains("?")); + + if (requestParameters == null) + { + requestParameters = new Dictionary(); + } + + requestParameters["pagelen"] = pageLen; + + IteratorBasedPage response; + int page = 1; + do + { + response = _sharpBucketV2.Get(logger, new IteratorBasedPage(), + overrideUrl.Replace(SharpBucketV2.BITBUCKET_URL, ""), requestParameters); + if (response == null) + { + break; + } + + yield return response.values; + + requestParameters["page"] = ++page; + } while (!String.IsNullOrEmpty(response.next)); + } + /// /// Returns a list of paginated values. /// @@ -94,5 +135,45 @@ protected List GetPaginatedValues(string overrideUrl, int max = return values; } + + /// + /// Returns a list of paginated values with Logging. + /// + /// The type of the value. + /// + /// The override URL. + /// Set to 0 for unlimited size. + /// + /// + /// Thrown when the server fails to respond. + protected List GetPaginatedValues(ILogger logger, string overrideUrl, int max = 0, IDictionary requestParameters = null) + { + bool isMaxConstrained = max > 0; + + int pageLen = (isMaxConstrained && max < DEFAULT_PAGE_LEN) ? max : DEFAULT_PAGE_LEN; + + List values = new List(); + + foreach (var page in IteratePages(logger, overrideUrl, pageLen, requestParameters)) + { + if (page == null) + { + break; + } + + if (isMaxConstrained && + +values.Count + page.Count >= max) + { + values.AddRange(page.GetRange(0, max - values.Count)); + Debug.Assert(values.Count == max); + break; + } + + values.AddRange(page); + } + + return values; + } + } } \ No newline at end of file From f9f10657ba957267006b0add534e4671767d45ba Mon Sep 17 00:00:00 2001 From: Anh-Duc Le Date: Wed, 25 Apr 2018 15:36:21 +0200 Subject: [PATCH 05/12] Added logging to repositoriesEndPoint --- SharpBucket/SharpBucket.cs | 2 +- .../V2/EndPoints/RepositoriesEndPoint.cs | 584 ++++++++++++++++++ 2 files changed, 585 insertions(+), 1 deletion(-) diff --git a/SharpBucket/SharpBucket.cs b/SharpBucket/SharpBucket.cs index 46c8dd5c..6acc8caf 100644 --- a/SharpBucket/SharpBucket.cs +++ b/SharpBucket/SharpBucket.cs @@ -145,7 +145,7 @@ private T Send(ILogger logger, T body, Method method, string overrideUrl = nu } return response; } - + internal T Get(T body, string overrideUrl, object requestParameters = null) { //Convert to dictionary to avoid refactoring the Send method. diff --git a/SharpBucket/V2/EndPoints/RepositoriesEndPoint.cs b/SharpBucket/V2/EndPoints/RepositoriesEndPoint.cs index 681462a4..6ce02e7c 100644 --- a/SharpBucket/V2/EndPoints/RepositoriesEndPoint.cs +++ b/SharpBucket/V2/EndPoints/RepositoriesEndPoint.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Serilog; using SharpBucket.V2.Pocos; using Comment = SharpBucket.V2.Pocos.Comment; using Repository = SharpBucket.V2.Pocos.Repository; @@ -35,6 +36,22 @@ public List ListRepositories(string accountName, int max = 0) return GetPaginatedValues(overrideUrl, max); } + /// + /// With Logging. + /// List of repositories associated with an account and project. If the caller is properly authenticated and authorized, + /// this method returns a collection containing public and private repositories. + /// Otherwise, this method returns a collection of the public repositories. + /// + /// + /// The account whose repositories you wish to get. + /// The maximum number of items to return. 0 returns all items. + /// + public List ListRepositories(ILogger logger, string accountName, int max = 0) + { + var overrideUrl = _baseUrl + accountName + "/"; + return GetPaginatedValues(logger, overrideUrl, max); + } + /// /// List of all the public repositories on Bitbucket. This produces a paginated response. /// Pagination only goes forward (it's not possible to navigate to previous pages) and navigation is done by following the URL for the next page. @@ -47,6 +64,19 @@ public List ListPublicRepositories(int max = 0) return GetPaginatedValues(_baseUrl, max); } + /// + /// With Logging. + /// List of all the public repositories on Bitbucket. This produces a paginated response. + /// Pagination only goes forward (it's not possible to navigate to previous pages) and navigation is done by following the URL for the next page. + /// The returned repositories are ordered by creation date, oldest repositories first. Only public repositories are returned. + /// + /// + /// The maximum number of items to return. 0 returns all items. + /// + public List ListPublicRepositories(ILogger logger, int max = 0) + { + return GetPaginatedValues(logger, _baseUrl, max); + } #endregion #region Repository resource @@ -71,24 +101,78 @@ internal Repository GetRepository(string accountName, string repository) return _sharpBucketV2.Get(new Repository(), overrideUrl); } + /// + /// With Logging + /// + /// + /// + /// + /// + internal Repository GetRepository(ILogger logger, string accountName, string repository) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, null); + return _sharpBucketV2.Get(logger, new Repository(), overrideUrl); + } + internal Repository PutRepository(Repository repo, string accountName, string repository) { var overrideUrl = GetRepositoryUrl(accountName, repository, null); return _sharpBucketV2.Put(repo, overrideUrl); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + internal Repository PutRepository(ILogger logger, Repository repo, string accountName, string repository) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, null); + return _sharpBucketV2.Put(repo, overrideUrl); + } + internal Repository PostRepository(Repository repo, string accountName) { var overrideUrl = GetRepositoryUrl(accountName, repo.name, null); return _sharpBucketV2.Post(repo, overrideUrl); } + /// + /// With Logging + /// + /// + /// + /// + /// + internal Repository PostRepository(ILogger logger, Repository repo, string accountName) + { + var overrideUrl = GetRepositoryUrl(accountName, repo.name, null); + return _sharpBucketV2.Post(logger, repo, overrideUrl); + } + internal Repository DeleteRepository(string accountName, string repository) { var overrideUrl = GetRepositoryUrl(accountName, repository, null); return _sharpBucketV2.Delete(new Repository(), overrideUrl); } + /// + /// With Logging + /// + /// + /// + /// + /// + internal Repository DeleteRepository(ILogger logger, string accountName, string repository) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, null); + return _sharpBucketV2.Delete(logger, new Repository(), overrideUrl); + } + + private string GetRepositoryUrl(string accountName, string repository, string append) { var format = _baseUrl + "{0}/{1}/{2}"; @@ -101,12 +185,40 @@ internal List ListWatchers(string accountName, string repository, int m return GetPaginatedValues(overrideUrl, max); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + internal List ListWatchers(ILogger logger, string accountName, string repository, int max = 0) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "watchers"); + return GetPaginatedValues(logger, overrideUrl, max); + } + internal List ListForks(string accountName, string repository, int max = 0) { var overrideUrl = GetRepositoryUrl(accountName, repository, "forks"); return GetPaginatedValues(overrideUrl, max); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + internal List ListForks(ILogger logger, string accountName, string repository, int max = 0) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "forks"); + return GetPaginatedValues(logger, overrideUrl, max); + } + #endregion #region Pull Requests Resource @@ -122,24 +234,80 @@ internal List ListPullRequests(string accountName, string repositor return GetPaginatedValues(overrideUrl, max); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + internal List ListPullRequests(ILogger logger, string accountName, string repository, int max) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/"); + return GetPaginatedValues(logger, overrideUrl, max); + } + internal PullRequest PostPullRequest(string accountName, string repository, PullRequest pullRequest) { var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/"); return _sharpBucketV2.Post(pullRequest, overrideUrl); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + internal PullRequest PostPullRequest(ILogger logger, string accountName, string repository, PullRequest pullRequest) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/"); + return _sharpBucketV2.Post(logger, pullRequest, overrideUrl); + } + internal PullRequest PutPullRequest(string accountName, string repository, PullRequest pullRequest) { var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/"); return _sharpBucketV2.Put(pullRequest, overrideUrl); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + internal PullRequest PutPullRequest(ILogger logger, string accountName, string repository, PullRequest pullRequest) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/"); + return _sharpBucketV2.Put(logger, pullRequest, overrideUrl); + } + internal List GetPullRequestLog(string accountName, string repository, int max = 0) { var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/activity/"); return GetPaginatedValues(overrideUrl, max); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + internal List GetPullRequestLog(ILogger logger, string accountName, string repository, int max = 0) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/activity/"); + return GetPaginatedValues(logger, overrideUrl, max); + } + #endregion #region Pull Request Resource @@ -150,47 +318,158 @@ internal PullRequest GetPullRequest(string accountName, string repository, int p return _sharpBucketV2.Get(new PullRequest(), overrideUrl); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + internal PullRequest GetPullRequest(ILogger logger, string accountName, string repository, int pullRequestId) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/" + pullRequestId + "/"); + return _sharpBucketV2.Get(logger, new PullRequest(), overrideUrl); + } + + internal List ListPullRequestCommits(string accountName, string repository, int pullRequestId, int max = 0) { var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/" + pullRequestId + "/commits/"); return GetPaginatedValues(overrideUrl, max); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + /// + internal List ListPullRequestCommits(ILogger logger, string accountName, string repository, int pullRequestId, int max = 0) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/" + pullRequestId + "/commits/"); + return GetPaginatedValues(logger, overrideUrl, max); + } + + internal PullRequestInfo ApprovePullRequest(string accountName, string repository, int pullRequestId) { var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/" + pullRequestId + "/approve/"); return _sharpBucketV2.Post(new PullRequestInfo(), overrideUrl); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + internal PullRequestInfo ApprovePullRequest(ILogger logger, string accountName, string repository, int pullRequestId) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/" + pullRequestId + "/approve/"); + return _sharpBucketV2.Post(logger, new PullRequestInfo(), overrideUrl); + } + internal object RemovePullRequestApproval(string accountName, string repository, int pullRequestId) { var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/" + pullRequestId + "/approve/"); return _sharpBucketV2.Delete(new PullRequestInfo(), overrideUrl); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + internal object RemovePullRequestApproval(ILogger logger, string accountName, string repository, int pullRequestId) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/" + pullRequestId + "/approve/"); + return _sharpBucketV2.Delete(logger, new PullRequestInfo(), overrideUrl); + } internal object GetDiffForPullRequest(string accountName, string repository, int pullRequestId) { var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/" + pullRequestId + "/diff/"); return _sharpBucketV2.Get(new Object(), overrideUrl); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + internal object GetDiffForPullRequest(ILogger logger, string accountName, string repository, int pullRequestId) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/" + pullRequestId + "/diff/"); + return _sharpBucketV2.Get(logger, new Object(), overrideUrl); + } internal List GetPullRequestActivity(string accountName, string repository, int pullRequestId, int max = 0) { var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/" + pullRequestId + "/activity/"); return GetPaginatedValues(overrideUrl, max); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + /// + internal List GetPullRequestActivity(ILogger logger, string accountName, string repository, int pullRequestId, int max = 0) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/" + pullRequestId + "/activity/"); + return GetPaginatedValues(logger, overrideUrl, max); + } internal Merge AcceptAndMergePullRequest(string accountName, string repository, int pullRequestId) { var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/" + pullRequestId + "/merge/"); return _sharpBucketV2.Post(new Merge(), overrideUrl); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + internal Merge AcceptAndMergePullRequest(ILogger logger, string accountName, string repository, int pullRequestId) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/" + pullRequestId + "/merge/"); + return _sharpBucketV2.Post(logger, new Merge(), overrideUrl); + } internal Merge DeclinePullRequest(string accountName, string repository, int pullRequestId) { var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/" + pullRequestId + "/decline/"); return _sharpBucketV2.Get(new Merge(), overrideUrl); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + internal Merge DeclinePullRequest(ILogger logger, string accountName, string repository, int pullRequestId) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/" + pullRequestId + "/decline/"); + return _sharpBucketV2.Get(logger, new Merge(), overrideUrl); + } internal List ListPullRequestComments(string accountName, string repository, int pullRequestId, int max = 0) { @@ -198,12 +477,42 @@ internal List ListPullRequestComments(string accountName, string reposi return GetPaginatedValues(overrideUrl, max); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + /// + internal List ListPullRequestComments(ILogger logger, string accountName, string repository, int pullRequestId, int max = 0) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/" + pullRequestId + "/comments/"); + return GetPaginatedValues(logger, overrideUrl, max); + } + internal Comment GetPullRequestComment(string accountName, string repository, int pullRequestId, int commentId) { var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/" + pullRequestId + "/comments/" + commentId + "/"); return _sharpBucketV2.Get(new Comment(), overrideUrl); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + /// + internal Comment GetPullRequestComment(ILogger logger, string accountName, string repository, int pullRequestId, int commentId) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/" + pullRequestId + "/comments/" + commentId + "/"); + return _sharpBucketV2.Get(logger, new Comment(), overrideUrl); + } + #endregion #region Branch Restrictions resource @@ -214,30 +523,99 @@ internal List ListBranchRestrictions(string accountName, stri return GetPaginatedValues(overrideUrl, max); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + internal List ListBranchRestrictions(ILogger logger, string accountName, string repository, int max = 0) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "branch-restrictions/"); + return GetPaginatedValues(logger, overrideUrl, max); + } + internal BranchRestriction PostBranchRestriction(string accountName, string repository, BranchRestriction restriction) { var overrideUrl = GetRepositoryUrl(accountName, repository, "branch-restrictions/"); return _sharpBucketV2.Post(restriction, overrideUrl); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + internal BranchRestriction PostBranchRestriction(ILogger logger, string accountName, string repository, BranchRestriction restriction) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "branch-restrictions/"); + return _sharpBucketV2.Post(logger, restriction, overrideUrl); + } + internal BranchRestriction GetBranchRestriction(string accountName, string repository, int restrictionId) { var overrideUrl = GetRepositoryUrl(accountName, repository, "branch-restrictions/" + restrictionId); return _sharpBucketV2.Get(new BranchRestriction(), overrideUrl); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + internal BranchRestriction GetBranchRestriction(ILogger logger, string accountName, string repository, int restrictionId) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "branch-restrictions/" + restrictionId); + return _sharpBucketV2.Get(logger, new BranchRestriction(), overrideUrl); + } + internal BranchRestriction PutBranchRestriction(string accountName, string repository, BranchRestriction restriction) { var overrideUrl = GetRepositoryUrl(accountName, repository, "branch-restrictions/" + restriction.id); return _sharpBucketV2.Put(restriction, overrideUrl); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + internal BranchRestriction PutBranchRestriction(ILogger logger, string accountName, string repository, BranchRestriction restriction) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "branch-restrictions/" + restriction.id); + return _sharpBucketV2.Put(logger, restriction, overrideUrl); + } internal BranchRestriction DeleteBranchRestriction(string accountName, string repository, int restrictionId) { var overrideUrl = GetRepositoryUrl(accountName, repository, "branch-restrictions/" + restrictionId); return _sharpBucketV2.Delete(new BranchRestriction(), overrideUrl); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + internal BranchRestriction DeleteBranchRestriction(ILogger logger, string accountName, string repository, int restrictionId) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "branch-restrictions/" + restrictionId); + return _sharpBucketV2.Delete(logger, new BranchRestriction(), overrideUrl); + } + #endregion #region Diff resource @@ -248,12 +626,40 @@ internal object GetDiff(string accountName, string repository, object options) return _sharpBucketV2.Get(new object(), overrideUrl); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + internal object GetDiff(ILogger logger, string accountName, string repository, object options) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "diff/" + options); + return _sharpBucketV2.Get(logger, new object(), overrideUrl); + } + internal object GetPatch(string accountName, string repository, object options) { var overrideUrl = GetRepositoryUrl(accountName, repository, "patch/" + options); return _sharpBucketV2.Get(new object(), overrideUrl); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + internal object GetPatch(ILogger logger, string accountName, string repository, object options) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "patch/" + options); + return _sharpBucketV2.Get(logger, new object(), overrideUrl); + } + #endregion #region Commits Resource @@ -268,54 +674,191 @@ internal List ListCommits(string accountName, string repository, string return GetPaginatedValues(overrideUrl, max); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + /// + internal List ListCommits(ILogger logger, string accountName, string repository, string branchortag = null, int max = 0) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "commits/"); + if (!string.IsNullOrEmpty(branchortag)) + { + overrideUrl += branchortag; + } + return GetPaginatedValues(logger, overrideUrl, max); + } + internal Commit GetCommit(string accountName, string repository, string revision) { var overrideUrl = GetRepositoryUrl(accountName, repository, "commit/" + revision); return _sharpBucketV2.Get(new Commit(), overrideUrl); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + internal Commit GetCommit(ILogger logger, string accountName, string repository, string revision) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "commit/" + revision); + return _sharpBucketV2.Get(logger, new Commit(), overrideUrl); + } + internal List ListCommitComments(string accountName, string repository, string revision, int max = 0) { var overrideUrl = GetRepositoryUrl(accountName, repository, "commits/" + revision + "/comments/"); return GetPaginatedValues(overrideUrl, max); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + /// + internal List ListCommitComments(ILogger logger, string accountName, string repository, string revision, int max = 0) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "commits/" + revision + "/comments/"); + return GetPaginatedValues(logger, overrideUrl, max); + } + internal object GetCommitComment(string accountName, string repository, string revision, int commentId) { var overrideUrl = GetRepositoryUrl(accountName, repository, "commits/" + revision + "/comments/" + revision + "/" + commentId + "/"); return _sharpBucketV2.Get(new object(), overrideUrl); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + /// + internal object GetCommitComment(ILogger logger, string accountName, string repository, string revision, int commentId) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "commits/" + revision + "/comments/" + revision + "/" + commentId + "/"); + return _sharpBucketV2.Get(logger, new object(), overrideUrl); + } + internal object ApproveCommit(string accountName, string repository, string revision) { var overrideUrl = GetRepositoryUrl(accountName, repository, "commits/" + revision + "/approve/"); return _sharpBucketV2.Post(new object(), overrideUrl); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + internal object ApproveCommit(ILogger logger, string accountName, string repository, string revision) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "commits/" + revision + "/approve/"); + return _sharpBucketV2.Post(logger, new object(), overrideUrl); + } + internal object DeleteCommitApproval(string accountName, string repository, string revision) { var overrideUrl = GetRepositoryUrl(accountName, repository, "commits/" + revision + "/approve/"); return _sharpBucketV2.Delete(new object(), overrideUrl); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + internal object DeleteCommitApproval(ILogger logger, string accountName, string repository, string revision) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "commits/" + revision + "/approve/"); + return _sharpBucketV2.Delete(logger, new object(), overrideUrl); + } + internal object AddNewBuildStatus(string accountName, string repository, string revision, BuildInfo buildInfo) { var overrideUrl = GetRepositoryUrl(accountName, repository, "commit/" + revision + "/statuses/build/"); return _sharpBucketV2.Post(buildInfo, overrideUrl); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + /// + internal object AddNewBuildStatus(ILogger logger, string accountName, string repository, string revision, BuildInfo buildInfo) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "commit/" + revision + "/statuses/build/"); + return _sharpBucketV2.Post(logger, buildInfo, overrideUrl); + } + internal BuildInfo GetBuildStatusInfo(string accountName, string repository, string revision, string key) { var overrideUrl = GetRepositoryUrl(accountName, repository, "commit/" + revision + "/statuses/build/" + key); return _sharpBucketV2.Get(new BuildInfo(), overrideUrl); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + /// + internal BuildInfo GetBuildStatusInfo(ILogger logger, string accountName, string repository, string revision, string key) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "commit/" + revision + "/statuses/build/" + key); + return _sharpBucketV2.Get(logger, new BuildInfo(), overrideUrl); + } + internal object ChangeBuildStatusInfo(string accountName, string repository, string revision, string key, BuildInfo buildInfo) { var overrideUrl = GetRepositoryUrl(accountName, repository, "commit/" + revision + "/statuses/build/" + key); return _sharpBucketV2.Put(buildInfo, overrideUrl); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + /// + /// + internal object ChangeBuildStatusInfo(ILogger logger, string accountName, string repository, string revision, string key, BuildInfo buildInfo) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "commit/" + revision + "/statuses/build/" + key); + return _sharpBucketV2.Put(logger, buildInfo, overrideUrl); + } + #endregion #region Default Reviewer Resource @@ -326,6 +869,19 @@ internal object PutDefaultReviewer(string accountName, string repository, string return _sharpBucketV2.Put(new object(), overrideUrl); } + /// + /// With Logging + /// + /// + /// + /// + /// + internal object PutDefaultReviewer(ILogger logger, string accountName, string repository, string targetUsername) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "default-reviewers/" + targetUsername); + return _sharpBucketV2.Put(logger, new object(), overrideUrl); + } + #endregion #region Branch Resource @@ -341,6 +897,20 @@ internal List ListBranches(string accountName, string repository, int ma return GetPaginatedValues(overrideUrl, max); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + internal List ListBranches(ILogger logger, string accountName, string repository, int max = 0) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "refs/branches/"); + return GetPaginatedValues(logger, overrideUrl, max); + } + #endregion #region Tag Resource @@ -356,6 +926,20 @@ internal List ListTags(string accountName, string repository, int max = 0) return GetPaginatedValues(overrideUrl, max); } + /// + /// With Logging + /// + /// + /// + /// + /// + /// + internal List ListTags(ILogger logger, string accountName, string repository, int max = 0) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "refs/tags/"); + return GetPaginatedValues(logger, overrideUrl, max); + } + #endregion } } \ No newline at end of file From 7bc5fc96992aee8d282138ce9bbfb64159c2afc9 Mon Sep 17 00:00:00 2001 From: Anh-Duc Le Date: Wed, 25 Apr 2018 15:58:30 +0200 Subject: [PATCH 06/12] Logging added to repository Resource. DeleteRepository returns HttpStatusCode instead of Repository. --- .../V2/EndPoints/RepositoriesEndPoint.cs | 17 +- .../V2/EndPoints/RepositoryResource.cs | 274 +++++++++++++++++- SharpBucketTests/SharpBucketTests.csproj | 9 + SharpBucketTests/packages.config | 1 + 4 files changed, 289 insertions(+), 12 deletions(-) diff --git a/SharpBucket/V2/EndPoints/RepositoriesEndPoint.cs b/SharpBucket/V2/EndPoints/RepositoriesEndPoint.cs index 6ce02e7c..3bcb781f 100644 --- a/SharpBucket/V2/EndPoints/RepositoriesEndPoint.cs +++ b/SharpBucket/V2/EndPoints/RepositoriesEndPoint.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Net; using Serilog; using SharpBucket.V2.Pocos; using Comment = SharpBucket.V2.Pocos.Comment; @@ -153,10 +154,10 @@ internal Repository PostRepository(ILogger logger, Repository repo, string accou return _sharpBucketV2.Post(logger, repo, overrideUrl); } - internal Repository DeleteRepository(string accountName, string repository) + internal HttpStatusCode DeleteRepository(string accountName, string repository) { var overrideUrl = GetRepositoryUrl(accountName, repository, null); - return _sharpBucketV2.Delete(new Repository(), overrideUrl); + return _sharpBucketV2.Delete(new HttpStatusCode(), overrideUrl); } /// @@ -166,10 +167,10 @@ internal Repository DeleteRepository(string accountName, string repository) /// /// /// - internal Repository DeleteRepository(ILogger logger, string accountName, string repository) + internal HttpStatusCode DeleteRepository(ILogger logger, string accountName, string repository) { var overrideUrl = GetRepositoryUrl(accountName, repository, null); - return _sharpBucketV2.Delete(logger, new Repository(), overrideUrl); + return _sharpBucketV2.Delete(logger, new HttpStatusCode(), overrideUrl); } @@ -596,10 +597,10 @@ internal BranchRestriction PutBranchRestriction(ILogger logger, string accountNa var overrideUrl = GetRepositoryUrl(accountName, repository, "branch-restrictions/" + restriction.id); return _sharpBucketV2.Put(logger, restriction, overrideUrl); } - internal BranchRestriction DeleteBranchRestriction(string accountName, string repository, int restrictionId) + internal HttpStatusCode DeleteBranchRestriction(string accountName, string repository, int restrictionId) { var overrideUrl = GetRepositoryUrl(accountName, repository, "branch-restrictions/" + restrictionId); - return _sharpBucketV2.Delete(new BranchRestriction(), overrideUrl); + return _sharpBucketV2.Delete(new HttpStatusCode(), overrideUrl); } /// @@ -610,10 +611,10 @@ internal BranchRestriction DeleteBranchRestriction(string accountName, string re /// /// /// - internal BranchRestriction DeleteBranchRestriction(ILogger logger, string accountName, string repository, int restrictionId) + internal HttpStatusCode DeleteBranchRestriction(ILogger logger, string accountName, string repository, int restrictionId) { var overrideUrl = GetRepositoryUrl(accountName, repository, "branch-restrictions/" + restrictionId); - return _sharpBucketV2.Delete(logger, new BranchRestriction(), overrideUrl); + return _sharpBucketV2.Delete(logger, new HttpStatusCode(), overrideUrl); } #endregion diff --git a/SharpBucket/V2/EndPoints/RepositoryResource.cs b/SharpBucket/V2/EndPoints/RepositoryResource.cs index 3baf7979..726fd8ba 100644 --- a/SharpBucket/V2/EndPoints/RepositoryResource.cs +++ b/SharpBucket/V2/EndPoints/RepositoryResource.cs @@ -1,4 +1,6 @@ using System.Collections.Generic; +using System.Net; +using Serilog; using SharpBucket.V2.Pocos; namespace SharpBucket.V2.EndPoints @@ -34,19 +36,51 @@ public Repository GetRepository() return _repositoriesEndPoint.GetRepository(_accountName, _repository); } + /// + /// With Logging. + /// Returns a single repository. + /// + /// + public Repository GetRepository(ILogger logger) + { + return _repositoriesEndPoint.GetRepository(logger, _accountName, _repository); + } + /// /// Removes a repository. /// /// - public Repository DeleteRepository() + public HttpStatusCode DeleteRepository() { return _repositoriesEndPoint.DeleteRepository(_accountName, _repository); } + + /// + /// With Logging. + /// Removes a repository. + /// + /// + /// + public HttpStatusCode DeleteRepository(ILogger logger) + { + return _repositoriesEndPoint.DeleteRepository(logger, _accountName, _repository); + } + public Repository PostRepository(Repository repository) { return _repositoriesEndPoint.PostRepository(repository, _accountName); } + /// + /// With Logging + /// + /// + /// + /// + public Repository PostRepository(ILogger logger, Repository repository) + { + return _repositoriesEndPoint.PostRepository(logger, repository, _accountName); + } /// /// Gets the list of accounts watching a repository. @@ -57,6 +91,15 @@ public List ListWatchers() return _repositoriesEndPoint.ListWatchers(_accountName, _repository); } + /// + /// Gets the list of accounts watching a repository. + /// + /// + public List ListWatchers(ILogger logger) + { + return _repositoriesEndPoint.ListWatchers(logger, _accountName, _repository); + } + /// /// List of repository forks, This call returns a repository object for each fork. /// @@ -66,6 +109,15 @@ public List ListForks() return _repositoriesEndPoint.ListForks(_accountName, _repository); } + /// + /// List of repository forks, This call returns a repository object for each fork. + /// + /// + public List ListForks(ILogger logger) + { + return _repositoriesEndPoint.ListForks(logger, _accountName, _repository); + } + #endregion #region Pull Requests Resource @@ -94,11 +146,23 @@ public PullRequestsResource PullRequestsResource() /// List the information associated with a repository's branch restrictions. /// /// - public object ListBranchRestrictions() + public List ListBranchRestrictions() { return _repositoriesEndPoint.ListBranchRestrictions(_accountName, _repository); } + /// More info: + /// https://confluence.atlassian.com/display/BITBUCKET/branch-restrictions+Resource + /// + /// With Logging. + /// List the information associated with a repository's branch restrictions. + /// + /// + public List ListBranchRestrictions(ILogger logger) + { + return _repositoriesEndPoint.ListBranchRestrictions(logger, _accountName, _repository); + } + /// /// Creates restrictions for the specified repository. You should specify a Content-Header with this call. /// @@ -109,16 +173,40 @@ public BranchRestriction PostBranchRestriction(BranchRestriction restriction) return _repositoriesEndPoint.PostBranchRestriction(_accountName, _repository, restriction); } + /// + /// With Logging. + /// Creates restrictions for the specified repository. You should specify a Content-Header with this call. + /// + /// + /// The branch restriction. + /// + public BranchRestriction PostBranchRestriction(ILogger logger, BranchRestriction restriction) + { + return _repositoriesEndPoint.PostBranchRestriction(logger, _accountName, _repository, restriction); + } + /// /// Gets the information associated with specific restriction. /// /// The restriction's identifier. /// - public object GetBranchRestriction(int restrictionId) + public BranchRestriction GetBranchRestriction(int restrictionId) { return _repositoriesEndPoint.GetBranchRestriction(_accountName, _repository, restrictionId); } + /// + /// With Logging. + /// Gets the information associated with specific restriction. + /// + /// + /// The restriction's identifier. + /// + public BranchRestriction GetBranchRestriction(ILogger logger, int restrictionId) + { + return _repositoriesEndPoint.GetBranchRestriction(logger, _accountName, _repository, restrictionId); + } + /// /// Updates a specific branch restriction. You cannot change the kind value with this call. /// @@ -129,15 +217,37 @@ public BranchRestriction PutBranchRestriction(BranchRestriction restriction) return _repositoriesEndPoint.PutBranchRestriction(_accountName, _repository, restriction); } + /// + /// With Logging + /// Updates a specific branch restriction. You cannot change the kind value with this call. + /// + /// + /// The branch restriction. + /// + public BranchRestriction PutBranchRestriction(ILogger logger, BranchRestriction restriction) + { + return _repositoriesEndPoint.PutBranchRestriction(logger, _accountName, _repository, restriction); + } + /// /// Deletes the specified restriction. /// /// The restriction's identifier. /// - public object DeleteBranchRestriction(int restrictionId) + public HttpStatusCode DeleteBranchRestriction(int restrictionId) { return _repositoriesEndPoint.DeleteBranchRestriction(_accountName, _repository, restrictionId); } + /// + /// With Logging + /// Deletes the specified restriction. + /// + /// The restriction's identifier. + /// + public HttpStatusCode DeleteBranchRestriction(ILogger logger, int restrictionId) + { + return _repositoriesEndPoint.DeleteBranchRestriction(logger, _accountName, _repository, restrictionId); + } #endregion @@ -155,6 +265,20 @@ public object GetDiff(object options) return _repositoriesEndPoint.GetDiff(_accountName, _repository, options); } + /// More info: + /// https://confluence.atlassian.com/display/BITBUCKET/diff+Resource + /// + /// With Logging + /// Gets the diff for the current repository. + /// + /// + /// The diff options. + /// + public object GetDiff(ILogger logger, object options) + { + return _repositoriesEndPoint.GetDiff(logger, _accountName, _repository, options); + } + /// /// Gets the patch for an individual specification. /// @@ -165,6 +289,18 @@ public object GetPatch(object options) return _repositoriesEndPoint.GetPatch(_accountName, _repository, options); } + /// + /// With Logging + /// Gets the patch for an individual specification. + /// + /// + /// The patch options. + /// + public object GetPatch(ILogger logger, object options) + { + return _repositoriesEndPoint.GetPatch(logger, _accountName, _repository, options); + } + #endregion #region Commits resource @@ -182,6 +318,21 @@ public List ListCommits(string branchortag = null, int max = 0) { return _repositoriesEndPoint.ListCommits(_accountName, _repository, branchortag, max); } + /// More info: + /// https://confluence.atlassian.com/display/BITBUCKET/commits+or+commit+Resource + /// + /// Gets the commit information associated with a repository. + /// By default, this call returns all the commits across all branches, bookmarks, and tags. The newest commit is first. + /// With Logging + /// + /// + /// The branch or tag to get, for example, master or default. + /// Values greater than 0 will set a maximum number of records to return. 0 or less returns all. + /// + public List ListCommits(ILogger logger, string branchortag = null, int max = 0) + { + return _repositoriesEndPoint.ListCommits(logger, _accountName, _repository, branchortag, max); + } /// /// Gets the information associated with an individual commit. @@ -193,6 +344,18 @@ public Commit GetCommit(string revision) return _repositoriesEndPoint.GetCommit(_accountName, _repository, revision); } + /// + /// Gets the information associated with an individual commit. + /// With Logging + /// + /// + /// The commit's SHA1. + /// + public Commit GetCommit(ILogger logger, string revision) + { + return _repositoriesEndPoint.GetCommit(logger, _accountName, _repository, revision); + } + /// /// List of comments on the specified commit. /// @@ -203,6 +366,18 @@ public List ListCommitComments(string revision) return _repositoriesEndPoint.ListCommitComments(_accountName, _repository, revision); } + /// + /// List of comments on the specified commit. + /// With Logging + /// + /// + /// The commit's SHA1. + /// + public List ListCommitComments(ILogger logger, string revision) + { + return _repositoriesEndPoint.ListCommitComments(logger, _accountName, _repository, revision); + } + /// /// To get an individual commit comment, just follow the object's self link. /// @@ -214,6 +389,19 @@ public object GetCommitComment(string revision, int commentId) return _repositoriesEndPoint.GetCommitComment(_accountName, _repository, revision, commentId); } + /// + /// To get an individual commit comment, just follow the object's self link. + /// With Logging + /// + /// + /// The commit's SHA1. + /// The comment identifier. + /// + public object GetCommitComment(ILogger logger, string revision, int commentId) + { + return _repositoriesEndPoint.GetCommitComment(logger, _accountName, _repository, revision, commentId); + } + /// /// Give your approval on a commit. /// You can only approve a comment on behalf of the authenticated account. This returns the participant object for the current user. @@ -225,6 +413,19 @@ public object ApproveCommit(string revision) return _repositoriesEndPoint.ApproveCommit(_accountName, _repository, revision); } + /// + /// Give your approval on a commit. + /// You can only approve a comment on behalf of the authenticated account. This returns the participant object for the current user. + /// With Logging + /// + /// + /// The commit's SHA1. + /// + public object ApproveCommit(ILogger logger, string revision) + { + return _repositoriesEndPoint.ApproveCommit(logger, _accountName, _repository, revision); + } + /// /// Revoke your approval of a commit. You can remove approvals on behalf of the authenticated account. /// @@ -235,6 +436,18 @@ public object DeleteCommitApproval(string revision) return _repositoriesEndPoint.DeleteCommitApproval(_accountName, _repository, revision); } + /// + /// Revoke your approval of a commit. You can remove approvals on behalf of the authenticated account. + /// With Logging + /// + /// + /// The commit's SHA1. + /// + public object DeleteCommitApproval(ILogger logger, string revision) + { + return _repositoriesEndPoint.DeleteCommitApproval(logger, _accountName, _repository, revision); + } + /// /// Creates a new build status against the specified commit. If the specified key already exists, the existing status object will be overwritten. /// @@ -246,6 +459,19 @@ public object AddNewBuildStatus(string revision, BuildInfo buildInfo) return _repositoriesEndPoint.AddNewBuildStatus(_accountName, _repository, revision, buildInfo); } + /// + /// Creates a new build status against the specified commit. If the specified key already exists, the existing status object will be overwritten. + /// With Logging + /// + /// + /// The commit's SHA1 + /// The new commit status object + /// + public object AddNewBuildStatus(ILogger logger, string revision, BuildInfo buildInfo) + { + return _repositoriesEndPoint.AddNewBuildStatus(logger, _accountName, _repository, revision, buildInfo); + } + /// /// Returns the specified build status for a commit. /// @@ -257,6 +483,19 @@ public BuildInfo GetBuildStatusInfo(string revision, string key) return _repositoriesEndPoint.GetBuildStatusInfo(_accountName, _repository, revision, key); } + /// + /// Returns the specified build status for a commit. + /// With Logging + /// + /// + /// The commit's SHA1 + /// The build status' unique key + /// + public BuildInfo GetBuildStatusInfo(ILogger logger, string revision, string key) + { + return _repositoriesEndPoint.GetBuildStatusInfo(logger, _accountName, _repository, revision, key); + } + /// /// Used to update the current status of a build status object on the specific commit. /// @@ -270,6 +509,21 @@ public object ChangeBuildStatusInfo(string revision, string key, BuildInfo build return _repositoriesEndPoint.ChangeBuildStatusInfo(_accountName, _repository, revision, key, buildInfo); } + /// + /// Used to update the current status of a build status object on the specific commit. + /// With Logging + /// + /// + /// The commit's SHA1 + /// The build status' unique key + /// The new commit status object + /// + /// /// This operation can also be used to change other properties of the build status: state, name, description, url, refname. The key cannot be changed. + public object ChangeBuildStatusInfo(ILogger logger, string revision, string key, BuildInfo buildInfo) + { + return _repositoriesEndPoint.ChangeBuildStatusInfo(logger, _accountName, _repository, revision, key, buildInfo); + } + #endregion #region Default Reviewer Resource @@ -284,6 +538,18 @@ public object PutDefaultReviewer(string targetUsername) return _repositoriesEndPoint.PutDefaultReviewer(_accountName, _repository, targetUsername); } + /// + /// Adds a user as the default review for pull requests on a repository. + /// With Logging + /// + /// + /// The user to add as the default reviewer. + /// + public object PutDefaultReviewer(ILogger logger, string targetUsername) + { + return _repositoriesEndPoint.PutDefaultReviewer(logger, _accountName, _repository, targetUsername); + } + #endregion } } \ No newline at end of file diff --git a/SharpBucketTests/SharpBucketTests.csproj b/SharpBucketTests/SharpBucketTests.csproj index 57cf1a27..39fb3022 100644 --- a/SharpBucketTests/SharpBucketTests.csproj +++ b/SharpBucketTests/SharpBucketTests.csproj @@ -47,6 +47,9 @@ ..\packages\NUnit.3.9.0\lib\net45\nunit.framework.dll + + ..\packages\Serilog.2.6.0\lib\net45\Serilog.dll + ..\packages\Shouldly.2.8.3\lib\net40\Shouldly.dll @@ -82,6 +85,12 @@ Designer + + + {F7C8FEF8-4ADB-4175-A4D8-2A0598B78786} + SharpBucket + + diff --git a/SharpBucketTests/packages.config b/SharpBucketTests/packages.config index 8df699ab..4716e363 100644 --- a/SharpBucketTests/packages.config +++ b/SharpBucketTests/packages.config @@ -1,5 +1,6 @@  + \ No newline at end of file From acf27a8c6b183c35f90a366f77c0265cdb6a1c2f Mon Sep 17 00:00:00 2001 From: Anh-Duc Le Date: Wed, 25 Apr 2018 16:07:56 +0200 Subject: [PATCH 07/12] * Added PutRepository * Added PostBranch * Added ListBranch --- SharpBucket/V2/EndPoints/BranchResource.cs | 30 ++++ .../V2/EndPoints/RepositoriesEndPoint.cs | 141 +++++++++++++----- .../V2/EndPoints/RepositoryResource.cs | 24 +++ 3 files changed, 161 insertions(+), 34 deletions(-) diff --git a/SharpBucket/V2/EndPoints/BranchResource.cs b/SharpBucket/V2/EndPoints/BranchResource.cs index 53e9000f..1d4c976b 100644 --- a/SharpBucket/V2/EndPoints/BranchResource.cs +++ b/SharpBucket/V2/EndPoints/BranchResource.cs @@ -1,5 +1,6 @@ using SharpBucket.V2.Pocos; using System.Collections.Generic; +using Serilog; namespace SharpBucket.V2.EndPoints { @@ -30,5 +31,34 @@ public List ListBranches() { return _repositoriesEndPoint.ListBranches(_accountName, _repository); } + + /// + /// With Logging + /// Returns a list of branches for the specific repository + /// + /// + public List ListBranches(ILogger logger) + { + return _repositoriesEndPoint.ListBranches(logger, _accountName, _repository); + } + + /// + /// Posts a new branch for the specific repository + /// + /// + public void PostBranch(Branch branch) + { + _repositoriesEndPoint.PostBranch(_accountName, _repository, branch); + } + + /// + /// With Logging + /// + /// + /// + public void PostBranch(ILogger logger, Branch branch) + { + _repositoriesEndPoint.PostBranch(logger, _accountName, _repository, branch); + } } } \ No newline at end of file diff --git a/SharpBucket/V2/EndPoints/RepositoriesEndPoint.cs b/SharpBucket/V2/EndPoints/RepositoriesEndPoint.cs index 3bcb781f..f2a712f0 100644 --- a/SharpBucket/V2/EndPoints/RepositoriesEndPoint.cs +++ b/SharpBucket/V2/EndPoints/RepositoriesEndPoint.cs @@ -78,6 +78,36 @@ public List ListPublicRepositories(ILogger logger, int max = 0) { return GetPaginatedValues(logger, _baseUrl, max); } + + + /// + /// Post a new branch + /// + /// + /// + /// + /// + public Branch PostBranch(string accountName, string repository, Branch branch) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "src/"); + return _sharpBucketV2.Post(branch, overrideUrl); + } + + + /// + /// Post a new branch with Logging + /// + /// + /// + /// + /// + /// + public Branch PostBranch(ILogger logger, string accountName, string repository, Branch branch) + { + var overrideUrl = GetRepositoryUrl(accountName, repository, "src/"); + return _sharpBucketV2.Post(logger, branch, overrideUrl); + } + #endregion #region Repository resource @@ -263,7 +293,8 @@ internal PullRequest PostPullRequest(string accountName, string repository, Pull /// /// /// - internal PullRequest PostPullRequest(ILogger logger, string accountName, string repository, PullRequest pullRequest) + internal PullRequest PostPullRequest(ILogger logger, string accountName, string repository, + PullRequest pullRequest) { var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/"); return _sharpBucketV2.Post(logger, pullRequest, overrideUrl); @@ -283,7 +314,8 @@ internal PullRequest PutPullRequest(string accountName, string repository, PullR /// /// /// - internal PullRequest PutPullRequest(ILogger logger, string accountName, string repository, PullRequest pullRequest) + internal PullRequest PutPullRequest(ILogger logger, string accountName, string repository, + PullRequest pullRequest) { var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/"); return _sharpBucketV2.Put(logger, pullRequest, overrideUrl); @@ -334,7 +366,8 @@ internal PullRequest GetPullRequest(ILogger logger, string accountName, string r } - internal List ListPullRequestCommits(string accountName, string repository, int pullRequestId, int max = 0) + internal List ListPullRequestCommits(string accountName, string repository, int pullRequestId, + int max = 0) { var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/" + pullRequestId + "/commits/"); return GetPaginatedValues(overrideUrl, max); @@ -349,7 +382,8 @@ internal List ListPullRequestCommits(string accountName, string reposito /// /// /// - internal List ListPullRequestCommits(ILogger logger, string accountName, string repository, int pullRequestId, int max = 0) + internal List ListPullRequestCommits(ILogger logger, string accountName, string repository, + int pullRequestId, int max = 0) { var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/" + pullRequestId + "/commits/"); return GetPaginatedValues(logger, overrideUrl, max); @@ -370,7 +404,8 @@ internal PullRequestInfo ApprovePullRequest(string accountName, string repositor /// /// /// - internal PullRequestInfo ApprovePullRequest(ILogger logger, string accountName, string repository, int pullRequestId) + internal PullRequestInfo ApprovePullRequest(ILogger logger, string accountName, string repository, + int pullRequestId) { var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/" + pullRequestId + "/approve/"); return _sharpBucketV2.Post(logger, new PullRequestInfo(), overrideUrl); @@ -381,6 +416,7 @@ internal object RemovePullRequestApproval(string accountName, string repository, var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/" + pullRequestId + "/approve/"); return _sharpBucketV2.Delete(new PullRequestInfo(), overrideUrl); } + /// /// With Logging /// @@ -389,7 +425,8 @@ internal object RemovePullRequestApproval(string accountName, string repository, /// /// /// - internal object RemovePullRequestApproval(ILogger logger, string accountName, string repository, int pullRequestId) + internal object RemovePullRequestApproval(ILogger logger, string accountName, string repository, + int pullRequestId) { var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/" + pullRequestId + "/approve/"); return _sharpBucketV2.Delete(logger, new PullRequestInfo(), overrideUrl); @@ -400,6 +437,7 @@ internal object GetDiffForPullRequest(string accountName, string repository, int var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/" + pullRequestId + "/diff/"); return _sharpBucketV2.Get(new Object(), overrideUrl); } + /// /// With Logging /// @@ -414,11 +452,13 @@ internal object GetDiffForPullRequest(ILogger logger, string accountName, string return _sharpBucketV2.Get(logger, new Object(), overrideUrl); } - internal List GetPullRequestActivity(string accountName, string repository, int pullRequestId, int max = 0) + internal List GetPullRequestActivity(string accountName, string repository, int pullRequestId, + int max = 0) { var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/" + pullRequestId + "/activity/"); return GetPaginatedValues(overrideUrl, max); } + /// /// With Logging /// @@ -428,7 +468,8 @@ internal List GetPullRequestActivity(string accountName, string reposi /// /// /// - internal List GetPullRequestActivity(ILogger logger, string accountName, string repository, int pullRequestId, int max = 0) + internal List GetPullRequestActivity(ILogger logger, string accountName, string repository, + int pullRequestId, int max = 0) { var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/" + pullRequestId + "/activity/"); return GetPaginatedValues(logger, overrideUrl, max); @@ -439,6 +480,7 @@ internal Merge AcceptAndMergePullRequest(string accountName, string repository, var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/" + pullRequestId + "/merge/"); return _sharpBucketV2.Post(new Merge(), overrideUrl); } + /// /// With Logging /// @@ -447,7 +489,8 @@ internal Merge AcceptAndMergePullRequest(string accountName, string repository, /// /// /// - internal Merge AcceptAndMergePullRequest(ILogger logger, string accountName, string repository, int pullRequestId) + internal Merge AcceptAndMergePullRequest(ILogger logger, string accountName, string repository, + int pullRequestId) { var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/" + pullRequestId + "/merge/"); return _sharpBucketV2.Post(logger, new Merge(), overrideUrl); @@ -458,6 +501,7 @@ internal Merge DeclinePullRequest(string accountName, string repository, int pul var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/" + pullRequestId + "/decline/"); return _sharpBucketV2.Get(new Merge(), overrideUrl); } + /// /// With Logging /// @@ -472,7 +516,8 @@ internal Merge DeclinePullRequest(ILogger logger, string accountName, string rep return _sharpBucketV2.Get(logger, new Merge(), overrideUrl); } - internal List ListPullRequestComments(string accountName, string repository, int pullRequestId, int max = 0) + internal List ListPullRequestComments(string accountName, string repository, int pullRequestId, + int max = 0) { var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/" + pullRequestId + "/comments/"); return GetPaginatedValues(overrideUrl, max); @@ -487,7 +532,8 @@ internal List ListPullRequestComments(string accountName, string reposi /// /// /// - internal List ListPullRequestComments(ILogger logger, string accountName, string repository, int pullRequestId, int max = 0) + internal List ListPullRequestComments(ILogger logger, string accountName, string repository, + int pullRequestId, int max = 0) { var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/" + pullRequestId + "/comments/"); return GetPaginatedValues(logger, overrideUrl, max); @@ -495,7 +541,8 @@ internal List ListPullRequestComments(ILogger logger, string accountNam internal Comment GetPullRequestComment(string accountName, string repository, int pullRequestId, int commentId) { - var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/" + pullRequestId + "/comments/" + commentId + "/"); + var overrideUrl = GetRepositoryUrl(accountName, repository, + "pullrequests/" + pullRequestId + "/comments/" + commentId + "/"); return _sharpBucketV2.Get(new Comment(), overrideUrl); } @@ -508,9 +555,11 @@ internal Comment GetPullRequestComment(string accountName, string repository, in /// /// /// - internal Comment GetPullRequestComment(ILogger logger, string accountName, string repository, int pullRequestId, int commentId) + internal Comment GetPullRequestComment(ILogger logger, string accountName, string repository, int pullRequestId, + int commentId) { - var overrideUrl = GetRepositoryUrl(accountName, repository, "pullrequests/" + pullRequestId + "/comments/" + commentId + "/"); + var overrideUrl = GetRepositoryUrl(accountName, repository, + "pullrequests/" + pullRequestId + "/comments/" + commentId + "/"); return _sharpBucketV2.Get(logger, new Comment(), overrideUrl); } @@ -532,13 +581,15 @@ internal List ListBranchRestrictions(string accountName, stri /// /// /// - internal List ListBranchRestrictions(ILogger logger, string accountName, string repository, int max = 0) + internal List ListBranchRestrictions(ILogger logger, string accountName, string repository, + int max = 0) { var overrideUrl = GetRepositoryUrl(accountName, repository, "branch-restrictions/"); return GetPaginatedValues(logger, overrideUrl, max); } - internal BranchRestriction PostBranchRestriction(string accountName, string repository, BranchRestriction restriction) + internal BranchRestriction PostBranchRestriction(string accountName, string repository, + BranchRestriction restriction) { var overrideUrl = GetRepositoryUrl(accountName, repository, "branch-restrictions/"); return _sharpBucketV2.Post(restriction, overrideUrl); @@ -552,7 +603,8 @@ internal BranchRestriction PostBranchRestriction(string accountName, string repo /// /// /// - internal BranchRestriction PostBranchRestriction(ILogger logger, string accountName, string repository, BranchRestriction restriction) + internal BranchRestriction PostBranchRestriction(ILogger logger, string accountName, string repository, + BranchRestriction restriction) { var overrideUrl = GetRepositoryUrl(accountName, repository, "branch-restrictions/"); return _sharpBucketV2.Post(logger, restriction, overrideUrl); @@ -572,13 +624,15 @@ internal BranchRestriction GetBranchRestriction(string accountName, string repos /// /// /// - internal BranchRestriction GetBranchRestriction(ILogger logger, string accountName, string repository, int restrictionId) + internal BranchRestriction GetBranchRestriction(ILogger logger, string accountName, string repository, + int restrictionId) { var overrideUrl = GetRepositoryUrl(accountName, repository, "branch-restrictions/" + restrictionId); return _sharpBucketV2.Get(logger, new BranchRestriction(), overrideUrl); } - internal BranchRestriction PutBranchRestriction(string accountName, string repository, BranchRestriction restriction) + internal BranchRestriction PutBranchRestriction(string accountName, string repository, + BranchRestriction restriction) { var overrideUrl = GetRepositoryUrl(accountName, repository, "branch-restrictions/" + restriction.id); return _sharpBucketV2.Put(restriction, overrideUrl); @@ -592,11 +646,13 @@ internal BranchRestriction PutBranchRestriction(string accountName, string repos /// /// /// - internal BranchRestriction PutBranchRestriction(ILogger logger, string accountName, string repository, BranchRestriction restriction) + internal BranchRestriction PutBranchRestriction(ILogger logger, string accountName, string repository, + BranchRestriction restriction) { var overrideUrl = GetRepositoryUrl(accountName, repository, "branch-restrictions/" + restriction.id); return _sharpBucketV2.Put(logger, restriction, overrideUrl); } + internal HttpStatusCode DeleteBranchRestriction(string accountName, string repository, int restrictionId) { var overrideUrl = GetRepositoryUrl(accountName, repository, "branch-restrictions/" + restrictionId); @@ -611,7 +667,8 @@ internal HttpStatusCode DeleteBranchRestriction(string accountName, string repos /// /// /// - internal HttpStatusCode DeleteBranchRestriction(ILogger logger, string accountName, string repository, int restrictionId) + internal HttpStatusCode DeleteBranchRestriction(ILogger logger, string accountName, string repository, + int restrictionId) { var overrideUrl = GetRepositoryUrl(accountName, repository, "branch-restrictions/" + restrictionId); return _sharpBucketV2.Delete(logger, new HttpStatusCode(), overrideUrl); @@ -672,6 +729,7 @@ internal List ListCommits(string accountName, string repository, string { overrideUrl += branchortag; } + return GetPaginatedValues(overrideUrl, max); } @@ -684,13 +742,15 @@ internal List ListCommits(string accountName, string repository, string /// /// /// - internal List ListCommits(ILogger logger, string accountName, string repository, string branchortag = null, int max = 0) + internal List ListCommits(ILogger logger, string accountName, string repository, + string branchortag = null, int max = 0) { var overrideUrl = GetRepositoryUrl(accountName, repository, "commits/"); if (!string.IsNullOrEmpty(branchortag)) { overrideUrl += branchortag; } + return GetPaginatedValues(logger, overrideUrl, max); } @@ -729,7 +789,8 @@ internal List ListCommitComments(string accountName, string repository, /// /// /// - internal List ListCommitComments(ILogger logger, string accountName, string repository, string revision, int max = 0) + internal List ListCommitComments(ILogger logger, string accountName, string repository, + string revision, int max = 0) { var overrideUrl = GetRepositoryUrl(accountName, repository, "commits/" + revision + "/comments/"); return GetPaginatedValues(logger, overrideUrl, max); @@ -737,7 +798,8 @@ internal List ListCommitComments(ILogger logger, string accountName, st internal object GetCommitComment(string accountName, string repository, string revision, int commentId) { - var overrideUrl = GetRepositoryUrl(accountName, repository, "commits/" + revision + "/comments/" + revision + "/" + commentId + "/"); + var overrideUrl = GetRepositoryUrl(accountName, repository, + "commits/" + revision + "/comments/" + revision + "/" + commentId + "/"); return _sharpBucketV2.Get(new object(), overrideUrl); } @@ -750,9 +812,11 @@ internal object GetCommitComment(string accountName, string repository, string r /// /// /// - internal object GetCommitComment(ILogger logger, string accountName, string repository, string revision, int commentId) + internal object GetCommitComment(ILogger logger, string accountName, string repository, string revision, + int commentId) { - var overrideUrl = GetRepositoryUrl(accountName, repository, "commits/" + revision + "/comments/" + revision + "/" + commentId + "/"); + var overrideUrl = GetRepositoryUrl(accountName, repository, + "commits/" + revision + "/comments/" + revision + "/" + commentId + "/"); return _sharpBucketV2.Get(logger, new object(), overrideUrl); } @@ -811,7 +875,8 @@ internal object AddNewBuildStatus(string accountName, string repository, string /// /// /// - internal object AddNewBuildStatus(ILogger logger, string accountName, string repository, string revision, BuildInfo buildInfo) + internal object AddNewBuildStatus(ILogger logger, string accountName, string repository, string revision, + BuildInfo buildInfo) { var overrideUrl = GetRepositoryUrl(accountName, repository, "commit/" + revision + "/statuses/build/"); return _sharpBucketV2.Post(logger, buildInfo, overrideUrl); @@ -819,7 +884,8 @@ internal object AddNewBuildStatus(ILogger logger, string accountName, string rep internal BuildInfo GetBuildStatusInfo(string accountName, string repository, string revision, string key) { - var overrideUrl = GetRepositoryUrl(accountName, repository, "commit/" + revision + "/statuses/build/" + key); + var overrideUrl = + GetRepositoryUrl(accountName, repository, "commit/" + revision + "/statuses/build/" + key); return _sharpBucketV2.Get(new BuildInfo(), overrideUrl); } @@ -832,15 +898,19 @@ internal BuildInfo GetBuildStatusInfo(string accountName, string repository, str /// /// /// - internal BuildInfo GetBuildStatusInfo(ILogger logger, string accountName, string repository, string revision, string key) + internal BuildInfo GetBuildStatusInfo(ILogger logger, string accountName, string repository, string revision, + string key) { - var overrideUrl = GetRepositoryUrl(accountName, repository, "commit/" + revision + "/statuses/build/" + key); + var overrideUrl = + GetRepositoryUrl(accountName, repository, "commit/" + revision + "/statuses/build/" + key); return _sharpBucketV2.Get(logger, new BuildInfo(), overrideUrl); } - internal object ChangeBuildStatusInfo(string accountName, string repository, string revision, string key, BuildInfo buildInfo) + internal object ChangeBuildStatusInfo(string accountName, string repository, string revision, string key, + BuildInfo buildInfo) { - var overrideUrl = GetRepositoryUrl(accountName, repository, "commit/" + revision + "/statuses/build/" + key); + var overrideUrl = + GetRepositoryUrl(accountName, repository, "commit/" + revision + "/statuses/build/" + key); return _sharpBucketV2.Put(buildInfo, overrideUrl); } @@ -854,9 +924,11 @@ internal object ChangeBuildStatusInfo(string accountName, string repository, str /// /// /// - internal object ChangeBuildStatusInfo(ILogger logger, string accountName, string repository, string revision, string key, BuildInfo buildInfo) + internal object ChangeBuildStatusInfo(ILogger logger, string accountName, string repository, string revision, + string key, BuildInfo buildInfo) { - var overrideUrl = GetRepositoryUrl(accountName, repository, "commit/" + revision + "/statuses/build/" + key); + var overrideUrl = + GetRepositoryUrl(accountName, repository, "commit/" + revision + "/statuses/build/" + key); return _sharpBucketV2.Put(logger, buildInfo, overrideUrl); } @@ -942,5 +1014,6 @@ internal List ListTags(ILogger logger, string accountName, string repositor } #endregion + } } \ No newline at end of file diff --git a/SharpBucket/V2/EndPoints/RepositoryResource.cs b/SharpBucket/V2/EndPoints/RepositoryResource.cs index 726fd8ba..35af1c77 100644 --- a/SharpBucket/V2/EndPoints/RepositoryResource.cs +++ b/SharpBucket/V2/EndPoints/RepositoryResource.cs @@ -82,6 +82,28 @@ public Repository PostRepository(ILogger logger, Repository repository) return _repositoriesEndPoint.PostRepository(logger, repository, _accountName); } + + /// + /// Put a specific repository + /// + /// + /// + public Repository PutRepository(Repository repository) + { + return _repositoriesEndPoint.PutRepository(repository, _accountName, repository.name.ToLowerInvariant()); + } + + /// + /// Put a specific repository + /// + /// + /// + /// + public Repository PutRepository(ILogger logger, Repository repository) + { + return _repositoriesEndPoint.PutRepository(logger, repository, _accountName, repository.name.ToLowerInvariant()); + } + /// /// Gets the list of accounts watching a repository. /// @@ -551,5 +573,7 @@ public object PutDefaultReviewer(ILogger logger, string targetUsername) } #endregion + + } } \ No newline at end of file From 20c058b3d8fd055b1828e291509772a0bc3d86d4 Mon Sep 17 00:00:00 2001 From: Anh-Duc Le Date: Wed, 25 Apr 2018 16:30:15 +0200 Subject: [PATCH 08/12] TeamEndPoin : Added PostProject/ ListProjects / GetProject UserEndPoint: Added GetEmails POCOS : + Added Email/ Group/ LinkConfigurations/ Member/ Project/ ProjectPostParams + Modified Branch / Branchrestriction / Repository / User --- SharpBucket/SharpBucket.csproj | 6 + SharpBucket/V2/EndPoints/TeamsEndPoint.cs | 152 +++++++++++++++++++++ SharpBucket/V2/EndPoints/UserEndpoint.cs | 36 ++++- SharpBucket/V2/Pocos/Branch.cs | 8 ++ SharpBucket/V2/Pocos/BranchRestriction.cs | 4 +- SharpBucket/V2/Pocos/Email.cs | 17 +++ SharpBucket/V2/Pocos/Group.cs | 19 +++ SharpBucket/V2/Pocos/LinkConfigurations.cs | 15 ++ SharpBucket/V2/Pocos/Member.cs | 8 ++ SharpBucket/V2/Pocos/Project.cs | 22 +++ SharpBucket/V2/Pocos/ProjectPostParams.cs | 16 +++ SharpBucket/V2/Pocos/Repository.cs | 2 +- SharpBucket/V2/Pocos/User.cs | 2 + 13 files changed, 304 insertions(+), 3 deletions(-) create mode 100644 SharpBucket/V2/Pocos/Email.cs create mode 100644 SharpBucket/V2/Pocos/Group.cs create mode 100644 SharpBucket/V2/Pocos/LinkConfigurations.cs create mode 100644 SharpBucket/V2/Pocos/Member.cs create mode 100644 SharpBucket/V2/Pocos/Project.cs create mode 100644 SharpBucket/V2/Pocos/ProjectPostParams.cs diff --git a/SharpBucket/SharpBucket.csproj b/SharpBucket/SharpBucket.csproj index 3da67654..760ebbbf 100644 --- a/SharpBucket/SharpBucket.csproj +++ b/SharpBucket/SharpBucket.csproj @@ -85,13 +85,19 @@ + + + + + + diff --git a/SharpBucket/V2/EndPoints/TeamsEndPoint.cs b/SharpBucket/V2/EndPoints/TeamsEndPoint.cs index 5f3ec930..981cb860 100644 --- a/SharpBucket/V2/EndPoints/TeamsEndPoint.cs +++ b/SharpBucket/V2/EndPoints/TeamsEndPoint.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Dynamic; +using Serilog; using SharpBucket.V2.Pocos; namespace SharpBucket.V2.EndPoints @@ -24,6 +25,20 @@ public List GetUserTeams(int max = 0) //return _sharpBucketV2.Get>(null, "teams/", parameters); } + /// + /// With Logging + /// + /// + /// + /// + public List GetUserTeams(ILogger logger, int max = 0) + { + dynamic parameters = new ExpandoObject(); + parameters.role = "member"; + return GetPaginatedValues(logger, "teams/", max, parameters); + //return _sharpBucketV2.Get>(null, "teams/", parameters); + } + /// /// Gets the public information associated with a team. /// If the team's profile is private, the caller must be authenticated and authorized to view this information. @@ -34,6 +49,18 @@ public Team GetProfile() return _sharpBucketV2.Get(new Team(), _baseUrl); } + /// + /// Gets the public information associated with a team. + /// If the team's profile is private, the caller must be authenticated and authorized to view this information. + /// With Logging + /// + /// + /// + public Team GetProfile(ILogger logger) + { + return _sharpBucketV2.Get(logger, new Team(), _baseUrl); + } + /// /// Gets the team's members. /// @@ -45,6 +72,19 @@ public List ListMembers(int max = 0) return GetPaginatedValues(overrideUrl, max); } + /// + /// Gets the team's members. + /// With Logging + /// + /// + /// The maximum number of items to return. 0 returns all items. + /// + public List ListMembers(ILogger logger, int max = 0) + { + var overrideUrl = _baseUrl + "members/"; + return GetPaginatedValues(logger, overrideUrl, max); + } + /// /// Gets the list of accounts following the team. /// @@ -56,6 +96,19 @@ public List ListFollowers(int max = 0) return GetPaginatedValues(overrideUrl, max); } + /// + /// Gets the list of accounts following the team. + /// With Logging + /// + /// + /// The maximum number of items to return. 0 returns all items. + /// + public List ListFollowers(ILogger logger, int max = 0) + { + var overrideUrl = _baseUrl + "followers/"; + return GetPaginatedValues(logger, overrideUrl, max); + } + /// /// Gets a list of accounts the team is following. /// @@ -67,6 +120,19 @@ public List ListFollowing(int max = 0) return GetPaginatedValues(overrideUrl, max); } + /// + /// Gets a list of accounts the team is following. + /// With Logging + /// + /// + /// The maximum number of items to return. 0 returns all items. + /// + public List ListFollowing(ILogger logger, int max = 0) + { + var overrideUrl = _baseUrl + "following/"; + return GetPaginatedValues(logger, overrideUrl, max); + } + /// /// Gets the list of the team's repositories. /// Private repositories only appear on this list if the caller is authenticated and is authorized to view the repository. @@ -78,5 +144,91 @@ public List ListRepositories(int max = 0) var overrideUrl = _baseUrl + "repositories/"; return GetPaginatedValues(overrideUrl, max); } + + /// + /// Gets the list of the team's repositories. + /// Private repositories only appear on this list if the caller is authenticated and is authorized to view the repository. + /// With Logging + /// + /// + /// The maximum number of items to return. 0 returns all items. + /// + public List ListRepositories(ILogger logger, int max = 0) + { + var overrideUrl = _baseUrl + "repositories/"; + return GetPaginatedValues(logger, overrideUrl, max); + } + + /// + /// Get's the list of the team's projects. + /// A paginated list of projects that belong to the specified team. + /// + /// + /// + public List ListProjects(int max = 0) + { + var overrideUrl = _baseUrl + "projects/"; + return GetPaginatedValues(overrideUrl, max); + } + + /// + /// With Logging + /// Get's the list of the team's projects. + /// A paginated list of projects that belong to the specified team. + /// + /// + /// + /// + public List ListProjects(ILogger logger, int max = 0) + { + var overrideUrl = _baseUrl + "projects/"; + return GetPaginatedValues(logger, overrideUrl, max); + } + /// + /// ProjectPostParams contains solely the required parameters for posting a project + /// + /// + /// + public ProjectPostParams PostProject(ProjectPostParams project) + { + var overrideUrl = _baseUrl + "projects/"; + return _sharpBucketV2.Post(project, overrideUrl); + } + + /// + /// With Logging + /// ProjectPostParams contains solely the required parameters for posting a project + /// + /// + /// + /// + public ProjectPostParams PostProject(ILogger logger, ProjectPostParams project) + { + var overrideUrl = _baseUrl + "projects/"; + return _sharpBucketV2.Post(logger, project, overrideUrl); + } + /// + /// Get a project by using + /// + /// + /// + public Project GetProject(string projectKey) + { + var overrideUrl = _baseUrl + "projects/" + projectKey; + return _sharpBucketV2.Get(new Project(), overrideUrl); + } + + /// + /// With Logging + /// Get a project by using project key + /// + /// + /// + /// + public Project GetProject(ILogger logger, string projectKey) + { + var overrideUrl = _baseUrl + "projects/" + projectKey; + return _sharpBucketV2.Get(logger, new Project(), overrideUrl); + } } } \ No newline at end of file diff --git a/SharpBucket/V2/EndPoints/UserEndpoint.cs b/SharpBucket/V2/EndPoints/UserEndpoint.cs index 7b1ba8fe..8b7bcae4 100644 --- a/SharpBucket/V2/EndPoints/UserEndpoint.cs +++ b/SharpBucket/V2/EndPoints/UserEndpoint.cs @@ -1,4 +1,6 @@ -using SharpBucket.V2.Pocos; +using System.Collections.Generic; +using Serilog; +using SharpBucket.V2.Pocos; namespace SharpBucket.V2.EndPoints { @@ -13,5 +15,37 @@ public User GetUser() { return _sharpBucketV2.Get(null, _baseUrl); } + + /// + /// Get With Logging + /// + /// + /// + public User GetUser(ILogger logger) + { + return _sharpBucketV2.Get(logger, null, _baseUrl); + } + + /// + /// Returns all the authenticated user's email addresses. Both confirmed and unconfirmed. + /// + /// + public List GetEmails(int max = 0) + { + var overrideUrl = _baseUrl + "emails/"; + return GetPaginatedValues(overrideUrl, max); + } + + /// + /// With Logging + /// + /// + /// + /// + public object GetEmails(ILogger logger, int max = 0) + { + var overrideUrl = _baseUrl + "emails/"; + return GetPaginatedValues(logger, overrideUrl, max); + } } } \ No newline at end of file diff --git a/SharpBucket/V2/Pocos/Branch.cs b/SharpBucket/V2/Pocos/Branch.cs index 5f07e6dc..8dfff0df 100644 --- a/SharpBucket/V2/Pocos/Branch.cs +++ b/SharpBucket/V2/Pocos/Branch.cs @@ -3,5 +3,13 @@ public class Branch { public string name { get; set; } + public string message { get; set; } + public string author { get; set; } + public string parents { get; set; } + public string files { get; set; } + public string branch { get; set; } + public string type { get; set; } + public string path { get; set; } + public Links links { get; set; } } } \ No newline at end of file diff --git a/SharpBucket/V2/Pocos/BranchRestriction.cs b/SharpBucket/V2/Pocos/BranchRestriction.cs index f3ad0084..34c3d8c1 100644 --- a/SharpBucket/V2/Pocos/BranchRestriction.cs +++ b/SharpBucket/V2/Pocos/BranchRestriction.cs @@ -4,11 +4,13 @@ namespace SharpBucket.V2.Pocos { public class BranchRestriction { - public List groups { get; set; } + public List groups { get; set; } public int? id { get; set; } public string kind { get; set; } public List links { get; set; } public string pattern { get; set; } public List users { get; set; } + public int? value { get; set; } + public string type { get; set; } } } \ No newline at end of file diff --git a/SharpBucket/V2/Pocos/Email.cs b/SharpBucket/V2/Pocos/Email.cs new file mode 100644 index 00000000..80907299 --- /dev/null +++ b/SharpBucket/V2/Pocos/Email.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SharpBucket.V2.Pocos +{ + public class Email + { + public bool is_primary { get; set; } + public bool is_confirmed { get; set; } + public string type { get; set; } + public string email { get; set; } + public Links links { get; set; } + } +} diff --git a/SharpBucket/V2/Pocos/Group.cs b/SharpBucket/V2/Pocos/Group.cs new file mode 100644 index 00000000..2d00e66e --- /dev/null +++ b/SharpBucket/V2/Pocos/Group.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SharpBucket.V2.Pocos +{ + public class Group + { + public string name { get; set; } + public Links links { get; set; } + public string account_privilege { get; set; } + public string full_slug { get; set; } + public Owner owner { get; set; } + public string type { get; set; } + public string slug { get; set; } + } +} diff --git a/SharpBucket/V2/Pocos/LinkConfigurations.cs b/SharpBucket/V2/Pocos/LinkConfigurations.cs new file mode 100644 index 00000000..6484a238 --- /dev/null +++ b/SharpBucket/V2/Pocos/LinkConfigurations.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SharpBucket.V2.Pocos +{ + public class LinkConfigurations : Link + { + public string handler { get; set; } + public string link_url { get; set; } + public string link_key { get; set; } + } +} diff --git a/SharpBucket/V2/Pocos/Member.cs b/SharpBucket/V2/Pocos/Member.cs new file mode 100644 index 00000000..943b5477 --- /dev/null +++ b/SharpBucket/V2/Pocos/Member.cs @@ -0,0 +1,8 @@ +namespace SharpBucket.V2.Pocos +{ + + public class Member : User + { + + } +} diff --git a/SharpBucket/V2/Pocos/Project.cs b/SharpBucket/V2/Pocos/Project.cs new file mode 100644 index 00000000..3e69c1cc --- /dev/null +++ b/SharpBucket/V2/Pocos/Project.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SharpBucket.V2.Pocos +{ + public class Project + { + public string uuid { get; set; } + public Links links { get; set; } + public string description { get; set; } + public DateTime? created_on { get; set; } + public string key { get; set; } + public Owner owner { get; set; } + public DateTime? updated_on { get; set; } + public string type { get; set; } + public bool? is_private { get; set; } + public string name { get; set; } + } +} diff --git a/SharpBucket/V2/Pocos/ProjectPostParams.cs b/SharpBucket/V2/Pocos/ProjectPostParams.cs new file mode 100644 index 00000000..03a188ba --- /dev/null +++ b/SharpBucket/V2/Pocos/ProjectPostParams.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SharpBucket.V2.Pocos +{ + public class ProjectPostParams + { + public string description { get; set; } + public string key { get; set; } + public bool? is_private { get; set; } + public string name { get; set; } + } +} diff --git a/SharpBucket/V2/Pocos/Repository.cs b/SharpBucket/V2/Pocos/Repository.cs index 7db6d339..be915a37 100644 --- a/SharpBucket/V2/Pocos/Repository.cs +++ b/SharpBucket/V2/Pocos/Repository.cs @@ -11,7 +11,7 @@ public class Repository public string created_on { get; set; } public string full_name { get; set; } public bool? has_issues { get; set; } - public string owner { get; set; } + public Owner owner { get; set; } public string updated_on { get; set; } public ulong? size { get; set; } public bool? is_private { get; set; } diff --git a/SharpBucket/V2/Pocos/User.cs b/SharpBucket/V2/Pocos/User.cs index 8c39bc5a..66952110 100644 --- a/SharpBucket/V2/Pocos/User.cs +++ b/SharpBucket/V2/Pocos/User.cs @@ -9,5 +9,7 @@ public class User public Links links { get; set; } public string created_on { get; set; } public string location { get; set; } + public string type { get; set; } + public string uuid { get; set; } } } \ No newline at end of file From dfcb474c4608df402328f0839a6d86f0c44c9039 Mon Sep 17 00:00:00 2001 From: Anh-Duc Le Date: Wed, 25 Apr 2018 17:18:12 +0200 Subject: [PATCH 09/12] endpoint and sharpbucket v2 interfaces --- SharpBucket/ISharpBucket.cs | 66 ++++++++++++++++++++ SharpBucket/SharpBucket.cs | 2 +- SharpBucket/SharpBucket.csproj | 2 + SharpBucket/V2/EndPoints/EndPoint.cs | 8 +++ SharpBucket/V2/ISharpBucketV2.cs | 91 ++++++++++++++++++++++++++++ SharpBucket/V2/SharpBucketV2.cs | 2 +- 6 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 SharpBucket/ISharpBucket.cs create mode 100644 SharpBucket/V2/ISharpBucketV2.cs diff --git a/SharpBucket/ISharpBucket.cs b/SharpBucket/ISharpBucket.cs new file mode 100644 index 00000000..8a7dae1b --- /dev/null +++ b/SharpBucket/ISharpBucket.cs @@ -0,0 +1,66 @@ +using Serilog; +using SharpBucket.Authentication; + +namespace SharpBucket +{ + public interface ISharpBucket + { + /// + /// Use basic authentication with the BitBucket API. OAuth authentication is preferred over + /// basic authentication, due to security reasons. + /// + /// Your BitBucket user name. + /// Your BitBucket password. + void BasicAuthentication(string username, string password); + + /// + /// Use 2 legged OAuth 1.0a authentication. This is similar to basic authentication, since + /// it requires the same number of steps. It is still safer to use than basic authentication, + /// since you can revoke the API keys. + /// More info: + /// https://confluence.atlassian.com/display/BITBUCKET/OAuth+on+Bitbucket + /// + /// Your consumer API key obtained from the BitBucket web page. + /// Your consumer secret API key also obtained from the BitBucket web page. + void OAuth2LeggedAuthentication(string consumerKey, string consumerSecretKey); + + /// + /// Use 3 legged OAuth 1.0a authentication. This is the most secure one, but for simple uses it might + /// be a bit too complex. + /// More info: + /// https://confluence.atlassian.com/display/BITBUCKET/OAuth+on+Bitbucket + /// + /// Your consumer API key obtained from the BitBucket web page. + /// Your consumer secret API key also obtained from the BitBucket web page. + /// Callback URL to which BitBucket will send the pin. + /// + OAuthentication3Legged OAuth3LeggedAuthentication( + string consumerKey, + string consumerSecretKey, + string callback = "oob"); + + /// + /// Use 3 legged OAuth 1.0a authentication. Use this method if you have already obtained the OAuthToken + /// and OAuthSecretToken. This method can be used so you do not have to go trough the whole 3 legged + /// process every time. You can save the tokens you receive the first time and reuse them in another session. + /// + /// Your consumer API key obtained from the BitBucket web page. + /// Your consumer secret API key also obtained from the BitBucket web page. + /// Your OAuth token that was obtained on a previous session. + /// Your OAuth secret token thata was obtained on a previous session. + /// + OAuthentication3Legged OAuth3LeggedAuthentication( + string consumerKey, + string consumerSecretKey, + string oauthToken, + string oauthTokenSecret); + + /// + /// Use Oauth2 authentication. This is the neweset version and is prefered. + /// + /// + /// + /// + OAuthentication2 OAuthentication2(string consumerKey, string consumerSecretKey); + } +} \ No newline at end of file diff --git a/SharpBucket/SharpBucket.cs b/SharpBucket/SharpBucket.cs index 6acc8caf..e3b075ce 100644 --- a/SharpBucket/SharpBucket.cs +++ b/SharpBucket/SharpBucket.cs @@ -13,7 +13,7 @@ namespace SharpBucket /// More info: /// https://confluence.atlassian.com/display/BITBUCKET/Use+the+Bitbucket+REST+APIs /// - public class SharpBucket + public class SharpBucket : ISharpBucket { private Authenticate authenticator; diff --git a/SharpBucket/SharpBucket.csproj b/SharpBucket/SharpBucket.csproj index 760ebbbf..314eeb23 100644 --- a/SharpBucket/SharpBucket.csproj +++ b/SharpBucket/SharpBucket.csproj @@ -55,6 +55,7 @@ + @@ -79,6 +80,7 @@ + diff --git a/SharpBucket/V2/EndPoints/EndPoint.cs b/SharpBucket/V2/EndPoints/EndPoint.cs index 94a1a69a..965709b7 100644 --- a/SharpBucket/V2/EndPoints/EndPoint.cs +++ b/SharpBucket/V2/EndPoints/EndPoint.cs @@ -21,6 +21,14 @@ public EndPoint(SharpBucketV2 sharpBucketV2, string resourcePath) _baseUrl = resourcePath; } + + public EndPoint(ISharpBucketV2 sharpBucketV2, string resourcePath) + { + _sharpBucketV2 = (SharpBucketV2) sharpBucketV2; + _baseUrl = resourcePath; + } + + /// /// Generator that allows lazy access to paginated resources. /// diff --git a/SharpBucket/V2/ISharpBucketV2.cs b/SharpBucket/V2/ISharpBucketV2.cs new file mode 100644 index 00000000..47430710 --- /dev/null +++ b/SharpBucket/V2/ISharpBucketV2.cs @@ -0,0 +1,91 @@ +using System.Collections.Generic; +using Serilog; +using SharpBucket.Authentication; +using SharpBucket.V2.EndPoints; +using SharpBucket.V2.Pocos; + +namespace SharpBucket.V2 +{ + public interface ISharpBucketV2 : ISharpBucket + { + /// + /// Get the Teams End Point for a specific team. + /// + /// The team whose team End Point you wish to get. + /// + TeamsEndPoint TeamsEndPoint(string teamName); + + /// + /// Get the Repositories End point. + /// + /// + RepositoriesEndPoint RepositoriesEndPoint(); + + /// + /// Get the UsersEndPoint End Point. + /// + /// The account for which you wish to get the UsersEndPoint End Point. + /// + UsersEndpoint UsersEndPoint(string accountName); + + UserEndpoint UserEndPoint(); + + /// + /// Use basic authentication with the BitBucket API. OAuth authentication is preferred over + /// basic authentication, due to security reasons. + /// + /// Your BitBucket user name. + /// Your BitBucket password. + void BasicAuthentication(string username, string password); + + /// + /// Use 2 legged OAuth 1.0a authentication. This is similar to basic authentication, since + /// it requires the same number of steps. It is still safer to use than basic authentication, + /// since you can revoke the API keys. + /// More info: + /// https://confluence.atlassian.com/display/BITBUCKET/OAuth+on+Bitbucket + /// + /// Your consumer API key obtained from the BitBucket web page. + /// Your consumer secret API key also obtained from the BitBucket web page. + void OAuth2LeggedAuthentication(string consumerKey, string consumerSecretKey); + + /// + /// Use 3 legged OAuth 1.0a authentication. This is the most secure one, but for simple uses it might + /// be a bit too complex. + /// More info: + /// https://confluence.atlassian.com/display/BITBUCKET/OAuth+on+Bitbucket + /// + /// Your consumer API key obtained from the BitBucket web page. + /// Your consumer secret API key also obtained from the BitBucket web page. + /// Callback URL to which BitBucket will send the pin. + /// + OAuthentication3Legged OAuth3LeggedAuthentication( + string consumerKey, + string consumerSecretKey, + string callback = "oob"); + + /// + /// Use 3 legged OAuth 1.0a authentication. Use this method if you have already obtained the OAuthToken + /// and OAuthSecretToken. This method can be used so you do not have to go trough the whole 3 legged + /// process every time. You can save the tokens you receive the first time and reuse them in another session. + /// + /// Your consumer API key obtained from the BitBucket web page. + /// Your consumer secret API key also obtained from the BitBucket web page. + /// Your OAuth token that was obtained on a previous session. + /// Your OAuth secret token thata was obtained on a previous session. + /// + OAuthentication3Legged OAuth3LeggedAuthentication( + string consumerKey, + string consumerSecretKey, + string oauthToken, + string oauthTokenSecret); + + /// + /// Use Oauth2 authentication. This is the neweset version and is prefered. + /// + /// + /// + /// + OAuthentication2 OAuthentication2(string consumerKey, string consumerSecretKey); + } +} \ No newline at end of file diff --git a/SharpBucket/V2/SharpBucketV2.cs b/SharpBucket/V2/SharpBucketV2.cs index eba6b0fb..5c1d4c9a 100644 --- a/SharpBucket/V2/SharpBucketV2.cs +++ b/SharpBucket/V2/SharpBucketV2.cs @@ -7,7 +7,7 @@ namespace SharpBucket.V2 /// You can read more about the V2 of the API here: /// https://confluence.atlassian.com/display/BITBUCKET/Version+2 /// - public sealed class SharpBucketV2 : SharpBucket + public sealed class SharpBucketV2 : SharpBucket, ISharpBucketV2 { internal const string BITBUCKET_URL = "https://api.bitbucket.org/2.0"; From 64d8c435729697d61d99f43ba6157e4cd6cce3a9 Mon Sep 17 00:00:00 2001 From: Anh-Duc Le Date: Thu, 26 Apr 2018 09:48:52 +0200 Subject: [PATCH 10/12] Revert "endpoint and sharpbucket v2 interfaces" This reverts commit dfcb474c4608df402328f0839a6d86f0c44c9039. --- SharpBucket/ISharpBucket.cs | 66 -------------------- SharpBucket/SharpBucket.cs | 2 +- SharpBucket/SharpBucket.csproj | 2 - SharpBucket/V2/EndPoints/EndPoint.cs | 8 --- SharpBucket/V2/ISharpBucketV2.cs | 91 ---------------------------- SharpBucket/V2/SharpBucketV2.cs | 2 +- 6 files changed, 2 insertions(+), 169 deletions(-) delete mode 100644 SharpBucket/ISharpBucket.cs delete mode 100644 SharpBucket/V2/ISharpBucketV2.cs diff --git a/SharpBucket/ISharpBucket.cs b/SharpBucket/ISharpBucket.cs deleted file mode 100644 index 8a7dae1b..00000000 --- a/SharpBucket/ISharpBucket.cs +++ /dev/null @@ -1,66 +0,0 @@ -using Serilog; -using SharpBucket.Authentication; - -namespace SharpBucket -{ - public interface ISharpBucket - { - /// - /// Use basic authentication with the BitBucket API. OAuth authentication is preferred over - /// basic authentication, due to security reasons. - /// - /// Your BitBucket user name. - /// Your BitBucket password. - void BasicAuthentication(string username, string password); - - /// - /// Use 2 legged OAuth 1.0a authentication. This is similar to basic authentication, since - /// it requires the same number of steps. It is still safer to use than basic authentication, - /// since you can revoke the API keys. - /// More info: - /// https://confluence.atlassian.com/display/BITBUCKET/OAuth+on+Bitbucket - /// - /// Your consumer API key obtained from the BitBucket web page. - /// Your consumer secret API key also obtained from the BitBucket web page. - void OAuth2LeggedAuthentication(string consumerKey, string consumerSecretKey); - - /// - /// Use 3 legged OAuth 1.0a authentication. This is the most secure one, but for simple uses it might - /// be a bit too complex. - /// More info: - /// https://confluence.atlassian.com/display/BITBUCKET/OAuth+on+Bitbucket - /// - /// Your consumer API key obtained from the BitBucket web page. - /// Your consumer secret API key also obtained from the BitBucket web page. - /// Callback URL to which BitBucket will send the pin. - /// - OAuthentication3Legged OAuth3LeggedAuthentication( - string consumerKey, - string consumerSecretKey, - string callback = "oob"); - - /// - /// Use 3 legged OAuth 1.0a authentication. Use this method if you have already obtained the OAuthToken - /// and OAuthSecretToken. This method can be used so you do not have to go trough the whole 3 legged - /// process every time. You can save the tokens you receive the first time and reuse them in another session. - /// - /// Your consumer API key obtained from the BitBucket web page. - /// Your consumer secret API key also obtained from the BitBucket web page. - /// Your OAuth token that was obtained on a previous session. - /// Your OAuth secret token thata was obtained on a previous session. - /// - OAuthentication3Legged OAuth3LeggedAuthentication( - string consumerKey, - string consumerSecretKey, - string oauthToken, - string oauthTokenSecret); - - /// - /// Use Oauth2 authentication. This is the neweset version and is prefered. - /// - /// - /// - /// - OAuthentication2 OAuthentication2(string consumerKey, string consumerSecretKey); - } -} \ No newline at end of file diff --git a/SharpBucket/SharpBucket.cs b/SharpBucket/SharpBucket.cs index e3b075ce..6acc8caf 100644 --- a/SharpBucket/SharpBucket.cs +++ b/SharpBucket/SharpBucket.cs @@ -13,7 +13,7 @@ namespace SharpBucket /// More info: /// https://confluence.atlassian.com/display/BITBUCKET/Use+the+Bitbucket+REST+APIs /// - public class SharpBucket : ISharpBucket + public class SharpBucket { private Authenticate authenticator; diff --git a/SharpBucket/SharpBucket.csproj b/SharpBucket/SharpBucket.csproj index 314eeb23..760ebbbf 100644 --- a/SharpBucket/SharpBucket.csproj +++ b/SharpBucket/SharpBucket.csproj @@ -55,7 +55,6 @@ - @@ -80,7 +79,6 @@ - diff --git a/SharpBucket/V2/EndPoints/EndPoint.cs b/SharpBucket/V2/EndPoints/EndPoint.cs index 965709b7..94a1a69a 100644 --- a/SharpBucket/V2/EndPoints/EndPoint.cs +++ b/SharpBucket/V2/EndPoints/EndPoint.cs @@ -21,14 +21,6 @@ public EndPoint(SharpBucketV2 sharpBucketV2, string resourcePath) _baseUrl = resourcePath; } - - public EndPoint(ISharpBucketV2 sharpBucketV2, string resourcePath) - { - _sharpBucketV2 = (SharpBucketV2) sharpBucketV2; - _baseUrl = resourcePath; - } - - /// /// Generator that allows lazy access to paginated resources. /// diff --git a/SharpBucket/V2/ISharpBucketV2.cs b/SharpBucket/V2/ISharpBucketV2.cs deleted file mode 100644 index 47430710..00000000 --- a/SharpBucket/V2/ISharpBucketV2.cs +++ /dev/null @@ -1,91 +0,0 @@ -using System.Collections.Generic; -using Serilog; -using SharpBucket.Authentication; -using SharpBucket.V2.EndPoints; -using SharpBucket.V2.Pocos; - -namespace SharpBucket.V2 -{ - public interface ISharpBucketV2 : ISharpBucket - { - /// - /// Get the Teams End Point for a specific team. - /// - /// The team whose team End Point you wish to get. - /// - TeamsEndPoint TeamsEndPoint(string teamName); - - /// - /// Get the Repositories End point. - /// - /// - RepositoriesEndPoint RepositoriesEndPoint(); - - /// - /// Get the UsersEndPoint End Point. - /// - /// The account for which you wish to get the UsersEndPoint End Point. - /// - UsersEndpoint UsersEndPoint(string accountName); - - UserEndpoint UserEndPoint(); - - /// - /// Use basic authentication with the BitBucket API. OAuth authentication is preferred over - /// basic authentication, due to security reasons. - /// - /// Your BitBucket user name. - /// Your BitBucket password. - void BasicAuthentication(string username, string password); - - /// - /// Use 2 legged OAuth 1.0a authentication. This is similar to basic authentication, since - /// it requires the same number of steps. It is still safer to use than basic authentication, - /// since you can revoke the API keys. - /// More info: - /// https://confluence.atlassian.com/display/BITBUCKET/OAuth+on+Bitbucket - /// - /// Your consumer API key obtained from the BitBucket web page. - /// Your consumer secret API key also obtained from the BitBucket web page. - void OAuth2LeggedAuthentication(string consumerKey, string consumerSecretKey); - - /// - /// Use 3 legged OAuth 1.0a authentication. This is the most secure one, but for simple uses it might - /// be a bit too complex. - /// More info: - /// https://confluence.atlassian.com/display/BITBUCKET/OAuth+on+Bitbucket - /// - /// Your consumer API key obtained from the BitBucket web page. - /// Your consumer secret API key also obtained from the BitBucket web page. - /// Callback URL to which BitBucket will send the pin. - /// - OAuthentication3Legged OAuth3LeggedAuthentication( - string consumerKey, - string consumerSecretKey, - string callback = "oob"); - - /// - /// Use 3 legged OAuth 1.0a authentication. Use this method if you have already obtained the OAuthToken - /// and OAuthSecretToken. This method can be used so you do not have to go trough the whole 3 legged - /// process every time. You can save the tokens you receive the first time and reuse them in another session. - /// - /// Your consumer API key obtained from the BitBucket web page. - /// Your consumer secret API key also obtained from the BitBucket web page. - /// Your OAuth token that was obtained on a previous session. - /// Your OAuth secret token thata was obtained on a previous session. - /// - OAuthentication3Legged OAuth3LeggedAuthentication( - string consumerKey, - string consumerSecretKey, - string oauthToken, - string oauthTokenSecret); - - /// - /// Use Oauth2 authentication. This is the neweset version and is prefered. - /// - /// - /// - /// - OAuthentication2 OAuthentication2(string consumerKey, string consumerSecretKey); - } -} \ No newline at end of file diff --git a/SharpBucket/V2/SharpBucketV2.cs b/SharpBucket/V2/SharpBucketV2.cs index 5c1d4c9a..eba6b0fb 100644 --- a/SharpBucket/V2/SharpBucketV2.cs +++ b/SharpBucket/V2/SharpBucketV2.cs @@ -7,7 +7,7 @@ namespace SharpBucket.V2 /// You can read more about the V2 of the API here: /// https://confluence.atlassian.com/display/BITBUCKET/Version+2 /// - public sealed class SharpBucketV2 : SharpBucket, ISharpBucketV2 + public sealed class SharpBucketV2 : SharpBucket { internal const string BITBUCKET_URL = "https://api.bitbucket.org/2.0"; From 983ba34de9b9ba221eec71850e45f5feb259dddd Mon Sep 17 00:00:00 2001 From: Anh-Duc Le Date: Thu, 26 Apr 2018 10:37:17 +0200 Subject: [PATCH 11/12] added ToLowerInvariant --- SharpBucket/V2/EndPoints/RepositoriesEndPoint.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SharpBucket/V2/EndPoints/RepositoriesEndPoint.cs b/SharpBucket/V2/EndPoints/RepositoriesEndPoint.cs index f2a712f0..2fd26eaa 100644 --- a/SharpBucket/V2/EndPoints/RepositoriesEndPoint.cs +++ b/SharpBucket/V2/EndPoints/RepositoriesEndPoint.cs @@ -167,7 +167,7 @@ internal Repository PutRepository(ILogger logger, Repository repo, string accoun internal Repository PostRepository(Repository repo, string accountName) { - var overrideUrl = GetRepositoryUrl(accountName, repo.name, null); + var overrideUrl = GetRepositoryUrl(accountName, repo.name.ToLowerInvariant(), null); return _sharpBucketV2.Post(repo, overrideUrl); } @@ -180,7 +180,7 @@ internal Repository PostRepository(Repository repo, string accountName) /// internal Repository PostRepository(ILogger logger, Repository repo, string accountName) { - var overrideUrl = GetRepositoryUrl(accountName, repo.name, null); + var overrideUrl = GetRepositoryUrl(accountName, repo.name.ToLowerInvariant(), null); return _sharpBucketV2.Post(logger, repo, overrideUrl); } From d9b54a64c161505a354a882798148e696c48c010 Mon Sep 17 00:00:00 2001 From: Anh-Duc Le Date: Thu, 26 Apr 2018 10:53:04 +0200 Subject: [PATCH 12/12] added public Project project { get; set; } public string slug { get; set; } --- .gitignore | 1 + SharpBucket/V2/Pocos/Repository.cs | 3 +++ 2 files changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 9404e7fa..7ed7f1b3 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ _ReSharper*/ /packages/ !packages/repositories.config /.vs/SharpBucket/v15/Server/sqlite3 +*.nupkg diff --git a/SharpBucket/V2/Pocos/Repository.cs b/SharpBucket/V2/Pocos/Repository.cs index be915a37..e9ea9011 100644 --- a/SharpBucket/V2/Pocos/Repository.cs +++ b/SharpBucket/V2/Pocos/Repository.cs @@ -17,5 +17,8 @@ public class Repository public bool? is_private { get; set; } public string name { get; set; } public string uuid { get; set; } + public Project project { get; set; } + public string slug { get; set; } + } } \ No newline at end of file