-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcreateHooks.py
More file actions
56 lines (42 loc) · 1.6 KB
/
createHooks.py
File metadata and controls
56 lines (42 loc) · 1.6 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""
This will create service hooks for integrating your repo with external services like Github
"""
#!/usr/bin/python
import sys
sys.path.append("./PyGithub");
from github import Github
import getpass
import argparse
from github import Github
from github import GithubException
parser = argparse.ArgumentParser(description='List all repos for an org')
parser.add_argument('repoName',help='github Repo name')
args = parser.parse_args()
username = raw_input("Github Username:")
pw = getpass.getpass()
g = Github(username, pw)
repoName = args.repoName
try:
repo = g.get_repo(repoName)
except GithubException as ghe:
print(ghe)
## this is where we create the actual repo:
# for clarity in the exmaple, I will simply hardcode the details:
# note: for the below you would need appropriate settings to be defined
repo_hooks = [ ## (name,config)
( 'campfire', {'room': settings.CAMPFIRE_ROOM_NAME, 'sound': '', 'subdomain': settings.CAMPFIRE_SUBDOMAIN,'token': settings.CAMPFIRE_AUTH_ID } ),
( 'pivotaltracker', {'branch': '', 'endpoint': '', 'token': settings.PIVOTAL_TOKEN } )
]
"""
tip: if you want to see what an example config looks like. On a repo that has hooks defined, do:
hooks = repo.get_hooks:
for hook in hooks:
print hook.__dict__
This will fetch hooks from an existing repo, and print out their details.
You will need the name and config details to configure a hook on a repo with the API as above
"""
try:
for name,hook in repo_hooks:
repo.create_hook(name,hook)
except GithubException as ghe:
print(ghe)