Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Added workspace class and editor preferences at Repo, Context and Global levels with cascade #30

Merged
merged 7 commits into from
Mar 16, 2023
86 changes: 75 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,81 @@
"Productivity"
],
"license": "MIT",
"preferences": [
{
"name": "preferredEditor",
"title": "Default Workspace Editor",
"description": "Choose your Preferred editor for Gitpod",
"type": "dropdown",
"data": [
{
"title": "VS Code Browser",
"value": "code"
},
{
"title": "VS Code Desktop",
"value": "code-desktop"
},
{
"title": "IntelliJ",
"value": "intellij"
},
{
"title": "GoLand",
"value": "goland"
},
{
"title": "PhpStorm",
"value": "phpstorm"
},
{
"title": "PyCharm",
"value": "pycharm"
},
{
"title": "RubyMine",
"value": "rubymine"
},
{
"title": "WebStorm",
"value": "webstorm"
},
{
"title": "Rider",
"value": "rider"
},
{
"title": "CLion",
"value": "clion"
}
],
Palanikannan1437 marked this conversation as resolved.
Show resolved Hide resolved
"required": true
},
{
"name": "useLatest",
"label": "Latest Release (Unstable)",
"description": "Use the latest version for each editor. Insiders for VS Code, EAP for JetBrains IDEs.",
"type": "checkbox",
"required": true
},
{
"name": "preferredEditorClass",
"title": "Default Workspace Class",
"description": "Up to 4 cores, 8GB RAM, 30GB storage in Standard and Up to 8 cores, 16GB RAM, 50GB storage in Large",
"type": "dropdown",
"data": [
{
"title": "Standard",
"value": "g1-standard"
},
{
"title": "Large",
"value": "g1-large"
}
],
"required": true
}
],
"commands": [
{
"name": "open_in_gitpod",
Expand Down Expand Up @@ -41,17 +116,6 @@
]
}
],

"preferences": [
{
"name": "personalAccessToken",
"title": "Personal Access Token",
"placeholder": "Visit https://github.com/settings/tokens",
"description": "Enter Classic Personal Access Token from GitHub",
"type": "password",
"required": true
}
],
"dependencies": {
"@graphql-codegen/cli": "^2.16.2",
"@graphql-codegen/typescript-graphql-request": "^4.5.8",
Expand Down
35 changes: 31 additions & 4 deletions src/components/BranchListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Action, ActionPanel, Color, List, open } from "@raycast/api";
import { Action, ActionPanel, Color, Icon, List, open, useNavigation } from "@raycast/api";
import { usePromise } from "@raycast/utils";

import { branchStatus, GitpodIcons } from "../../constants";
import { branchStatus, GitpodIcons, UIColors } from "../../constants";
import { BranchDetailsFragment, UserFieldsFragment } from "../generated/graphql";
import OpenInGitpod, { getPreferencesForContext } from "../helpers/openInGitpod";
import ContextPreferences from "../preferences/context_preferences";

type BranchItemProps = {
branch: BranchDetailsFragment;
Expand All @@ -11,9 +14,18 @@ type BranchItemProps = {
};

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

const { data: preferences, revalidate } = usePromise(
async () => {
const response = await getPreferencesForContext("Branch", repository, branch.branchName);
return response;
},
);

const { push } = useNavigation();

if (branch.compData) {
if (branch.compData.status) {
switch (branch.compData.status.toString()) {
Expand Down Expand Up @@ -44,6 +56,19 @@ export default function BranchListItem({ branch, mainBranch, repository }: Branc
}
}

accessories.unshift(
{
text: {
value: preferences?.preferredEditorClass === "g1-large" ? "L" : "S",
},
icon: {
source: Icon.ComputerChip,
tintColor: UIColors.gitpod_gold,
},
tooltip: `Editor: ${preferences?.preferredEditor}, Class: ${preferences?.preferredEditorClass} `
},

)
if (branch.compData.commits) {
accessories.unshift({
tag: {
Expand All @@ -66,15 +91,17 @@ export default function BranchListItem({ branch, mainBranch, repository }: Branc
<Action
title="Open Branch in Gitpod"
onAction={() => {
open(`https://gitpod.io/#${branchURL}`);
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 revalidate={revalidate} type="Branch" repository={repository} context={branch.branchName} />)} shortcut={{ modifiers: ["cmd"], key: "w" }} />
</ActionPanel>
}
/>
Expand Down
42 changes: 29 additions & 13 deletions src/components/IssueListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,56 @@
import { Action, ActionPanel, Icon, List, open } from "@raycast/api";
import { MutatePromise } from "@raycast/utils";
import { Action, ActionPanel, Icon, List, open, useNavigation } from "@raycast/api";
import { MutatePromise, usePromise } from "@raycast/utils";
import { format } from "date-fns";

import { UIColors } from "../../constants";
import {
IssueFieldsFragment,
SearchCreatedIssuesQuery,
SearchOpenIssuesQuery,
UserFieldsFragment,
} from "../generated/graphql";
import { getIssueAuthor, getIssueStatus } from "../helpers/issue";
import OpenInGitpod, { getPreferencesForContext } from "../helpers/openInGitpod";
import ContextPreferences from "../preferences/context_preferences";

type IssueListItemProps = {
issue: IssueFieldsFragment;
viewer?: UserFieldsFragment;
mutateList?:
| MutatePromise<SearchCreatedIssuesQuery | undefined>
| MutatePromise<SearchOpenIssuesQuery | undefined>
| MutatePromise<IssueFieldsFragment[] | undefined>;
| MutatePromise<SearchCreatedIssuesQuery | undefined>
| MutatePromise<SearchOpenIssuesQuery | undefined>
| MutatePromise<IssueFieldsFragment[] | undefined>;
};

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

const author = getIssueAuthor(issue);
const status = getIssueStatus(issue);

const { data: preferences, revalidate } = usePromise(
async () => {
const response = await getPreferencesForContext("Issue", issue.repository.nameWithOwner, issue.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}`,
Expand Down Expand Up @@ -62,25 +83,20 @@ export default function IssueListItem({ issue }: IssueListItemProps) {
<Action
title="Open Issue in Gitpod"
onAction={() => {
open(`https://gitpod.io/#${issue.url}`);
OpenInGitpod(issue.url, "Issue", issue.repository.nameWithOwner, issue.title)
}}
shortcut={{ modifiers: ["cmd"], key: "g" }}
/>
<Action
title="View Issue in GitHub"
onAction={() => {
open(issue.url);
}}
/>
<Action title="Configure Workspace" onAction={() => push(<ContextPreferences revalidate={revalidate} repository={issue.repository.nameWithOwner} type="Issue" context={issue.title} />)} shortcut={{ modifiers: ["cmd"], key: "w" }} />
</ActionPanel>
}
/>
);
}

// <IssueActions issue={issue} mutateList={mutateList} viewer={viewer}>
// <Action.Push
// title="Show Details"
// icon={Icon.Sidebar}
// target={<IssueDetail initialIssue={issue} viewer={viewer} mutateList={mutateList} />}
// />
// </IssueActions>
47 changes: 28 additions & 19 deletions src/components/PullRequestListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,56 @@
import { Action, ActionPanel, Icon, List, open } from "@raycast/api";
// import { MutatePromise } from "@raycast/utils";
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 { MyPullRequestsQuery, PullRequestFieldsFragment, UserFieldsFragment } from "../generated/graphql";
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 PullRequestActions from "./PullRequestActions";
// import PullRequestDetail from "./PullRequestDetail";
import ContextPreferences from "../preferences/context_preferences";

type PullRequestListItemProps = {
pullRequest: PullRequestFieldsFragment;
viewer?: UserFieldsFragment;
// mutateList: MutatePromise<MyPullRequestsQuery | undefined> | MutatePromise<PullRequestFieldsFragment[] | undefined>;
};

export default function PullRequestListItem({ pullRequest, viewer }: PullRequestListItemProps) {
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}`,
Expand Down Expand Up @@ -79,27 +96,19 @@ export default function PullRequestListItem({ pullRequest, viewer }: PullRequest
<Action
title="Open PR in Gitpod"
onAction={() => {
open(`https://gitpod.io/#${pullRequest.permalink}`);
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>
}
/>
);
}

{
/* <PullRequestActions pullRequest={pullRequest} viewer={viewer} mutateList={mutateList}>
<Action.Push
title="Show Details"
icon={Icon.Sidebar}
target={<PullRequestDetail initialPullRequest={pullRequest} viewer={viewer} mutateList={mutateList} />}
/>
</PullRequestActions>; */
}
Loading