blob: 089a6ef93ec29d61984d93904f4d2f197e12e5b3 [file] [log] [blame]
Clint Adamse3e80512016-02-18 14:46:35 -05001#! /usr/bin/env python
2
3# Copyright 2016 Hewlett Packard Enterprise Development Company, L.P.
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may
6# not use this file except in compliance with the License. You may obtain
7# a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations
15# under the License.
16
17# This script is intended to be run as part of a periodic proposal bot
18# job in OpenStack infrastructure.
19#
20# In order to function correctly, the environment in which the
21# script runs must have
22# * network access to the review.openstack.org Gerrit API
23# working directory
24# * network access to https://git.openstack.org/cgit
25
Ian Wienandc10989b2016-03-21 13:03:34 +110026import logging
Clint Adamse3e80512016-02-18 14:46:35 -050027import json
28import requests
29
Ian Wienandc10989b2016-03-21 13:03:34 +110030logging.basicConfig(level=logging.DEBUG)
31
Clint Adamse3e80512016-02-18 14:46:35 -050032url = 'https://review.openstack.org/projects/'
33
34# This is what a project looks like
35'''
36 "openstack-attic/akanda": {
37 "id": "openstack-attic%2Fakanda",
38 "state": "READ_ONLY"
39 },
40'''
41
42def is_in_openstack_namespace(proj):
Ian Wienandc10989b2016-03-21 13:03:34 +110043 # only interested in openstack namespace (e.g. not retired
44 # stackforge, etc)
Clint Adamse3e80512016-02-18 14:46:35 -050045 return proj.startswith('openstack/')
46
47# Rather than returning a 404 for a nonexistent file, cgit delivers a
48# 0-byte response to a GET request. It also does not provide a
49# Content-Length in a HEAD response, so the way we tell if a file exists
50# is to check the length of the entire GET response body.
51def has_devstack_plugin(proj):
52 r = requests.get("https://git.openstack.org/cgit/%s/plain/devstack/plugin.sh" % proj)
53 if len(r.text) > 0:
54 return True
55 else:
Eyale7361772016-04-05 16:18:56 +030056 return False
Clint Adamse3e80512016-02-18 14:46:35 -050057
Ian Wienandc10989b2016-03-21 13:03:34 +110058logging.debug("Getting project list from %s" % url)
Clint Adamse3e80512016-02-18 14:46:35 -050059r = requests.get(url)
60projects = sorted(filter(is_in_openstack_namespace, json.loads(r.text[4:])))
Ian Wienandc10989b2016-03-21 13:03:34 +110061logging.debug("Found %d projects" % len(projects))
Clint Adamse3e80512016-02-18 14:46:35 -050062
63found_plugins = filter(has_devstack_plugin, projects)
64
65for project in found_plugins:
Ian Wienandc10989b2016-03-21 13:03:34 +110066 # strip of openstack/
Eyale7361772016-04-05 16:18:56 +030067 print(project[10:])