Python automations? #613
-
How can I automatically generate Kanban charts for GitHub projects using Python? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hello, @grahamj89 To generate Kanban charts for GitHub projects, you can use the GitHub API to retrieve issues from a specific project board and categorize them by columns (e.g., To Do, In Progress, Done). Here's a simple approach:
Here's an outline of a Python script: import requests
import matplotlib.pyplot as plt
# Set up GitHub API authentication (personal access token)
headers = {
'Authorization': 'token YOUR_GITHUB_TOKEN',
}
# Function to fetch issues from a GitHub project board
def fetch_kanban_data(owner, repo, project_id):
url = f'https://api.github.com/repos/{owner}/{repo}/projects/{project_id}/columns'
response = requests.get(url, headers=headers)
columns = response.json()
kanban_data = {}
for column in columns:
column_id = column['id']
column_name = column['name']
# Fetch issues for each column
issues_url = f'https://api.github.com/projects/columns/{column_id}/cards'
issues_response = requests.get(issues_url, headers=headers)
issues = issues_response.json()
kanban_data[column_name] = [issue['note'] for issue in issues]
return kanban_data
# Function to visualize the Kanban board (basic chart)
def plot_kanban(kanban_data):
columns = list(kanban_data.keys())
counts = [len(kanban_data[col]) for col in columns]
plt.bar(columns, counts)
plt.xlabel('Kanban Columns')
plt.ylabel('Number of Issues')
plt.title('GitHub Project Kanban Chart')
plt.show()
# Example usage
if __name__ == '__main__':
owner = 'your-github-username'
repo = 'your-repo-name'
project_id = 'your-project-id' # Replace with your actual project ID
kanban_data = fetch_kanban_data(owner, repo, project_id)
plot_kanban(kanban_data) Explanation:
Good luck!! |
Beta Was this translation helpful? Give feedback.
-
📌 Automatically Generate Kanban Charts for GitHub Projects Using PythonIf you want to automatically generate Kanban charts for your GitHub projects using Python, you can achieve this by integrating the GitHub API with a visualization library like Matplotlib, Plotly, or Pandas. Here’s a simple approach to get started: 1️⃣ Fetch Data from GitHub ProjectsGitHub provides a Projects API that allows you to retrieve issues, pull requests, and project board columns. You’ll need a Personal Access Token (PAT) to authenticate requests. import requests
GITHUB_TOKEN = "your_personal_access_token"
OWNER = "your_github_username"
REPO = "your_repository_name"
headers = {"Authorization": f"token {GITHUB_TOKEN}"}
def get_issues():
url = f"https://api.github.com/repos/{OWNER}/{REPO}/issues"
response = requests.get(url, headers=headers)
return response.json()
issues = get_issues()
for issue in issues:
print(issue["title"], "-", issue["state"]) This script fetches all issues from your repository, which can be categorized into a Kanban-style board. 2️⃣ Organize Data into Kanban ColumnsGitHub Projects usually have statuses like To Do, In Progress, and Done. You can categorize issues based on labels, milestones, or state (open/closed). kanban = {"To Do": [], "In Progress": [], "Done": []}
for issue in issues:
labels = [label["name"].lower() for label in issue.get("labels", [])]
if "in progress" in labels:
kanban["In Progress"].append(issue["title"])
elif issue["state"] == "closed":
kanban["Done"].append(issue["title"])
else:
kanban["To Do"].append(issue["title"])
print(kanban) 3️⃣ Generate Kanban Charts using MatplotlibNow, let’s visualize the Kanban board using a bar chart. import matplotlib.pyplot as plt
categories = list(kanban.keys())
values = [len(kanban[cat]) for cat in categories]
plt.figure(figsize=(8, 5))
plt.bar(categories, values, color=["blue", "orange", "green"])
plt.xlabel("Kanban Columns")
plt.ylabel("Number of Issues")
plt.title("GitHub Project Kanban Chart")
plt.show() 4️⃣ (Optional) Create an Interactive Kanban Board using PlotlyFor a more interactive visualization, use Plotly: import plotly.express as px
import pandas as pd
data = []
for status, issues in kanban.items():
for issue in issues:
data.append({"Status": status, "Issue": issue})
df = pd.DataFrame(data)
fig = px.bar(df, x="Status", title="GitHub Kanban Board", color="Status")
fig.show() |
Beta Was this translation helpful? Give feedback.
Hello, @grahamj89
To generate Kanban charts for GitHub projects, you can use the GitHub API to retrieve issues from a specific project board and categorize them by columns (e.g., To Do, In Progress, Done). Here's a simple approach:
requests
library to access GitHub's API./projects
and/projects/columns
endpoints.matplotlib
orplotly
to create Kanban charts.Here's an outline of a Python script: