~kubuntu-packagers/kubuntu-dev-tools/trunk

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
31
32
33
34
35
#!/usr/bin/env python3

from launchpadlib.launchpad import Launchpad
import sys

lp = Launchpad.login_with("kubuntu-dev-tools", "production", version="devel")

baseUrl = 'http://kci.pangea.pub/git/notifyCommit?url=git%2Bssh://git.launchpad.net/~kubuntu-packagers/kubuntu-packaging/%2Bgit/'

action = sys.argv[1]

for repo in lp.git_repositories.getRepositories(target=lp.projects['kubuntu-packaging']):
    if repo.owner == lp.people['kubuntu-packagers']:
        hookExists = False
        for hook in repo.webhooks:
            if hook.delivery_url == baseUrl + repo.name:
                if action == 'add':
                    print(repo.name + ' already has a hook')
                    hookExists = True
                elif action == 'enable':
                    print('enabling hook for ' + repo.name)
                    hook.active = True
                    hook.lp_save()
                elif action == 'disable':
                    print('disabling hook for ' + repo.name)
                    hook.active = False
                    hook.lp_save()
                elif action == 'delete':
                    print('delete hook for ' + repo.name)
                    hook.lp_delete()

        if action == 'add' and (len(repo.webhooks) == 0 or not hookExists):
            print('add hoook for ' + repo.name)
            repo.newWebhook(active=True, delivery_url=baseUrl + repo.name, event_types=[u'git:push:0.1'])
            repo.lp_save()