@@ -0,0 +1,1782 @@
+#!/usr/bin/env python2%0A%0A# Copyright 2017 The Kubernetes Authors.%0A#%0A# Licensed under the Apache License, Version 2.0 (the %22License%22);%0A# you may not use this file except in compliance with the License.%0A# You may obtain a copy of the License at%0A#%0A#     http://www.apache.org/licenses/LICENSE-2.0%0A#%0A# Unless required by applicable law or agreed to in writing, software%0A# distributed under the License is distributed on an %22AS IS%22 BASIS,%0A# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A# See the License for the specific language governing permissions and%0A# limitations under the License.%0A%0A%22%22%22Cancel old, duplicate tests of the same pr.%0A%0AThis can happen with repeated '@k8s-bot test this' commands, or%0Aeven something as simple as pushing new code while builds are already queued.%0A%22%22%22%0A%0Aimport sys%0A%0Aimport requests%0A%0A%0Adef prune(host):%0A    queue = requests.get('http://%25s/queue/api/json' %25 host).json()%0A%0A    dupes = %7B%7D%0A    for item in queue%5B'items'%5D:%0A        params = %7B%7D%0A        for action in item%5B'actions'%5D:%0A            if 'parameters' in action:%0A                params = %7Bd%5B'name'%5D: d%5B'value'%5D for d in action%5B'parameters'%5D%7D%0A        if 'PULL_NUMBER' in params:%0A            name = item%5B'task'%5D%5B'name'%5D%0A            queueId = item%5B'id'%5D%0A            since = item%5B'inQueueSince'%5D%0A            dupes.setdefault((name, params%5B'PULL_NUMBER'%5D), %5B%5D).append((since, queueId, params))%0A%0A    for k, v in dupes.iteritems():%0A        if len(v) %3C 2:%0A            continue%0A        v.sort()%0A        print '===', k%0A        for p in v%5B:-1%5D:%0A            print p%0A            resp = requests.post('http://%25s/queue/cancelItem?id=%25d' %25 (host, p%5B1%5D))%0A        print 'GOOD:', v%5B-1%5D%0A%0A%0Aif __name__ == '__main__':%0A    host = sys.argv%5B1%5D if len(sys.argv) %3E 1 else 'localhost:8080'%0A    prune(host)%0A

Add bilge, a quick hack to clear pointless jobs from the Jenkins queue.