Skip to content

Commit

Permalink
[feat] Added workspace class and editor preferences at Repo, Context …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
Palanikannan1437 authored Mar 16, 2023
1 parent f4594fc commit e82ebb1
Show file tree
Hide file tree
Showing 10 changed files with 471 additions and 56 deletions.
75 changes: 75 additions & 0 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"
}
],
"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
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

0 comments on commit e82ebb1

Please sign in to comment.