~doctormo/python-snippets/lp-merge-request-example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Code by Martin Owens, (c) 2010 GPLv3

import os
import time
from launchpadlib.launchpad import Launchpad, STAGING_SERVICE_ROOT
from launchpadlib.credentials import Credentials

CACHE_DIR = os.path.expanduser('~/.cache/launchpadlib/')

if not os.path.exists(CACHE_DIR):
    os.mkdir(CACHE_DIR)

# connect ot the staging service of launchpad
lp = Launchpad.login_with("python-snippets", STAGING_SERVICE_ROOT)

branch = lp.branches.getByUniqueName(unique_name='lp:~foo/bar/child')
parent = lp.branches.getByUniqueName(unique_name='lp:~foo/bar/parent')

reviewer  = parent.reviewer
if not reviewer:
    reviewer = parent.owner

result = self.source_branch.createMergeProposal(
    initial_comment=comment,
    needs_review=True,
    target_branch=parent,
    reviewers=(reviewer),
    review_types=('')
)