Skip to content

Commit e82ebb1

Browse files
[feat] Added workspace class and editor preferences at Repo, Context and Global levels with cascade (#30)
* GitHub oAuth added for simpler auth * added preferences at repo, context and global level with cascading behaviour * fixed default preferences and added more context in navigation title at bottom * Delete workspace_preferences.tsx * added global preferences as default preferences for non-configured repos and contexts * removed showOptions from url to directly open in the set ide * added workspace class icons with revalidation and fixed useLatest editor option
1 parent f4594fc commit e82ebb1

10 files changed

+471
-56
lines changed

package.json

+75
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,81 @@
1414
"Productivity"
1515
],
1616
"license": "MIT",
17+
"preferences": [
18+
{
19+
"name": "preferredEditor",
20+
"title": "Default Workspace Editor",
21+
"description": "Choose your Preferred editor for Gitpod",
22+
"type": "dropdown",
23+
"data": [
24+
{
25+
"title": "VS Code Browser",
26+
"value": "code"
27+
},
28+
{
29+
"title": "VS Code Desktop",
30+
"value": "code-desktop"
31+
},
32+
{
33+
"title": "IntelliJ",
34+
"value": "intellij"
35+
},
36+
{
37+
"title": "GoLand",
38+
"value": "goland"
39+
},
40+
{
41+
"title": "PhpStorm",
42+
"value": "phpstorm"
43+
},
44+
{
45+
"title": "PyCharm",
46+
"value": "pycharm"
47+
},
48+
{
49+
"title": "RubyMine",
50+
"value": "rubymine"
51+
},
52+
{
53+
"title": "WebStorm",
54+
"value": "webstorm"
55+
},
56+
{
57+
"title": "Rider",
58+
"value": "rider"
59+
},
60+
{
61+
"title": "CLion",
62+
"value": "clion"
63+
}
64+
],
65+
"required": true
66+
},
67+
{
68+
"name": "useLatest",
69+
"label": "Latest Release (Unstable)",
70+
"description": "Use the latest version for each editor. Insiders for VS Code, EAP for JetBrains IDEs.",
71+
"type": "checkbox",
72+
"required": true
73+
},
74+
{
75+
"name": "preferredEditorClass",
76+
"title": "Default Workspace Class",
77+
"description": "Up to 4 cores, 8GB RAM, 30GB storage in Standard and Up to 8 cores, 16GB RAM, 50GB storage in Large",
78+
"type": "dropdown",
79+
"data": [
80+
{
81+
"title": "Standard",
82+
"value": "g1-standard"
83+
},
84+
{
85+
"title": "Large",
86+
"value": "g1-large"
87+
}
88+
],
89+
"required": true
90+
}
91+
],
1792
"commands": [
1893
{
1994
"name": "open_in_gitpod",

src/components/BranchListItem.tsx

+31-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
import { Action, ActionPanel, Color, List, open } from "@raycast/api";
1+
import { Action, ActionPanel, Color, Icon, List, open, useNavigation } from "@raycast/api";
2+
import { usePromise } from "@raycast/utils";
23

3-
import { branchStatus, GitpodIcons } from "../../constants";
4+
import { branchStatus, GitpodIcons, UIColors } from "../../constants";
45
import { BranchDetailsFragment, UserFieldsFragment } from "../generated/graphql";
6+
import OpenInGitpod, { getPreferencesForContext } from "../helpers/openInGitpod";
7+
import ContextPreferences from "../preferences/context_preferences";
58

69
type BranchItemProps = {
710
branch: BranchDetailsFragment;
@@ -11,9 +14,18 @@ type BranchItemProps = {
1114
};
1215

1316
export default function BranchListItem({ branch, mainBranch, repository }: BranchItemProps) {
14-
const accessories: List.Item.Accessory[] = [];
17+
const accessories: List.Item.Accessory[] = []
1518
const branchURL = "https://github.com/" + repository + "/tree/" + branch.branchName;
1619

20+
const { data: preferences, revalidate } = usePromise(
21+
async () => {
22+
const response = await getPreferencesForContext("Branch", repository, branch.branchName);
23+
return response;
24+
},
25+
);
26+
27+
const { push } = useNavigation();
28+
1729
if (branch.compData) {
1830
if (branch.compData.status) {
1931
switch (branch.compData.status.toString()) {
@@ -44,6 +56,19 @@ export default function BranchListItem({ branch, mainBranch, repository }: Branc
4456
}
4557
}
4658

59+
accessories.unshift(
60+
{
61+
text: {
62+
value: preferences?.preferredEditorClass === "g1-large" ? "L" : "S",
63+
},
64+
icon: {
65+
source: Icon.ComputerChip,
66+
tintColor: UIColors.gitpod_gold,
67+
},
68+
tooltip: `Editor: ${preferences?.preferredEditor}, Class: ${preferences?.preferredEditorClass} `
69+
},
70+
71+
)
4772
if (branch.compData.commits) {
4873
accessories.unshift({
4974
tag: {
@@ -66,15 +91,17 @@ export default function BranchListItem({ branch, mainBranch, repository }: Branc
6691
<Action
6792
title="Open Branch in Gitpod"
6893
onAction={() => {
69-
open(`https://gitpod.io/#${branchURL}`);
94+
OpenInGitpod(branchURL, "Branch", repository, branch.branchName)
7095
}}
96+
shortcut={{ modifiers: ["cmd"], key: "g" }}
7197
/>
7298
<Action
7399
title="Open Branch in GitHub"
74100
onAction={() => {
75101
open(branchURL);
76102
}}
77103
/>
104+
<Action title="Configure Workspace" onAction={() => push(<ContextPreferences revalidate={revalidate} type="Branch" repository={repository} context={branch.branchName} />)} shortcut={{ modifiers: ["cmd"], key: "w" }} />
78105
</ActionPanel>
79106
}
80107
/>

src/components/IssueListItem.tsx

+29-13
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,56 @@
1-
import { Action, ActionPanel, Icon, List, open } from "@raycast/api";
2-
import { MutatePromise } from "@raycast/utils";
1+
import { Action, ActionPanel, Icon, List, open, useNavigation } from "@raycast/api";
2+
import { MutatePromise, usePromise } from "@raycast/utils";
33
import { format } from "date-fns";
44

5+
import { UIColors } from "../../constants";
56
import {
67
IssueFieldsFragment,
78
SearchCreatedIssuesQuery,
89
SearchOpenIssuesQuery,
910
UserFieldsFragment,
1011
} from "../generated/graphql";
1112
import { getIssueAuthor, getIssueStatus } from "../helpers/issue";
13+
import OpenInGitpod, { getPreferencesForContext } from "../helpers/openInGitpod";
14+
import ContextPreferences from "../preferences/context_preferences";
1215

1316
type IssueListItemProps = {
1417
issue: IssueFieldsFragment;
1518
viewer?: UserFieldsFragment;
1619
mutateList?:
17-
| MutatePromise<SearchCreatedIssuesQuery | undefined>
18-
| MutatePromise<SearchOpenIssuesQuery | undefined>
19-
| MutatePromise<IssueFieldsFragment[] | undefined>;
20+
| MutatePromise<SearchCreatedIssuesQuery | undefined>
21+
| MutatePromise<SearchOpenIssuesQuery | undefined>
22+
| MutatePromise<IssueFieldsFragment[] | undefined>;
2023
};
2124

2225
export default function IssueListItem({ issue }: IssueListItemProps) {
26+
const { push } = useNavigation();
2327
const updatedAt = new Date(issue.updatedAt);
2428

2529
const author = getIssueAuthor(issue);
2630
const status = getIssueStatus(issue);
2731

32+
const { data: preferences, revalidate } = usePromise(
33+
async () => {
34+
const response = await getPreferencesForContext("Issue", issue.repository.nameWithOwner, issue.title);
35+
return response;
36+
},
37+
);
38+
2839
const accessories: List.Item.Accessory[] = [
2940
{
3041
date: updatedAt,
3142
tooltip: `Updated: ${format(updatedAt, "EEEE d MMMM yyyy 'at' HH:mm")}`,
3243
},
44+
{
45+
text: {
46+
value: preferences?.preferredEditorClass === "g1-large" ? "L" : "S",
47+
},
48+
icon: {
49+
source: Icon.ComputerChip,
50+
tintColor: UIColors.gitpod_gold,
51+
},
52+
tooltip: `Editor: ${preferences?.preferredEditor}, Class: ${preferences?.preferredEditorClass} `
53+
},
3354
{
3455
icon: author.icon,
3556
tooltip: `Author: ${author.text}`,
@@ -62,25 +83,20 @@ export default function IssueListItem({ issue }: IssueListItemProps) {
6283
<Action
6384
title="Open Issue in Gitpod"
6485
onAction={() => {
65-
open(`https://gitpod.io/#${issue.url}`);
86+
OpenInGitpod(issue.url, "Issue", issue.repository.nameWithOwner, issue.title)
6687
}}
88+
shortcut={{ modifiers: ["cmd"], key: "g" }}
6789
/>
6890
<Action
6991
title="View Issue in GitHub"
7092
onAction={() => {
7193
open(issue.url);
7294
}}
7395
/>
96+
<Action title="Configure Workspace" onAction={() => push(<ContextPreferences revalidate={revalidate} repository={issue.repository.nameWithOwner} type="Issue" context={issue.title} />)} shortcut={{ modifiers: ["cmd"], key: "w" }} />
7497
</ActionPanel>
7598
}
7699
/>
77100
);
78101
}
79102

80-
// <IssueActions issue={issue} mutateList={mutateList} viewer={viewer}>
81-
// <Action.Push
82-
// title="Show Details"
83-
// icon={Icon.Sidebar}
84-
// target={<IssueDetail initialIssue={issue} viewer={viewer} mutateList={mutateList} />}
85-
// />
86-
// </IssueActions>

src/components/PullRequestListItem.tsx

+28-19
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,56 @@
1-
import { Action, ActionPanel, Icon, List, open } from "@raycast/api";
2-
// import { MutatePromise } from "@raycast/utils";
1+
import { Action, ActionPanel, Icon, List, open, useNavigation } from "@raycast/api";
2+
import { usePromise } from "@raycast/utils";
33
import { format } from "date-fns";
44
import { useMemo } from "react";
55

6-
import { MyPullRequestsQuery, PullRequestFieldsFragment, UserFieldsFragment } from "../generated/graphql";
6+
import { UIColors } from "../../constants";
7+
import { PullRequestFieldsFragment, UserFieldsFragment } from "../generated/graphql";
8+
import OpenInGitpod, { getPreferencesForContext } from "../helpers/openInGitpod";
79
import {
810
getCheckStateAccessory,
911
getNumberOfComments,
1012
getPullRequestAuthor,
1113
getPullRequestStatus,
1214
getReviewDecision,
1315
} from "../helpers/pull-request";
14-
15-
// import PullRequestActions from "./PullRequestActions";
16-
// import PullRequestDetail from "./PullRequestDetail";
16+
import ContextPreferences from "../preferences/context_preferences";
1717

1818
type PullRequestListItemProps = {
1919
pullRequest: PullRequestFieldsFragment;
2020
viewer?: UserFieldsFragment;
21-
// mutateList: MutatePromise<MyPullRequestsQuery | undefined> | MutatePromise<PullRequestFieldsFragment[] | undefined>;
2221
};
2322

24-
export default function PullRequestListItem({ pullRequest, viewer }: PullRequestListItemProps) {
23+
export default function PullRequestListItem({ pullRequest }: PullRequestListItemProps) {
2524
const updatedAt = new Date(pullRequest.updatedAt);
25+
const { push } = useNavigation();
2626

2727
const numberOfComments = useMemo(() => getNumberOfComments(pullRequest), []);
2828
const author = getPullRequestAuthor(pullRequest);
2929
const status = getPullRequestStatus(pullRequest);
3030
const reviewDecision = getReviewDecision(pullRequest.reviewDecision);
3131

32+
const { data: preferences, revalidate } = usePromise(
33+
async () => {
34+
const response = await getPreferencesForContext("Pull Request", pullRequest.repository.nameWithOwner, pullRequest.title);
35+
return response;
36+
},
37+
);
38+
3239
const accessories: List.Item.Accessory[] = [
3340
{
3441
date: updatedAt,
3542
tooltip: `Updated: ${format(updatedAt, "EEEE d MMMM yyyy 'at' HH:mm")}`,
3643
},
44+
{
45+
text: {
46+
value: preferences?.preferredEditorClass === "g1-large" ? "L" : "S",
47+
},
48+
icon: {
49+
source: Icon.ComputerChip,
50+
tintColor: UIColors.gitpod_gold,
51+
},
52+
tooltip: `Editor: ${preferences?.preferredEditor}, Class: ${preferences?.preferredEditorClass} `
53+
},
3754
{
3855
icon: author.icon,
3956
tooltip: `Author: ${author.text}`,
@@ -79,27 +96,19 @@ export default function PullRequestListItem({ pullRequest, viewer }: PullRequest
7996
<Action
8097
title="Open PR in Gitpod"
8198
onAction={() => {
82-
open(`https://gitpod.io/#${pullRequest.permalink}`);
99+
OpenInGitpod(pullRequest.permalink, "Pull Request", pullRequest.repository.nameWithOwner, pullRequest.title);
83100
}}
101+
shortcut={{ modifiers: ["cmd"], key: "g" }}
84102
/>
85103
<Action
86104
title="View PR in GitHub"
87105
onAction={() => {
88106
open(pullRequest.permalink);
89107
}}
90108
/>
109+
<Action title="Configure Workspace" onAction={() => push(<ContextPreferences revalidate={revalidate} type="Pull Request" repository={pullRequest.repository.nameWithOwner} context={pullRequest.title} />)} shortcut={{ modifiers: ["cmd"], key: "w" }} />
91110
</ActionPanel>
92111
}
93112
/>
94113
);
95114
}
96-
97-
{
98-
/* <PullRequestActions pullRequest={pullRequest} viewer={viewer} mutateList={mutateList}>
99-
<Action.Push
100-
title="Show Details"
101-
icon={Icon.Sidebar}
102-
target={<PullRequestDetail initialPullRequest={pullRequest} viewer={viewer} mutateList={mutateList} />}
103-
/>
104-
</PullRequestActions>; */
105-
}

0 commit comments

Comments
 (0)