Public
HTTP (deprecated)
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Readme

GitHub Collaboration Suggester

This tool analyzes the recent GitHub activity of two users and suggests potential collaboration opportunities.

Features

  • Fetches the last 3 months of GitHub activity for two users
  • Summarizes activity including event counts, repositories, commits, issues, and pull requests
  • Uses AI to generate collaboration suggestions based on the activity summaries

Usage

To use it, make a GET request with two GitHub usernames as query parameters:

https://ejfox-githubcollabgen.web.val.run?user1=<username1>&user2=<username2>

Curl

  1. Compare two specific users:
    curl "https://ejfox-githubcollabgen.web.val.run?user1=ejfox&user2=stevekrouse"
    

Response

The API returns a plain text response with AI-generated collaboration suggestions, including:

  1. Potential collaborative projects
  2. Technologies to explore or learn
  3. Ways to complement each other's skills
  4. Opportunities for knowledge sharing or mentoring
  5. Possible open-source contributions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { OpenAI } from "https://esm.town/v/std/openai";
const OPENAI_API_KEY = "your_openai_api_key"; // Replace with your actual OpenAI API key
export default async function main(req: Request): Promise<Response> {
const url = new URL(req.url);
const user1 = url.searchParams.get("user1") || "ejfox";
const user2 = url.searchParams.get("user2") || "stevekrouse";
async function fetchUserActivity(username: string) {
const threeMonthsAgo = new Date(Date.now() - 90 * 24 * 60 * 60 * 1000).toISOString();
const response = await fetch(
`https://api.github.com/users/${username}/events?per_page=100&since=${threeMonthsAgo}`,
);
const data = await response.json();
if (!Array.isArray(data)) {
throw new Error(`Unexpected GitHub API response for user ${username}`);
}
return data;
}
function summarizeActivity(data: any[]): string {
const summary = [];
const repoSet = new Set<string>();
const eventCounts: { [key: string]: number } = {};
data.forEach((event: any) => {
repoSet.add(event.repo.name);
eventCounts[event.type] = (eventCounts[event.type] || 0) + 1;
if (event.type === "PushEvent" && event.payload.commits) {
event.payload.commits.forEach((commit: any) => {
summary.push(`Commit: ${commit.message.split("\n")[0].substring(0, 50)}`);
});
} else if (event.type === "IssuesEvent") {
summary.push(`Issue: ${event.payload.action} - ${event.payload.issue.title.substring(0, 50)}`);
} else if (event.type === "PullRequestEvent") {
summary.push(`PR: ${event.payload.action} - ${event.payload.pull_request.title.substring(0, 50)}`);
}
});
summary.unshift(`Repos: ${Array.from(repoSet).join(", ")}`);
Object.entries(eventCounts).forEach(([eventType, count]) => {
summary.unshift(`${eventType}: ${count}`);
});
return summary.join("\n");
}
try {
const [user1Data, user2Data] = await Promise.all([
fetchUserActivity(user1),
fetchUserActivity(user2),
]);
const user1Summary = summarizeActivity(user1Data);
const user2Summary = summarizeActivity(user2Data);
const openai = new OpenAI(OPENAI_API_KEY);
const completion = await openai.chat.completions.create({
model: "gpt-3.5-turbo",
messages: [
{
role: "system",
content:
"You are a helpful assistant that suggests collaboration opportunities based on GitHub activity summaries.",
},
{
role: "user",
content:
`Analyze the GitHub activity summaries of two users from the past 3 months and suggest innovative collaboration opportunities:
User 1 (${user1}):
${user1Summary}
User 2 (${user2}):
${user2Summary}
Based on these summaries, please provide:
1. Potential collaborative projects they could work on together
2. Technologies they could explore or learn from each other
3. Ways they could complement each other's skills
4. Opportunities for knowledge sharing or mentoring
5. Possible open-source contributions they could pursue together
Provide specific, actionable suggestions focusing on fostering meaningful collaboration and mutual growth.`,
},
],
max_tokens: 1024,
});
const suggestions = completion.choices[0].message.content;
return new Response(suggestions, {
headers: { "Content-Type": "text/plain" },
});
} catch (error) {
console.error("Error in main function:", error);
return new Response(`Error: ${error.message}. Please check the logs for more details.`, { status: 500 });
}
ejfox-githubcollabgen.web.val.run
August 16, 2024