Skip to content

Commit dbcad97

Browse files
committed
Add a webservice for updating feedstocks
Provides an asynchronous webservice, which listens to push events on the feedstocks. When a push event occurs on a feedstock, the webservice updates the commit that the appropriate submodule points to in the feedstocks repo. This way it is a lot easier to handle updates of various feedstocks throughout the organization on demand instead of running a massive batch script over all of the feedstocks (even when most haven't changed).
1 parent 8e46830 commit dbcad97

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import git
2+
import github
3+
import os
4+
from .utils import tmp_directory
5+
6+
7+
def update_feedstock(org_name, repo_name):
8+
if not repo_name.endswith("-feedstock"):
9+
return
10+
11+
gh = github.Github(os.environ['GH_TOKEN'])
12+
13+
gh.get_repo("{}/{}".format(org_name, repo_name))
14+
name = repo_name[:-len("-feedstock")]
15+
16+
with tmp_directory() as tmp_dir:
17+
feedstocks_url = (
18+
"https://{}@github.com/conda-forge/feedstocks.git"
19+
"".format(os.environ["GH_TOKEN"])
20+
)
21+
feedstocks_repo = git.Repo.clone_from(
22+
feedstocks_url,
23+
tmp_dir
24+
)
25+
26+
# Get the submodule
27+
try:
28+
feedstock_submodule = feedstocks_repo.submodule(name)
29+
except ValueError:
30+
feedstock_submodule = feedstocks_repo.create_submodule(
31+
name=name,
32+
path=os.path.join("feedstocks", name),
33+
url=repo_gh.clone_url,
34+
branch="master"
35+
)
36+
37+
# Update the feedstocks submodule
38+
feedstock_submodule.update(init=True, recursive=False, force=True)
39+
feedstock_submodule.branch.checkout(force=True)
40+
feedstock_submodule.update(
41+
init=True,
42+
recursive=False,
43+
force=True,
44+
to_latest_revision=True
45+
)
46+
47+
# Submit changes
48+
if feedstocks_repo.is_dirty():
49+
feedstocks_repo.index.commit("Updated feedstocks submodules. [ci skip]")
50+
feedstocks_repo.remote().pull(rebase=True)
51+
feedstocks_repo.remote().push()
52+
53+
54+
if __name__ == '__main__':
55+
import argparse
56+
parser = argparse.ArgumentParser()
57+
parser.add_argument('org')
58+
parser.add_argument('repo')
59+
args = parser.parse_args()
60+
update_team(args.org, args.repo)

conda_forge_webservices/webapp.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import conda_forge_webservices.linting as linting
2020
import conda_forge_webservices.status as status
21+
import conda_forge_webservices.update_feedstocks as update_feedstocks
2122
import conda_forge_webservices.update_teams as update_teams
2223
import conda_forge_webservices.commands as commands
2324

@@ -108,6 +109,27 @@ def post(self):
108109
self.write_error(404)
109110

110111

112+
class UpdateFeedstockHookHandler(tornado.web.RequestHandler):
113+
def post(self):
114+
headers = self.request.headers
115+
event = headers.get('X-GitHub-Event', None)
116+
117+
if event == 'ping':
118+
self.write('pong')
119+
elif event == 'push':
120+
body = tornado.escape.json_decode(self.request.body)
121+
repo_name = body['repository']['name']
122+
owner = body['repository']['owner']['login']
123+
ref = body['ref']
124+
# Only do anything if we are working with conda-forge, and a push to master.
125+
if owner == 'conda-forge' and ref == "refs/heads/master":
126+
update_feedstocks.update_feedstock(owner, repo_name)
127+
else:
128+
print('Unhandled event "{}".'.format(event))
129+
self.set_status(404)
130+
self.write_error(404)
131+
132+
111133
class UpdateTeamHookHandler(tornado.web.RequestHandler):
112134
def post(self):
113135
headers = self.request.headers
@@ -193,6 +215,7 @@ def create_webapp():
193215
application = tornado.web.Application([
194216
(r"/conda-linting/hook", LintingHookHandler),
195217
(r"/conda-forge-status/hook", StatusHookHandler),
218+
(r"/conda-forge-feedstocks/hook", UpdateFeedstockHookHandler),
196219
(r"/conda-forge-teams/hook", UpdateTeamHookHandler),
197220
(r"/conda-forge-command/hook", CommandHookHandler),
198221
])

0 commit comments

Comments
 (0)