mirror of
https://github.com/reiyua/github-profile-trophy-reiyua-mirror.git
synced 2026-11-17 06:02:09 +11:00
Refactor: code cleanup and xss fix (#270)
* fix: remove unnecessary xssable text * chore: remove typo * fix: ignored promise * fix: imports can be summarized and the repository already has the typing * fix: cleanup and remove domain * chore: lint * tests: `assert` is deprecated, replace to `with` docs reference: https://lint.deno.land/rules/no-import-assertions * ci: bump checkout and Deno * chore: fix readme tags * refactor: remove unnecessary constructor * chore: remove import duplicate * refactor: replace sort with toSorted https://rules.sonarsource.com/typescript/RSPEC-4043/?search=Array-mutating%20methods%20should%20not%20be%20used%20misleadingly * chore: format
This commit is contained in:
parent
a50a8b71fd
commit
5aa2caf7c9
13 changed files with 39 additions and 53 deletions
8
.github/workflows/testing.yml
vendored
8
.github/workflows/testing.yml
vendored
|
|
@ -7,19 +7,19 @@ on:
|
|||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
workflow_dispatch:
|
||||
jobs:
|
||||
install-dependencies:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
deno-version: [1.36.1]
|
||||
deno-version: [1.43.6]
|
||||
|
||||
steps:
|
||||
- name: Git Checkout Deno Module
|
||||
uses: actions/checkout@v2
|
||||
- name: Use Deno Version ${{ matrix.deno-version }}
|
||||
uses: denolib/setup-deno@v2
|
||||
uses: actions/checkout@v4
|
||||
- uses: denoland/setup-deno@v1
|
||||
with:
|
||||
deno-version: ${{ matrix.deno-version }}
|
||||
- name: Deno format check
|
||||
|
|
|
|||
|
|
@ -45,8 +45,8 @@ Read the [.editorconfig](./.editorconfig)
|
|||
|
||||
## Pull Requests
|
||||
|
||||
Pull requests are are always welcome! In general, they should a single concern
|
||||
in the least number of changed lines as possible. For changes that address core
|
||||
Pull requests are always welcome! In general, they should a single concern in
|
||||
the least number of changed lines as possible. For changes that address core
|
||||
functionality, it is best to open an issue to discuss your proposal first. I
|
||||
look forward to seeing what you come up with!
|
||||
|
||||
|
|
|
|||
33
README.md
33
README.md
|
|
@ -1,36 +1,35 @@
|
|||
<p align="center">
|
||||
<img width="140" src="https://user-images.githubusercontent.com/6661165/91657958-61b4fd00-eb00-11ea-9def-dc7ef5367e34.png" />
|
||||
<div align="center">
|
||||
<img width="140" src="https://user-images.githubusercontent.com/6661165/91657958-61b4fd00-eb00-11ea-9def-dc7ef5367e34.png" alt="GitHub Profile Trophy"/>
|
||||
<h2 align="center">GitHub Profile Trophy</h2>
|
||||
<p align="center">🏆 Add dynamically generated GitHub Stat Trophies on your readme</p>
|
||||
</p>
|
||||
<p align="center">
|
||||
</div>
|
||||
<div align="center">
|
||||
<a href="https://github.com/ryo-ma/github-profile-trophy/issues">
|
||||
<img src="https://img.shields.io/github/issues/ryo-ma/github-profile-trophy"/>
|
||||
<img src="https://img.shields.io/github/issues/ryo-ma/github-profile-trophy" alt="Issues"/>
|
||||
</a>
|
||||
<a href="https://github.com/ryo-ma/github-profile-trophy/network/members">
|
||||
<img src="https://img.shields.io/github/forks/ryo-ma/github-profile-trophy"/>
|
||||
<img src="https://img.shields.io/github/forks/ryo-ma/github-profile-trophy" alt="Forks"/>
|
||||
</a>
|
||||
<a href="https://github.com/ryo-ma/github-profile-trophy/stargazers">
|
||||
<img src="https://img.shields.io/github/stars/ryo-ma/github-profile-trophy"/>
|
||||
<img src="https://img.shields.io/github/stars/ryo-ma/github-profile-trophy" alt="Stargazers"/>
|
||||
</a>
|
||||
<a href="https://github.com/ryo-ma/github-profile-trophy/LICENSE">
|
||||
<img src="https://img.shields.io/github/license/ryo-ma/github-profile-trophy"/>
|
||||
</a>
|
||||
</p>
|
||||
<p align="center">
|
||||
<img src="https://img.shields.io/github/license/ryo-ma/github-profile-trophy" alt="License"/>
|
||||
</a>
|
||||
</div>
|
||||
<div align="center">
|
||||
<a href="https://twitter.com/intent/tweet?text=Add%20dynamically%20generated%20GitHub%20Trophy%20on%20your%20readme%0D%0A&url=https%3A%2F%2Fgithub.com%2Fryo-ma%2Fgithub-profile-trophy">
|
||||
<img src="https://img.shields.io/twitter/url?style=social&url=https%3A%2F%2Fgithub.com%2Fryo-ma%2Fgithub-profile-trophy"/>
|
||||
<img src="https://img.shields.io/twitter/url?style=social&url=https%3A%2F%2Fgithub.com%2Fryo-ma%2Fgithub-profile-trophy" alt="Share"/>
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
<p align="center">
|
||||
You can use this service for free. I'm looking for sponsors to help us keep up with this service❤️
|
||||
</p>
|
||||
<p align="center">
|
||||
<div align="center">
|
||||
<a href="https://github.com/sponsors/ryo-ma">
|
||||
<img src="https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=ff69b4"/>
|
||||
<img src="https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=ff69b4" alt="Sponsor"/>
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
# Quick Start
|
||||
|
||||
|
|
@ -42,7 +41,7 @@ readme, change the `?username=` value to your GitHub's username.
|
|||
```
|
||||
|
||||
<p align="center">
|
||||
<img alig src="https://github-profile-trophy.vercel.app/?username=ryo-ma&column=8&rank=SSS,SS,S,AAA,AA,A,B,C" />
|
||||
<img src="https://github-profile-trophy.vercel.app/?username=ryo-ma&column=8&rank=SSS,SS,S,AAA,AA,A,B,C" />
|
||||
</p>
|
||||
|
||||
## Use theme
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ async function app(req: Request): Promise<Response> {
|
|||
const userResponseInfo = await client.requestUserInfo(username);
|
||||
if (userResponseInfo instanceof ServiceError) {
|
||||
return new Response(
|
||||
ErrorPage({ error: userResponseInfo, username }).render(),
|
||||
ErrorPage({ error: userResponseInfo }).render(),
|
||||
{
|
||||
status: userResponseInfo.code,
|
||||
headers: new Headers({ "Content-Type": "text" }),
|
||||
|
|
|
|||
|
|
@ -14,8 +14,7 @@ import {
|
|||
} from "../Schemas/index.ts";
|
||||
import { Retry } from "../Helpers/Retry.ts";
|
||||
import { CONSTANTS } from "../utils.ts";
|
||||
import { EServiceKindError } from "../Types/EServiceKindError.ts";
|
||||
import { ServiceError } from "../Types/ServiceError.ts";
|
||||
import { EServiceKindError, ServiceError } from "../Types/index.ts";
|
||||
import { Logger } from "../Helpers/Logger.ts";
|
||||
import { requestGithubData } from "./request.ts";
|
||||
|
||||
|
|
@ -85,7 +84,7 @@ export class GithubApiService extends GithubRepository {
|
|||
(activity as PromiseFulfilledResult<GitHubUserActivity>).value,
|
||||
(issue as PromiseFulfilledResult<GitHubUserIssue>).value,
|
||||
(pullRequest as PromiseFulfilledResult<GitHubUserPullRequest>).value,
|
||||
repository as GitHubUserRepository,
|
||||
repository,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -98,15 +97,13 @@ export class GithubApiService extends GithubRepository {
|
|||
TOKENS.length,
|
||||
CONSTANTS.DEFAULT_GITHUB_RETRY_DELAY,
|
||||
);
|
||||
const response = await retry.fetch<Promise<T>>(async ({ attempt }) => {
|
||||
return await retry.fetch<Promise<T>>(async ({ attempt }) => {
|
||||
return await requestGithubData(
|
||||
query,
|
||||
variables,
|
||||
TOKENS[attempt],
|
||||
);
|
||||
});
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
if (error.cause instanceof ServiceError) {
|
||||
Logger.error(error.cause.message);
|
||||
|
|
|
|||
|
|
@ -3,17 +3,17 @@ import { assertEquals, returnsNext, soxa, stub } from "../../../deps.ts";
|
|||
import { GitHubUserRepository } from "../../user_info.ts";
|
||||
|
||||
const rateLimitMock = await import("../__mocks__/rateLimitMock.json", {
|
||||
assert: { type: "json" },
|
||||
with: { type: "json" },
|
||||
});
|
||||
|
||||
const successGithubResponseMock = await import(
|
||||
"../__mocks__/successGithubResponse.json",
|
||||
{ assert: { type: "json" } }
|
||||
{ with: { type: "json" } }
|
||||
);
|
||||
|
||||
const notFoundGithubResponseMock = await import(
|
||||
"../__mocks__/notFoundUserMock.json",
|
||||
{ assert: { type: "json" } }
|
||||
{ with: { type: "json" } }
|
||||
);
|
||||
|
||||
import { ServiceError } from "../../Types/index.ts";
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ export async function staticRenderRegeneration(
|
|||
const response = await render(request);
|
||||
|
||||
if (response.status >= 200 && response.status < 300) {
|
||||
cacheManager.save(response);
|
||||
void cacheManager.save(response);
|
||||
}
|
||||
|
||||
return response;
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ export class Card {
|
|||
return row;
|
||||
}
|
||||
private getHeight(row: number) {
|
||||
// Calculate the height of card from turns
|
||||
// Calculate the height of the card from turns
|
||||
return this.panelSize * row + this.marginHeight * (row - 1);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,12 +3,11 @@ abstract class BaseError {
|
|||
readonly message!: string;
|
||||
constructor(readonly content?: string) {}
|
||||
render() {
|
||||
const page = this.renderPage();
|
||||
return page;
|
||||
return this.renderPage();
|
||||
}
|
||||
|
||||
private renderPage() {
|
||||
const htmlPage = `<!DOCTYPE html>
|
||||
return `<!DOCTYPE html>
|
||||
<html lang="en"><head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
|
@ -46,7 +45,7 @@ abstract class BaseError {
|
|||
border-radius: 5px;
|
||||
padding: 20px;
|
||||
margin-bottom: 20px;
|
||||
box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.1);
|
||||
box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
form {
|
||||
display: flex;
|
||||
|
|
@ -108,12 +107,10 @@ abstract class BaseError {
|
|||
<p style="text-align: center;">${this.content ?? ""}</p>
|
||||
${
|
||||
this.content &&
|
||||
'<a id="back-link" href="https://github-profile-trophy.vercel.app/">Go back</a>'
|
||||
'<a id="back-link" href="/">Go back</a>'
|
||||
}
|
||||
</body>
|
||||
</html>`;
|
||||
|
||||
return htmlPage;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,10 +3,9 @@ import { Error400, Error404, Error419 } from "../error_page.ts";
|
|||
|
||||
interface ErrorPageProps {
|
||||
error: ServiceError;
|
||||
username: string;
|
||||
}
|
||||
|
||||
export function ErrorPage({ error, username }: ErrorPageProps) {
|
||||
export function ErrorPage({ error }: ErrorPageProps) {
|
||||
let cause: Error400 | Error404 | Error419 = new Error400();
|
||||
|
||||
if (error.cause === EServiceKindError.RATE_LIMIT) {
|
||||
|
|
@ -15,7 +14,7 @@ export function ErrorPage({ error, username }: ErrorPageProps) {
|
|||
|
||||
if (error.cause === EServiceKindError.NOT_FOUND) {
|
||||
cause = new Error404(
|
||||
"Can not find a user with username: " + username,
|
||||
"Sorry, the user you are looking for was not found.",
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ export class Trophy {
|
|||
this.setRank();
|
||||
}
|
||||
setRank() {
|
||||
const sortedRankConditions = this.rankConditions.sort((a, b) =>
|
||||
const sortedRankConditions = this.rankConditions.toSorted((a, b) =>
|
||||
RANK_ORDER.indexOf(a.rank) - RANK_ORDER.indexOf(b.rank)
|
||||
);
|
||||
// Set the rank that hit the first condition
|
||||
|
|
@ -314,7 +314,6 @@ export class AccountDurationTrophy extends Trophy {
|
|||
super(score, rankConditions);
|
||||
this.title = "Experience";
|
||||
this.filterTitles = ["Experience", "Duration", "Since"];
|
||||
// this.hidden = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ export class TrophyList {
|
|||
);
|
||||
}
|
||||
sortByRank() {
|
||||
this.trophies = this.trophies.sort((a: Trophy, b: Trophy) =>
|
||||
this.trophies = this.trophies.toSorted((a: Trophy, b: Trophy) =>
|
||||
RANK_ORDER.indexOf(a.rank) - RANK_ORDER.indexOf(b.rank)
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,4 @@
|
|||
export class CustomURLSearchParams extends URLSearchParams {
|
||||
constructor(
|
||||
init?: string[][] | Record<string, string> | string | URLSearchParams,
|
||||
) {
|
||||
super(init);
|
||||
}
|
||||
getStringValue(key: string, defaultValue: string): string {
|
||||
if (super.has(key)) {
|
||||
const param = super.get(key);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue