Skip to content

Commit 9f41a9e

Browse files
authored
fix(jargons-editor): wrong pending contribution stats computation (#57)
This Pull request fixes the issue where all Pull Requests are considered in the computation of pending word contribution; this was because of a missing imperative labels i.e. `📖 new word` and `📖 edit word` which should've been used to within the search request filter to narrow down list of PRs returns by checking for the presence of either of both label in opened pull requests on the jargons.dev repo. ### Changes Made - Added missing labels `label:":book: edit word",":book: new word"` to the `pendingType` pull search as filter that check for the presence of either label - Extracted `buildStatsUrl` to utils from `doContributionStats` action - Added the same missing labels `label:":book: edit word",":book: new word"` to the `buildStatsUrl` execution queryString param for the computation of `totalWords` stats url ### Screencast https://github.com/babblebey/jargons.dev/assets/25631971/1db9a614-8432-466b-a234-44693b2253d5 📖
1 parent 3298a9a commit 9f41a9e

3 files changed

Lines changed: 17 additions & 12 deletions

File tree

src/lib/actions/do-contribution-stats.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import app from "../octokit/app.js";
22
import { decrypt } from "../utils/crypto.js";
3+
import { buildStatsUrl } from "../utils/index.js";
34
import { PROJECT_REPO_DETAILS } from "../../../constants.js";
45

56
/**
@@ -30,7 +31,7 @@ export default async function doContributionStats(astroGlobal) {
3031
q: `${baseQuery} label:":book: edit word" is:merged is:closed`
3132
});
3233
const { data: pendingType } = await userOctokit.request("GET /search/issues", {
33-
q: `${baseQuery} is:unmerged is:open`
34+
q: `${baseQuery} label:":book: edit word",":book: new word" is:unmerged is:open`
3435
});
3536

3637
return {
@@ -47,14 +48,4 @@ export default async function doContributionStats(astroGlobal) {
4748
url: buildStatsUrl(repoFullname, `${baseStatsUrlQuery} is:unmerged is:open`)
4849
}
4950
}
50-
}
51-
52-
/**
53-
* Build URL to the Pull Request list on the project's Repo
54-
* @param {string} repoFullname
55-
* @param {string} queryString
56-
* @returns {string}
57-
*/
58-
function buildStatsUrl(repoFullname, queryString) {
59-
return `https://github.com/${repoFullname}/pulls?q=${encodeURIComponent(queryString)}`;
6051
}

src/lib/utils/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,14 @@ export function capitalizeText(text) {
6767
*/
6868
export function generateBranchName(action, wordTitle) {
6969
return `word/${action}/${normalizeAsUrl(wordTitle)}`;
70+
}
71+
72+
/**
73+
* Build URL to the Pull Request list on the project's Repo
74+
* @param {string} repoFullname
75+
* @param {string} queryString
76+
* @returns {string}
77+
*/
78+
export function buildStatsUrl(repoFullname, queryString) {
79+
return `https://github.com/${repoFullname}/pulls?q=${encodeURIComponent(queryString)}`;
7080
}

src/pages/editor/index.astro

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Image } from "astro:assets";
33
import BaseLayout from "../../layouts/base.astro";
44
import doAuth from "../../lib/actions/do-auth.js";
55
import Navbar from "../../components/navbar.astro";
6+
import { buildStatsUrl } from "../../lib/utils/index.js";
67
import { PROJECT_REPO_DETAILS } from "../../../constants.js";
78
import doContributionStats from "../../lib/actions/do-contribution-stats.js";
89
@@ -14,7 +15,10 @@ if (!isAuthed) return redirect(`/login?return_to=${encodeURIComponent(pathname)}
1415
const { newWords, editedWords, pendingWords } = await doContributionStats(Astro);
1516
const totalWords = {
1617
count: newWords.count + editedWords.count,
17-
url: `https://github.com/${PROJECT_REPO_DETAILS.repoFullname}/pulls?q=${encodeURIComponent(`is:pr is:closed is:merged author:@me`)}`
18+
url: buildStatsUrl(
19+
PROJECT_REPO_DETAILS.repoFullname,
20+
`label:":book: edit word",":book: new word" is:pr is:closed is:merged author:@me`
21+
)
1822
}
1923
---
2024

0 commit comments

Comments
 (0)