-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathPullRequestListItem.tsx
114 lines (101 loc) · 3.66 KB
/
PullRequestListItem.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { Action, ActionPanel, Icon, List, open, useNavigation } from "@raycast/api";
import { usePromise } from "@raycast/utils";
import { format } from "date-fns";
import { useMemo } from "react";
import { UIColors } from "../../constants";
import { PullRequestFieldsFragment, UserFieldsFragment } from "../generated/graphql";
import OpenInGitpod, { getPreferencesForContext } from "../helpers/openInGitpod";
import {
getCheckStateAccessory,
getNumberOfComments,
getPullRequestAuthor,
getPullRequestStatus,
getReviewDecision,
} from "../helpers/pull-request";
import ContextPreferences from "../preferences/context_preferences";
type PullRequestListItemProps = {
pullRequest: PullRequestFieldsFragment;
viewer?: UserFieldsFragment;
};
export default function PullRequestListItem({ pullRequest }: PullRequestListItemProps) {
const updatedAt = new Date(pullRequest.updatedAt);
const { push } = useNavigation();
const numberOfComments = useMemo(() => getNumberOfComments(pullRequest), []);
const author = getPullRequestAuthor(pullRequest);
const status = getPullRequestStatus(pullRequest);
const reviewDecision = getReviewDecision(pullRequest.reviewDecision);
const { data: preferences, revalidate } = usePromise(
async () => {
const response = await getPreferencesForContext("Pull Request", pullRequest.repository.nameWithOwner, pullRequest.title);
return response;
},
);
const accessories: List.Item.Accessory[] = [
{
date: updatedAt,
tooltip: `Updated: ${format(updatedAt, "EEEE d MMMM yyyy 'at' HH:mm")}`,
},
{
text: {
value: preferences?.preferredEditorClass === "g1-large" ? "L" : "S",
},
icon: {
source: Icon.ComputerChip,
tintColor: UIColors.gitpod_gold,
},
tooltip: `Editor: ${preferences?.preferredEditor}, Class: ${preferences?.preferredEditorClass} `
},
{
icon: author.icon,
tooltip: `Author: ${author.text}`,
},
];
if (reviewDecision) {
accessories.unshift(reviewDecision);
}
if (numberOfComments > 0) {
accessories.unshift({
text: `${numberOfComments}`,
icon: Icon.Bubble,
});
}
if (pullRequest.commits.nodes) {
const checkState = pullRequest.commits.nodes[0]?.commit.statusCheckRollup?.state;
const checkStateAccessory = checkState ? getCheckStateAccessory(checkState) : null;
if (checkStateAccessory) {
accessories.unshift(checkStateAccessory);
}
}
const keywords = [`${pullRequest.number}`];
if (pullRequest.author?.login) {
keywords.push(pullRequest.author.login);
}
return (
<List.Item
key={pullRequest.id}
title={pullRequest.title}
subtitle={{ value: `#${pullRequest.number}`, tooltip: `Repository: ${pullRequest.repository.nameWithOwner}` }}
icon={{ value: status.icon, tooltip: `Status: ${status.text}` }}
keywords={keywords}
accessories={accessories}
actions={
<ActionPanel>
<Action
title="Open PR in Gitpod"
onAction={() => {
OpenInGitpod(pullRequest.permalink, "Pull Request", pullRequest.repository.nameWithOwner, pullRequest.title);
}}
shortcut={{ modifiers: ["cmd"], key: "g" }}
/>
<Action
title="View PR in GitHub"
onAction={() => {
open(pullRequest.permalink);
}}
/>
<Action title="Configure Workspace" onAction={() => push(<ContextPreferences revalidate={revalidate} type="Pull Request" repository={pullRequest.repository.nameWithOwner} context={pullRequest.title} />)} shortcut={{ modifiers: ["cmd"], key: "w" }} />
</ActionPanel>
}
/>
);
}