Skip to content

Commit 4282020

Browse files
author
Jeremy Dai
authored
update (#41)
1 parent 6fde652 commit 4282020

File tree

2 files changed

+40
-62
lines changed

2 files changed

+40
-62
lines changed

.github/workflows/auto-update.yml

Lines changed: 5 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -93,50 +93,6 @@ jobs:
9393
git push origin "$BRANCH_NAME" --force # Push to the new branch
9494
echo "branch_name=$BRANCH_NAME" >> $GITHUB_ENV
9595
96-
- name: Create Pull Request
97-
if: steps.run_script.outputs.script_success == 'true'
98-
uses: actions/github-script@v6
99-
id: create_pr
100-
with:
101-
github-token: ${{ secrets.GITHUB_TOKEN }}
102-
script: |
103-
const { owner, repo } = context.repo;
104-
const issue_number = context.issue.number;
105-
const issue_body = context.payload.issue.body;
106-
const branch_name = process.env.branch_name;
107-
108-
// Check if PR already exists
109-
const prs = await github.rest.pulls.list({
110-
owner,
111-
repo,
112-
head: `${owner}:${branch_name}`,
113-
state: 'open'
114-
});
115-
116-
let pr_number;
117-
let pr_url;
118-
119-
if (prs.data.length === 0) {
120-
// Create new PR
121-
const result = await github.rest.pulls.create({
122-
owner,
123-
repo,
124-
title: `Add server from issue #${issue_number}`,
125-
body: `Automated PR from issue #${issue_number}\n\nServer URL: ${issue_body}`,
126-
head: branch_name,
127-
base: 'main'
128-
});
129-
130-
pr_number = result.data.number;
131-
pr_url = result.data.html_url;
132-
} else {
133-
// PR exists
134-
pr_number = prs.data[0].number;
135-
pr_url = prs.data[0].html_url;
136-
}
137-
138-
return { pr_number, pr_url };
139-
14096
- name: Comment on issue with success
14197
if: steps.run_script.outputs.script_success == 'true'
14298
uses: actions/github-script@v6
@@ -145,21 +101,17 @@ jobs:
145101
script: |
146102
const issue_number = context.issue.number;
147103
const repo = context.repo;
148-
const pr_result = ${{ steps.create_pr.outputs.result }};
149-
const result = JSON.parse(pr_result);
104+
const branch_name = process.env.branch_name;
150105
151-
let body = '';
152-
if (result.pr_number) {
153-
body = `✅ Processing complete!\n\nA pull request has been created with the server manifest: [PR #${result.pr_number}](${result.pr_url})`;
154-
} else {
155-
body = `⚠️ Processing completed, but no pull request was created. Please check the action logs for details.`;
156-
}
106+
// Generate direct PR creation URL
107+
const pr_title = encodeURIComponent(`Add server from issue #${issue_number}`);
108+
const pr_url = `https://github.com/${repo.owner}/${repo.repo}/compare/main...${branch_name}?quick_pull=1&title=${pr_title}`;
157109
158110
await github.rest.issues.createComment({
159111
owner: repo.owner,
160112
repo: repo.repo,
161113
issue_number: issue_number,
162-
body: body
114+
body: `✅ Processing complete!\n\nClick here to create the pull request with one click: [Create PR](${pr_url})`
163115
});
164116
165117
- name: Comment on issue with failure

scripts/get_manifest.py

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def __init__(self):
2626
api_key=os.environ.get("OPENROUTER_API_KEY"),
2727
)
2828

29-
def extract_description_from_readme(self, readme_content: str) -> str:
29+
def extract_description_from_readme(self, readme_content: str, repo_url: str = "") -> str:
3030
"""Extract a concise description from README content.
3131
3232
Looks for the first meaningful description paragraph near the beginning
@@ -35,6 +35,7 @@ def extract_description_from_readme(self, readme_content: str) -> str:
3535
3636
Args:
3737
readme_content: Contents of README.md
38+
repo_url: GitHub repository URL to extract name for title matching
3839
3940
Returns:
4041
Extracted description or empty string if not found
@@ -90,10 +91,10 @@ def extract_description_from_readme(self, readme_content: str) -> str:
9091

9192
# If we couldn't find a good description in regular text,
9293
# check content under main repo name heading
93-
if not description:
94+
if not description and repo_url:
9495
for heading, content in title_content.items():
9596
# Look for the repo name in the heading
96-
if heading and "/" in repo_url:
97+
if heading:
9798
repo_name = repo_url.strip('/').split('/')[-1].lower()
9899
if repo_name.lower() in heading.lower():
99100
for line in content:
@@ -184,13 +185,31 @@ def _convert_to_raw_url(self, repo_url: str) -> str:
184185
if "github.com" not in repo_url:
185186
raise ValueError(f"Invalid GitHub URL: {repo_url}")
186187

188+
# Handle subdirectory URLs (tree format)
187189
if "/tree/" in repo_url:
188-
return repo_url.replace("/tree/", "/raw/")
190+
# For URLs like github.com/user/repo/tree/branch/path/to/dir
191+
parts = repo_url.split("/tree/")
192+
base_url = parts[0].replace(
193+
"github.com", "raw.githubusercontent.com")
194+
path_parts = parts[1].split("/", 1)
195+
196+
if len(path_parts) > 1:
197+
branch = path_parts[0]
198+
subdir = path_parts[1]
199+
return f"{base_url}/{branch}/{subdir}/README.md"
200+
else:
201+
branch = path_parts[0]
202+
return f"{base_url}/{branch}/README.md"
189203

204+
# Handle direct file URLs
190205
if "/blob/" in repo_url:
191206
raw_url = repo_url.replace("/blob/", "/raw/")
192-
return raw_url if raw_url.endswith(".md") else f"{raw_url}/README.md"
207+
if raw_url.endswith(".md"):
208+
return raw_url
209+
else:
210+
return f"{raw_url}/README.md"
193211

212+
# Handle repository root URLs
194213
raw_url = repo_url.replace("github.com", "raw.githubusercontent.com")
195214
return f"{raw_url.rstrip('/')}/main/README.md"
196215

@@ -434,7 +453,15 @@ def generate_manifest(self, repo_url: str, server_name: Optional[str] = None) ->
434453
# Extract repo info
435454
parts = repo_url.strip("/").split("/")
436455
owner = parts[3]
437-
name = parts[4]
456+
457+
# Extract name, handling subdirectories in tree format
458+
if "/tree/" in repo_url and "/src/" in repo_url:
459+
# For subdirectories in the src folder, use the subdirectory name
460+
src_path = repo_url.split("/src/")[1]
461+
name = src_path.split("/")[0]
462+
else:
463+
# Default is the last path component
464+
name = parts[-1]
438465

439466
# If no server name was explicitly provided, use the one from URL
440467
if server_name:
@@ -445,7 +472,6 @@ def generate_manifest(self, repo_url: str, server_name: Optional[str] = None) ->
445472

446473
# Get prompt as tuple and extract manifest
447474
manifest = self.extract_with_llms(repo_url, readme_content)
448-
449475
# Update manifest with repository information
450476
manifest.update({
451477
"name": name,
@@ -455,7 +481,8 @@ def generate_manifest(self, repo_url: str, server_name: Optional[str] = None) ->
455481
})
456482

457483
# Update manifest with description
458-
description = self.extract_description_from_readme(readme_content)
484+
description = self.extract_description_from_readme(
485+
readme_content, repo_url)
459486
if not description:
460487
description = self.extract_description_from_readme_with_llms(
461488
readme_content)
@@ -620,7 +647,6 @@ def main(repo_url: str, is_official: bool = False):
620647
sys.exit(1)
621648

622649
repo_url = sys.argv[1].strip()
623-
624650
# Check if the URL is a simple URL without protocol
625651
if not repo_url.startswith(("http://", "https://")):
626652
# Add https:// if it's a github.com URL without protocol

0 commit comments

Comments
 (0)