(plugin_instance, settings, device_config)
| 23 | """ |
| 24 | |
| 25 | def contributions_generate_image(plugin_instance, settings, device_config): |
| 26 | dimensions = device_config.get_resolution() |
| 27 | if device_config.get_config("orientation") == "vertical": |
| 28 | dimensions = dimensions[::-1] |
| 29 | |
| 30 | api_key = device_config.load_env_key("GITHUB_SECRET") |
| 31 | if not api_key: |
| 32 | raise RuntimeError("GitHub API Key not configured.") |
| 33 | |
| 34 | colors = settings.get("contributionColor[]") |
| 35 | github_username = settings.get("githubUsername") |
| 36 | if not github_username: |
| 37 | raise RuntimeError("GitHub username is required.") |
| 38 | |
| 39 | data = fetch_contributions(github_username, api_key) |
| 40 | grid, month_positions = parse_contributions(data, colors) |
| 41 | metrics = calculate_metrics(data) |
| 42 | |
| 43 | template_params = { |
| 44 | "username": github_username, |
| 45 | "grid": grid, |
| 46 | "month_positions": month_positions, |
| 47 | "metrics": metrics, |
| 48 | "plugin_settings": settings |
| 49 | } |
| 50 | |
| 51 | return plugin_instance.render_image( |
| 52 | dimensions, |
| 53 | "github_contributions.html", |
| 54 | "github.css", |
| 55 | template_params |
| 56 | ) |
| 57 | |
| 58 | # ------------------------- |
| 59 | # Helper functions |
no test coverage detected