Skip to content

Commit c698aa3

Browse files
committed
feat(repo-item): use same style badge
1 parent 1715cec commit c698aa3

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

src/components/repo-item.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@
7777
</span>
7878
</div>
7979
<div v-if="settings.displayBadges && hasBadges">
80-
<img v-if="hostingStatusBadge" :src="hostingStatusBadge" alt="hosting status">
81-
<img v-if="uptimerobotBadge" :src="uptimerobotBadge" alt="uptimerobot ratio">
8280
<img v-if="workflowBadge" :src="workflowBadge" alt="workflow badge">
81+
<img v-if="hostingStatusBadge" :src="hostingStatusBadge" alt="hosting status">
82+
<img v-if="uptimeRobotBadge" :src="uptimeRobotBadge" alt="uptimerobot ratio">
8383
</div>
8484
</footer>
8585
</li>
@@ -135,7 +135,7 @@ const {
135135
testFramework,
136136
hasBadges,
137137
hostingName,
138-
uptimerobotBadge,
138+
uptimeRobotBadge,
139139
hostingStatusBadge,
140140
workflowBadge,
141141
packageManager,

src/composable/useRepo.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ const TEST_FRAMEWORKS = [
4040
"zora"
4141
];
4242

43+
function composeBadgeUrl(base: string): string {
44+
const url = new URL(base);
45+
url.searchParams.set("style", "flat-square");
46+
return url.href;
47+
}
48+
4349
export function useRepository(data: Ref<Repository>) {
4450
const hostingName = computed<string | null>(() => {
4551
if (!data.value.homepage) return null;
@@ -51,18 +57,24 @@ export function useRepository(data: Ref<Repository>) {
5157
return null;
5258
}
5359
});
54-
const uptimerobotBadge = computed<string | null>(() => {
55-
if (!data.value.integrations?.uptimerobotKey) return null;
56-
return `https://img.shields.io/uptimerobot/ratio/${data.value.integrations.uptimerobotKey}`;
60+
const uptimeRobotBadge = computed<string | null>(() => {
61+
const key = data.value.integrations?.uptimerobotKey;
62+
if (!key) return null;
63+
return composeBadgeUrl(`https://img.shields.io/uptimerobot/ratio/${key}`);
5764
});
5865
const hostingStatusBadge = computed<string | null>(() => {
59-
if (!data.value.integrations?.hostingProjectId) return null;
60-
if (hostingName.value?.includes("netlify")) {
61-
return `https://api.netlify.com/api/v1/badges/${data.value.integrations.hostingProjectId}/deploy-status`;
62-
}
66+
const projectId = data.value.integrations?.hostingProjectId;
67+
if (!projectId) return null;
68+
if (hostingName.value?.includes("netlify")) return composeBadgeUrl(`https://img.shields.io/netlify/${projectId}`);
6369
return null;
6470
});
65-
const workflowBadge = computed<string | null>(() => data.value.integrations.workflowBadge ?? null);
71+
const workflowBadge = computed<string | null>(() => {
72+
const { integrations, owner, name } = data.value;
73+
if (!integrations.workflowBadge) return null;
74+
return composeBadgeUrl(
75+
`https://img.shields.io/github/actions/workflow/status/${owner.login}/${name}/${integrations.workflowBadge}`
76+
);
77+
});
6678
const packageManager = computed<string | null>(() => data.value.integrations.packageManager ?? null);
6779
const license = computed<string | null>(() => {
6880
if (!data.value.license) return null;
@@ -71,7 +83,7 @@ export function useRepository(data: Ref<Repository>) {
7183
});
7284

7385
const hasBadges = computed<boolean>(() => {
74-
return !!hostingStatusBadge.value || !!uptimerobotBadge.value || !!workflowBadge.value;
86+
return !!hostingStatusBadge.value || !!uptimeRobotBadge.value || !!workflowBadge.value;
7587
});
7688

7789
const bundler = computed<string[]>(() => {
@@ -85,7 +97,7 @@ export function useRepository(data: Ref<Repository>) {
8597

8698
return {
8799
hostingName,
88-
uptimerobotBadge,
100+
uptimeRobotBadge,
89101
hostingStatusBadge,
90102
workflowBadge,
91103
packageManager,

src/store/repositories.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const DEFAULT_STORE: RepositoriesStore = {
1818
async function parseWorkflows(fullName: Repository["full_name"]): Promise<Repository["integrations"]["workflowBadge"]> {
1919
const workflowsData = await fetchRepositoryWorkflows(fullName);
2020
const firstWorkflow = workflowsData?.workflows[0];
21-
return firstWorkflow?.state === "active" ? firstWorkflow.badge_url : undefined;
21+
return firstWorkflow?.state === "active" ? firstWorkflow.path : undefined;
2222
}
2323
async function parsePackageManager(fullName: Repository["full_name"]): Promise<"npm" | "pnpm" | "yarn" | undefined> {
2424
const files = await fetchRepositoryFiles(fullName);

0 commit comments

Comments
 (0)