parent
044b8da55a
commit
759617c9c0
288 changed files with 13040 additions and 1 deletions
93
bots/naughty-prune
Executable file
93
bots/naughty-prune
Executable file
|
|
@ -0,0 +1,93 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# This file is part of Cockpit.
|
||||
#
|
||||
# Copyright (C) 2017 Red Hat, Inc.
|
||||
#
|
||||
# Cockpit is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation; either version 2.1 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Cockpit is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Cockpit; If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# To use this example add a line to an issue with the "bot" label
|
||||
#
|
||||
# * [ ] naughty-prune
|
||||
#
|
||||
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
sys.dont_write_bytecode = True
|
||||
|
||||
import task
|
||||
|
||||
# Number of days after which a known issue is treated as stale
|
||||
DAYS = 21
|
||||
|
||||
# In case this ever changes
|
||||
SECONDS_PER_DAY = 3600 * 24
|
||||
|
||||
BOTS = os.path.abspath(os.path.dirname(__file__))
|
||||
BASE = os.path.normpath(os.path.join(BOTS, ".."))
|
||||
|
||||
def execute(*args):
|
||||
if task.verbose:
|
||||
sys.stderr.write("+ " + " ".join(args) + "\n")
|
||||
return subprocess.check_output(args, cwd=BASE, universal_newlines=True)
|
||||
|
||||
def run(unused, verbose=False, **kwargs):
|
||||
|
||||
# Since a month ago
|
||||
now = time.time()
|
||||
since = now - (DAYS * SECONDS_PER_DAY)
|
||||
|
||||
# The head
|
||||
head = execute("git", "rev-parse", "HEAD").strip()
|
||||
|
||||
# Don't replace this issue with the pull request(s)
|
||||
if "issue" in kwargs:
|
||||
del kwargs["issue"]
|
||||
|
||||
# Get all the open known issues
|
||||
issues = task.api.issues(labels=["knownissue"])
|
||||
for issue in issues:
|
||||
number = issue["number"]
|
||||
|
||||
updated = issue.get("updated_at", None)
|
||||
if not updated:
|
||||
updated = issue.get("created_at", None)
|
||||
if not updated:
|
||||
continue
|
||||
|
||||
# Don't touch recently updated issues
|
||||
updated = time.mktime(time.strptime(updated, "%Y-%m-%dT%H:%M:%SZ"))
|
||||
if updated > since:
|
||||
continue
|
||||
|
||||
# Try to close this issue
|
||||
execute("git", "checkout", "--detach", head)
|
||||
execute("find", "bots/naughty/", "-name", "{0}-*".format(number), "-delete")
|
||||
|
||||
# Create a pull request from these changes
|
||||
title = "naughty: Close {0}: {1}".format(number, issue["title"])
|
||||
days = int((now - updated) / SECONDS_PER_DAY)
|
||||
body = "Known issue which has not occurred in {0} days\n\n{1}\n\nFixes #{2}".format(days, issue["title"], number)
|
||||
branch = task.branch(number, "{0}\n\n{1}".format(title, body), pathspec="bots/naughty/", **kwargs)
|
||||
|
||||
if branch:
|
||||
kwargs["title"] = title
|
||||
pull = task.pull(branch, body=body, **kwargs)
|
||||
task.comment(pull, "Please comment on the upstream distro bug manually before accepting this pull request.\n\nIf you wish to keep this known issue open, then update it")
|
||||
|
||||
if __name__ == '__main__':
|
||||
task.main(function=run, title="Close known issues")
|
||||
Loading…
Add table
Add a link
Reference in a new issue