-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathgithub-bounties.js
125 lines (112 loc) · 4.67 KB
/
github-bounties.js
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
export class GitHubBountyFetcher {
constructor() {
this.owner = 'ai16z';
this.repo = 'eliza';
this.baseUrl = 'https://api.github.com';
}
// Helper method to ensure label text is readable
getLabelTextColor(backgroundColor) {
const hex = backgroundColor.replace('#', '');
const r = parseInt(hex.substr(0, 2), 16);
const g = parseInt(hex.substr(2, 2), 16);
const b = parseInt(hex.substr(4, 2), 16);
const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
return luminance > 0.5 ? '#000000' : '#FFFFFF';
}
async fetchBountyIssues() {
try {
const url = `${this.baseUrl}/repos/${this.owner}/${this.repo}/issues?labels=Bounty&state=open`;
console.log('Fetching from URL:', url);
const response = await fetch(url, {
headers: {
'Accept': 'application/vnd.github.v3+json'
},
cache: 'no-store'
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const issues = await response.json();
return this.processIssues(issues);
} catch (error) {
console.error('Error fetching bounty issues:', error);
return [];
}
}
processIssues(issues) {
return issues.map(issue => ({
title: issue.title,
number: issue.number,
url: issue.html_url,
created_at: new Date(issue.created_at),
updated_at: new Date(issue.updated_at),
labels: issue.labels.map(label => ({
name: label.name,
color: label.color,
textColor: this.getLabelTextColor(`#${label.color}`)
})),
body: issue.body,
user: {
login: issue.user.login,
avatar: issue.user.avatar_url,
profile: issue.user.html_url
}
}));
}
}
// Only run browser code if we're in a browser environment
if (typeof window !== 'undefined') {
document.addEventListener('DOMContentLoaded', async () => {
try {
const container = document.getElementById('bounty-container');
if (!container) {
console.error('Bounty container not found');
return;
}
container.innerHTML = '<p>Loading bounties...</p>';
const bountyFetcher = new GitHubBountyFetcher();
const issues = await bountyFetcher.fetchBountyIssues();
if (issues.length === 0) {
container.innerHTML = '<p class="no-bounties">No bounty issues found.</p>';
return;
}
const issuesHTML = issues.map(issue => `
<div class="bounty-issue">
<div class="bounty-header">
<h3>
<a href="${issue.url}" target="_blank" rel="noopener noreferrer">
${issue.title}
</a>
</h3>
<div class="issue-meta">
<span class="issue-number">#${issue.number}</span>
<span class="issue-date">Created: ${issue.created_at.toLocaleDateString()}</span>
</div>
</div>
<div class="bounty-content">
<div class="issue-labels">
${issue.labels.map(label =>
`<span class="label" style="background-color: #${label.color}; color: ${label.textColor}">
${label.name}
</span>`
).join('')}
</div>
<div class="issue-user">
<img src="${issue.user.avatar}" alt="${issue.user.login}" class="user-avatar">
<a href="${issue.user.profile}" target="_blank" rel="noopener noreferrer">
${issue.user.login}
</a>
</div>
</div>
</div>
`).join('');
container.innerHTML = issuesHTML;
} catch (error) {
console.error('Error displaying bounties:', error);
const container = document.getElementById('bounty-container');
if (container) {
container.innerHTML = `<p class="error-message">Error loading bounties: ${error.message}</p>`;
}
}
});
}