@@ -221,41 +221,65 @@ def gist_delete(self, gist_id):
221
221
raise ResourceNotFoundError ('Could not find gist' )
222
222
gist .delete ()
223
223
224
- def request_create (self , user , repo , from_branch , onto_branch , title = None , description = None , auto_slug = False , edit = None ):
225
- repository = self .gh .repository (user , repo )
226
- if not repository :
227
- raise ResourceNotFoundError ('Could not find repository `{}/{}`!' .format (user , repo ))
224
+ def request_create (self , onto_user , onto_repo , from_branch , onto_branch , title = None , description = None , auto_slug = False , edit = None ):
225
+ onto_project = self .gh .repository (onto_user , onto_repo )
226
+
227
+ if not onto_project :
228
+ raise ResourceNotFoundError ('Could not find project `{}/{}`!' .format (onto_user , onto_repo ))
229
+
230
+ from_reposlug = self .guess_repo_slug (self .repository , self )
231
+ if from_reposlug :
232
+ from_user , from_repo = from_reposlug .split ('/' )
233
+ if (onto_user , onto_repo ) == (from_user , from_repo ):
234
+ from_project = onto_project
235
+ else :
236
+ from_project = self .gh .repository (from_user , from_repo )
237
+ else :
238
+ from_project = None
239
+
240
+ if not from_project :
241
+ raise ResourceNotFoundError ('Could not find project `{}`!' .format (from_user , from_repo ))
242
+
228
243
# when no repo slug has been given to `git-repo X request create`
229
- if auto_slug :
230
- # then chances are current repository is a fork of the target
231
- # repository we want to push to
232
- if repository . fork :
233
- user = repository .parent .owner . login
234
- repo = repository . parent . name
235
- from_branch = from_branch or repository . parent . default_branch
244
+ # then chances are current project is a fork of the target
245
+ # project we want to push to
246
+ if auto_slug and onto_project . fork :
247
+ onto_user = onto_project . parent . owner . login
248
+ onto_repo = onto_project .parent .name
249
+ onto_project = self . gh . repository ( onto_user , onto_repo )
250
+
236
251
# if no onto branch has been defined, take the default one
237
252
# with a fallback on master
238
253
if not from_branch :
239
254
from_branch = self .repository .active_branch .name
240
255
# if no from branch has been defined, chances are we want to push
241
256
# the branch we're currently working on
242
257
if not onto_branch :
243
- onto_branch = repository .default_branch or 'master'
258
+ onto_branch = onto_project .default_branch or 'master'
244
259
245
- from_ref = self ._extracts_ref (user , from_branch )
246
- if user != repository .owner .login :
247
- from_branch = ':' .join ([user , from_branch ])
260
+ from_target = '{}:{}' .format (from_user , from_branch )
261
+ onto_target = '{}/{}:{}' .format (onto_user , onto_project , onto_branch )
248
262
249
263
# translate from github username to git remote name
250
264
if not title and not description and edit :
251
- title , description = edit (self .repository , from_ref )
265
+ title , description = edit (self .repository , from_branch , onto_target )
252
266
if not title and not description :
253
267
raise ArgumentError ('Missing message for request creation' )
268
+
254
269
try :
255
- request = repository .create_pull (title ,
270
+ request = onto_project .create_pull (title ,
271
+ head = from_target ,
256
272
base = onto_branch ,
257
- head = from_branch ,
258
273
body = description )
274
+
275
+ return {
276
+ 'local' : from_branch ,
277
+ 'project' : '/' .join ([onto_user , onto_repo ]),
278
+ 'remote' : onto_branch ,
279
+ 'ref' : request .number ,
280
+ 'url' : request .html_url
281
+ }
282
+
259
283
except github3 .models .GitHubError as err :
260
284
if err .code == 422 :
261
285
if err .message == 'Validation Failed' :
@@ -272,9 +296,6 @@ def request_create(self, user, repo, from_branch, onto_branch, title=None, descr
272
296
raise ResourceError ("Unhandled formatting error: {}" .format (err .errors ))
273
297
raise ResourceError (err .message )
274
298
275
- return {'local' : from_branch , 'remote' : onto_branch , 'ref' : request .number ,
276
- 'url' : request .html_url }
277
-
278
299
def request_list (self , user , repo ):
279
300
repository = self .gh .repository (user , repo )
280
301
yield "{}\t {:<60}\t {}"
0 commit comments