This commit is contained in:
Edward Betts 2024-03-26 13:42:43 +00:00
commit 0aaabd8671
3 changed files with 72 additions and 3 deletions

55
README.md Normal file
View file

@ -0,0 +1,55 @@
# README for Bug Chart
## Overview
Bug Chart is a Python tool designed to visualize the number of open bugs over time in a Forgejo repository. It retrieves data from Forgejo's API and generates a line graph showing the trend of open bugs. This tool is particularly useful for project managers and developers who want to track bug trends in their software projects.
## Features
- **Data Retrieval**: Downloads bug data from Forgejo using API tokens.
- **Graph Generation**: Creates an HTML file with a line graph representing open bugs over time.
- **Caching**: Stores bug data locally to reduce API calls.
- **Refresh Capability**: Can be manually refreshed to update the data and graph.
## Requirements
- Python 3
- Libraries: `requests`, `json`, `configparser`
## Installation
Clone the repository from [https://git.4angle.com/edward/bug-chart](https://git.4angle.com/edward/bug-chart). Ensure you have Python 3 and the required libraries installed.
## Configuration
Create a configuration file with the following structure:
```ini
[forgejo]
hostname=<Your Forgejo hostname>
token=<Your Forgejo Token>
[output]
dest=<Path to output HTML file>
cache=<Path to cache JSON file>
```
## Usage
Run `build.py` to generate the bug chart. The script can be scheduled to run periodically using cron. For example:
```bash
40 9 * * * python3 ~/src/bug-chart/backup.py --refresh
```
To force a data refresh, run:
```bash
python3 build.py --refresh
```
## Output
The script generates an HTML file (`chart.html`) displaying the line graph of open bugs over time.
## License
This project is licensed under the MIT License.
## Contact
For queries or contributions, please email Edward Betts at [edward@4angle.com](mailto:edward@4angle.com).
## Acknowledgements
Developed and maintained by Edward Betts.

View file

@ -7,9 +7,8 @@ import json
import os
import sys
import typing
from datetime import datetime
from datetime import datetime, timezone
import pytz
import requests
config = configparser.ConfigParser()
@ -69,7 +68,7 @@ def parse_date(date_str: str | None) -> datetime | None:
return None
fmt = "%Y-%m-%dT%H:%M:%SZ" if date_str.endswith("Z") else "%Y-%m-%dT%H:%M:%S%z"
return datetime.strptime(date_str, fmt).astimezone(pytz.utc)
return datetime.strptime(date_str, fmt).astimezone(timezone.utc)
def count_open_bugs(bug_reports: list[Bug]) -> list[tuple[str, int]]:

View file

@ -5,6 +5,8 @@
<title>Open bugs over time</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns/dist/chartjs-adapter-date-fns.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/hammerjs@2.0.8"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-zoom/dist/chartjs-plugin-zoom.min.js"></script>
</head>
<body>
@ -31,7 +33,20 @@ document.addEventListener('DOMContentLoaded', function () {
data: data
}]
},
options: {
plugins: {
zoom: {
pan: {
enabled: true,
},
zoom: {
wheel: { enabled: true },
pinch: { enabled: true },
mode: 'xy',
}
}
},
scales: {
x: {
type: 'time',