Skip to content

Commit

Permalink
made some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mubashirshariq committed Sep 29, 2024
1 parent e1e5fcf commit d2e90fd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 60 deletions.
45 changes: 29 additions & 16 deletions keep-ui/app/runbooks/runbook-table.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
"use client";

import React, { useState } from "react";
import Modal from "react-modal"; // Add this import for react-modal
import Modal from "react-modal";
import {
Button,
Badge,
Table as TremorTable,
TableBody,
TableCell,
TableHead,
TableHeaderCell,
TableRow,
} from "@tremor/react";
import { DisplayColumnDef } from "@tanstack/react-table";
import { GenericTable } from "@/components/table/GenericTable";
import { GenericTable } from "@/components/table/GenericTable";
import { useSession } from "next-auth/react";


const customStyles = {
Expand Down Expand Up @@ -95,6 +90,8 @@ function RunbookIncidentTable() {
const [repositoryName, setRepositoryName] = useState('');
const [pathToMdFiles, setPathToMdFiles] = useState('');

const { data: session } = useSession();

const handlePaginationChange = (newLimit: number, newOffset: number) => {
setLimit(newLimit);
setOffset(newOffset);
Expand All @@ -110,12 +107,28 @@ function RunbookIncidentTable() {
setIsModalOpen(false);
};

// Handle save action from modal
const handleSave = () => {
// You can handle saving the data here (e.g., API call or updating state)
console.log('Repository:', repositoryName);
console.log('Path to MD Files:', pathToMdFiles);
closeModal();
const handleQuerySettings = async ({ repositoryName, pathToMdFiles }) => {
try {
const [owner, repo] = repositoryName.split("/");
const response = await fetch(`https://api.github.com/repos/${owner}/${repo}/contents/${pathToMdFiles}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${session?.accessToken}`,
},
});

if (!response.ok) {
throw new Error('Failed to query settings');
}

const data = await response.json();
console.log('Settings queried successfully:', data);

} catch (error) {
console.error('Error while querying settings:', error);
alert('An error occurred while querying settings');
}
};

return (
Expand Down Expand Up @@ -149,7 +162,7 @@ function RunbookIncidentTable() {
type="text"
value={repositoryName}
onChange={(e) => setRepositoryName(e.target.value)}
placeholder="Enter repository name"
placeholder="Enter repository name (e.g., owner/repo)"
style={{ width: '100%', padding: '8px', marginBottom: '10px' }}
/>
</div>
Expand All @@ -167,7 +180,7 @@ function RunbookIncidentTable() {

<div style={{ textAlign: 'right' }}>
<Button onClick={closeModal} style={{ marginRight: '10px' }}>Cancel</Button>
<Button onClick={handleSave} color="blue">Save</Button>
<Button onClick={() => handleQuerySettings({ repositoryName, pathToMdFiles })} color="blue">Query</Button>
</div>
</Modal>
</div>
Expand Down
44 changes: 0 additions & 44 deletions keep/providers/github_provider/github_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,6 @@ class GithubProviderAuthConfig:
"sensitive": True,
}
)
repository: str = dataclasses.field(
metadata={
"description": "GitHub Repository",
"sensitive": False,
},
default=None,
)
md_path: str = dataclasses.field(
metadata={
"description": "Path to .md files in the repository",
"sensitive": False,
},
default=None,
)


class GithubProvider(BaseProvider):
"""
Expand Down Expand Up @@ -72,33 +57,6 @@ def validate_config(self):
self.authentication_config = GithubProviderAuthConfig(
**self.config.authentication
)
def query_runbook(self,query):
"""Retrieve markdown files from the GitHub repository."""

if not query:
raise ValueError("Query is required")

auth=None
if self.authentication_config.repository and self.authentication_config.md_path:
auth = HTTPBasicAuth(
self.authentication_config.repository,
self.authentication_config.md_path,
)

resp = requests.get(
f"{self.authentication_config.url}/api/v1/query",
params={"query": query},
auth=(
auth
if self.authentication_config.repository and self.authentication_config.md_path
else None
)
)
if response.status_code != 200:
raise Exception(f"Runbook Query Failed: {response.content}")

return response.json()


class GithubStarsProvider(GithubProvider):
"""
Expand Down Expand Up @@ -153,8 +111,6 @@ def _query(
"test",
ProviderConfig(authentication={
"access_token": os.environ.get("GITHUB_PAT"),
"repository": os.environ.get("GITHUB_REPOSITORY"),
"md_path": os.environ.get("MARKDOWN_PATH"),
}
),
)
Expand Down

0 comments on commit d2e90fd

Please sign in to comment.