@rmdes/indiekit-endpoint-github 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -82,6 +82,7 @@ export default class GitHubEndpoint {
82
82
  // JSON API for widgets - publicly accessible
83
83
  publicRouter.get("/api/commits", commitsController.api);
84
84
  publicRouter.get("/api/stars", starsController.api);
85
+ publicRouter.get("/api/contributions", contributionsController.api);
85
86
  publicRouter.get("/api/activity", activityController.api);
86
87
  publicRouter.get("/api/featured", featuredController.api);
87
88
 
@@ -57,4 +57,31 @@ export const contributionsController = {
57
57
  next(error);
58
58
  }
59
59
  },
60
+
61
+ async api(request, response, next) {
62
+ try {
63
+ const { username, token, cacheTtl, limits } =
64
+ request.app.locals.application.githubConfig;
65
+
66
+ if (!username) {
67
+ return response.status(400).json({ error: "No username configured" });
68
+ }
69
+
70
+ const client = new GitHubClient({ token, cacheTtl });
71
+
72
+ let contributions = [];
73
+ try {
74
+ const events = await client.getUserEvents(username, 100);
75
+ contributions = utils
76
+ .extractContributions(events)
77
+ .slice(0, limits.contributions);
78
+ } catch (apiError) {
79
+ console.log("[contributions API] Events API error:", apiError.message);
80
+ }
81
+
82
+ response.json({ contributions });
83
+ } catch (error) {
84
+ next(error);
85
+ }
86
+ },
60
87
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rmdes/indiekit-endpoint-github",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "GitHub activity endpoint for Indiekit. Display commits, stars, contributions, and featured repositories.",
5
5
  "keywords": [
6
6
  "indiekit",