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: get all gitlab projects #1107

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/backend/src/graphql/__generated__/resolver-types.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion apps/backend/src/graphql/definitions/GlApiNamespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ export const typeDefs = gql`
glApiProjects(
userId: ID
groupId: ID
allProjects: Boolean!
accessToken: String!
page: Int!
search: String
): GlApiProjectConnection!
}
`;
Expand All @@ -40,14 +42,20 @@ export const resolvers: IResolvers = {
maxPages: 1,
page: args.page,
showExpanded: true as const,
...(args.search && args.search.length > 1 && { search: args.search }),
};
if (args.userId) {
return client.Users.allProjects(args.userId, options);
}
if (args.groupId) {
return client.Groups.allProjects(args.groupId, options);
}
throw new Error("Either userId or groupId must be provided");
if (args.allProjects) {
return client.Projects.all({ ...options, membership: true });
}
throw new Error(
"Either userId, groupId or allProjects option must be provided",
);
})();
return {
edges: projects.data,
Expand Down
1 change: 1 addition & 0 deletions apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"tailwindcss": "^3.3.5",
"tailwindcss-animate": "^1.0.7",
"use-clipboard-copy": "^0.2.0",
"use-debounce": "^10.0.0",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1",
Expand Down
28 changes: 9 additions & 19 deletions apps/frontend/src/containers/GitlabNamespacesSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
SelectSeparator,
useSelectState,
} from "@/ui/Select";
import { ListIcon, PlusIcon } from "lucide-react";
import { ListIcon } from "lucide-react";
import { GitLabLogo } from "./GitLab";

const NamespaceFragment = graphql(`
Expand Down Expand Up @@ -36,7 +36,7 @@ export const GitlabNamespacesSelect = (props: {
(namespace) => namespace.id === props.value,
);

if (!activeNamespace) {
if (props.value !== "all" && !activeNamespace) {
throw new Error("No active installation");
}

Expand All @@ -46,7 +46,9 @@ export const GitlabNamespacesSelect = (props: {
<div className="flex w-full items-center justify-between">
<div className="flex items-center gap-2">
<GitLabLogo aria-hidden />
{activeNamespace.name || activeNamespace.path}
{activeNamespace
? activeNamespace.name || activeNamespace.path
: "All Projects..."}
</div>
<SelectArrow />
</div>
Expand All @@ -63,25 +65,13 @@ export const GitlabNamespacesSelect = (props: {
</SelectItem>
);
})}
<SelectSeparator />
<SelectItem
state={select}
button
onClick={(event) => {
event.preventDefault();
window.open(
"https://argos-ci.com/docs/gitlab",
"_blank",
"noopener noreferrer",
);
}}
className="cursor-pointer"
>
<SelectItem value="all">
<div className="flex items-center gap-2">
<PlusIcon className="w-[1em] h-[1em]" />
Add GitLab Namespace
<GitLabLogo aria-hidden />
All Projects...
</div>
</SelectItem>
<SelectSeparator />
<SelectItem
state={select}
button
Expand Down
35 changes: 19 additions & 16 deletions apps/frontend/src/containers/GitlabProjectList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ const ProjectsQuery = graphql(`
query GitlabProjectList_glApiProjects(
$userId: ID
$groupId: ID
$allProjects: Boolean!
$accessToken: String!
$page: Int!
$search: String
) {
glApiProjects(
userId: $userId
groupId: $groupId
allProjects: $allProjects
accessToken: $accessToken
page: $page
search: $search
) {
edges {
id
Expand All @@ -32,32 +36,31 @@ const ProjectsQuery = graphql(`
`);

export type GitlabProjectListProps = {
namespace: {
id: string;
kind: string;
};
gitlabAccessToken: string;
onSelectProject: (project: { id: string }) => void;
disabled?: boolean;
connectButtonLabel: string;
};
search: string;
allProjects: boolean;
} & (
| { groupId: string; userId?: never }
| { groupId?: never; userId: string }
| { groupId?: never; userId?: never }
);

export const GitlabProjectList = (props: GitlabProjectListProps) => {
const args = (() => {
switch (props.namespace.kind) {
case "user":
return { userId: props.namespace.id };
case "group":
return { groupId: props.namespace.id };
default:
throw new Error("Invalid namespace kind");
}
})();
return (
<Query
fallback={<Loader />}
query={ProjectsQuery}
variables={{ ...args, accessToken: props.gitlabAccessToken, page: 1 }}
variables={{
userId: props.userId,
groupId: props.groupId,
allProjects: props.allProjects,
accessToken: props.gitlabAccessToken,
search: props.search,
page: 1,
}}
>
{({ glApiProjects }) => {
if (glApiProjects.edges.length === 0) {
Expand Down
32 changes: 30 additions & 2 deletions apps/frontend/src/containers/Project/ConnectRepository.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
import { Anchor } from "@/ui/Link";
import { Permission } from "@/gql/graphql";
import { getItem, removeItem, setItem } from "@/util/storage";
import { TextInput } from "@/ui/TextInput";
import { useDebounce } from "use-debounce";

const ConnectRepositoryQuery = graphql(`
query ConnectRepository($accountSlug: String!) {
Expand Down Expand Up @@ -115,12 +117,26 @@ const GitlabNamespaces = (props: GitlabNamespacesProps) => {
throw new Error("No namespaces");
}
const [value, setValue] = React.useState<string>(defaultNamespace.id);
const [search, setSearch] = React.useState<string>("");
const [debouncedSearch] = useDebounce(search, 500);
const namespace = props.namespaces.find(
(namespace) => namespace.id === value,
);
if (!namespace) {
if (value !== "all" && !namespace) {
throw new Error("No active namespace");
}

const projectListProps = (() => {
switch (namespace?.kind) {
case "user":
return { userId: namespace.id, groupId: undefined, allProjects: false };
case "group":
return { userId: undefined, groupId: namespace.id, allProjects: false };
default:
return { userId: undefined, groupId: undefined, allProjects: true };
}
})();

return (
<div className="flex flex-col gap-4 max-w-4xl" style={{ height: 400 }}>
<GitlabNamespacesSelect
Expand All @@ -130,12 +146,24 @@ const GitlabNamespaces = (props: GitlabNamespacesProps) => {
setValue={setValue}
onSwitch={props.onSwitch}
/>
{value === "all" && (
<div className="flex flex-col gap-1 mb-2">
<label className="font-medium text-sm">Search</label>
<TextInput
name="search"
placeholder="Project name"
onChange={(event) => setSearch(event.target.value)}
value={search}
/>
</div>
)}
<GitlabProjectList
namespace={namespace}
{...projectListProps}
disabled={props.disabled}
onSelectProject={props.onSelectProject}
connectButtonLabel={props.connectButtonLabel}
gitlabAccessToken={props.gitlabAccessToken}
search={debouncedSearch}
/>
</div>
);
Expand Down
4 changes: 2 additions & 2 deletions apps/frontend/src/gql/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const documents = {
"\n fragment GithubInstallationsSelect_GhApiInstallation on GhApiInstallation {\n id\n account {\n id\n login\n name\n }\n }\n": types.GithubInstallationsSelect_GhApiInstallationFragmentDoc,
"\n query GithubRepositoryList_ghApiInstallationRepositories(\n $installationId: ID!\n $page: Int!\n ) {\n ghApiInstallationRepositories(\n installationId: $installationId\n page: $page\n ) {\n edges {\n id\n name\n updated_at\n owner_login\n }\n pageInfo {\n hasNextPage\n }\n }\n }\n": types.GithubRepositoryList_GhApiInstallationRepositoriesDocument,
"\n fragment GitlabNamespacesSelect_GlApiNamespace on GlApiNamespace {\n id\n name\n path\n }\n": types.GitlabNamespacesSelect_GlApiNamespaceFragmentDoc,
"\n query GitlabProjectList_glApiProjects(\n $userId: ID\n $groupId: ID\n $accessToken: String!\n $page: Int!\n ) {\n glApiProjects(\n userId: $userId\n groupId: $groupId\n accessToken: $accessToken\n page: $page\n ) {\n edges {\n id\n name\n last_activity_at\n }\n pageInfo {\n hasNextPage\n }\n }\n }\n": types.GitlabProjectList_GlApiProjectsDocument,
"\n query GitlabProjectList_glApiProjects(\n $userId: ID\n $groupId: ID\n $allProjects: Boolean!\n $accessToken: String!\n $page: Int!\n $search: String\n ) {\n glApiProjects(\n userId: $userId\n groupId: $groupId\n allProjects: $allProjects\n accessToken: $accessToken\n page: $page\n search: $search\n ) {\n edges {\n id\n name\n last_activity_at\n }\n pageInfo {\n hasNextPage\n }\n }\n }\n": types.GitlabProjectList_GlApiProjectsDocument,
"\n query NavUserControl_account($slug: String!) {\n account(slug: $slug) {\n id\n avatar {\n ...AccountAvatarFragment\n }\n }\n }\n": types.NavUserControl_AccountDocument,
"\n fragment PaymentBanner_Account on Account {\n id\n purchaseStatus\n permissions\n stripeCustomerId\n pendingCancelAt\n\n purchase {\n id\n trialDaysRemaining\n source\n paymentMethodFilled\n }\n }\n": types.PaymentBanner_AccountFragmentDoc,
"\n query PaymentBanner_me {\n me {\n id\n hasSubscribedToTrial\n }\n }\n": types.PaymentBanner_MeDocument,
Expand Down Expand Up @@ -223,7 +223,7 @@ export function graphql(source: "\n fragment GitlabNamespacesSelect_GlApiNamesp
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "\n query GitlabProjectList_glApiProjects(\n $userId: ID\n $groupId: ID\n $accessToken: String!\n $page: Int!\n ) {\n glApiProjects(\n userId: $userId\n groupId: $groupId\n accessToken: $accessToken\n page: $page\n ) {\n edges {\n id\n name\n last_activity_at\n }\n pageInfo {\n hasNextPage\n }\n }\n }\n"): (typeof documents)["\n query GitlabProjectList_glApiProjects(\n $userId: ID\n $groupId: ID\n $accessToken: String!\n $page: Int!\n ) {\n glApiProjects(\n userId: $userId\n groupId: $groupId\n accessToken: $accessToken\n page: $page\n ) {\n edges {\n id\n name\n last_activity_at\n }\n pageInfo {\n hasNextPage\n }\n }\n }\n"];
export function graphql(source: "\n query GitlabProjectList_glApiProjects(\n $userId: ID\n $groupId: ID\n $allProjects: Boolean!\n $accessToken: String!\n $page: Int!\n $search: String\n ) {\n glApiProjects(\n userId: $userId\n groupId: $groupId\n allProjects: $allProjects\n accessToken: $accessToken\n page: $page\n search: $search\n ) {\n edges {\n id\n name\n last_activity_at\n }\n pageInfo {\n hasNextPage\n }\n }\n }\n"): (typeof documents)["\n query GitlabProjectList_glApiProjects(\n $userId: ID\n $groupId: ID\n $allProjects: Boolean!\n $accessToken: String!\n $page: Int!\n $search: String\n ) {\n glApiProjects(\n userId: $userId\n groupId: $groupId\n allProjects: $allProjects\n accessToken: $accessToken\n page: $page\n search: $search\n ) {\n edges {\n id\n name\n last_activity_at\n }\n pageInfo {\n hasNextPage\n }\n }\n }\n"];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
Expand Down
Loading
Loading