Skip to content

Commit f6bc93f

Browse files
make PAT optional, avoid PostHog init error, update readme
1 parent d23b001 commit f6bc93f

File tree

5 files changed

+36
-11
lines changed

5 files changed

+36
-11
lines changed

.env.example

+2
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ NEXT_PUBLIC_API_DEV_URL=http://localhost:8000
33

44
# backend
55
ANTHROPIC_API_KEY=
6+
7+
# OPTIONAL: providing your own GitHub PAT increases rate limits from 60/hr to 5000/hr to the GitHub API
68
GITHUB_PAT=

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ yarn-error.log*
3535
# do not commit any .env files to git, except for the .env.example file. https://create.t3.gg/en/usage/env-variables#using-environment-variables
3636
.env
3737
.env*.local
38+
.env-e
3839

3940
# vercel
4041
.vercel

README.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Image](./docs/readme_img.png "GitDiagram Front Page")](https:/gitdiagram.com/)
1+
[![Image](./docs/readme_img.png "GitDiagram Front Page")](https://gitdiagram.com/)
22

33
![License](https://img.shields.io/badge/license-MIT-blue.svg)
44

@@ -47,7 +47,7 @@ pnpm i
4747
cp .env.example .env
4848
```
4949

50-
Then edit the `.env` file with your Anthropic API key and GitHub personal access token.
50+
Then edit the `.env` file with your Anthropic API key and optional GitHub personal access token.
5151

5252
4. Run backend
5353

@@ -56,6 +56,7 @@ docker-compose up --build -d
5656
```
5757

5858
Logs available at `docker-compose logs -f`
59+
The server will be available at `localhost:8000`
5960

6061
5. Start local database
6162

@@ -64,12 +65,16 @@ chmod +x start-database.sh
6465
./start-database.sh
6566
```
6667

68+
The database will start in a container at `localhost:5432`
69+
6770
6. Initialize the database schema
6871

6972
```bash
7073
pnpm db:push
7174
```
7275

76+
You can view and interact with the database using `pnpm db:studio`
77+
7378
7. Run Frontend
7479

7580
```bash
@@ -82,7 +87,7 @@ Contributions are welcome! Please feel free to submit a Pull Request.
8287

8388
## 📈 Rate Limits
8489

85-
I am currently hosting it for free with the following rate limits. If you would like to bypass these, self-hosting instructions are provided.
90+
I am currently hosting it for free with the following rate limits. If you would like to bypass these, self-hosting instructions are provided. I also plan on adding an input for your own Anthropic API key.
8691

8792
Diagram generation:
8893

backend/app/services/github_service.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ def __init__(self):
1818
# Fallback to PAT if app credentials not found
1919
self.github_token = os.getenv("GITHUB_PAT")
2020

21+
# If no credentials are provided, warn about rate limits
2122
if not all([self.client_id, self.private_key, self.installation_id]) and not self.github_token:
22-
raise ValueError(
23-
"Either GitHub App credentials or PAT must be provided")
23+
print("\033[93mWarning: No GitHub credentials provided. Using unauthenticated requests with rate limit of 60 requests/hour.\033[0m")
2424

2525
self.access_token = None
2626
self.token_expires_at = None
@@ -56,8 +56,14 @@ def _get_installation_token(self):
5656
return self.access_token
5757

5858
def _get_headers(self):
59-
# Use PAT if app credentials not available
60-
if not all([self.client_id, self.private_key, self.installation_id]):
59+
# If no credentials are available, return basic headers
60+
if not all([self.client_id, self.private_key, self.installation_id]) and not self.github_token:
61+
return {
62+
"Accept": "application/vnd.github+json"
63+
}
64+
65+
# Use PAT if available
66+
if self.github_token:
6167
return {
6268
"Authorization": f"token {self.github_token}",
6369
"Accept": "application/vnd.github+json"

src/app/providers.tsx

+15-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,22 @@ import posthog from "posthog-js";
44
import { PostHogProvider } from "posthog-js/react";
55

66
if (typeof window !== "undefined") {
7-
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
8-
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST!,
9-
person_profiles: "always",
10-
});
7+
// Only initialize PostHog if the environment variables are available
8+
const posthogKey = process.env.NEXT_PUBLIC_POSTHOG_KEY;
9+
const posthogHost = process.env.NEXT_PUBLIC_POSTHOG_HOST;
10+
11+
if (posthogKey && posthogHost) {
12+
posthog.init(posthogKey, {
13+
api_host: posthogHost,
14+
person_profiles: "always",
15+
});
16+
} else {
17+
console.log(
18+
"PostHog environment variables are not set. Analytics will be disabled. Skipping PostHog initialization.",
19+
);
20+
}
1121
}
22+
1223
export function CSPostHogProvider({ children }: { children: React.ReactNode }) {
1324
return <PostHogProvider client={posthog}>{children}</PostHogProvider>;
1425
}

0 commit comments

Comments
 (0)