Skip to content

Commit b879ca2

Browse files
fix(repos): default create_repository to private when visibility omitted (#2694)
Previously, omitting the `private` parameter on create_repository defaulted the new repository to public, an insecure default that could unintentionally expose code, configuration, and history. Omission now defaults to a private repository; public repositories are only created when `private` is explicitly set to false. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 3422703 commit b879ca2

4 files changed

Lines changed: 30 additions & 6 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,7 @@ The following sets of tools are available:
12041204
- `description`: Repository description (string, optional)
12051205
- `name`: Repository name (string, required)
12061206
- `organization`: Organization to create the repository in (omit to create in your personal account) (string, optional)
1207-
- `private`: Whether repo should be private (boolean, optional)
1207+
- `private`: Whether the repository should be private. Defaults to true (private) when omitted. (boolean, optional)
12081208

12091209
- **delete_file** - Delete file
12101210
- **Required OAuth Scopes**: `repo`

pkg/github/__toolsnaps__/create_repository.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"type": "string"
2323
},
2424
"private": {
25-
"description": "Whether repo should be private",
25+
"default": true,
26+
"description": "Whether the repository should be private. Defaults to true (private) when omitted.",
2627
"type": "boolean"
2728
}
2829
},

pkg/github/repositories.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,8 @@ func CreateRepository(t translations.TranslationHelperFunc) inventory.ServerTool
600600
},
601601
"private": {
602602
Type: "boolean",
603-
Description: "Whether repo should be private",
603+
Description: "Whether the repository should be private. Defaults to true (private) when omitted.",
604+
Default: json.RawMessage("true"),
604605
},
605606
"autoInit": {
606607
Type: "boolean",
@@ -624,7 +625,7 @@ func CreateRepository(t translations.TranslationHelperFunc) inventory.ServerTool
624625
if err != nil {
625626
return utils.NewToolResultError(err.Error()), nil, nil
626627
}
627-
private, err := OptionalParam[bool](args, "private")
628+
private, err := OptionalBoolParamWithDefault(args, "private", true)
628629
if err != nil {
629630
return utils.NewToolResultError(err.Error()), nil, nil
630631
}

pkg/github/repositories_test.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,15 +2020,15 @@ func Test_CreateRepository(t *testing.T) {
20202020
expectedRepo: mockRepo,
20212021
},
20222022
{
2023-
name: "successful repository creation with minimal parameters",
2023+
name: "successful repository creation with minimal parameters defaults to private",
20242024
mockedClient: NewMockedHTTPClient(
20252025
WithRequestMatchHandler(
20262026
EndpointPattern("POST /user/repos"),
20272027
expectRequestBody(t, map[string]any{
20282028
"name": "test-repo",
20292029
"auto_init": false,
20302030
"description": "",
2031-
"private": false,
2031+
"private": true,
20322032
}).andThen(
20332033
mockResponse(t, http.StatusCreated, mockRepo),
20342034
),
@@ -2040,6 +2040,28 @@ func Test_CreateRepository(t *testing.T) {
20402040
expectError: false,
20412041
expectedRepo: mockRepo,
20422042
},
2043+
{
2044+
name: "successful public repository creation when private is explicitly false",
2045+
mockedClient: NewMockedHTTPClient(
2046+
WithRequestMatchHandler(
2047+
EndpointPattern("POST /user/repos"),
2048+
expectRequestBody(t, map[string]any{
2049+
"name": "test-repo",
2050+
"auto_init": false,
2051+
"description": "",
2052+
"private": false,
2053+
}).andThen(
2054+
mockResponse(t, http.StatusCreated, mockRepo),
2055+
),
2056+
),
2057+
),
2058+
requestArgs: map[string]any{
2059+
"name": "test-repo",
2060+
"private": false,
2061+
},
2062+
expectError: false,
2063+
expectedRepo: mockRepo,
2064+
},
20432065
{
20442066
name: "repository creation fails",
20452067
mockedClient: NewMockedHTTPClient(

0 commit comments

Comments
 (0)