diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2020-11-16 05:38:13 +0100 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2020-11-16 05:38:13 +0100 |
commit | 32e0d83016bbf5fdff9a562998fb8564adb3d952 (patch) | |
tree | 77f9303a0d040e46d59e0b53585a6db85e4a0cdc | |
parent | 0baa3810d9216f763c3f2fdf5c70fe5e453c36d3 (diff) | |
download | psutil-32e0d83016bbf5fdff9a562998fb8564adb3d952.tar.gz |
refact
-rw-r--r-- | Makefile | 2 | ||||
-rwxr-xr-x | scripts/internal/github_issue_labeler.py | 36 |
2 files changed, 25 insertions, 13 deletions
@@ -326,7 +326,7 @@ 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 + $(PYTHON) scripts/internal/github_issue_labeler.py 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 index 0ef51a36..32c22b4a 100755 --- a/scripts/internal/github_issue_labeler.py +++ b/scripts/internal/github_issue_labeler.py @@ -9,6 +9,7 @@ Check for certain keywords in GitHub's issue's titles and apply the appropriate labels. """ +from __future__ import print_function import argparse import os @@ -18,19 +19,24 @@ from github import Github USER = "giampaolo" PROJECT = "psutil" TOKEN = "" +DRYRUN = False -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 add_label(issue, label): + print("adding label %r to '#%r: %s'" % ( + label, issue.number, issue.title)) + if not DRYRUN: + issue.add_to_labels(label) -def recommended_labels(issue): +def set_labels_from_title(issue): + 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: + add_label(issue, label) + # platforms check_for( issue, "linux", @@ -92,9 +98,15 @@ def recommended_labels(issue): def main(): - global TOKEN + global TOKEN, DRYRUN + parser = argparse.ArgumentParser(description='GitHub issue labeler') - parser.add_argument('--tokenfile', required=True) + parser.add_argument('--tokenfile', required=False, + default='~/.github.token', + help="a path to file contaning the GH token") + parser.add_argument('-d', '--dryrun', required=False, default=False, + action='store_true', + help="don't make actual changes") args = parser.parse_args() with open(os.path.expanduser(args.tokenfile)) as f: TOKEN = f.read().strip() @@ -103,7 +115,7 @@ def main(): repo = g.get_repo("%s/%s" % (USER, PROJECT)) issues = repo.get_issues(state='all') for issue in issues: - recommended_labels(issue) + set_labels_from_title(issue) if __name__ == '__main__': |