Skip to content

Commit 3503e57

Browse files
committed
Add 'closed' PR state to support closed but not merged PRs
This change addresses issue open-telemetry#7 from the upstream repository. It adds a 'closed' state to differentiate between PRs that were closed without merging and PRs that were merged. - Add 'closed' to ChangelogEntry state type - Update webhook handler to set state correctly for closed PRs - Add closed state UI with red icon in FilteredList - Update test controls to allow creating test entries with different states Closes open-telemetry#7
1 parent 7642cb4 commit 3503e57

File tree

5 files changed

+43
-21
lines changed

5 files changed

+43
-21
lines changed

src/app/api/test/route.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,27 @@
66
import { saveEntry } from "@/lib/store";
77
import { ChangelogEntry } from "@/types/entry";
88

9-
export async function POST() {
9+
export async function POST(request: Request) {
1010
// Only allow in development
1111
if (process.env.NODE_ENV !== "development") {
1212
return new Response("Test endpoint only available in development", {
1313
status: 403,
1414
});
1515
}
1616

17+
// Get state from query parameters if provided, default to "opened"
18+
const url = new URL(request.url);
19+
const state = url.searchParams.get("state") || "opened";
20+
const validStates = ["opened", "closed", "merged", "released"];
21+
1722
const testEntry: ChangelogEntry = {
1823
id: Date.now(), // Use timestamp as ID for test entries
19-
title: `Test Entry ${new Date().toISOString()}`,
24+
title: `Test Entry ${new Date().toISOString()} (${state})`,
2025
description: "This is a test entry with **bold text**, *italic* and a [link text](http://example.com) to verify markdown handling in RSS feed.",
2126
date: new Date().toISOString(),
2227
metadata: {
2328
sourceRepo: "open-telemetry/test-repo",
24-
state: "opened",
29+
state: validStates.includes(state) ? state as "opened" | "closed" | "merged" | "released" : "opened",
2530
url: "https://github.com/open-telemetry/test-repo/pull/123",
2631
author: "test-user",
2732
},

src/app/api/webhook/route.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ export async function POST(request: NextRequest) {
6262
await saveEntry(entry);
6363
} else if (
6464
payload.action === "closed" &&
65-
payload.pull_request.merged &&
6665
payload.pull_request.labels.some(
6766
(label) => label.name === CHANGELOG_LABEL,
6867
)
@@ -74,7 +73,7 @@ export async function POST(request: NextRequest) {
7473
date: payload.pull_request.merged_at || payload.pull_request.updated_at,
7574
metadata: {
7675
sourceRepo: payload.repository.full_name,
77-
state: "merged",
76+
state: payload.pull_request.merged ? "merged" : "closed",
7877
url: payload.pull_request.html_url,
7978
author: payload.pull_request.user.login,
8079
},

src/components/filtered-list.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,15 @@ const StatusIcon = ({ state, label }: { state: string; label: string }) => {
6161
merged: RiCheckboxCircleFill,
6262
opened: RiAddCircleFill,
6363
released: RiRocketFill,
64+
closed: RiCheckboxCircleFill,
6465
};
6566

6667
const Icon = icons[state as keyof typeof icons];
6768
const colors = {
6869
merged: "text-purple-500",
6970
opened: "text-green-500",
7071
released: "text-blue-500",
72+
closed: "text-red-500",
7173
};
7274

7375
return Icon ? (
@@ -91,6 +93,7 @@ export function FilteredList({ entries }: { entries: ChangelogEntry[] }) {
9193
const stateOptions = [
9294
{ value: "all", label: "All States" },
9395
{ value: "opened", label: "Opened" },
96+
{ value: "closed", label: "Closed" },
9497
{ value: "merged", label: "Merged" },
9598
{ value: "released", label: "Released" },
9699
];

src/components/test-controls.tsx

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,20 @@ import { useState } from "react";
99

1010
export function TestControls() {
1111
const [status, setStatus] = useState<string>("");
12+
const [entryState, setEntryState] = useState<string>("opened");
1213

13-
const addTestEntry = async () => {
14+
const addTestEntry = async (state: string) => {
1415
try {
15-
setStatus("Adding test entry...");
16-
const response = await fetch("/api/test", {
16+
setStatus(`Adding test entry with state: ${state}...`);
17+
const response = await fetch(`/api/test?state=${state}`, {
1718
method: "POST",
1819
});
1920

2021
if (!response.ok) {
2122
throw new Error(`HTTP error! status: ${response.status}`);
2223
}
2324

24-
setStatus("Test entry added! Check if the page updates.");
25+
setStatus(`Test entry (${state}) added! Check if the page updates.`);
2526

2627
// Clear status after 3 seconds
2728
setTimeout(() => setStatus(""), 3000);
@@ -34,17 +35,31 @@ export function TestControls() {
3435

3536
return (
3637
<div className="fixed bottom-4 right-4 p-4 bg-white dark:bg-gray-800 rounded-lg shadow-lg border border-gray-200 dark:border-gray-700">
37-
<button
38-
onClick={addTestEntry}
39-
className="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2"
40-
>
41-
Add Test Entry
42-
</button>
43-
{status && (
44-
<p className="mt-2 text-sm text-gray-600 dark:text-gray-300">
45-
{status}
46-
</p>
47-
)}
38+
<div className="flex flex-col gap-2">
39+
<div className="flex gap-2">
40+
<select
41+
value={entryState}
42+
onChange={(e) => setEntryState(e.target.value)}
43+
className="px-2 py-2 border border-gray-300 dark:border-gray-600 rounded bg-white dark:bg-gray-700 text-gray-900 dark:text-white"
44+
>
45+
<option value="opened">Opened</option>
46+
<option value="closed">Closed</option>
47+
<option value="merged">Merged</option>
48+
<option value="released">Released</option>
49+
</select>
50+
<button
51+
onClick={() => addTestEntry(entryState)}
52+
className="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2"
53+
>
54+
Add Test Entry
55+
</button>
56+
</div>
57+
{status && (
58+
<p className="mt-2 text-sm text-gray-600 dark:text-gray-300">
59+
{status}
60+
</p>
61+
)}
62+
</div>
4863
</div>
4964
);
5065
}

src/types/entry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface ChangelogEntry {
1010
date: string;
1111
metadata: {
1212
sourceRepo: string;
13-
state: "opened" | "merged" | "released";
13+
state: "opened" | "merged" | "released" | "closed";
1414
url: string;
1515
author: string;
1616
};

0 commit comments

Comments
 (0)