fix tests, rename "owners"->"owner" and "repos"->"repo"
This commit is contained in:
+12
-12
@@ -14,8 +14,8 @@ import { storeRequest } from "../src/common/database.js";
|
||||
export default async (req, res) => {
|
||||
const {
|
||||
username,
|
||||
repos,
|
||||
owners,
|
||||
repo,
|
||||
owner,
|
||||
hide,
|
||||
hide_title,
|
||||
hide_border,
|
||||
@@ -72,8 +72,8 @@ export default async (req, res) => {
|
||||
const safePattern = /^[-\w\/.,]+$/;
|
||||
if (
|
||||
(username && !safePattern.test(username)) ||
|
||||
(repos && !safePattern.test(repos)) ||
|
||||
(owners && !safePattern.test(owners))
|
||||
(repo && !safePattern.test(repo)) ||
|
||||
(owner && !safePattern.test(owner))
|
||||
) {
|
||||
return res.send(
|
||||
renderError(
|
||||
@@ -93,9 +93,9 @@ export default async (req, res) => {
|
||||
try {
|
||||
await storeRequest(req);
|
||||
const showStats = parseArray(show);
|
||||
const organizations = parseArray(owners);
|
||||
let repositories = parseArray(repos);
|
||||
repositories = repositories.map((repo) =>
|
||||
const repoOwner = parseArray(owner);
|
||||
let repository = parseArray(repo);
|
||||
repository = repository.map((repo) =>
|
||||
repo.includes("/") ? repo : `${username}/${repo}`,
|
||||
);
|
||||
|
||||
@@ -103,18 +103,18 @@ export default async (req, res) => {
|
||||
username,
|
||||
parseBoolean(include_all_commits),
|
||||
parseArray(exclude_repo),
|
||||
parseArray(role),
|
||||
showStats.includes("prs_merged") ||
|
||||
showStats.includes("prs_merged_percentage"),
|
||||
showStats.includes("discussions_started"),
|
||||
showStats.includes("discussions_answered"),
|
||||
repositories,
|
||||
organizations,
|
||||
repository,
|
||||
repoOwner,
|
||||
showStats.includes("prs_authored"),
|
||||
showStats.includes("prs_commented"),
|
||||
showStats.includes("prs_reviewed"),
|
||||
showStats.includes("issues_authored"),
|
||||
showStats.includes("issues_commented"),
|
||||
parseArray(role),
|
||||
);
|
||||
|
||||
let cacheSeconds = clampValue(
|
||||
@@ -160,8 +160,8 @@ export default async (req, res) => {
|
||||
show: showStats,
|
||||
},
|
||||
username,
|
||||
repositories,
|
||||
organizations,
|
||||
repository,
|
||||
repoOwner,
|
||||
),
|
||||
);
|
||||
} catch (err) {
|
||||
|
||||
@@ -178,7 +178,7 @@ To enable icons, you can pass `&show_icons=true` in the query param, like so:
|
||||
|
||||
### Filtering by repository and owner
|
||||
|
||||
To compute your stats for only a specific repository, you can pass a query parameter `&repos=<user_or_organization>/<repository>`. You can also specify a comma-separated list of multiple repositories, e.g. `&repos=userA/repositoryA,organizationB/repositoryB`. And you can select all repositories owned by specific organizations or users by providing a comma-separated list of owners via the `owners` query parameter, e.g. `&owners=userA,organizationB,organizationC`. The `repos` and `owners` filters are supported by the following items: `commits` (when used with `&include_all_commits=true`), `prs_authored`, `prs_commented`, `prs_reviewed`, `issues_authored` and `issues_commented`. Note that most of these items are not displayed by default, but [you can enable them individually](#showing-additional-individual-stats).
|
||||
To compute your stats for only a specific repository, you can pass a query parameter `&repo=<user_or_organization>/<repository>`. You can also specify a comma-separated list of multiple repositories, e.g. `&repo=userA/repositoryA,organizationB/repositoryB`. And you can select all repositories owned by specific organizations or users by providing a comma-separated list of owners via the `owner` query parameter, e.g. `&owner=userA,organizationB,organizationC`. The `repo` and `owner` filters are supported by the following items: `commits` (when used with `&include_all_commits=true`), `prs_authored`, `prs_commented`, `prs_reviewed`, `issues_authored` and `issues_commented`. Note that most of these items are not displayed by default, but [you can enable them individually](#showing-additional-individual-stats).
|
||||
|
||||
(Some of these mentioned items are similar to other items which are included by default, e.g. `issues_authored` is similar to `issues`. The difference is how these values are fetched - [via GraphQL or via REST API](https://github.com/anuraghazra/github-readme-stats/discussions/1770#number-of-commits-is-incorrect). The default items use GraphQL, but filtering by repository works better via REST API.)
|
||||
|
||||
@@ -384,14 +384,14 @@ If we don't support your language, please consider contributing! You can find mo
|
||||
| `include_all_commits` | Count total commits instead of just the current year commits. | boolean | `false` |
|
||||
| `line_height` | Sets the line height between text. | integer | `25` |
|
||||
| `exclude_repo` | Excludes specified repositories. Affects only the count for "Total Stars Earned". | string (comma-separated values) | `null` |
|
||||
| `repos` | Count only stats from the specified repositories. Affects only [certain items](#filtering-by-repository-and-owner). | string (comma-separated values) | `null` |
|
||||
| `owners` | Count only stats from the specified organizations or users. Affects only [certain items](#filtering-by-repository-and-owner). | string (comma-separated values) | `null` |
|
||||
| `repo` | Count only stats from the specified repositories. Affects only [certain items](#filtering-by-repository-and-owner). | string (comma-separated values) | `null` |
|
||||
| `owner` | Count only stats from the specified organizations or users. Affects only [certain items](#filtering-by-repository-and-owner). | string (comma-separated values) | `null` |
|
||||
| `custom_title` | Sets a custom title for the card. | string | `<username> GitHub Stats` |
|
||||
| `text_bold` | Uses bold text. | boolean | `true` |
|
||||
| `disable_animations` | Disables all animations in the card. | boolean | `false` |
|
||||
| `ring_color` | Color of the rank circle. | string (hex color) | `2f80ed` |
|
||||
| `number_format` | Switches between two available formats for displaying the card values: `short` (i.e. `6.6k`) and `long` (i.e. `6626`). | enum | `short` |
|
||||
| `show` | Shows [additional items](#showing-additional-individual-stats) on stats card (i.e. `reviews`, `discussions_started`, `discussions_answered`, `prs_merged` or `prs_merged_percentage`. And the following, which support the `repos` and `owners` filters: `prs_authored`, `prs_commented`, `prs_reviewed`, `issues_authored` or `issues_commented`). | string (comma-separated values) | `null` |
|
||||
| `show` | Shows [additional items](#showing-additional-individual-stats) on stats card (i.e. `reviews`, `discussions_started`, `discussions_answered`, `prs_merged` or `prs_merged_percentage`. And the following, which support the `repo` and `owner` filters: `prs_authored`, `prs_commented`, `prs_reviewed`, `issues_authored` or `issues_commented`). | string (comma-separated values) | `null` |
|
||||
|
||||
> [!NOTE]\
|
||||
> When hide\_rank=`true`, the minimum card width is 270 px + the title length and padding.
|
||||
@@ -678,11 +678,11 @@ Change the `?username=` value to your [WakaTime](https://wakatime.com) username.
|
||||
|
||||
* Showing stats for a specific repository
|
||||
|
||||

|
||||

|
||||
|
||||
* Showing stats for a specific organization
|
||||
|
||||

|
||||

|
||||
|
||||
* Showing icons
|
||||
|
||||
|
||||
@@ -214,8 +214,8 @@ const renderStatsCard = (
|
||||
stats,
|
||||
options = {},
|
||||
username,
|
||||
repos = [],
|
||||
owners = [],
|
||||
repo = [],
|
||||
owner = [],
|
||||
) => {
|
||||
const {
|
||||
name,
|
||||
@@ -360,7 +360,7 @@ const renderStatsCard = (
|
||||
};
|
||||
}
|
||||
|
||||
let repoFilter = encodeURIComponent(buildSearchFilter(repos, owners));
|
||||
let repoFilter = encodeURIComponent(buildSearchFilter(repo, owner));
|
||||
if (show.includes("prs_authored")) {
|
||||
STATS.prs_authored = {
|
||||
icon: icons.prs,
|
||||
|
||||
@@ -134,7 +134,7 @@ const statsFetcher = async ({
|
||||
includeMergedPullRequests,
|
||||
includeDiscussions,
|
||||
includeDiscussionsAnswers,
|
||||
ownerAffiliations: ownerAffiliations,
|
||||
ownerAffiliations,
|
||||
};
|
||||
let res = await retryer(fetcher, variables);
|
||||
if (res.data.errors) {
|
||||
@@ -172,7 +172,7 @@ const statsFetcher = async ({
|
||||
* @description Done like this because the GitHub API does not provide a way to fetch all the commits. See
|
||||
* #92#issuecomment-661026467 and #211 for more information.
|
||||
*/
|
||||
const totalItemsFetcher = async (username, repos, owners, type, filter) => {
|
||||
const totalItemsFetcher = async (username, repo, owner, type, filter) => {
|
||||
if (!githubUsernameRegex.test(username)) {
|
||||
logger.log("Invalid username provided.");
|
||||
throw new Error("Invalid username provided.");
|
||||
@@ -186,7 +186,7 @@ const totalItemsFetcher = async (username, repos, owners, type, filter) => {
|
||||
`https://api.github.com/search/` +
|
||||
type +
|
||||
`?per_page=1&q=` +
|
||||
buildSearchFilter(variables.repos, variables.owners).replaceAll(
|
||||
buildSearchFilter(variables.repo, variables.owner).replaceAll(
|
||||
" ",
|
||||
"+",
|
||||
) +
|
||||
@@ -201,7 +201,11 @@ const totalItemsFetcher = async (username, repos, owners, type, filter) => {
|
||||
|
||||
let res;
|
||||
try {
|
||||
res = await retryer(fetchTotalItems, { login: username, repos, owners });
|
||||
res = await retryer(fetchTotalItems, {
|
||||
login: username,
|
||||
repo,
|
||||
owner,
|
||||
});
|
||||
} catch (err) {
|
||||
logger.log(err);
|
||||
throw new Error(err);
|
||||
@@ -219,8 +223,8 @@ const totalItemsFetcher = async (username, repos, owners, type, filter) => {
|
||||
|
||||
const fetchRepoUserStats = async (
|
||||
username,
|
||||
repos,
|
||||
owners,
|
||||
repo,
|
||||
owner,
|
||||
include_prs_authored,
|
||||
include_prs_commented,
|
||||
include_prs_reviewed,
|
||||
@@ -231,8 +235,8 @@ const fetchRepoUserStats = async (
|
||||
if (include_prs_authored) {
|
||||
stats.totalPRsAuthored = await totalItemsFetcher(
|
||||
username,
|
||||
repos,
|
||||
owners,
|
||||
repo,
|
||||
owner,
|
||||
"issues",
|
||||
`author:${username}+type:pr`,
|
||||
);
|
||||
@@ -240,8 +244,8 @@ const fetchRepoUserStats = async (
|
||||
if (include_prs_commented) {
|
||||
stats.totalPRsCommented = await totalItemsFetcher(
|
||||
username,
|
||||
repos,
|
||||
owners,
|
||||
repo,
|
||||
owner,
|
||||
"issues",
|
||||
`commenter:${username}+-author:${username}+type:pr`,
|
||||
);
|
||||
@@ -249,8 +253,8 @@ const fetchRepoUserStats = async (
|
||||
if (include_prs_reviewed) {
|
||||
stats.totalPRsReviewed = await totalItemsFetcher(
|
||||
username,
|
||||
repos,
|
||||
owners,
|
||||
repo,
|
||||
owner,
|
||||
"issues",
|
||||
`reviewed-by:${username}+-author:${username}+type:pr`,
|
||||
);
|
||||
@@ -258,8 +262,8 @@ const fetchRepoUserStats = async (
|
||||
if (include_issues_authored) {
|
||||
stats.totalIssuesAuthored = await totalItemsFetcher(
|
||||
username,
|
||||
repos,
|
||||
owners,
|
||||
repo,
|
||||
owner,
|
||||
"issues",
|
||||
`author:${username}+type:issue`,
|
||||
);
|
||||
@@ -267,8 +271,8 @@ const fetchRepoUserStats = async (
|
||||
if (include_issues_commented) {
|
||||
stats.totalIssuesCommented = await totalItemsFetcher(
|
||||
username,
|
||||
repos,
|
||||
owners,
|
||||
repo,
|
||||
owner,
|
||||
"issues",
|
||||
`commenter:${username}+-author:${username}+type:issue`,
|
||||
);
|
||||
@@ -286,27 +290,27 @@ const fetchRepoUserStats = async (
|
||||
* @param {string} username GitHub username.
|
||||
* @param {boolean} include_all_commits Include all commits.
|
||||
* @param {string[]} exclude_repo Repositories to exclude.
|
||||
* @param {string[]} ownerAffiliations Owner affiliations. Default: OWNER.
|
||||
* @param {boolean} include_merged_pull_requests Include merged pull requests.
|
||||
* @param {boolean} include_discussions Include discussions.
|
||||
* @param {boolean} include_discussions_answers Include discussions answers.
|
||||
* @param {string[]} ownerAffiliations Owner affiliations. Default: OWNER.
|
||||
* @returns {Promise<StatsData>} Stats data.
|
||||
*/
|
||||
const fetchStats = async (
|
||||
username,
|
||||
include_all_commits = false,
|
||||
exclude_repo = [],
|
||||
ownerAffiliations = [],
|
||||
include_merged_pull_requests = false,
|
||||
include_discussions = false,
|
||||
include_discussions_answers = false,
|
||||
repos = [],
|
||||
owners = [],
|
||||
repo = [],
|
||||
owner = [],
|
||||
include_prs_authored = false,
|
||||
include_prs_commented = false,
|
||||
include_prs_reviewed = false,
|
||||
include_issues_authored = false,
|
||||
include_issues_commented = false,
|
||||
ownerAffiliations = [],
|
||||
) => {
|
||||
if (!username) {
|
||||
throw new MissingParamError(["username"]);
|
||||
@@ -370,8 +374,8 @@ const fetchStats = async (
|
||||
if (include_all_commits) {
|
||||
stats.totalCommits = await totalItemsFetcher(
|
||||
username,
|
||||
repos,
|
||||
owners,
|
||||
repo,
|
||||
owner,
|
||||
"commits",
|
||||
`author:${username}`,
|
||||
);
|
||||
@@ -380,8 +384,8 @@ const fetchStats = async (
|
||||
}
|
||||
let repoUserStats = await fetchRepoUserStats(
|
||||
username,
|
||||
repos,
|
||||
owners,
|
||||
repo,
|
||||
owner,
|
||||
include_prs_authored,
|
||||
include_prs_commented,
|
||||
include_prs_reviewed,
|
||||
|
||||
@@ -62,9 +62,9 @@ const fetcher = (variables, token) => {
|
||||
*
|
||||
* @param {string} username GitHub username.
|
||||
* @param {string[]} exclude_repo List of repositories to exclude. Default: [].
|
||||
* @param {string[]} ownerAffiliations The owner affiliations to filter by. Default: OWNER.
|
||||
* @param {number} size_weight Weightage to be given to size.
|
||||
* @param {number} count_weight Weightage to be given to count.
|
||||
* @param {string[]} ownerAffiliations The owner affiliations to filter by. Default: OWNER.
|
||||
* @returns {Promise<TopLangData>} Top languages data.
|
||||
*/
|
||||
const fetchTopLanguages = async (
|
||||
|
||||
Reference in New Issue
Block a user