Visualize the timeline of the number of issues on GitHub assigned to you in Python

Introduction

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)

Actual code and execution result

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.

issues.png

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

Visualize the timeline of the number of issues on GitHub assigned to you in Python
How to get the number of digits in Python
Get the number of readers of a treatise on Mendeley in Python
Output the number of CPU cores in Python
python beginners tried to predict the number of criminals
Try to estimate the number of likes on Twitter
Get the size (number of elements) of UnionFind in Python
To do the equivalent of Ruby's ObjectSpace._id2ref in Python
An easy way to pad the number with zeros depending on the number of digits [Python]
How to count the number of occurrences of each element in the list in Python with weight
Posted the number of new corona positives in Tokyo to Slack (deployed on Heroku)
read the tag assigned to you on ec2 with boto3
Analyzing data on the number of corona patients in Japan
Get the number of specific elements in a python list
[Homology] Count the number of holes in data with Python
[Python] I tried to visualize the follow relationship of Twitter
[Python] Programming to find the number of a in a character string that repeats a specified number of times.
How to know the number of GPUs from python ~ Notes on using multiprocessing with pytorch ~
In the python command python points to python3.8
Count the number of Thai and Arabic characters well in Python
How to determine the existence of a selenium element in Python
[Python] PCA scratch in the example of "Introduction to multivariate analysis"
[Cloudian # 9] Try to display the metadata of the object in Python (boto3)
[Python] Let's reduce the number of elements in the result in set operations
Output the contents of ~ .xlsx in the folder to HTML with Python
Feel free to change the label of the legend in Seaborn in python
I wrote the code to write the code of Brainf * ck in python
How to check the memory size of a dictionary in Python
Visualize the frequency of word occurrences in sentences with Word Cloud. [Python]
How to update the python version of Cloud Shell on GCP
How to write when you want to put a number after the group number to be replaced with a regular expression in re.sub of Python
[Python] Yuriko Koike Calculate the number of votes you need exactly [matplotlib]
If you want a singleton in python, think of the module as a singleton
Have Alexa run Python to give you a sense of the future
[Python] A program that calculates the number of socks to be paired
Python Note: When you want to know the attributes of an object
[Python] How to put any number of standard inputs in a list
Check the in-memory bytes of a floating point number float in Python
[Python] Calculate the number of digits required when filling in 0s [Note]
4 methods to count the number of occurrences of integers in a certain interval (including imos method) [Python implementation]
The result of installing python in Anaconda
I want to batch convert the result of "string" .split () in Python
(Python) I tried to analyze 1 million hands ~ I tried to estimate the number of AA ~
Download all the images attached to the body of the pull request on Github
The basics of running NoxPlayer in Python
You can see the transition of points in the J League on the graph!
I tried to visualize the text of the novel "Weathering with You" with WordCloud
[Completed version] Try to find out the number of residents in the town from the address list with Python
In search of the fastest FizzBuzz in Python
[Introduction to Python] Thorough explanation of the character string type used in Python!
I made a program to check the size of a file in Python
Project Euler # 17 "Number of Characters" in Python
An example of the answer to the reference question of the study session. In python.
Move the turtle to the place where you click the mouse with turtle in Python
Various ways to read the last line of a csv file in Python
How to pass the execution result of a shell command in a list in Python
plot the coordinates of the processing (python) list and specify the number of times in draw ()
Set the number of elements in a NumPy one-dimensional array to a power of 2 (0 padded)
How to write environment variables that you don't want to put on [GitHub] Python
I installed Pygame with Python 3.5.1 in the environment of pyenv on OS X
You can call the method of the class directly in Python3 without adding @staticmethod