Skip to content

Commit 958d16a

Browse files
committed
optimizing api calls, replaced ajax with modern await/async
Signed-off-by: Vedansh Saini <[email protected]>
1 parent 7e092b8 commit 958d16a

File tree

1 file changed

+24
-63
lines changed

1 file changed

+24
-63
lines changed

src/scripts/scrumHelper.js

Lines changed: 24 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -150,71 +150,32 @@ function allIncluded(outputTarget = 'email') {
150150
let yesterdayDisplayPadded = ('0000' + yesterdayYear.toString()).slice(-4) + '-' + ('00' + yesterdayMonth.toString()).slice(-2) + '-' + ('00' + yesterdayDay.toString()).slice(-2);
151151
return yesterdayDisplayPadded;
152152
}
153+
153154
// fetch github data
154-
function fetchGithubData() {
155-
let issueUrl = 'https://api.github.com/search/issues?q=author%3A' +
156-
githubUsername +
157-
'+org%3Afossasia+created%3A' +
158-
startingDate +
159-
'..' +
160-
endingDate +
161-
'&per_page=100';
162-
163-
$.ajax({
164-
dataType: 'json',
165-
type: 'GET',
166-
url: issueUrl,
167-
error: (xhr, textStatus, errorThrown) => {
168-
console.error('Error fetching GitHub data:', {
169-
status: xhr.status,
170-
textStatus: textStatus,
171-
error: errorThrown
172-
});
173-
},
174-
success: (data) => {
175-
githubIssuesData = data;
176-
writeGithubIssuesPrs();
177-
},
178-
});
155+
async function fetchGithubData() {
156+
try {
157+
const issueUrl = `https://api.github.com/search/issues?q=author%3A${githubUsername}+org%3Afossasia+created%3A${startingDate}..${endingDate}&per_page=100`;
158+
const prUrl = `https://api.github.com/search/issues?q=author%3A${githubUsername}+org%3Afossasia+updated%3A${startingDate}..${endingDate}&per_page=100`;
159+
const userUrl = `https://api.github.com/users/${githubUsername}`;
160+
161+
// Fetch issues
162+
const issuesRes = await fetch(issueUrl);
163+
if (!issuesRes.ok) throw new Error(`Error fetching Github issues: ${issuesRes.status} ${issuesRes.statusText}`);
164+
githubIssuesData = await issuesRes.json();
165+
writeGithubIssuesPrs();
179166

180-
// PR reviews fetch
181-
let prUrl = 'https://api.github.com/search/issues?q=commenter%3A' +
182-
githubUsername +
183-
'+org%3Afossasia+updated%3A' +
184-
startingDate +
185-
'..' +
186-
endingDate +
187-
'&per_page=100';
188-
189-
$.ajax({
190-
dataType: 'json',
191-
type: 'GET',
192-
url: prUrl,
193-
error: (xhr, textStatus, errorThrown) => {
194-
console.error('Error fetching PR reviews:', {
195-
status: xhr.status,
196-
textStatus: textStatus,
197-
error: errorThrown
198-
});
199-
},
200-
success: (data) => {
201-
githubPrsReviewData = data;
202-
writeGithubPrsReviews();
203-
},
204-
});
205-
// fetch github user data
206-
let userUrl = 'https://api.github.com/users/' + githubUsername;
207-
$.ajax({
208-
dataType: 'json',
209-
type: 'GET',
210-
url: userUrl,
211-
error: (xhr, textStatus, errorThrown) => {
212-
// error
213-
},
214-
success: (data) => {
215-
githubUserData = data;
216-
},
217-
});
167+
// Fetch PR reviews
168+
const prRes = await fetch(prUrl);
169+
if(!prRes.ok) throw new Error(`Error fetching Github PR reviews: ${prRes.status} ${prRes.statusText}`);
170+
githubPrsReviewData = await prRes.json();
171+
writeGithubPrsReviews();
172+
173+
// Fetch github user data
174+
const userRes = await fetch(userUrl);
175+
if(!userRes.ok) throw new Error(`Error fetching Github user data: ${userRes.status} ${userRes.statusText}`);
176+
} catch(err) {
177+
console.error(err);
178+
}
218179
}
219180

220181
function formatDate(dateString) {

0 commit comments

Comments
 (0)