summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2020-11-16 02:11:36 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2020-11-16 02:11:36 +0100
commit0baa3810d9216f763c3f2fdf5c70fe5e453c36d3 (patch)
tree70a7b42a5cabbdecff0336a605169f6821bfcc7f
parente12d8853cd5d6f44f75ab1bab23c54f7f91b32af (diff)
downloadpsutil-0baa3810d9216f763c3f2fdf5c70fe5e453c36d3.tar.gz
add script to relabel old issues
-rw-r--r--.github/workflows/issue_labels.yml24
-rw-r--r--MANIFEST.in1
-rw-r--r--Makefile3
-rwxr-xr-xscripts/internal/github_issue_labeler.py110
4 files changed, 128 insertions, 10 deletions
diff --git a/.github/workflows/issue_labels.yml b/.github/workflows/issue_labels.yml
index a5a7cf0c..0ee5ef2e 100644
--- a/.github/workflows/issue_labels.yml
+++ b/.github/workflows/issue_labels.yml
@@ -20,19 +20,23 @@ jobs:
{"keywords": ["aix"], "labels": ["aix"], "assignees": ["wiggin15"]},
{"keywords": ["cygwin"], "labels": ["cygwin"], "assignees": [""]},
{"keywords": ["freebsd"], "labels": ["freebsd"], "assignees": [""]},
- {"keywords": ["linux", "ubuntu", "redhat", "mint", "centos", "archlinux", "debian", "alpine", "gentoo", "fedora", "slackware", "suse", "opensuse", "manylinux"], "labels": ["linux"], "assignees": [""]},
- {"keywords": ["macos", "osx", "mojave", "sierra", "capitan", "yosemite"], "labels": ["osx"], "assignees": [""]},
+ {"keywords": ["linux", "ubuntu", "redhat", "red hat", "mint", "centos", "archlinux", "debian", "alpine", "gentoo", "fedora", "slackware", "suse", "opensuse", "manylinux", "apt", "rpm", "yum", "RHEL", "/sys/class", "/sys/block", "/proc/net", "/proc/disk", "/proc/smaps"], "labels": ["linux"], "assignees": [""]},
+ {"keywords": ["macos", "mac ", "osx", "os x", "mojave", "sierra", "capitan", "darwin", "yosemite", "catalina", "xcode"], "labels": ["macos"], "assignees": [""]},
{"keywords": ["netbsd"], "labels": ["netbsd"], "assignees": [""]},
{"keywords": ["openbsd"], "labels": ["openbsd"], "assignees": [""]},
{"keywords": ["sunos", "solaris"], "labels": ["sunos"], "assignees": ["wiggin15"]},
- {"keywords": ["unix", "posix"], "labels": ["unix"], "assignees": [""]},
- {"keywords": ["windows", "WinError", "win10", "win7", "win"], "labels": ["windows"], "assignees": [""]},
+ {"keywords": ["windows", "win32", "WinError", "WindowsError", "win10", "win7", "win", "mingw", "msys", "studio", "microsoft", "MSVC", "TCHAR", "WCHAR", "make.bat", ".bat", "appveyor", "handles", "CloseHandle", "GetLastError", "NtQuery", "OpenProcess", "TerminateProcess", "DLL"], "labels": ["windows"], "assignees": [""]},
{"keywords": ["wsl"], "labels": ["wsl"], "assignees": [""]},
- {"keywords": ["bug", "bug"], "labels": ["bug"], "assignees": [""]},
- {"keywords": ["doc", "documentation"], "labels": ["doc"], "assignees": [""]},
- {"keywords": ["idea", "proposal", "api", "request", "feature"], "labels": ["api", "enhancement"], "assignees": [""]},
- {"keywords": ["performance", "speed"], "labels": ["performance"], "assignees": [""]},
- {"keywords": ["pypy", "pypy2", "pypy3"], "labels": ["pypy"], "assignees": [""]},
- {"keywords": ["test", "tests"], "labels": ["tests"], "assignees": [""]},
+ {"keywords": ["bug", "raise", "exception", "traceback"], "labels": ["bug"], "assignees": [""]},
+ {"keywords": ["enhancement"], "labels": ["enhancement"], "assignees": [""]},
+ {"keywords": ["doc ", "document ", "documentation", "readthedocs", "pythonhosted", "HISTORY.txt", "README"], "labels": ["doc"], "assignees": [""]},
+ {"keywords": ["idea", "proposal", "api", "feature"], "labels": ["api", "enhancement"], "assignees": [""]},
+ {"keywords": ["performance", "speedup", "slow", "fast"], "labels": ["performance"], "assignees": [""]},
+ {"keywords": ["pypy"], "labels": ["pypy"], "assignees": [""]},
+ {"keywords": ["psposix", "waitpid", "statvfs", "/dev/tty", "/dev/pts"], "labels": ["unix"], "assignees": [""]},
+ {"keywords": ["memory leak", "leaks memory", "memleak", "mem leak"], "labels": ["memleak"], "assignees": [""]},
+ {"keywords": ["test", "tests", "travis", "coverage", "travis", "cirrus", "appveyor", "continuous integration", "dev guide", "devguide", "sphinx", "unittest", "pytest"], "labels": ["tests"], "assignees": [""]},
+ {"keywords": ["Makefile"], "labels": ["unix"], "assignees": [""]},
+ {"keywords": ["segfault", "segmentation fault", "RuntimeError", "WinError", "WindowsError", "MemoryError", "OverflowError", "ZeroDivisionError", "SystemError"], "labels": ["priority-high"], "assignees": [""]},
{"keywords": ["wheel", "wheels"], "labels": ["wheels"], "assignees": [""]}
]'
diff --git a/MANIFEST.in b/MANIFEST.in
index 2bed87e7..5c02ed13 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -122,6 +122,7 @@ include scripts/internal/download_wheels_github.py
include scripts/internal/fix_flake8.py
include scripts/internal/generate_manifest.py
include scripts/internal/git_pre_commit.py
+include scripts/internal/github_issue_labeler.py
include scripts/internal/print_access_denied.py
include scripts/internal/print_announce.py
include scripts/internal/print_api_speed.py
diff --git a/Makefile b/Makefile
index f03930dd..e127a30c 100644
--- a/Makefile
+++ b/Makefile
@@ -325,5 +325,8 @@ bench-oneshot-2: ## Same as above but using perf module (supposed to be more pr
check-broken-links: ## Look for broken links in source files.
git ls-files | xargs $(PYTHON) -Wa scripts/internal/check_broken_links.py
+github-issue-labeler: ## Apply labels to GitHub issues from their titles
+ $(PYTHON) scripts/internal/github_issue_labeler.py --tokenfile=~/.github.token
+
help: ## Display callable targets.
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
diff --git a/scripts/internal/github_issue_labeler.py b/scripts/internal/github_issue_labeler.py
new file mode 100755
index 00000000..0ef51a36
--- /dev/null
+++ b/scripts/internal/github_issue_labeler.py
@@ -0,0 +1,110 @@
+#!/usr/bin/env python3
+
+# Copyright (c) 2009 Giampaolo Rodola'. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""
+Check for certain keywords in GitHub's issue's titles and apply the
+appropriate labels.
+"""
+
+import argparse
+import os
+
+from github import Github
+
+
+USER = "giampaolo"
+PROJECT = "psutil"
+TOKEN = ""
+
+
+def check_for(issue, label, keywords):
+ for key in keywords:
+ if key in issue.title.lower():
+ issue_labels = [x.name for x in issue.labels]
+ if label not in issue_labels:
+ print("adding label %r to '#%r: %s'" % (
+ label, issue.number, issue.title))
+ issue.add_to_labels(label)
+
+
+def recommended_labels(issue):
+ # platforms
+ check_for(
+ issue, "linux",
+ ["linux", "ubuntu", "redhat", "mint", "centos", "red hat", "archlinux",
+ "debian", "alpine", "gentoo", "fedora", "slackware", "suse", "RHEL",
+ "opensuse", "manylinux", "apt", "rpm", "yum", "/sys/class",
+ "/sys/block", "/proc/net", "/proc/disk", "/proc/smaps"])
+ check_for(
+ issue, "windows",
+ ["windows", "win32", "WinError", "WindowsError", "win10", "win7",
+ "win", "mingw", "msys", "studio", "microsoft", "make.bat",
+ "CloseHandle", "GetLastError", "NtQuery", "DLL", "MSVC", "TCHAR",
+ "WCHAR", ".bat", "OpenProcess", "TerminateProcess",
+ "appveyor"])
+ check_for(
+ issue, "macos",
+ ["macos", "mac ", "osx", "os x", "mojave", "sierra", "capitan",
+ "yosemite", "catalina", "xcode", "darwin"])
+ check_for(issue, "aix", ["aix"])
+ check_for(issue, "cygwin", ["cygwin"])
+ check_for(issue, "freebsd", ["freebsd"])
+ check_for(issue, "netbsd", ["netbsd"])
+ check_for(issue, "openbsd", ["openbsd"])
+ check_for(issue, "sunos", ["sunos", "solaris"])
+ check_for(issue, "unix", ["makefile"])
+ check_for(issue, "wsl", ["wsl"])
+ check_for(issue, "pypy", ["pypy"])
+ check_for(
+ issue, "unix",
+ ["psposix", "waitpid", "statvfs", "/dev/tty", "/dev/pts"])
+
+ # types
+ check_for(issue, "bug", ["bug", "raise", "exception", "traceback"])
+ check_for(issue, "enhancement", ["enhancement"])
+ check_for(
+ issue, "memleak",
+ ["memory leak", "leaks memory", "memleak", "mem leak"])
+
+ # doc
+ check_for(
+ issue, "doc",
+ ["doc ", "document ", "documentation", "readthedocs", "pythonhosted",
+ "HISTORY.rst", "README", "dev guide", "devguide", "sphinx"])
+ check_for(issue, "api", ["idea", "proposal", "api", "feature"])
+ check_for(issue, "performance", ["performance", "speedup", "slow", "fast"])
+
+ # tests
+ check_for(
+ issue, "tests",
+ ["test", "tests", "travis", "coverage", "cirrus", "appveyor",
+ "continuous integration", "unittest", "pytest"])
+ check_for(issue, "wheels", ["wheel", "wheels"])
+
+ # critical errors
+ check_for(
+ issue, "priority-high",
+ ["WinError", "WindowsError", "RuntimeError", "segfault",
+ "segmentation fault", "ZeroDivisionError", "SystemError"])
+
+
+def main():
+ global TOKEN
+ parser = argparse.ArgumentParser(description='GitHub issue labeler')
+ parser.add_argument('--tokenfile', required=True)
+ args = parser.parse_args()
+ with open(os.path.expanduser(args.tokenfile)) as f:
+ TOKEN = f.read().strip()
+
+ g = Github(TOKEN)
+ repo = g.get_repo("%s/%s" % (USER, PROJECT))
+ issues = repo.get_issues(state='all')
+ for issue in issues:
+ recommended_labels(issue)
+
+
+if __name__ == '__main__':
+ main()