-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get GitHub issues from dependency repo
- Loading branch information
Showing
5 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const { Redis } = require('@senecacdot/satellite'); | ||
const { request } = require('@octokit/request'); | ||
|
||
const hasGitHubExpired = (dateTime) => Date.now() - dateTime > 60 * 60 * 1000; | ||
|
||
const gitHubInformationRequestor = {}; | ||
|
||
async function constructGitHubRequest(packageName, gitHubUrl) { | ||
const labelsToSearchFor = ['hacktoberfest', 'good first issue', 'help wanted']; | ||
|
||
const [owner, repo] = new URL(gitHubUrl).pathname.substring(1).split('/'); | ||
let issues = []; | ||
|
||
for (const label of labelsToSearchFor) { | ||
const response = await request('GET /repos/{owner}/{repo}/issues{?assignee,state,labels}', { | ||
owner, | ||
repo, | ||
assignee: 'none', | ||
state: 'open', | ||
labels: label, | ||
}); | ||
|
||
if (response.status != 200) { | ||
continue; | ||
} | ||
|
||
issues = issues.concat( | ||
response.data.map((issue) => { | ||
return { | ||
htmlUrl: issue.html_url, | ||
title: issue.title, | ||
body: issue.body, | ||
createdAt: issue.created_at, | ||
}; | ||
}) | ||
); | ||
} | ||
|
||
return issues; | ||
} | ||
|
||
async function requestGitHubInfo(packageName, gitHubUrl) { | ||
const request = gitHubInformationRequestor[packageName]; | ||
|
||
if (request && !hasGitHubExpired(request.expireAt)) { | ||
return request.request; | ||
} | ||
|
||
const newRequest = constructGitHubRequest(packageName, gitHubUrl); | ||
|
||
const now = new Date(Date.now()); | ||
now.setHours(now.getHours() + 1); | ||
|
||
gitHubInformationRequestor[packageName] = { | ||
expireAt: now, | ||
request: newRequest, | ||
}; | ||
|
||
return await newRequest; | ||
} | ||
|
||
module.exports = { | ||
requestGitHubInfo, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters