Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d408518

Browse files
committed
Added PullRequests
1 parent 95fd852 commit d408518

File tree

5 files changed

+197
-19
lines changed

5 files changed

+197
-19
lines changed

BitbucketSharp.MonoTouch/BitbucketSharp.MonoTouch.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@
136136
<Compile Include="..\BitbucketSharp\Controllers\PrivilegesController.cs">
137137
<Link>Controllers\PrivilegesController.cs</Link>
138138
</Compile>
139+
<Compile Include="..\BitbucketSharp\Controllers\PullRequestController.cs">
140+
<Link>Controllers\PullRequestController.cs</Link>
141+
</Compile>
142+
<Compile Include="..\BitbucketSharp\PullRequestModel.cs">
143+
<Link>Models\PullRequestModel.cs</Link>
144+
</Compile>
139145
</ItemGroup>
140146
<ItemGroup />
141147
<ProjectExtensions>
@@ -144,6 +150,7 @@
144150
<Policies>
145151
<TextStylePolicy EolMarker="Windows" inheritsSet="VisualStudio" inheritsScope="text/plain" scope="text/x-csharp" />
146152
<CSharpFormattingPolicy IndentSwitchBody="True" AnonymousMethodBraceStyle="NextLine" PropertyBraceStyle="NextLine" PropertyGetBraceStyle="NextLine" PropertySetBraceStyle="NextLine" EventBraceStyle="NextLine" EventAddBraceStyle="NextLine" EventRemoveBraceStyle="NextLine" StatementBraceStyle="NextLine" ElseNewLinePlacement="NewLine" CatchNewLinePlacement="NewLine" FinallyNewLinePlacement="NewLine" WhileNewLinePlacement="DoNotCare" ArrayInitializerWrapping="DoNotChange" ArrayInitializerBraceStyle="NextLine" BeforeMethodDeclarationParentheses="False" BeforeMethodCallParentheses="False" BeforeConstructorDeclarationParentheses="False" BeforeDelegateDeclarationParentheses="False" NewParentheses="False" SpacesBeforeBrackets="False" inheritsSet="Mono" inheritsScope="text/x-csharp" scope="text/x-csharp" />
153+
<DotNetNamingPolicy DirectoryNamespaceAssociation="PrefixedHierarchical" ResourceNamePolicy="FileFormatDefault" />
147154
</Policies>
148155
</Properties>
149156
</MonoDevelop>

BitbucketSharp/Client.cs

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -193,24 +193,24 @@ public void InvalidateCacheObjects(string startsWithUri)
193193
/// <param name="forceCacheInvalidation"></param>
194194
/// <returns>An object with response data</returns>
195195
public T Get<T>(String uri, bool forceCacheInvalidation = false, string baseUri = ApiUrl) where T : class
196-
{
197-
T obj = null;
196+
{
197+
T obj = null;
198198

199-
//If there's a cache provider, check it.
200-
if (CacheProvider != null && !forceCacheInvalidation)
201-
obj = CacheProvider.Get<T>(uri);
199+
//If there's a cache provider, check it.
200+
if (CacheProvider != null && !forceCacheInvalidation)
201+
obj = CacheProvider.Get<T>(uri);
202202

203-
if (obj == null)
204-
{
205-
obj = Request<T>(uri, baseUri: baseUri);
203+
if (obj == null)
204+
{
205+
obj = Request<T>(uri, baseUri: baseUri);
206206

207-
//If there's a cache provider, save it!
208-
if (CacheProvider != null)
209-
CacheProvider.Set(obj, uri);
210-
}
207+
//If there's a cache provider, save it!
208+
if (CacheProvider != null)
209+
CacheProvider.Set(obj, uri);
210+
}
211211

212-
return obj;
213-
}
212+
return obj;
213+
}
214214

215215
/// <summary>
216216
/// Makes a 'PUT' request to the server
@@ -276,11 +276,25 @@ public void Delete(string uri, string baseUri = ApiUrl)
276276
/// <returns></returns>
277277
public T Request<T>(string uri, Method method = Method.GET, Dictionary<string, string> data = null, string baseUri = ApiUrl)
278278
{
279-
var response = ExecuteRequest(uri, method, data, baseUri);
279+
var response = ExecuteRequest(new Uri(new Uri(baseUri), uri), method, data);
280280
var d = new JsonDeserializer();
281281
return d.Deserialize<T>(response);
282282
}
283283

284+
/// <summary>
285+
/// Dummy thing.. for now
286+
/// </summary>
287+
/// <param name="uri">URI.</param>
288+
/// <param name="method">Method.</param>
289+
/// <param name="data">Data.</param>
290+
/// <typeparam name="T">The 1st type parameter.</typeparam>
291+
public T Request2<T>(string uri, Method method = Method.GET, Dictionary<string, string> data = null)
292+
{
293+
var response = ExecuteRequest(new Uri(uri), method, data);
294+
var d = new JsonDeserializer();
295+
return d.Deserialize<T>(response);
296+
}
297+
284298
/// <summary>
285299
/// Makes a request to the server but does not expect a response.
286300
/// </summary>
@@ -289,7 +303,7 @@ public T Request<T>(string uri, Method method = Method.GET, Dictionary<string, s
289303
/// <param name="data"></param>
290304
public void Request(string uri, Method method = Method.GET, Dictionary<string, string> data = null, string baseUri = ApiUrl)
291305
{
292-
ExecuteRequest(uri, method, data, baseUri);
306+
ExecuteRequest(new Uri(new Uri(baseUri), uri), method, data);
293307
}
294308

295309
/// <summary>
@@ -299,14 +313,13 @@ public void Request(string uri, Method method = Method.GET, Dictionary<string, s
299313
/// <param name="method"></param>
300314
/// <param name="data"></param>
301315
/// <returns></returns>
302-
internal IRestResponse ExecuteRequest(string uri, Method method, Dictionary<string, string> data, string baseUri)
316+
internal IRestResponse ExecuteRequest(Uri uri, Method method, Dictionary<string, string> data)
303317
{
304318
if (uri == null)
305319
throw new ArgumentNullException("uri");
306320

307-
var requestUri = new Uri(new Uri(baseUri), uri);
308321
var request = new RestRequest(method);
309-
request.Resource = requestUri.AbsoluteUri;
322+
request.Resource = uri.AbsoluteUri;
310323
if (data != null)
311324
foreach (var hd in data)
312325
request.AddParameter(hd.Key, hd.Value);
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
using System;
2+
using BitbucketSharp.Models.V2;
3+
using BitbucketSharp.Models;
4+
using System.Collections.Generic;
5+
6+
namespace BitbucketSharp.Controllers
7+
{
8+
public class PullRequestsController : Controller
9+
{
10+
/// <summary>
11+
/// Gets the repository.
12+
/// </summary>
13+
public RepositoryController Repository { get; private set; }
14+
15+
/// <summary>
16+
/// Constructor
17+
/// </summary>
18+
/// <param name="client">A handle to the client</param>
19+
/// <param name="repo">The repository the branch belongs to</param>
20+
public PullRequestsController(Client client, RepositoryController repo) : base(client)
21+
{
22+
Repository = repo;
23+
}
24+
25+
/// <summary>
26+
/// Access a specific branch via the slug
27+
/// </summary>
28+
/// <param name="branch">The repository branch</param>
29+
/// <returns></returns>
30+
public PullRequestController this[ulong id]
31+
{
32+
get { return new PullRequestController(Client, this, id); }
33+
}
34+
35+
/// <summary>
36+
/// Gets all the branches in this repository
37+
/// </summary>
38+
/// <returns></returns>
39+
public Collection<PullRequestModel> GetAll(string state = "OPEN", bool forceCacheInvalidation = false)
40+
{
41+
return Client.Get<Collection<PullRequestModel>>(Uri + "?state=" + state, forceCacheInvalidation, Client.ApiUrl2);
42+
}
43+
44+
/// <summary>
45+
/// The URI of this controller
46+
/// </summary>
47+
public override string Uri
48+
{
49+
get { return Repository.Uri + "/pullrequests"; }
50+
}
51+
}
52+
53+
public class PullRequestController : Controller
54+
{
55+
public PullRequestsController Parent { get; private set; }
56+
57+
public ulong Id { get; private set; }
58+
59+
public PullRequestController(Client client, PullRequestsController parent, ulong id)
60+
: base(client)
61+
{
62+
Parent = parent;
63+
Id = id;
64+
}
65+
66+
public PullRequestModel Get(bool forceCacheInvalidation = false)
67+
{
68+
return Client.Get<PullRequestModel>(Uri, forceCacheInvalidation, Client.ApiUrl2);
69+
}
70+
71+
public PullRequestModel Merge()
72+
{
73+
return Client.Post<PullRequestModel>(Uri + "/merge", null, baseUri: Client.ApiUrl2);
74+
}
75+
76+
public PullRequestModel Decline()
77+
{
78+
return Client.Post<PullRequestModel>(Uri + "/decline", null, baseUri: Client.ApiUrl2);
79+
}
80+
81+
public Collection<PullRequestCommentModel> GetComments(bool forceCacheInvalidation = false)
82+
{
83+
return Client.Get<Collection<PullRequestCommentModel>>(Uri + "/comments", forceCacheInvalidation, Client.ApiUrl2);
84+
}
85+
86+
public OldPullRequestCommentModel AddComment(string content)
87+
{
88+
var d = new Dictionary<string, string>() {{"content", content}};
89+
return Client.Post<OldPullRequestCommentModel>(Uri + "/comments", d);
90+
}
91+
92+
public override string Uri
93+
{
94+
get { return Parent.Uri + "/" + Id; }
95+
}
96+
}
97+
}
98+

BitbucketSharp/Controllers/RepositoryController.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,14 @@ public RepositoryGroupPrivilegeController GroupPrivileges
146146
get { return new RepositoryGroupPrivilegeController(Client, this); }
147147
}
148148

149+
/// <summary>
150+
/// Gets the pull requests.
151+
/// </summary>
152+
public PullRequestsController PullRequests
153+
{
154+
get { return new PullRequestsController(Client, this); }
155+
}
156+
149157
/// <summary>
150158
/// Constructor
151159
/// </summary>

BitbucketSharp/PullRequestModel.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace BitbucketSharp.Models
5+
{
6+
public class PullRequestModel
7+
{
8+
public ulong Id { get; set; }
9+
public DateTime UpdatedOn { get; set; }
10+
public DateTime CreatedOn { get; set; }
11+
public string State { get; set; }
12+
public string Description { get; set; }
13+
public string Title { get; set; }
14+
public bool CloseSourceBranch { get; set; }
15+
public string Reason { get; set; }
16+
public List<BitbucketSharp.Models.V2.UserModel> Reviewers { get; set; }
17+
public BitbucketSharp.Models.V2.UserModel Author { get; set; }
18+
public List<ParticipantModel> Participants { get; set; }
19+
20+
public class ParticipantModel
21+
{
22+
public string Role { get; set; }
23+
public BitbucketSharp.Models.V2.UserModel User { get; set; }
24+
public bool Approved { get; set; }
25+
}
26+
}
27+
28+
public class PullRequestCommentModel
29+
{
30+
public DateTime CreatedOn { get; set; }
31+
public DateTime UpdatedOn { get; set; }
32+
public ulong Id { get; set; }
33+
public ContentModel Content { get; set; }
34+
public BitbucketSharp.Models.V2.UserModel User { get; set; }
35+
36+
public class ContentModel
37+
{
38+
public string Raw { get; set; }
39+
public string Markup { get; set; }
40+
public string Html { get; set; }
41+
}
42+
}
43+
44+
public class OldPullRequestCommentModel
45+
{
46+
public string Username { get; set; }
47+
public string Content { get; set; }
48+
public string ContentRendered { get; set; }
49+
}
50+
51+
}
52+

0 commit comments

Comments
 (0)