Skip to content
2 changes: 1 addition & 1 deletion tools-src/github/github-tool.capabilities.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"notes": [
"Use `tool_info(name: \"github\", detail: \"schema\")` for the full action schema before guessing fields.",
"Supported families: repositories, issues, pull requests, reviews/comments, search, branches, code reads, file writes, releases, workflow dispatch/runs, and webhook normalization.",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low Severity · [Certain] · Documentation

The "Supported families" note on line 18 wasn't updated to include forks. The "Not supported yet" note on line 19 correctly removed "forks", but the preceding line still reads:

Supported families: repositories, issues, pull requests, reviews/comments, search, branches, code reads, file writes, releases, workflow dispatch/runs, and webhook normalization.

An LLM reading discovery_summary gets a "supported" list that doesn't mention forks and a "not supported" list that no longer mentions them either — a minor gap. Consider appending ", forks" to the supported families list.

Take-it-or-leave-it nit — the code itself is clean.

"Not supported yet: forks, labels, milestones, projects, org/team admin, GraphQL, release asset uploads, and repository deletion."
"Not supported yet: labels, milestones, projects, org/team admin, GraphQL, release asset uploads, and repository deletion."
],
Comment thread
gagdiez marked this conversation as resolved.
Resolved
"examples": [
{
Expand Down
73 changes: 73 additions & 0 deletions tools-src/github/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,14 @@ enum GitHubAction {
page: Option<u32>,
limit: Option<u32>,
},
#[serde(rename = "fork_repo")]
ForkRepo {
owner: String,
repo: String,
organization: Option<String>,
name: Option<String>,
default_branch_only: Option<bool>,
},
#[serde(rename = "handle_webhook")]
HandleWebhook { webhook: GitHubWebhookRequest },
}
Expand Down Expand Up @@ -745,6 +753,19 @@ fn execute_inner(params: &str) -> Result<String, String> {
page,
limit,
} => get_workflow_runs(&owner, &repo, workflow_id.as_deref(), page, limit),
GitHubAction::ForkRepo {
owner,
repo,
organization,
name,
default_branch_only,
} => fork_repo(
&owner,
&repo,
organization.as_deref(),
name.as_deref(),
default_branch_only,
),
GitHubAction::HandleWebhook { webhook } => handle_webhook(webhook),
}
}
Expand Down Expand Up @@ -919,6 +940,46 @@ fn create_repo(
github_request("POST", &path, Some(req_body.to_string()))
}

fn fork_repo(
owner: &str,
repo: &str,
organization: Option<&str>,
name: Option<&str>,
default_branch_only: Option<bool>,
) -> Result<String, String> {
if !validate_path_segment(owner) || !validate_path_segment(repo) {
return Err("Invalid owner or repo name".into());
}
if let Some(org) = organization {
if !validate_path_segment(org) {
return Err("Invalid organization name".into());
Comment thread
gagdiez marked this conversation as resolved.
Resolved
}
}
Comment thread
gagdiez marked this conversation as resolved.
Resolved
Comment thread
gagdiez marked this conversation as resolved.
Resolved
if let Some(n) = name {
validate_input_length(n, "name")?;
if !validate_path_segment(n) {
return Err("Invalid fork name".into());
}
}

let encoded_owner = url_encode_path(owner);
let encoded_repo = url_encode_path(repo);
let path = format!("/repos/{}/{}/forks", encoded_owner, encoded_repo);

let mut req_body = serde_json::json!({});
if let Some(org) = organization {
req_body["organization"] = serde_json::json!(org);
}
if let Some(n) = name {
req_body["name"] = serde_json::json!(n);
}
if let Some(only) = default_branch_only {
req_body["default_branch_only"] = serde_json::json!(only);
}

github_request("POST", &path, Some(req_body.to_string()))
}

fn list_issues(
owner: &str,
repo: &str,
Expand Down Expand Up @@ -2293,6 +2354,17 @@ const SCHEMA: &str = r#"{
},
"required": ["action", "owner", "repo"]
},
{
"properties": {
"action": { "const": "fork_repo" },
"owner": { "type": "string", "description": "Repository owner (user or org) to fork from" },
"repo": { "type": "string", "description": "Repository name to fork" },
"organization": { "type": "string", "description": "Optional organization to fork into; omit to fork into the authenticated user's account" },
"name": { "type": "string", "description": "Optional name for the fork; defaults to the original repo name" },
"default_branch_only": { "type": "boolean", "default": false, "description": "When true, only the default branch is copied into the fork" }
},
"required": ["action", "owner", "repo"]
},
{
"properties": {
"action": { "const": "handle_webhook" },
Expand Down Expand Up @@ -2370,6 +2442,7 @@ mod tests {
"create_release",
"trigger_workflow",
"get_workflow_runs",
"fork_repo",
"handle_webhook",
]
.into_iter()
Expand Down
Loading