From 32b4ef837c644856dea077d5ab948cb823cb6faf Mon Sep 17 00:00:00 2001 From: Palanikannan1437 Date: Mon, 6 Mar 2023 20:46:45 +0530 Subject: [PATCH 1/7] GitHub oAuth added for simpler auth --- package.json | 13 +------------ src/helpers/withGithubClient.tsx | 6 ++---- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 3227824..5515669 100644 --- a/package.json +++ b/package.json @@ -41,17 +41,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", @@ -84,4 +73,4 @@ "publish": "ray publish", "generate": "graphql-codegen --config codegen.ts" } -} +} \ No newline at end of file diff --git a/src/helpers/withGithubClient.tsx b/src/helpers/withGithubClient.tsx index 28f2b3e..15604dc 100644 --- a/src/helpers/withGithubClient.tsx +++ b/src/helpers/withGithubClient.tsx @@ -1,5 +1,4 @@ import { Detail, environment, MenuBarExtra } from "@raycast/api"; -import { getPreferenceValues } from "@raycast/api"; import { GraphQLClient } from "graphql-request"; import { Octokit } from "octokit"; import { useMemo, useState } from "react"; @@ -16,9 +15,8 @@ export function withGithubClient(component: JSX.Element) { // we use a `useMemo` instead of `useEffect` to avoid a render useMemo(() => { (async function () { - const { personalAccessToken } = getPreferenceValues(); - const token = personalAccessToken || (await authorize()); - const authorization = personalAccessToken ? `token ${token}` : `bearer ${token}`; + const token = await authorize(); + const authorization = `bearer ${token}`; github = getSdk(new GraphQLClient("https://api.github.com/graphql", { headers: { authorization } })); octokit = new Octokit({ auth: token }); From 2994d55f2acb7f90d5280a47b11dd7593171bfda Mon Sep 17 00:00:00 2001 From: Palanikannan1437 Date: Thu, 9 Mar 2023 02:51:33 +0530 Subject: [PATCH 2/7] added preferences at repo, context and global level with cascading behaviour --- package.json | 77 +++++++++++++++++++- src/components/BranchListItem.tsx | 9 ++- src/components/IssueListItem.tsx | 16 ++--- src/components/PullRequestListItem.tsx | 29 +++----- src/components/RepositoryListItem.tsx | 6 +- src/components/SearchRepositoryDropdown.tsx | 2 +- src/helpers/branch.ts | 41 +++++++++++ src/helpers/openInGitpod.ts | 55 +++++++++++++++ src/preferences/context_preferences.tsx | 78 +++++++++++++++++++++ src/preferences/repository_preferences.tsx | 69 ++++++++++++++++++ src/workspace_preferences.tsx | 15 ++++ 11 files changed, 364 insertions(+), 33 deletions(-) create mode 100644 src/helpers/branch.ts create mode 100644 src/helpers/openInGitpod.ts create mode 100644 src/preferences/context_preferences.tsx create mode 100644 src/preferences/repository_preferences.tsx create mode 100644 src/workspace_preferences.tsx diff --git a/package.json b/package.json index 5515669..e5e92e4 100644 --- a/package.json +++ b/package.json @@ -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", @@ -73,4 +148,4 @@ "publish": "ray publish", "generate": "graphql-codegen --config codegen.ts" } -} \ No newline at end of file +} diff --git a/src/components/BranchListItem.tsx b/src/components/BranchListItem.tsx index f957242..41ef9f4 100644 --- a/src/components/BranchListItem.tsx +++ b/src/components/BranchListItem.tsx @@ -1,7 +1,9 @@ -import { Action, ActionPanel, Color, List, open } from "@raycast/api"; +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; @@ -14,6 +16,7 @@ export default function BranchListItem({ branch, mainBranch, repository }: Branc 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()) { @@ -66,8 +69,9 @@ export default function BranchListItem({ branch, mainBranch, repository }: Branc { - open(`https://gitpod.io/#${branchURL}`); + OpenInGitpod(branchURL,"Branch",repository,branch.branchName) }} + shortcut={{ modifiers: ["cmd"], key: "g" }} /> + push()} shortcut={{ modifiers: ["cmd"], key: "w" }}/> } /> diff --git a/src/components/IssueListItem.tsx b/src/components/IssueListItem.tsx index e9de57c..2e7b468 100644 --- a/src/components/IssueListItem.tsx +++ b/src/components/IssueListItem.tsx @@ -1,4 +1,4 @@ -import { Action, ActionPanel, Icon, List, open } from "@raycast/api"; +import { Action, ActionPanel, Icon, List, open, useNavigation } from "@raycast/api"; import { MutatePromise } from "@raycast/utils"; import { format } from "date-fns"; @@ -9,6 +9,8 @@ import { UserFieldsFragment, } from "../generated/graphql"; import { getIssueAuthor, getIssueStatus } from "../helpers/issue"; +import OpenInGitpod from "../helpers/openInGitpod"; +import ContextPreferences from "../preferences/context_preferences"; type IssueListItemProps = { issue: IssueFieldsFragment; @@ -20,6 +22,7 @@ type IssueListItemProps = { }; export default function IssueListItem({ issue }: IssueListItemProps) { + const { push } = useNavigation(); const updatedAt = new Date(issue.updatedAt); const author = getIssueAuthor(issue); @@ -62,8 +65,9 @@ export default function IssueListItem({ issue }: IssueListItemProps) { { - open(`https://gitpod.io/#${issue.url}`); + OpenInGitpod(issue.url,"Issue",issue.repository.nameWithOwner, issue.title) }} + shortcut={{ modifiers: ["cmd"], key: "g" }} /> + push()} shortcut={{ modifiers: ["cmd"], key: "w" }}/> } /> ); } -// -// } -// /> -// diff --git a/src/components/PullRequestListItem.tsx b/src/components/PullRequestListItem.tsx index e87b4e3..aac0938 100644 --- a/src/components/PullRequestListItem.tsx +++ b/src/components/PullRequestListItem.tsx @@ -1,9 +1,10 @@ -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 { format } from "date-fns"; +import { pull } from "lodash"; import { useMemo } from "react"; -import { MyPullRequestsQuery, PullRequestFieldsFragment, UserFieldsFragment } from "../generated/graphql"; +import { PullRequestFieldsFragment, UserFieldsFragment } from "../generated/graphql"; +import OpenInGitpod from "../helpers/openInGitpod"; import { getCheckStateAccessory, getNumberOfComments, @@ -11,18 +12,16 @@ import { 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 | MutatePromise; }; -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); @@ -79,8 +78,9 @@ export default function PullRequestListItem({ pullRequest, viewer }: PullRequest { - open(`https://gitpod.io/#${pullRequest.permalink}`); + OpenInGitpod(pullRequest.permalink, "Pull Request", pullRequest.repository.nameWithOwner,pullRequest.title); }} + shortcut={{ modifiers: ["cmd"], key: "g" }} /> + push()} shortcut={{ modifiers: ["cmd"], key: "w" }}/> } /> ); } - -{ - /* - } - /> -; */ -} diff --git a/src/components/RepositoryListItem.tsx b/src/components/RepositoryListItem.tsx index 991478f..d1f5333 100644 --- a/src/components/RepositoryListItem.tsx +++ b/src/components/RepositoryListItem.tsx @@ -3,8 +3,10 @@ import { MutatePromise } from "@raycast/utils"; import { GitpodIcons } from "../../constants"; import { ExtendedRepositoryFieldsFragment } from "../generated/graphql"; +import OpenInGitpod from "../helpers/openInGitpod"; import { getGitHubUser } from "../helpers/users"; import SearchContext from "../open_repo_context"; +import RepositoryPreference from "../preferences/repository_preferences"; type RepositoryListItemProps = { repository: ExtendedRepositoryFieldsFragment; @@ -81,7 +83,9 @@ export default function RepositoryListItem({ repository, isGitpodified, onVisit push(); }} /> - + open(repository.url)} /> + OpenInGitpod(repository.url,"Repository",repository.nameWithOwner)} shortcut={{ modifiers: ["cmd"], key: "g" }}/> + push()} shortcut={{ modifiers: ["cmd"], key: "w" }}/> } /> diff --git a/src/components/SearchRepositoryDropdown.tsx b/src/components/SearchRepositoryDropdown.tsx index c34fece..15d3185 100644 --- a/src/components/SearchRepositoryDropdown.tsx +++ b/src/components/SearchRepositoryDropdown.tsx @@ -8,13 +8,13 @@ export default function SearchRepositoryDropdown(props: { onFilterChange: (filte return ( + {viewer ? ( `org:${org?.login}`).join(" ")}`} /> ) : null} - diff --git a/src/helpers/branch.ts b/src/helpers/branch.ts new file mode 100644 index 0000000..0022180 --- /dev/null +++ b/src/helpers/branch.ts @@ -0,0 +1,41 @@ +import { LocalStorage } from "@raycast/api"; +import { useCachedState } from "@raycast/utils"; +import { useEffect } from "react"; + +import { BranchDetailsFragment, ExtendedRepositoryFieldsFragment } from "../generated/graphql"; + +const VISITED_BRANCH_KEY = "VISITED_BRANCHES"; +const VISITED_BRANCH_LENGTH = 10; + +// History was stored in `LocalStorage` before, after migration it's stored in `Cache` +async function loadVisitedBranches() { + const item = await LocalStorage.getItem(VISITED_BRANCH_KEY); + if (item) { + const parsed = JSON.parse(item).slice(0, VISITED_BRANCH_LENGTH); + return parsed as BranchDetailsFragment[]; + } else { + return []; + } +} +export function useBranchHistory() { + const [history, setHistory] = useCachedState("BranchHistory", []); + const [migratedHistory, setMigratedHistory] = useCachedState("migratedBranchHistory", false); + + useEffect(() => { + if (!migratedHistory) { + loadVisitedBranches().then((branches) => { + setHistory(branches); + setMigratedHistory(true); + }); + } + }, [migratedHistory]); + + function visitBranch(branch: BranchDetailsFragment, repository: ExtendedRepositoryFieldsFragment) { + const visitedBranch = [branch, ...(history?.filter((item) => item.branchName !== branch.branchName) ?? [])]; + LocalStorage.setItem(VISITED_BRANCH_KEY, JSON.stringify(visitedBranch)); + const nextBranch = visitedBranch.slice(0, VISITED_BRANCH_LENGTH); + setHistory(nextBranch); + } + + return { history, visitBranch }; +} diff --git a/src/helpers/openInGitpod.ts b/src/helpers/openInGitpod.ts new file mode 100644 index 0000000..78da782 --- /dev/null +++ b/src/helpers/openInGitpod.ts @@ -0,0 +1,55 @@ +import { LocalStorage, open, showToast, Toast } from "@raycast/api"; +import { getPreferenceValues } from "@raycast/api"; + +interface Preferences { + preferredEditor: string; + useLatest: boolean; + preferredEditorClass: "g1-standard" | "g1-large"; +} + +export default async function OpenInGitpod(contextUrl: string, type: "Branch" | "Pull Request" | "Issue" | "Repository", repository: string, context?: string) { + let preferences = getPreferenceValues(); + + if (type === "Branch" || type === "Pull Request" || type === "Issue") { + const item = await LocalStorage.getItem(`${repository}%${context}`) + const contextPref = item ? await JSON.parse(item) : null + if (contextPref && contextPref.preferredEditor && contextPref.preferredEditorClass) { + preferences = contextPref + } else { + const repoItem = await LocalStorage.getItem(`${repository}`); + const repoPref = repoItem ? await JSON.parse(repoItem) : null + if (repoPref && repoPref.preferredEditor && repoPref.preferredEditorClass) { + preferences = repoPref + } + } + } else if (type === "Repository") { + const item = await LocalStorage.getItem(`${repository}`); + const repoPref = item ? await JSON.parse(item) : null + if (repoPref && repoPref.preferredEditor && repoPref.preferredEditorClass) { + preferences = repoPref + } + } + + if (type === "Branch") { + //visit branch + } else if (type === "Pull Request") { + //vitit pr + } else if (type === "Issue") { + //visit issue + } + + try { + await showToast({ + title: "Launching your workspace", + style: Toast.Style.Success, + }); + setTimeout(() => { + open(`https://gitpod.io/new/?showOptions=false&useLatest=${preferences.useLatest}&editor=${preferences.preferredEditor}&workspaceClass=${preferences.preferredEditorClass}#${contextUrl}`); + }, 1000); + } catch (error) { + await showToast({ + title: "Error launching workspace", + style: Toast.Style.Failure, + }); + } +} diff --git a/src/preferences/context_preferences.tsx b/src/preferences/context_preferences.tsx new file mode 100644 index 0000000..c8ed24d --- /dev/null +++ b/src/preferences/context_preferences.tsx @@ -0,0 +1,78 @@ +import { ActionPanel, Form, Action, LocalStorage, showHUD, useNavigation } from "@raycast/api"; +import { useEffect, useState } from "react"; + +type ContextPreferenceProps = { + repository: string; + type: "Branch" | "Pull Request" | "Issue"; + context: string +} + +interface Preferences { + preferredEditor: string; + useLatest: boolean; + preferredEditorClass: "g1-standard" | "g1-large"; +} + +async function getDefaultValue(repository: string, context: string) { + let defaultPrefValue: Preferences = { preferredEditor: "code", preferredEditorClass: "g1-large", useLatest: false }; + const item = await LocalStorage.getItem(`${repository}%${context}`) + const contextPref = item ? await JSON.parse(item) : null + if (contextPref && contextPref.preferredEditor && contextPref.preferredEditorClass) { + defaultPrefValue = contextPref + } else { + const repoItem = await LocalStorage.getItem(`${repository}`); + const repoPref = repoItem ? await JSON.parse(repoItem) : null + if (repoPref && repoPref.preferredEditor && repoPref.preferredEditorClass) { + defaultPrefValue = repoPref + } + } + + return defaultPrefValue +} + +export default function ContextPreferences({ repository, type, context }: ContextPreferenceProps) { + const [defaultPrefValue, setDefaultPrefValue] = useState(null) + + useEffect(() => { + const getUsers = async () => { + const res = await getDefaultValue(repository, context); + setDefaultPrefValue(res); + }; + + getUsers(); + }, []); + + const { pop } = useNavigation(); + + return ( + defaultPrefValue && + (
+ { + await LocalStorage.setItem(`${repository}%${context}`, JSON.stringify(values)); + pop(); + }} /> + + } + > + + + + + + + + + + + + + + + + + + ) + ); +} diff --git a/src/preferences/repository_preferences.tsx b/src/preferences/repository_preferences.tsx new file mode 100644 index 0000000..53db285 --- /dev/null +++ b/src/preferences/repository_preferences.tsx @@ -0,0 +1,69 @@ +import { ActionPanel, Form, Action, LocalStorage, showHUD, useNavigation } from "@raycast/api"; +import { useEffect, useState } from "react"; + +type RepositoryPreferenceProps = { + repository: string; +} + +interface Preferences { + preferredEditor: string; + useLatest: boolean; + preferredEditorClass: "g1-standard" | "g1-large"; +} + +async function getDefaultValue(repository: string) { + let defaultPrefValue: Preferences = { preferredEditor: "code", preferredEditorClass: "g1-large", useLatest: false }; + const item = await LocalStorage.getItem(`${repository}`) + const contextPref = item ? await JSON.parse(item) : null + if (contextPref && contextPref.preferredEditor && contextPref.preferredEditorClass) { + defaultPrefValue = contextPref + } + return defaultPrefValue +} + +export default function RepositoryPreference({ repository }: RepositoryPreferenceProps) { + const [defaultPrefValue, setDefaultPrefValue] = useState(null) + + const { pop } = useNavigation(); + + useEffect(() => { + const loadDefaultValues = async () => { + const res = await getDefaultValue(repository); + setDefaultPrefValue(res); + }; + + loadDefaultValues(); + }, []); + + return ( + defaultPrefValue && ( +
+ { + await LocalStorage.setItem(`${repository}`, JSON.stringify(values)); + pop(); + }} /> + + } + > + + + + + + + + + + + + + + + + + + ) + ); +} diff --git a/src/workspace_preferences.tsx b/src/workspace_preferences.tsx new file mode 100644 index 0000000..771dcf5 --- /dev/null +++ b/src/workspace_preferences.tsx @@ -0,0 +1,15 @@ +import { ActionPanel, Action, Detail, openCommandPreferences } from "@raycast/api"; + +export default function Command() { + const markdown = "API key incorrect. Please update it in command preferences and try again."; + return ( + + + + } + /> + ); +} From 5acdfd3f81aefcf0acb5d658d2e283d160f1d5ca Mon Sep 17 00:00:00 2001 From: Palanikannan1437 Date: Thu, 9 Mar 2023 03:30:50 +0530 Subject: [PATCH 3/7] fixed default preferences and added more context in navigation title at bottom --- src/preferences/context_preferences.tsx | 31 +++++++++++++++------- src/preferences/repository_preferences.tsx | 21 ++++++++++++--- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/preferences/context_preferences.tsx b/src/preferences/context_preferences.tsx index c8ed24d..beb4773 100644 --- a/src/preferences/context_preferences.tsx +++ b/src/preferences/context_preferences.tsx @@ -1,4 +1,4 @@ -import { ActionPanel, Form, Action, LocalStorage, showHUD, useNavigation } from "@raycast/api"; +import { ActionPanel, Form, Action, LocalStorage, useNavigation, showToast, Toast } from "@raycast/api"; import { useEffect, useState } from "react"; type ContextPreferenceProps = { @@ -14,18 +14,18 @@ interface Preferences { } async function getDefaultValue(repository: string, context: string) { - let defaultPrefValue: Preferences = { preferredEditor: "code", preferredEditorClass: "g1-large", useLatest: false }; + let defaultPrefValue: Preferences = { preferredEditor: "code", preferredEditorClass: "g1-standard", useLatest: false }; const item = await LocalStorage.getItem(`${repository}%${context}`) const contextPref = item ? await JSON.parse(item) : null if (contextPref && contextPref.preferredEditor && contextPref.preferredEditorClass) { defaultPrefValue = contextPref } else { - const repoItem = await LocalStorage.getItem(`${repository}`); - const repoPref = repoItem ? await JSON.parse(repoItem) : null - if (repoPref && repoPref.preferredEditor && repoPref.preferredEditorClass) { - defaultPrefValue = repoPref - } + const repoItem = await LocalStorage.getItem(`${repository}`); + const repoPref = repoItem ? await JSON.parse(repoItem) : null + if (repoPref && repoPref.preferredEditor && repoPref.preferredEditorClass) { + defaultPrefValue = repoPref } + } return defaultPrefValue } @@ -47,11 +47,24 @@ export default function ContextPreferences({ repository, type, context }: Contex return ( defaultPrefValue && (
{ - await LocalStorage.setItem(`${repository}%${context}`, JSON.stringify(values)); - pop(); + try { + await LocalStorage.setItem(`${repository}%${context}`, JSON.stringify(values)); + await showToast({ + title: "Preferences saved successfully", + style: Toast.Style.Success, + }); + pop(); + } + catch (error) { + await showToast({ + title: "Error saving preferences", + style: Toast.Style.Failure, + }); + } }} /> } diff --git a/src/preferences/repository_preferences.tsx b/src/preferences/repository_preferences.tsx index 53db285..a89d649 100644 --- a/src/preferences/repository_preferences.tsx +++ b/src/preferences/repository_preferences.tsx @@ -1,4 +1,4 @@ -import { ActionPanel, Form, Action, LocalStorage, showHUD, useNavigation } from "@raycast/api"; +import { ActionPanel, Form, Action, LocalStorage, showHUD, useNavigation, showToast, Toast } from "@raycast/api"; import { useEffect, useState } from "react"; type RepositoryPreferenceProps = { @@ -12,7 +12,7 @@ interface Preferences { } async function getDefaultValue(repository: string) { - let defaultPrefValue: Preferences = { preferredEditor: "code", preferredEditorClass: "g1-large", useLatest: false }; + let defaultPrefValue: Preferences = { preferredEditor: "code", preferredEditorClass: "g1-standard", useLatest: false }; const item = await LocalStorage.getItem(`${repository}`) const contextPref = item ? await JSON.parse(item) : null if (contextPref && contextPref.preferredEditor && contextPref.preferredEditorClass) { @@ -38,11 +38,24 @@ export default function RepositoryPreference({ repository }: RepositoryPreferenc return ( defaultPrefValue && ( { - await LocalStorage.setItem(`${repository}`, JSON.stringify(values)); - pop(); + try { + await LocalStorage.setItem(`${repository}`, JSON.stringify(values)); + await showToast({ + title: "Preferences saved successfully", + style: Toast.Style.Success, + }); + pop(); + } + catch (error) { + await showToast({ + title: "Error saving preferences", + style: Toast.Style.Failure, + }); + } }} /> } From c153fc50fb280fb8db383d33a760985a66e9fd65 Mon Sep 17 00:00:00 2001 From: PalanikannanM <73993394+Palanikannan1437@users.noreply.github.com> Date: Thu, 9 Mar 2023 03:34:18 +0530 Subject: [PATCH 4/7] Delete workspace_preferences.tsx --- src/workspace_preferences.tsx | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 src/workspace_preferences.tsx diff --git a/src/workspace_preferences.tsx b/src/workspace_preferences.tsx deleted file mode 100644 index 771dcf5..0000000 --- a/src/workspace_preferences.tsx +++ /dev/null @@ -1,15 +0,0 @@ -import { ActionPanel, Action, Detail, openCommandPreferences } from "@raycast/api"; - -export default function Command() { - const markdown = "API key incorrect. Please update it in command preferences and try again."; - return ( - - - - } - /> - ); -} From c304cf6af1e3b19d3c853f29affb402aa0044825 Mon Sep 17 00:00:00 2001 From: Palanikannan1437 Date: Thu, 9 Mar 2023 09:31:06 +0530 Subject: [PATCH 5/7] added global preferences as default preferences for non-configured repos and contexts --- src/preferences/context_preferences.tsx | 4 ++-- src/preferences/repository_preferences.tsx | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/preferences/context_preferences.tsx b/src/preferences/context_preferences.tsx index beb4773..e6a2ce7 100644 --- a/src/preferences/context_preferences.tsx +++ b/src/preferences/context_preferences.tsx @@ -1,4 +1,4 @@ -import { ActionPanel, Form, Action, LocalStorage, useNavigation, showToast, Toast } from "@raycast/api"; +import { ActionPanel, Form, Action, LocalStorage, useNavigation, showToast, Toast, getPreferenceValues } from "@raycast/api"; import { useEffect, useState } from "react"; type ContextPreferenceProps = { @@ -14,7 +14,7 @@ interface Preferences { } async function getDefaultValue(repository: string, context: string) { - let defaultPrefValue: Preferences = { preferredEditor: "code", preferredEditorClass: "g1-standard", useLatest: false }; + let defaultPrefValue: Preferences = getPreferenceValues(); const item = await LocalStorage.getItem(`${repository}%${context}`) const contextPref = item ? await JSON.parse(item) : null if (contextPref && contextPref.preferredEditor && contextPref.preferredEditorClass) { diff --git a/src/preferences/repository_preferences.tsx b/src/preferences/repository_preferences.tsx index a89d649..8fcd1b0 100644 --- a/src/preferences/repository_preferences.tsx +++ b/src/preferences/repository_preferences.tsx @@ -1,4 +1,4 @@ -import { ActionPanel, Form, Action, LocalStorage, showHUD, useNavigation, showToast, Toast } from "@raycast/api"; +import { ActionPanel, Form, Action, LocalStorage, showHUD, useNavigation, showToast, Toast, getPreferenceValues } from "@raycast/api"; import { useEffect, useState } from "react"; type RepositoryPreferenceProps = { @@ -12,7 +12,8 @@ interface Preferences { } async function getDefaultValue(repository: string) { - let defaultPrefValue: Preferences = { preferredEditor: "code", preferredEditorClass: "g1-standard", useLatest: false }; + let defaultPrefValue: Preferences = getPreferenceValues(); + const item = await LocalStorage.getItem(`${repository}`) const contextPref = item ? await JSON.parse(item) : null if (contextPref && contextPref.preferredEditor && contextPref.preferredEditorClass) { From 436fa820f9c5ce3df7f52e0933ddbbe9415da070 Mon Sep 17 00:00:00 2001 From: Palanikannan1437 Date: Thu, 9 Mar 2023 11:00:57 +0530 Subject: [PATCH 6/7] removed showOptions from url to directly open in the set ide --- src/helpers/openInGitpod.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/openInGitpod.ts b/src/helpers/openInGitpod.ts index 78da782..d5abfde 100644 --- a/src/helpers/openInGitpod.ts +++ b/src/helpers/openInGitpod.ts @@ -44,7 +44,7 @@ export default async function OpenInGitpod(contextUrl: string, type: "Branch" | style: Toast.Style.Success, }); setTimeout(() => { - open(`https://gitpod.io/new/?showOptions=false&useLatest=${preferences.useLatest}&editor=${preferences.preferredEditor}&workspaceClass=${preferences.preferredEditorClass}#${contextUrl}`); + open(`https://gitpod.io/?useLatest=${preferences.useLatest}&editor=${preferences.preferredEditor}&workspaceClass=${preferences.preferredEditorClass}#${contextUrl}`); }, 1000); } catch (error) { await showToast({ From 657b8380558582507f09610b67bf8dc055ec6c0d Mon Sep 17 00:00:00 2001 From: Palanikannan1437 Date: Thu, 16 Mar 2023 16:49:35 +0530 Subject: [PATCH 7/7] added workspace class icons with revalidation and fixed useLatest editor option --- src/components/BranchListItem.tsx | 34 ++++++++++++--- src/components/IssueListItem.tsx | 34 +++++++++++---- src/components/PullRequestListItem.tsx | 28 +++++++++--- src/components/RepositoryListItem.tsx | 51 ++++++++++++---------- src/helpers/openInGitpod.ts | 9 ++-- src/preferences/context_preferences.tsx | 4 +- src/preferences/repository_preferences.tsx | 4 +- 7 files changed, 118 insertions(+), 46 deletions(-) diff --git a/src/components/BranchListItem.tsx b/src/components/BranchListItem.tsx index 41ef9f4..82af784 100644 --- a/src/components/BranchListItem.tsx +++ b/src/components/BranchListItem.tsx @@ -1,8 +1,9 @@ -import { Action, ActionPanel, Color, List, open, useNavigation } 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 from "../helpers/openInGitpod"; +import OpenInGitpod, { getPreferencesForContext } from "../helpers/openInGitpod"; import ContextPreferences from "../preferences/context_preferences"; type BranchItemProps = { @@ -13,10 +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()) { @@ -47,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: { @@ -69,7 +91,7 @@ export default function BranchListItem({ branch, mainBranch, repository }: Branc { - OpenInGitpod(branchURL,"Branch",repository,branch.branchName) + OpenInGitpod(branchURL, "Branch", repository, branch.branchName) }} shortcut={{ modifiers: ["cmd"], key: "g" }} /> @@ -79,7 +101,7 @@ export default function BranchListItem({ branch, mainBranch, repository }: Branc open(branchURL); }} /> - push()} shortcut={{ modifiers: ["cmd"], key: "w" }}/> + push()} shortcut={{ modifiers: ["cmd"], key: "w" }} /> } /> diff --git a/src/components/IssueListItem.tsx b/src/components/IssueListItem.tsx index 2e7b468..43db255 100644 --- a/src/components/IssueListItem.tsx +++ b/src/components/IssueListItem.tsx @@ -1,7 +1,8 @@ import { Action, ActionPanel, Icon, List, open, useNavigation } from "@raycast/api"; -import { MutatePromise } from "@raycast/utils"; +import { MutatePromise, usePromise } from "@raycast/utils"; import { format } from "date-fns"; +import { UIColors } from "../../constants"; import { IssueFieldsFragment, SearchCreatedIssuesQuery, @@ -9,30 +10,47 @@ import { UserFieldsFragment, } from "../generated/graphql"; import { getIssueAuthor, getIssueStatus } from "../helpers/issue"; -import OpenInGitpod from "../helpers/openInGitpod"; +import OpenInGitpod, { getPreferencesForContext } from "../helpers/openInGitpod"; import ContextPreferences from "../preferences/context_preferences"; type IssueListItemProps = { issue: IssueFieldsFragment; viewer?: UserFieldsFragment; mutateList?: - | MutatePromise - | MutatePromise - | MutatePromise; + | MutatePromise + | MutatePromise + | MutatePromise; }; export default function IssueListItem({ issue }: IssueListItemProps) { - const { push } = useNavigation(); + 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}`, @@ -65,7 +83,7 @@ export default function IssueListItem({ issue }: IssueListItemProps) { { - OpenInGitpod(issue.url,"Issue",issue.repository.nameWithOwner, issue.title) + OpenInGitpod(issue.url, "Issue", issue.repository.nameWithOwner, issue.title) }} shortcut={{ modifiers: ["cmd"], key: "g" }} /> @@ -75,7 +93,7 @@ export default function IssueListItem({ issue }: IssueListItemProps) { open(issue.url); }} /> - push()} shortcut={{ modifiers: ["cmd"], key: "w" }}/> + push()} shortcut={{ modifiers: ["cmd"], key: "w" }} /> } /> diff --git a/src/components/PullRequestListItem.tsx b/src/components/PullRequestListItem.tsx index aac0938..e0a848c 100644 --- a/src/components/PullRequestListItem.tsx +++ b/src/components/PullRequestListItem.tsx @@ -1,10 +1,11 @@ import { Action, ActionPanel, Icon, List, open, useNavigation } from "@raycast/api"; +import { usePromise } from "@raycast/utils"; import { format } from "date-fns"; -import { pull } from "lodash"; import { useMemo } from "react"; +import { UIColors } from "../../constants"; import { PullRequestFieldsFragment, UserFieldsFragment } from "../generated/graphql"; -import OpenInGitpod from "../helpers/openInGitpod"; +import OpenInGitpod, { getPreferencesForContext } from "../helpers/openInGitpod"; import { getCheckStateAccessory, getNumberOfComments, @@ -19,7 +20,7 @@ type PullRequestListItemProps = { viewer?: UserFieldsFragment; }; -export default function PullRequestListItem({ pullRequest}: PullRequestListItemProps) { +export default function PullRequestListItem({ pullRequest }: PullRequestListItemProps) { const updatedAt = new Date(pullRequest.updatedAt); const { push } = useNavigation(); @@ -28,11 +29,28 @@ export default function PullRequestListItem({ pullRequest}: PullRequestListItemP 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}`, @@ -78,7 +96,7 @@ export default function PullRequestListItem({ pullRequest}: PullRequestListItemP { - OpenInGitpod(pullRequest.permalink, "Pull Request", pullRequest.repository.nameWithOwner,pullRequest.title); + OpenInGitpod(pullRequest.permalink, "Pull Request", pullRequest.repository.nameWithOwner, pullRequest.title); }} shortcut={{ modifiers: ["cmd"], key: "g" }} /> @@ -88,7 +106,7 @@ export default function PullRequestListItem({ pullRequest}: PullRequestListItemP open(pullRequest.permalink); }} /> - push()} shortcut={{ modifiers: ["cmd"], key: "w" }}/> + push()} shortcut={{ modifiers: ["cmd"], key: "w" }} /> } /> diff --git a/src/components/RepositoryListItem.tsx b/src/components/RepositoryListItem.tsx index d1f5333..8fcaf03 100644 --- a/src/components/RepositoryListItem.tsx +++ b/src/components/RepositoryListItem.tsx @@ -1,9 +1,9 @@ -import { Color, List, ActionPanel, Action, showToast, Toast, open, useNavigation } from "@raycast/api"; -import { MutatePromise } from "@raycast/utils"; +import { Color, List, ActionPanel, Action, open, useNavigation, Icon } from "@raycast/api"; +import { MutatePromise, usePromise } from "@raycast/utils"; -import { GitpodIcons } from "../../constants"; +import { GitpodIcons, UIColors } from "../../constants"; import { ExtendedRepositoryFieldsFragment } from "../generated/graphql"; -import OpenInGitpod from "../helpers/openInGitpod"; +import OpenInGitpod, { getPreferencesForContext } from "../helpers/openInGitpod"; import { getGitHubUser } from "../helpers/users"; import SearchContext from "../open_repo_context"; import RepositoryPreference from "../preferences/repository_preferences"; @@ -20,22 +20,29 @@ export default function RepositoryListItem({ repository, isGitpodified, onVisit const owner = getGitHubUser(repository.owner); const numberOfStars = repository.stargazerCount; + const { data: preferences, revalidate } = usePromise( + async () => { + const response = await getPreferencesForContext("Repository", repository.nameWithOwner); + return response; + }, + ); + const accessories: List.Item.Accessory[] = [ + { + text: { + value: preferences?.preferredEditorClass === "g1-large" ? "L" : "S", + }, + icon: { + source: Icon.ComputerChip, + tintColor: UIColors.gitpod_gold, + }, + tooltip: `Editor: ${preferences?.preferredEditor}, Class: ${preferences?.preferredEditorClass} ` + }, { icon: isGitpodified ? GitpodIcons.gitpod_logo_primary : GitpodIcons.gitpod_logo_secondary, }, ]; - const showLaunchToast = async () => { - await showToast({ - title: "Launching your workspace", - style: Toast.Style.Success, - }); - setTimeout(() => { - open(`https://gitpod.io/#${repository.url}`); - }, 1500); - }; - accessories.unshift( { text: { @@ -67,11 +74,11 @@ export default function RepositoryListItem({ repository, isGitpodified, onVisit title={repository.name} {...(numberOfStars > 0 ? { - subtitle: { - value: `${numberOfStars}`, - tooltip: `Number of Stars: ${numberOfStars}`, - }, - } + subtitle: { + value: `${numberOfStars}`, + tooltip: `Number of Stars: ${numberOfStars}`, + }, + } : {})} accessories={accessories} actions={ @@ -83,9 +90,9 @@ export default function RepositoryListItem({ repository, isGitpodified, onVisit push(); }} /> - open(repository.url)} /> - OpenInGitpod(repository.url,"Repository",repository.nameWithOwner)} shortcut={{ modifiers: ["cmd"], key: "g" }}/> - push()} shortcut={{ modifiers: ["cmd"], key: "w" }}/> + open(repository.url)} /> + OpenInGitpod(repository.url, "Repository", repository.nameWithOwner)} shortcut={{ modifiers: ["cmd"], key: "g" }} /> + push()} shortcut={{ modifiers: ["cmd"], key: "w" }} /> } /> diff --git a/src/helpers/openInGitpod.ts b/src/helpers/openInGitpod.ts index d5abfde..9186b73 100644 --- a/src/helpers/openInGitpod.ts +++ b/src/helpers/openInGitpod.ts @@ -7,9 +7,8 @@ interface Preferences { preferredEditorClass: "g1-standard" | "g1-large"; } -export default async function OpenInGitpod(contextUrl: string, type: "Branch" | "Pull Request" | "Issue" | "Repository", repository: string, context?: string) { +export async function getPreferencesForContext(type: "Branch" | "Pull Request" | "Issue" | "Repository", repository: string, context?: string) { let preferences = getPreferenceValues(); - if (type === "Branch" || type === "Pull Request" || type === "Issue") { const item = await LocalStorage.getItem(`${repository}%${context}`) const contextPref = item ? await JSON.parse(item) : null @@ -29,7 +28,11 @@ export default async function OpenInGitpod(contextUrl: string, type: "Branch" | preferences = repoPref } } + return preferences; +} +export default async function OpenInGitpod(contextUrl: string, type: "Branch" | "Pull Request" | "Issue" | "Repository", repository: string, context?: string) { + const preferences = await getPreferencesForContext(type, repository, context) if (type === "Branch") { //visit branch } else if (type === "Pull Request") { @@ -44,7 +47,7 @@ export default async function OpenInGitpod(contextUrl: string, type: "Branch" | style: Toast.Style.Success, }); setTimeout(() => { - open(`https://gitpod.io/?useLatest=${preferences.useLatest}&editor=${preferences.preferredEditor}&workspaceClass=${preferences.preferredEditorClass}#${contextUrl}`); + open(`https://gitpod.io/?useLatest=${preferences.useLatest}&editor=${preferences.preferredEditor}${preferences.useLatest ? "-latest" : ""}&workspaceClass=${preferences.preferredEditorClass}#${contextUrl}`); }, 1000); } catch (error) { await showToast({ diff --git a/src/preferences/context_preferences.tsx b/src/preferences/context_preferences.tsx index e6a2ce7..d479e85 100644 --- a/src/preferences/context_preferences.tsx +++ b/src/preferences/context_preferences.tsx @@ -5,6 +5,7 @@ type ContextPreferenceProps = { repository: string; type: "Branch" | "Pull Request" | "Issue"; context: string + revalidate: () => void; } interface Preferences { @@ -30,7 +31,7 @@ async function getDefaultValue(repository: string, context: string) { return defaultPrefValue } -export default function ContextPreferences({ repository, type, context }: ContextPreferenceProps) { +export default function ContextPreferences({ repository, type, context, revalidate }: ContextPreferenceProps) { const [defaultPrefValue, setDefaultPrefValue] = useState(null) useEffect(() => { @@ -57,6 +58,7 @@ export default function ContextPreferences({ repository, type, context }: Contex title: "Preferences saved successfully", style: Toast.Style.Success, }); + revalidate(); pop(); } catch (error) { diff --git a/src/preferences/repository_preferences.tsx b/src/preferences/repository_preferences.tsx index 8fcd1b0..8ed8250 100644 --- a/src/preferences/repository_preferences.tsx +++ b/src/preferences/repository_preferences.tsx @@ -3,6 +3,7 @@ import { useEffect, useState } from "react"; type RepositoryPreferenceProps = { repository: string; + revalidate: ()=>void; } interface Preferences { @@ -22,7 +23,7 @@ async function getDefaultValue(repository: string) { return defaultPrefValue } -export default function RepositoryPreference({ repository }: RepositoryPreferenceProps) { +export default function RepositoryPreference({ repository ,revalidate}: RepositoryPreferenceProps) { const [defaultPrefValue, setDefaultPrefValue] = useState(null) const { pop } = useNavigation(); @@ -49,6 +50,7 @@ export default function RepositoryPreference({ repository }: RepositoryPreferenc title: "Preferences saved successfully", style: Toast.Style.Success, }); + revalidate(); pop(); } catch (error) {