Skip to content

Commit 8734b60

Browse files
committed
make it support other repo
1 parent a82b059 commit 8734b60

File tree

8 files changed

+195
-14
lines changed

8 files changed

+195
-14
lines changed

index.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33

44
<head>
55
<meta charset="UTF-8">
6-
<link rel="icon" href="/favicon.ico">
6+
<link href="/logo.png" rel="shortcut icon">
77
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8-
<title>Vite App</title>
8+
<title>Lychee Stacked Pr viewer</title>
99
</head>
1010

1111
<body class="dark">
12+
<a class="github-fork-ribbon" href="https://github.com/LycheeOrg/Lychee-Pull-Requests" data-ribbon="Fork me on GitHub"
13+
title="Fork me on GitHub">Fork me on GitHub</a>
1214
<div id="app"></div>
1315
<script type="module" src="/src/main.ts"></script>
1416
</body>

public/favicon.ico

-4.19 KB
Binary file not shown.

public/logo.png

3.24 KB
Loading

src/App.vue

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,43 @@
11
<template>
22
<Panel
33
class="bg-transparent border-none"
4-
header="Lychee Pull Requests"
4+
:header="formatOwnerRepo() + ' Pull Requests'"
55
:pt:header:class="'justify-center text-4xl font-bold'"
66
>
77
<div class="flex flex-col max-w-4xl mx-auto gap-4 text-left">
88
<div class="group mb-4 text-muted-color text-center cursor-pointer" @click="refresh">
99
<span class="group-hover:hidden">Last update: {{ formattedUpdated }}</span>
1010
<span class="hidden group-hover:inline text-primary-emphasis">Click to clear cache.</span>
1111
</div>
12+
<div class="flex flex-col gap-4 -mt-12">
13+
<i
14+
class="self-end flex pi pi-question-circle text-xl text-muted-color hover:text-primary-emphasis peer cursor-help"
15+
></i>
16+
<div
17+
class="text-muted-color flex flex-col gap-4 max-h-0 overflow-y-hidden peer-hover:max-h-dvh hover:max-h-dvh transition-all duration-1000 ease-in-out"
18+
>
19+
<p>
20+
The support of stacked PR on the GitHub pull request page is pretty much non-existent. This page
21+
attempts to provide a better way to visualize them.
22+
</p>
23+
<p>
24+
A stack is automatically recognized by following the branch naming-convention
25+
<span class="text-sm font-mono text-muted-color-emphasis">feature-name/pr-name</span>: all the
26+
pull requests that start with the same
27+
<span class="text-sm font-mono text-muted-color-emphasis">feature-name/</span> are part of the
28+
same stack. All other pull requests are considered standalone.
29+
</p>
30+
<p>
31+
You can also use this page for your projects by adding
32+
<span class="text-sm font-mono text-muted-color-emphasis">#&lt;owner&gt;/&lt;repo&gt;</span> at
33+
the end of the url.
34+
</p>
35+
</div>
36+
</div>
1237
<template v-if="pullRequests">
38+
<template v-if="pullRequests.length === 0">
39+
<p class="text-center text-muted-color">No active pull requests.</p>
40+
</template>
1341
<template v-if="pullRequests.length === 1">
1442
<PrList v-if="pullRequests" :pull-requests="pullRequests[0].data" />
1543
</template>
@@ -88,15 +116,33 @@ const formattedUpdated = computed(() => {
88116
);
89117
});
90118
119+
function getOwnerRepo(): { owner: string; repo: string } {
120+
const search = window.location.hash;
121+
const [owner, repo] = search.replace('#', '').split('/');
122+
return {
123+
owner: owner || 'LycheeOrg',
124+
repo: repo || 'Lychee',
125+
};
126+
}
127+
128+
const { owner, repo } = getOwnerRepo();
129+
130+
function formatOwnerRepo(): string {
131+
if (owner === 'LycheeOrg' && repo === 'Lychee') {
132+
return 'Lychee';
133+
}
134+
return `${owner}/${repo}`;
135+
}
136+
91137
async function refresh() {
92138
queryStore.reset();
93139
pullRequestsData.value = undefined;
94-
await getPrs();
95-
getStatuses();
140+
await getPrs(owner, repo);
141+
getStatuses(owner, repo);
96142
}
97143
98144
onMounted(async () => {
99-
await getPrs();
100-
getStatuses();
145+
await getPrs(owner, repo);
146+
getStatuses(owner, repo);
101147
});
102148
</script>

src/ResponsesTypes.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export type PullRequest = {
3939
head: { ref: string };
4040
};
4141

42-
export const CONTRIBUTORS = ['JasonMillward', 'ppshobi', 'ildyria', 'RonnieTaz', 'sancsin', 'd7415'];
4342
export const APPROVED = 'APPROVED';
4443
export const CHANGES_REQUESTED = 'CHANGES_REQUESTED';
4544
export type PullRequestReview = {

src/assets/main.css

Lines changed: 88 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/composables/getData.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import {
22
APPROVED,
33
CHANGES_REQUESTED,
4-
CONTRIBUTORS,
54
type PullRequest,
65
type PullRequestReview,
76
type ReviewStatus,
87
type User,
98
} from '@/ResponsesTypes';
109
import { ref } from 'vue';
10+
import { useOwnerRepo } from './getOwnerRepo';
11+
12+
const { getReviewers } = useOwnerRepo();
1113

1214
export function useGetData(
1315
fetchPullRequests: (owner: string, repo: string) => Promise<PullRequest[] | undefined>,
@@ -19,20 +21,20 @@ export function useGetData(
1921
) {
2022
const pullRequestsData = ref<(PullRequest & ReviewStatus)[] | undefined>(undefined);
2123

22-
async function getPrs(): Promise<void> {
23-
return fetchPullRequests('LycheeOrg', 'Lychee').then((data) => {
24+
async function getPrs(owner: string, repo: string): Promise<void> {
25+
return fetchPullRequests(owner, repo).then((data) => {
2426
pullRequestsData.value = data;
2527
});
2628
}
2729

28-
async function getStatuses() {
30+
async function getStatuses(owner: string, repo: string): Promise<void> {
2931
if (!pullRequestsData.value || pullRequestsData.value.length === 0) {
3032
console.warn('No pull requests available to fetch statuses for.');
3133
return;
3234
}
3335

3436
pullRequestsData.value.forEach(async (pr, idx) => {
35-
await fetchPullRequestReviews('LycheeOrg', 'Lychee', pr.number)
37+
await fetchPullRequestReviews(owner, repo, pr.number)
3638
.then((data) => {
3739
if (!pullRequestsData.value) {
3840
console.warn('pullRequestsData.value is undefined, cannot update review status.');
@@ -70,9 +72,15 @@ export function useGetData(
7072
by: [],
7173
},
7274
};
75+
76+
const constributors = getReviewers();
77+
7378
// eslint-disable-next-line @typescript-eslint/no-unused-vars
7479
Object.entries(statuses).forEach(([_, review]) => {
75-
if (review.status === APPROVED && CONTRIBUTORS.includes(review.user.login)) {
80+
if (
81+
review.status === APPROVED &&
82+
(constributors.length === 0 || constributors.includes(review.user.login))
83+
) {
7684
result.review!.approved = true;
7785
result.review!.code_owner_approved = true;
7886
} else if (review.status === APPROVED) {

src/composables/getOwnerRepo.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
export function useOwnerRepo() {
2+
function getOwnerRepo(): { owner: string; repo: string } {
3+
const search = window.location.hash;
4+
const [owner, repo] = search.replace('#', '').split('/');
5+
return {
6+
owner: owner || 'LycheeOrg',
7+
repo: repo || 'Lychee',
8+
};
9+
}
10+
11+
const { owner, repo } = getOwnerRepo();
12+
13+
function formatOwnerRepo(): string {
14+
if (isLychee()) {
15+
return 'Lychee';
16+
}
17+
return `${owner}/${repo}`;
18+
}
19+
20+
function isLychee(): boolean {
21+
return owner === 'LycheeOrg' && repo === 'Lychee';
22+
}
23+
24+
function getReviewers(): string[] {
25+
if (isLychee()) {
26+
return ['JasonMillward', 'ppshobi', 'ildyria', 'RonnieTaz', 'sancsin', 'd7415'];
27+
}
28+
return [];
29+
}
30+
31+
return {
32+
owner,
33+
repo,
34+
formatOwnerRepo,
35+
isLychee,
36+
getReviewers,
37+
};
38+
}

0 commit comments

Comments
 (0)