the github badge is not looking right
https://blt.owasp.org/issue/4782 found by Anonymous at url: http://blt.owasp.org
@bug-reporter-bot i would like solve this issue
@DonnieBLT Hi sir there is nothing wrong with this badge The badge mentioned in the issue refers to the "view" badge which displays the number of views the repository has received. However if the issue is related to the styling of the badge I’d be happy to make the necessary changes. otherwise there doesn’t appear to be any issue here.
it is supposed to show a chart like it did before
⏰ This issue has been automatically unassigned due to 24 hours of inactivity. The issue is now available for anyone to work on again.
The reason this might not be working is because I was removing some library to save memory so we could try adding the library back or another way to generate the chart if it could be done without a library, that would be better
Hello @bug-reporter-bot ,
I’m new to this organization and would love to contribute. This will be my first pull request (PR), and I’d appreciate any guidance or feedback. Can I get started on this?
Thank you!
so this was fixed but it still doesn't look right I think the stats are grouped together and sorted before being displayed.
Oops, something went wrong! Please try again later. 🐰 💔
[!TIP] For best results, initiate chat on the files or code changes.
🧩 Analysis chain
I need to gather more information about this GitHub badge issue to provide a proper explanation. Let me check the GitHub issue and search for relevant code in the repository.
🏁 Script executed:
#!/bin/bash
# Fetch the issue details
gh issue view 3226 --repo OWASP-BLT/BLT
# Search for code related to GitHub badges
rg -i "github badge" --type-not=lock --type-not=json -A 5 -B 5
# Search for chart-related code
rg -i "chart" --type-not=lock --type-not=json -A 3 -B 3
# Look for view badge implementation
rg -i "view badge" --type-not=lock --type-not=json -A 3 -B 3
# Check recent changes related to badges
git log --grep="badge" -n 5 --pretty=format:"%h - %an, %ar : %s"
Length of output: 85305
🏁 Script executed:
#!/bin/bash
# Look for badge view implementations
rg -i "badge view" --type=py -A 5 -B 5
# Check all badge-related code in Python files
rg -i "badge" --type=py -A 3 -B 3 | head -n 200
# Look for the problematic repo badge rendering
rg -i "repo badge" --type=py -A 5 -B 5
# Check repo visit count related code
rg -i "repo_visit_count" --type=py -A 3 -B 3
# Look for Chart.js implementations for badges
rg -i "badge.*chart" --type=py -A 5 -B 5
Length of output: 25014
Let me search for the specific badge rendering implementation to understand how the charts are being generated.
🏁 Script executed:
#!/bin/bash
# Look for the badge implementation in the project view
rg -i "def get\(self, request, slug\)" --type=py -A 20 -B 5 | grep -A 40 "Badge"
# Check the URLs to find the badge routes
rg -i "badge" --type=py --files-with-matches | grep urls.py
cat $(rg -i "badge" --type=py --files-with-matches | grep urls.py)
# Check the actual badge rendering code
rg -i "create.*image" --type=py -A 10 -B 10
Length of output: 50161
@razzasid After checking the code and review comments, I can explain the GitHub badge issue:
The Issue
The GitHub badge is supposed to display a chart showing repository visit statistics, but it's not displaying correctly. According to DonnieBLT's comments, the badge previously showed a chart visualization, but now it doesn't appear as expected. The issue might be with how the visit data is being grouped and sorted before display.
Technical Details
The badge is generated through RepoBadgeView which creates a PNG image with visit statistics. The implementation:
- Tracks repository visits
- Collects visit count data from the last 7 days
- Creates an image with a bar chart using Python's PIL library
- Returns this as a badge image
Why It's Not Working
DonnieBLT mentioned removing a library to save memory, which likely affected how the chart is rendered. The current implementation uses basic PIL drawing functions rather than a specialized chart library, which might not produce the same visual quality or formatting.
Potential Solutions
- Restore the previously used charting library (if memory constraints allow)
- Improve the current PIL-based implementation to properly group and sort the data
- Use a more efficient charting library that maintains the desired visual quality
Looking at the model code, there's even a comment about this issue: # rename this to repo_visit_count and make sure the github badge works with this
Would you like me to look deeper into the badge implementation or suggest specific fixes?
@coderabbitai the chart is displaying a bar graph and it’s very close to working how it’s supposed to, but I think the time serious is not correct. It should be showing 30 days of most recent visits and started showing seven or so large paragraphs and not 30 days.
[!TIP] For best results, initiate chat on the files or code changes.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Find badge view implementation
rg -i "def badge" --type=py -A 15 -B 5
# Find code related to data collection for badges
rg -i "repo_visit" --type=py -A 5 -B 5
# Look for time period definitions in badge code
rg -i "days|time|period|series" --type=py | grep -i "badge" -A 5 -B 5
# Check for chart generation code
rg -i "generate.*chart|create.*chart|draw.*chart" --type=py -A 10 -B 10
Length of output: 16878
🏁 Script executed:
#!/bin/bash
# Find the badge implementation for repo badges specifically
rg "RepoBadgeView" --type=py -A 20 -B 10
# Find any chart drawing or image creation for badges
rg -i "create_image|draw_chart|badge" --type=py | grep -i "image" -A 10 -B 5
# Check for time series data collection related to the badge
rg -i "seven_days_ago|30_days|timedelta" --type=py | grep -i "repo" -A 10 -B 5
# Let's also check for any implementation of the badge view with image creation
rg -i "def get.*badge|image.*badge" --type=py -A 20 -B 5
Length of output: 18419
🏁 Script executed:
#!/bin/bash
# Let's get the entire implementation of RepoBadgeView
rg "def get\(self, request, slug\)" -A 100 -B 10 website/views/project.py
# Check for any time period definitions in the badge view
rg "timedelta" website/views/project.py | grep -A 5 -B 5 "days"
# Find where the image/chart is created in the project.py file
rg "Image|chart|draw|plot" website/views/project.py -A 5 -B 5
Length of output: 15736
@DonnieBLT I've found the exact issue with the GitHub badge! The code in RepoBadgeView is currently configured to display only 7 days of repository visits instead of 30 days.
Here's what's happening:
# Current code in RepoBadgeView
seven_days_ago = today - timedelta(days=7)
visit_counts = (
IP.objects.filter(path=request.path, created__date__gte=seven_days_ago)
# ... rest of the query
)
The issue is that with only 7 data points, each bar in the chart becomes very wide (the "large paragraphs" you're seeing). When the bar width is calculated using bar_width = chart_width / (len(counts) * 2), fewer days means wider bars.
To fix this:
- Change
seven_days_ago = today - timedelta(days=7)tothirty_days_ago = today - timedelta(days=30) - Update the filter to use this new time period
This will make each bar thinner and show the proper 30-day time series, as originally intended. The good news is this doesn't require adding back any library since it's using Python's PIL for rendering.
Would you like me to provide the exact code changes needed to implement this fix?
@coderabbitai please provide the exact code changes needed to implement this fix?
[!TIP] For best results, initiate chat on the files or code changes.
@razzasid Here are the exact code changes needed to fix the GitHub badge time series issue:
File: website/views/project.py
# In the RepoBadgeView.get() method, around line 1028-1038
# Change this:
seven_days_ago = today - timedelta(days=7)
visit_counts = (
IP.objects.filter(path=request.path, created__date__gte=seven_days_ago)
.extra({"created_date": "date(created)"})
.values("created_date")
.annotate(count=Count("id"))
.order_by("created_date")
)
# To this:
thirty_days_ago = today - timedelta(days=30)
visit_counts = (
IP.objects.filter(path=request.path, created__date__gte=thirty_days_ago)
.extra({"created_date": "date(created)"})
.values("created_date")
.annotate(count=Count("id"))
.order_by("created_date")
)
Summary of changes:
- Change
seven_days_agovariable name tothirty_days_ago - Change
timedelta(days=7)totimedelta(days=30) - Update the filter to use
thirty_days_agoinstead ofseven_days_ago
This will:
- Show 30 days of repository visit data instead of 7
- Make the chart bars thinner and more readable
- Provide a better time series visualization as originally intended
The fix is simple and doesn't require any additional libraries since it's just changing the time period for data collection.
/assign
Hello @Yajush-afk! You've been assigned to OWASP-BLT/BLT issue #3226. You have 24 hours to complete a pull request.
@DonnieBLT check on this once, please.