Skip to content

Commit 61d6333

Browse files
committed
Add missing Doc Blocks
1 parent e930dd6 commit 61d6333

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

main.js

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ const gitHubAPIURLs = {
77
'https://api.github.com/search/issues?per_page=1000&q=-label:invalid+created:%year%-09-30T00:00:00-12:00..%year%-10-31T23:59:59-12:00+type:pr+is:public+author:%username%'
88
}
99

10+
/**
11+
* Returns the minimum number of pull requests required for Hacktoberfest completion for a given year
12+
* @param {number} year - The year to check requirements for
13+
* @returns {number} The minimum number of pull requests required (5 for 2018, 6 for 2025, 4 for all other years)
14+
*/
1015
const getMinPullRequests = (year) => {
1116
switch (year) {
1217
case 2018:
@@ -18,6 +23,13 @@ const getMinPullRequests = (year) => {
1823
}
1924
}
2025

26+
/**
27+
* Validates that the provided year is within acceptable bounds for Hacktoberfest
28+
* @private
29+
* @param {number} year - The year to validate
30+
* @throws {Error} If year is greater than the current year
31+
* @throws {Error} If year is less than 2013 (when Hacktoberfest started)
32+
*/
2133
const _checkForValidYear = (year) => {
2234
let currentYear = new Date().getFullYear()
2335
if (year > currentYear) {
@@ -28,6 +40,13 @@ const _checkForValidYear = (year) => {
2840
}
2941
}
3042

43+
/**
44+
* Makes an HTTP request to the specified URL
45+
* @private
46+
* @param {string} url - The URL to fetch
47+
* @returns {Promise<string>} A promise that resolves to the response text
48+
* @throws {Error} If the HTTP request fails
49+
*/
3150
const _query = async (url) => {
3251
const response = await fetch(url, {
3352
headers: { 'User-Agent': 'request' }
@@ -40,6 +59,15 @@ const _query = async (url) => {
4059
return response.text()
4160
}
4261

62+
/**
63+
* Processes the result of a GitHub API query
64+
* @private
65+
* @param {string} url - The URL to query
66+
* @param {function} [callback] - Optional callback function to handle the result
67+
* @param {function} [transform] - Optional transformation function to apply to the parsed data
68+
* @returns {Promise|undefined} Returns a promise if no callback is provided, otherwise undefined
69+
* @throws {Error} If there's a problem retrieving information from the API
70+
*/
4371
const _processResult = (url, callback, transform) => {
4472
if (callback) {
4573
_query(url)
@@ -58,6 +86,12 @@ const _processResult = (url, callback, transform) => {
5886
}
5987
}
6088

89+
/**
90+
* Parses a JSON string into an object
91+
* @private
92+
* @param {string} body - The JSON string to parse
93+
* @returns {Object} The parsed JSON object
94+
*/
6195
const jsonPipe = (body) => JSON.parse(body)
6296

6397

@@ -72,6 +106,18 @@ const getUserInfo = (username, callback) => {
72106
return _processResult(url, callback)
73107
}
74108

109+
/**
110+
* Transforms GitHub API pull request data into Hacktoberfest statistics
111+
* @private
112+
* @param {number} minPullRequest - The minimum number of pull requests required
113+
* @returns {function} A transformation function that takes GitHub API stats and returns formatted Hacktoberfest stats
114+
* @returns {Object} The transformed stats object
115+
* @returns {boolean} returns.completed - Whether the user has completed Hacktoberfest requirements
116+
* @returns {number} returns.current - The current number of pull requests
117+
* @returns {number} returns.required - The required number of pull requests
118+
* @returns {string} returns.progress - Progress as a formatted string (e.g., "4/4")
119+
* @returns {string[]} returns.contributions - Array of repository URLs where contributions were made
120+
*/
75121
const _transformHacktoberfestResult = (minPullRequest) => (statsInfo) => ({
76122
completed: !!(statsInfo.total_count >= minPullRequest),
77123
current: statsInfo.total_count,
@@ -107,4 +153,4 @@ const getHacktoberfestStats = (username, year, callback) => {
107153
return _processResult(url, callback, _transformHacktoberfestResult(minPullRequest))
108154
}
109155

110-
export { getUserInfo, getHacktoberfestStats }
156+
export { getUserInfo, getHacktoberfestStats }

0 commit comments

Comments
 (0)