From a5f2d147076af43211b07727f2a980f70adeb62f Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 26 Feb 2021 11:53:15 +0100 Subject: [PATCH] [CHG] forwardport: try to create PRs in draft mode Fall back to creating in not-draft mode if that doesn't work: draft pull requests on private repositories requires the Team plan. Closes #459 --- forwardport/models/project.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/forwardport/models/project.py b/forwardport/models/project.py index d2e7692f..15c0a037 100644 --- a/forwardport/models/project.py +++ b/forwardport/models/project.py @@ -637,10 +637,19 @@ class PullRequests(models.Model): body = None self.env.cr.execute('LOCK runbot_merge_pull_requests IN SHARE MODE') - r = gh.post('https://api.github.com/repos/{}/pulls'.format(pr.repository.name), json={ + url = 'https://api.github.com/repos/{}/pulls'.format(pr.repository.name) + pr_data = { 'base': target.name, 'head': '%s:%s' % (owner, new_branch), - 'title': title, 'body': body, - }) + 'title': title, 'body': body, 'draft': True + } + r = gh.post(url, json=pr_data) + if r.status_code == 422: + # assume this is a private repo which doesn't support draft PRs + # (github error response doesn't provide any machine + # information, only a human-readable message) so retry without + del pr_data['draft'] + r = gh.post(url, json=pr_data) + results = r.json() if not (200 <= r.status_code < 300): _logger.warning("Failed to create forward-port PR for %s, deleting branches", pr.display_name)