Last active
November 3, 2020 12:38
-
-
Save wintondeshong/4f6ebb6d435edde7f77891559437301f to your computer and use it in GitHub Desktop.
Calculate maintainer reviews for Hacktoberfest using AndcultureCode/AndcultureCode.Cli
This file contains hidden or 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
// https://github.com/AndcultureCode/AndcultureCode.Cli/blob/main/and-cli-github.js | |
await github.getToken(); // make all requests authenticated | |
const repos = await github.repositoriesByAndculture(); | |
echo.headerSuccess("Calculating review counts..."); | |
const reviewCounts = {}; | |
await js.asyncForEach(repos, async (repo) => { | |
echo.message(` - Processing ${repo.full_name}`); | |
if (repo.owner.login == null) { | |
return; | |
} | |
const prs = await github.getPullRequests( | |
repo.owner.login, | |
repo.name, | |
"closed" | |
); | |
await js.asyncForEach(prs, async (pr) => { | |
const created = new Date(pr.created_at); | |
if (created.getMonth() !== 9) { // hacktoberfest | |
// october | |
return; | |
} | |
const reviews = await github.getPullRequestReviews( | |
repo.owner.login, | |
repo.name, | |
pr.number | |
); | |
reviews.forEach((review) => { | |
if (review.user == null) { | |
return; | |
} | |
const user = review.user.login; | |
if (reviewCounts[user] == null) { | |
reviewCounts[user] = 0; | |
} | |
reviewCounts[user]++; | |
}); | |
}); | |
}); | |
echo.message(JSON.stringify(reviewCounts, null, 4)); |
This file contains hidden or 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
// https://github.com/AndcultureCode/AndcultureCode.Cli/blob/main/modules/github.js | |
/** | |
* Retrieves list of pull requests for a repository | |
* @param {string} owner user or organization name owning the repo | |
* @param {string} repoName name of repository | |
* @param {string} state all, closed, open | |
*/ | |
async getPullRequests(owner, repoName, state) { | |
state = StringUtils.isEmpty(state) ? "all" : state; | |
try { | |
const response = await _client().pulls.list({ | |
owner: owner, | |
repo: repoName, | |
state, | |
}); | |
_throwIfApiError(response); | |
return response.data; | |
} catch (e) { | |
echo.error( | |
`Error retrieving pull requests for ${owner}/${repoName} - ${e}` | |
); | |
return null; | |
} | |
}, | |
/** | |
* Retrieves list of reviews for a pull request | |
* @param {string} owner user or organization name owning the repo | |
* @param {string} repoName name of repository | |
* @param {number} number pull request number | |
*/ | |
async getPullRequestReviews(owner, repoName, number) { | |
try { | |
const response = await _client().pulls.listReviews({ | |
owner: owner, | |
repo: repoName, | |
pull_number: number, | |
}); | |
_throwIfApiError(response); | |
return response.data; | |
} catch (e) { | |
echo.error( | |
`Error retrieving reviews for ${owner}/${repoName}/pulls/${number} - ${e}` | |
); | |
return null; | |
} | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Quick and dirty script whipped up in 20-30 minutes - likely to pretty it up and add to
and-cli