I started personally managing tasks using Issues on GitHub. You can see the list of issues assigned to you at https://github.com/issues/assigned, but I could not see the past history of how much I actually processed, so I will visualize it using Python It was to be.
The main execution environment is as follows.
PyGithub
To hit the GitHub API from Python, there is a convenient module called PyGithub, so use this. You can install it with conda install -c conda-forge pygithub
.
You need to create a GitHub access token as a preliminary preparation. According to the article I tried to get GitHub information using PyGithub, check the repo of Select Scopes and create a token.
All you have to do is get the issues assigned to you and get their creation time (and closed time).
See PyGithub Official Documentation for details, but the code snippet is as follows.
from github import Github
#Create a Github object with a token
g = Github(token)
#Get with no arguments_myself as user(AuthenticatedUser)To get
user = g.get_user()
# get_user_Get a Paginated List of closed issues assigned to you in issues
issues = user.get_user_issues(filter="assigned", state="closed")
#Get creation time and close time
for issue in issues:
print(issue.created_at)
print(issue.closed_at)
The number and increase/decrease of issues in the last 30 days is graphed. In the title, I also wrote the number of open/closed within the period.
from datetime import datetime as dt
from datetime import timedelta
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from github import Github
#Initialization of time array
today = dt.strptime(dt.now().strftime("%Y-%m-%d"), "%Y-%m-%d")
times = []
counts = []
for day in range(-30, 2):
times.append(today + timedelta(days=day))
counts.append(0)
times2 = []
increments = []
decrements = []
for day in range(-30, 1):
times2.append(today + timedelta(days=day) + timedelta(hours=12))
increments.append(0)
decrements.append(0)
#Get issues on GitHub
token = "" #Your token
g = Github(token)
user = g.get_user()
for issue in user.get_user_issues(filter="assigned", state="open"):
created = issue.created_at
for index, time in enumerate(times):
if created <= time:
counts[index] += 1
for index, time2 in enumerate(times2):
begin_time = time2 - timedelta(hours=12)
end_time = time2 + timedelta(hours=12)
if begin_time <= created and created < end_time:
increments[index] += 1
for issue in user.get_user_issues(filter="assigned", state="closed"):
created = issue.created_at
closed = issue.closed_at
for index, time in enumerate(times):
if created <= time and time < closed:
counts[index] += 1
for index, time2 in enumerate(times2):
begin_time = time2 - timedelta(hours=12)
end_time = time2 + timedelta(hours=12)
if begin_time <= created and created < end_time:
increments[index] += 1
if begin_time <= closed and closed < end_time:
decrements[index] -= 1
#Drawing a graph
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.plot(times, counts, color="black")
ax.bar(times2, increments, color="red")
ax.bar(times2, decrements, color="blue")
ax.xaxis.set_major_formatter(mdates.DateFormatter('%m/%d'))
plt.title(
f"wm-ytakano's issues (open={np.sum(increments)} closed={np.sum(decrements)})")
plt.grid()
plt.savefig("issues.png ")
Recommended Posts