Skip to content

Commit 48742bc

Browse files
committed
initial org repo create support
1 parent 0418808 commit 48742bc

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,7 @@ The following sets of tools are available (all are on by default):
815815
- `autoInit`: Initialize with README (boolean, optional)
816816
- `description`: Repository description (string, optional)
817817
- `name`: Repository name (string, required)
818+
- `organization`: Organization to create the repository in (omit to create in your personal account) (string, optional)
818819
- `private`: Whether repo should be private (boolean, optional)
819820

820821
- **delete_file** - Delete file

pkg/github/__toolsnaps__/create_repository.snap

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"title": "Create repository",
44
"readOnlyHint": false
55
},
6-
"description": "Create a new GitHub repository in your account",
6+
"description": "Create a new GitHub repository in your account or specified organization",
77
"inputSchema": {
88
"properties": {
99
"autoInit": {
@@ -18,6 +18,10 @@
1818
"description": "Repository name",
1919
"type": "string"
2020
},
21+
"organization": {
22+
"description": "Organization to create the repository in (omit to create in your personal account)",
23+
"type": "string"
24+
},
2125
"private": {
2226
"description": "Whether repo should be private",
2327
"type": "boolean"

pkg/github/repositories.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ func CreateOrUpdateFile(getClient GetClientFn, t translations.TranslationHelperF
370370
// CreateRepository creates a tool to create a new GitHub repository.
371371
func CreateRepository(getClient GetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
372372
return mcp.NewTool("create_repository",
373-
mcp.WithDescription(t("TOOL_CREATE_REPOSITORY_DESCRIPTION", "Create a new GitHub repository in your account")),
373+
mcp.WithDescription(t("TOOL_CREATE_REPOSITORY_DESCRIPTION", "Create a new GitHub repository in your account or specified organization")),
374374
mcp.WithToolAnnotation(mcp.ToolAnnotation{
375375
Title: t("TOOL_CREATE_REPOSITORY_USER_TITLE", "Create repository"),
376376
ReadOnlyHint: ToBoolPtr(false),
@@ -382,6 +382,9 @@ func CreateRepository(getClient GetClientFn, t translations.TranslationHelperFun
382382
mcp.WithString("description",
383383
mcp.Description("Repository description"),
384384
),
385+
mcp.WithString("organization",
386+
mcp.Description("Organization to create the repository in (omit to create in your personal account)"),
387+
),
385388
mcp.WithBoolean("private",
386389
mcp.Description("Whether repo should be private"),
387390
),
@@ -398,6 +401,10 @@ func CreateRepository(getClient GetClientFn, t translations.TranslationHelperFun
398401
if err != nil {
399402
return mcp.NewToolResultError(err.Error()), nil
400403
}
404+
organization, err := OptionalParam[string](request, "organization")
405+
if err != nil {
406+
return mcp.NewToolResultError(err.Error()), nil
407+
}
401408
private, err := OptionalParam[bool](request, "private")
402409
if err != nil {
403410
return mcp.NewToolResultError(err.Error()), nil
@@ -418,7 +425,7 @@ func CreateRepository(getClient GetClientFn, t translations.TranslationHelperFun
418425
if err != nil {
419426
return nil, fmt.Errorf("failed to get GitHub client: %w", err)
420427
}
421-
createdRepo, resp, err := client.Repositories.Create(ctx, "", repo)
428+
createdRepo, resp, err := client.Repositories.Create(ctx, organization, repo)
422429
if err != nil {
423430
return ghErrors.NewGitHubAPIErrorResponse(ctx,
424431
"failed to create repository",

pkg/github/repositories_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,7 @@ func Test_CreateRepository(t *testing.T) {
10671067
assert.NotEmpty(t, tool.Description)
10681068
assert.Contains(t, tool.InputSchema.Properties, "name")
10691069
assert.Contains(t, tool.InputSchema.Properties, "description")
1070+
assert.Contains(t, tool.InputSchema.Properties, "organization")
10701071
assert.Contains(t, tool.InputSchema.Properties, "private")
10711072
assert.Contains(t, tool.InputSchema.Properties, "autoInit")
10721073
assert.ElementsMatch(t, tool.InputSchema.Required, []string{"name"})
@@ -1119,6 +1120,34 @@ func Test_CreateRepository(t *testing.T) {
11191120
expectError: false,
11201121
expectedRepo: mockRepo,
11211122
},
1123+
{
1124+
name: "successful repository creation in organization",
1125+
mockedClient: mock.NewMockedHTTPClient(
1126+
mock.WithRequestMatchHandler(
1127+
mock.EndpointPattern{
1128+
Pattern: "/orgs/testorg/repos",
1129+
Method: "POST",
1130+
},
1131+
expectRequestBody(t, map[string]interface{}{
1132+
"name": "test-repo",
1133+
"description": "Test repository",
1134+
"private": false,
1135+
"auto_init": true,
1136+
}).andThen(
1137+
mockResponse(t, http.StatusCreated, mockRepo),
1138+
),
1139+
),
1140+
),
1141+
requestArgs: map[string]interface{}{
1142+
"name": "test-repo",
1143+
"description": "Test repository",
1144+
"organization": "testorg",
1145+
"private": false,
1146+
"autoInit": true,
1147+
},
1148+
expectError: false,
1149+
expectedRepo: mockRepo,
1150+
},
11221151
{
11231152
name: "successful repository creation with minimal parameters",
11241153
mockedClient: mock.NewMockedHTTPClient(

0 commit comments

Comments
 (0)