-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathBranchListItem.tsx
87 lines (81 loc) · 2.66 KB
/
BranchListItem.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
import { Action, ActionPanel, Color, List, open, useNavigation } from "@raycast/api";
import { branchStatus, GitpodIcons } from "../../constants";
import { BranchDetailsFragment, UserFieldsFragment } from "../generated/graphql";
import OpenInGitpod from "../helpers/openInGitpod";
import ContextPreferences from "../preferences/context_preferences";
type BranchItemProps = {
branch: BranchDetailsFragment;
mainBranch: string;
viewer?: UserFieldsFragment;
repository: string;
};
export default function BranchListItem({ branch, mainBranch, repository }: BranchItemProps) {
const accessories: List.Item.Accessory[] = [];
const branchURL = "https://github.com/" + repository + "/tree/" + branch.branchName;
const { push } = useNavigation();
if (branch.compData) {
if (branch.compData.status) {
switch (branch.compData.status.toString()) {
case branchStatus.ahead:
accessories.unshift({
text: branch.compData.aheadBy.toString(),
icon: GitpodIcons.branchAhead,
});
break;
case branchStatus.behind:
accessories.unshift({
text: branch.compData.aheadBy.toString(),
icon: GitpodIcons.branchBehind,
});
break;
case branchStatus.diverged:
accessories.unshift({
text: branch.compData.aheadBy.toString(),
icon: GitpodIcons.branchDiverged,
});
break;
case branchStatus.IDENTICAL:
accessories.unshift({
text: "IDN",
icon: GitpodIcons.branchIdentical,
});
break;
}
}
if (branch.compData.commits) {
accessories.unshift({
tag: {
value: branch.compData.commits.totalCount.toString(),
color: Color.Yellow,
},
icon: GitpodIcons.commit_icon,
});
}
}
return (
<List.Item
icon={GitpodIcons.branchIcon}
subtitle={mainBranch}
title={branch.branchName}
accessories={accessories}
actions={
<ActionPanel>
<Action
title="Open Branch in Gitpod"
onAction={() => {
OpenInGitpod(branchURL,"Branch",repository,branch.branchName)
}}
shortcut={{ modifiers: ["cmd"], key: "g" }}
/>
<Action
title="Open Branch in GitHub"
onAction={() => {
open(branchURL);
}}
/>
<Action title="Configure Workspace" onAction={()=> push(<ContextPreferences type="Branch" repository={repository} context={branch.branchName}/>)} shortcut={{ modifiers: ["cmd"], key: "w" }}/>
</ActionPanel>
}
/>
);
}