diff --git a/.agent/utils/gitbucket/add_comment.py b/.agent/utils/gitbucket/add_comment.py new file mode 100644 index 0000000..fd53415 --- /dev/null +++ b/.agent/utils/gitbucket/add_comment.py @@ -0,0 +1,37 @@ +import argparse +import json +import urllib.request +import os +import sys + +def add_comment(issue_number, body, repo="yangyangxie/cortex-hub"): + token = os.getenv("GITBUCKET_TOKEN") + if not token: + print("Error: GITBUCKET_TOKEN environment variable not set.") + sys.exit(1) + + url = f"https://gitbucket.jerxie.com/api/v3/repos/{repo}/issues/{issue_number}/comments" + data = {"body": body} + + req = urllib.request.Request(url, json.dumps(data).encode("utf-8"), headers={ + "Authorization": f"token {token}", + "Content-Type": "application/json" + }) + + try: + with urllib.request.urlopen(req) as response: + print(f"Comment added to Issue #{issue_number}") + except Exception as e: + print(f"Error adding comment: {e}") + if hasattr(e, 'read'): + print(e.read().decode()) + sys.exit(1) + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Add a comment to a GitBucket issue.") + parser.add_argument("--issue", required=True, type=int, help="Issue number") + parser.add_argument("--body", required=True, help="Comment body markdown") + parser.add_argument("--repo", default="yangyangxie/cortex-hub", help="Repository (owner/repo)") + + args = parser.parse_args() + add_comment(args.issue, args.body, args.repo) diff --git a/.agent/utils/gitbucket/create_issue.py b/.agent/utils/gitbucket/create_issue.py new file mode 100644 index 0000000..09d497f --- /dev/null +++ b/.agent/utils/gitbucket/create_issue.py @@ -0,0 +1,39 @@ +import argparse +import json +import urllib.request +import os +import sys + +def create_issue(title, body, repo="yangyangxie/cortex-hub"): + token = os.getenv("GITBUCKET_TOKEN") + if not token: + print("Error: GITBUCKET_TOKEN environment variable not set.") + sys.exit(1) + + url = f"https://gitbucket.jerxie.com/api/v3/repos/{repo}/issues" + data = {"title": title, "body": body} + + req = urllib.request.Request(url, json.dumps(data).encode("utf-8"), headers={ + "Authorization": f"token {token}", + "Content-Type": "application/json" + }) + + try: + with urllib.request.urlopen(req) as response: + res = json.loads(response.read().decode()) + print(f"Created Issue #{res.get('number')} - {res.get('html_url')}") + return res.get('number') + except Exception as e: + print(f"Error creating issue: {e}") + if hasattr(e, 'read'): + print(e.read().decode()) + sys.exit(1) + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Create a GitBucket issue.") + parser.add_argument("--title", required=True, help="Issue title") + parser.add_argument("--body", required=True, help="Issue body markdown") + parser.add_argument("--repo", default="yangyangxie/cortex-hub", help="Repository (owner/repo)") + + args = parser.parse_args() + create_issue(args.title, args.body, args.repo) diff --git a/.agent/workflows/gitbucket_api.md b/.agent/workflows/gitbucket_api.md index 2ad4034..7c97633 100644 --- a/.agent/workflows/gitbucket_api.md +++ b/.agent/workflows/gitbucket_api.md @@ -7,32 +7,38 @@ ## Core API Usage -### Setting Up Authentication -The token must be provided in the `Authorization` header: -`Authorization: token ` +## Core API Usage -### Examples: +### Setting Up Authentication +Set the required environment variable before running scripts or `curl`: +```bash +export GITBUCKET_TOKEN="58ff61c1a0ede2fb4a984f8d5be97d5ae1d8d855" +``` + +### Preferred Utilities (Python) +Use these pre-parameterized scripts to avoid repetitive `curl` syntax: #### 1. Create an Issue ```bash -curl -H "Authorization: token " \ - -X POST -d '{"title": "Issue Title", "body": "Issue Description"}' \ +python .agent/utils/gitbucket/create_issue.py \ + --title "Feature: [Name]" \ + --body "Goal: ... \n\n### Tasks: \n- [ ] Task 1" +``` + +#### 2. Add a Comment / Progress Update +```bash +python .agent/utils/gitbucket/add_comment.py \ + --issue \ + --body "### Status Update\nCompleted Step 1." +``` + +### Raw API (Alternative) +Use `curl` for direct queries or when scripts are unavailable: +```bash +curl -H "Authorization: token $GITBUCKET_TOKEN" \ https://gitbucket.jerxie.com/api/v3/repos/yangyangxie/cortex-hub/issues ``` -#### 2. Create a Pull Request -```bash -curl -H "Authorization: token " \ - -X POST -d '{"title": "PR Title", "base": "master", "head": "feature-branch", "body": "PR Description"}' \ - https://gitbucket.jerxie.com/api/v3/repos/yangyangxie/cortex-hub/pulls -``` - -#### 3. List Releases -```bash -curl -H "Authorization: token " \ - https://gitbucket.jerxie.com/api/v3/repos/yangyangxie/cortex-hub/releases -``` - ### Using Snippets (Gists) as a Secret Store GitBucket's Snippet feature works primarily via **Git** or **Raw Web Access**. The standard GitHub JSON API for gists is currently not active on this instance.