Skip to content

Commit aa652ca

Browse files
authored
Merge pull request #3460 from mrmundt/bwom
Big Wheel of Misfortune - A Practice in Reviewing Old Issues
2 parents bd3e444 + 5ef19dd commit aa652ca

File tree

2 files changed

+185
-5
lines changed

2 files changed

+185
-5
lines changed

scripts/admin/README.md

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
# Contributors Script
1+
# Admin Scripts
2+
3+
--------
4+
5+
## Contributors Script
26

37
The `contributors.py` script is intended to be used to determine contributors
48
to a public GitHub repository within a given time frame.
59

6-
## Requirements
10+
### Requirements
711

8-
1. Python 3.7+
12+
1. Python 3.9+
913
1. [PyGithub](https://pypi.org/project/PyGithub/)
1014
1. A [GitHub Access Token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens) with `repo` access, exported to the environment variable `GH_TOKEN`
1115

12-
## Usage
16+
### Usage
1317

1418
```
1519
Usage: contributors.py <Org/Repo> <start_date> <end_date>
@@ -21,8 +25,48 @@ ALSO REQUIRED: Please generate a GitHub token (with repo permissions) and export
2125
Visit GitHub's official documentation for more details.
2226
```
2327

24-
## Results
28+
### Results
2529

2630
A list of contributors will print to the terminal upon completion. More detailed
2731
information, including authors, committers, reviewers, and pull requests, can
2832
be found in the `contributors-start_date-end_date.json` generated file.
33+
34+
35+
----------
36+
37+
## Big Wheel of Misfortune
38+
39+
The `bwom.py` script is intended to be used during weekly Dev Calls to generate
40+
a list of random open issues so developers can more proactively review issues
41+
in the backlog.
42+
43+
### Requirements
44+
45+
1. Python 3.9+
46+
1. [PyGithub](https://pypi.org/project/PyGithub/)
47+
1. A [GitHub Access Token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens) with `repo` access, exported to the environment variable `GH_TOKEN`
48+
49+
### Usage
50+
51+
```
52+
Usage: bwom.py <Org/Repo> [num_issues]
53+
<Org/Repo> : the GitHub organization/repository combo (e.g., Pyomo/pyomo)
54+
[Number of issues] : optional number of random open issues to return (default is 5)
55+
56+
ALSO REQUIRED: Please generate a GitHub token (with repo permissions) and export to the environment variable GH_TOKEN.
57+
Visit GitHub's official documentation for more details.
58+
```
59+
60+
### Results
61+
62+
A list of `n` random open issues (default is 5) on the target repository.
63+
This list includes the issue number, title, and URL. For example:
64+
65+
```
66+
Randomly selected open issues from Pyomo/pyomo:
67+
- Issue #2087: Add Installation Environment Test (URL: https://github.com/Pyomo/pyomo/issues/2087)
68+
- Issue #1310: Pynumero.sparse transpose (URL: https://github.com/Pyomo/pyomo/issues/1310)
69+
- Issue #2218: cyipopt does not support `symbolic_solver_labels` or `load_solutions=False` (URL: https://github.com/Pyomo/pyomo/issues/2218)
70+
- Issue #2123: k_aug interface in Pyomo sensitivity toolbox reports wrong answer (URL: https://github.com/Pyomo/pyomo/issues/2123)
71+
- Issue #1761: slow quadratic constraint creation (URL: https://github.com/Pyomo/pyomo/issues/1761)
72+
```

scripts/admin/bwom.py

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# ___________________________________________________________________________
2+
#
3+
# Pyomo: Python Optimization Modeling Objects
4+
# Copyright (c) 2008-2024
5+
# National Technology and Engineering Solutions of Sandia, LLC
6+
# Under the terms of Contract DE-NA0003525 with National Technology and
7+
# Engineering Solutions of Sandia, LLC, the U.S. Government retains certain
8+
# rights in this software.
9+
# This software is distributed under the 3-clause BSD License.
10+
# ___________________________________________________________________________
11+
12+
13+
"""
14+
This script is intended to query the GitHub REST API and get a list of open
15+
issues for a given repository, returning a random selection of n issues.
16+
17+
We colloquially call this the "Big Wheel of Misfortune" (BWOM)
18+
"""
19+
20+
import sys
21+
import random
22+
import os
23+
24+
from github import Github, Auth
25+
26+
27+
def get_random_open_issues(repository, number_to_return):
28+
"""
29+
Return a random selection of open issues from a repository.
30+
31+
Parameters
32+
----------
33+
repository : String
34+
The org/repo combination for target repository (GitHub). E.g.,
35+
IDAES/idaes-pse.
36+
number_to_return : int
37+
The number of random open issues to return.
38+
39+
Returns
40+
-------
41+
random_issues : List
42+
A list of dictionaries containing information about randomly selected open issues.
43+
"""
44+
# Collect the authorization token from the user's environment
45+
token = os.environ.get('GH_TOKEN')
46+
auth_token = Auth.Token(token)
47+
# Create a connection to GitHub
48+
gh = Github(auth=auth_token)
49+
# Create a repository object for the requested repository
50+
repo = gh.get_repo(repository)
51+
# Get all open issues
52+
open_issues = repo.get_issues(state='open')
53+
open_issues_list = [issue for issue in open_issues]
54+
55+
# Randomly select the specified number of issues
56+
random_issues = random.sample(
57+
open_issues_list, min(number_to_return, len(open_issues_list))
58+
)
59+
60+
return random_issues
61+
62+
63+
def print_big_wheel():
64+
"""Prints a specified ASCII art representation of a big wheel."""
65+
wheel = [
66+
" . __",
67+
" / \\ . ' || ' .",
68+
" )J( .` || `.",
69+
" (8)7) . \\ || / .",
70+
" (') .'/ _ \\ .-''-. / _ \\",
71+
" (=) .' J `- .' .--. '. -` L",
72+
" (') .' F======' ((<>)) '======J",
73+
" )J(' L '. `||' .' F",
74+
" (7(8) \\ _.- `-||-' -._ /",
75+
" \\' . / || \\ .",
76+
" / | . / || \\ .",
77+
" / | ` . _||_ . `",
78+
" / |___________ _.-||_________",
79+
" (()\\.'| ___.....'''' ||._ .'",
80+
" \\.`- .'. /__\\/ .'|",
81+
".'_______________________________.' ||",
82+
" |'---------------------------'|==.||",
83+
" ||.' || ||.' ||",
84+
" ||===========================|| (__)",
85+
" || ||",
86+
" (__) LGB (__)",
87+
" Credit: ascii.co.uk/art/spinningwheel",
88+
]
89+
for line in wheel:
90+
print(line)
91+
92+
93+
def main():
94+
if len(sys.argv) < 2 or len(sys.argv) > 3:
95+
print(f"Usage: {sys.argv[0]} <Org/Repo> [num_issues]")
96+
print(
97+
" <Org/Repo> : the GitHub organization/repository combo (e.g., Pyomo/pyomo)"
98+
)
99+
print(
100+
" [Number of issues] : optional number of random open issues to return (default is 5)"
101+
)
102+
print("")
103+
print(
104+
"ALSO REQUIRED: Please generate a GitHub token (with repo permissions) "
105+
"and export to the environment variable GH_TOKEN."
106+
)
107+
print(" Visit GitHub's official documentation for more details.")
108+
sys.exit(1)
109+
110+
repository = sys.argv[1]
111+
if len(sys.argv) == 3:
112+
try:
113+
num_issues = int(sys.argv[2])
114+
if num_issues <= 0:
115+
raise (ValueError("Need a positive number; why did you try <= 0?"))
116+
except ValueError as e:
117+
print(
118+
"*** ERROR: You did something weird when declaring the number of issues. Defaulting to 5.\n"
119+
f"(For posterity, this is the error that was returned: {e})\n"
120+
)
121+
num_issues = 5
122+
else:
123+
num_issues = 5
124+
125+
print("Spinning the Big Wheel of Misfortune...\n")
126+
print_big_wheel()
127+
128+
random_issues = get_random_open_issues(repository, num_issues)
129+
130+
print(f"\nRandomly selected open issues from {repository}:")
131+
for issue in random_issues:
132+
print(f"- Issue #{issue.number}: {issue.title} (URL: {issue.html_url})")
133+
134+
135+
if __name__ == '__main__':
136+
main()

0 commit comments

Comments
 (0)