@@ -171,6 +171,24 @@ public ITrackingCollection<IPullRequestModel> GetPullRequests(ISimpleRepositoryM
171171 return collection ;
172172 }
173173
174+ public IObservable < IPullRequestModel > CreatePullRequest ( ISimpleRepositoryModel repository , string title , IBranch source , IBranch target )
175+ {
176+ var keyobs = GetUserFromCache ( )
177+ . Select ( user => string . Format ( CultureInfo . InvariantCulture , "{0}|{1}|pr" , user . Login , repository . Name ) ) ;
178+
179+ return Observable . Defer ( ( ) => keyobs
180+ . SelectMany ( key =>
181+ hostCache . PutAndUpdateIndex ( key , ( ) =>
182+ apiClient . CreatePullRequest ( new NewPullRequest ( title , source . Name , target . Name ) ,
183+ repository . CloneUrl . Owner ,
184+ repository . CloneUrl . RepositoryName )
185+ . Select ( PullRequestCacheItem . Create ) ,
186+ TimeSpan . FromMinutes ( 30 ) )
187+ )
188+ . Select ( Create )
189+ ) ;
190+ }
191+
174192 public IObservable < Unit > InvalidateAll ( )
175193 {
176194 return hostCache . InvalidateAll ( ) . ContinueAfter ( ( ) => hostCache . Vacuum ( ) ) ;
@@ -234,12 +252,22 @@ IObservable<IReadOnlyList<IRepositoryModel>> GetOrganizationRepositories(string
234252 } ) ;
235253 }
236254
255+ public IObservable < IBranch > GetBranches ( ISimpleRepositoryModel repo )
256+ {
257+ var keyobs = GetUserFromCache ( )
258+ . Select ( user => string . Format ( CultureInfo . InvariantCulture , "{0}|{1}|branch" , user . Login , repo . Name ) ) ;
259+
260+ return Observable . Defer ( ( ) => keyobs
261+ . SelectMany ( key => apiClient . GetBranches ( repo . CloneUrl . Owner , repo . CloneUrl . RepositoryName ) ) )
262+ . Select ( Create ) ;
263+ }
264+
237265 static LicenseItem Create ( LicenseCacheItem licenseCacheItem )
238266 {
239267 return new LicenseItem ( licenseCacheItem . Key , licenseCacheItem . Name ) ;
240268 }
241269
242- Models . Account Create ( AccountCacheItem accountCacheItem )
270+ IAccount Create ( AccountCacheItem accountCacheItem )
243271 {
244272 return new Models . Account (
245273 accountCacheItem . Login ,
@@ -275,6 +303,11 @@ IPullRequestModel Create(PullRequestCacheItem prCacheItem)
275303 } ;
276304 }
277305
306+ IBranch Create ( Branch branch )
307+ {
308+ return new BranchModel ( branch ) ;
309+ }
310+
278311 public IObservable < Unit > InsertUser ( AccountCacheItem user )
279312 {
280313 return hostCache . InsertObject ( "user" , user ) ;
0 commit comments