File tree Expand file tree Collapse file tree 2 files changed +30
-3
lines changed Expand file tree Collapse file tree 2 files changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import (
12
12
"bytes"
13
13
"encoding/json"
14
14
"errors"
15
+ "fmt"
15
16
"net/http"
16
17
"strconv"
17
18
"strings"
@@ -134,8 +135,15 @@ type AppManifest struct {
134
135
}
135
136
136
137
// CreateApp creates a new GitHub App with the given manifest configuration.
137
- func (c * Client ) CreateApp (m * AppManifest ) (* http.Response , error ) {
138
- u , err := c .baseURL .Parse ("/settings/apps/new" )
138
+ // orgName is optional, and if provided, the App will be created within the specified organization.
139
+ func (c * Client ) CreateApp (m * AppManifest , orgName string ) (* http.Response , error ) {
140
+ url := "/settings/apps/new"
141
+
142
+ if orgName != "" {
143
+ url = fmt .Sprintf ("/organizations/%v/settings/apps/new" , orgName )
144
+ }
145
+
146
+ u , err := c .baseURL .Parse (url )
139
147
if err != nil {
140
148
return nil , err
141
149
}
Original file line number Diff line number Diff line change @@ -97,7 +97,26 @@ func Test_CreateApp(t *testing.T) {
97
97
HookAttributes : map [string ]string {
98
98
"url" : "https://example.com/hook" ,
99
99
},
100
- }); err != nil {
100
+ }, "" ); err != nil {
101
101
t .Fatalf ("CreateApp: %v" , err )
102
102
}
103
103
}
104
+
105
+ func Test_CreateAppWithOrg (t * testing.T ) {
106
+ client , mux , cleanup := setup ()
107
+
108
+ defer cleanup ()
109
+
110
+ mux .HandleFunc ("/organizations/example/apps/settings/new" , func (w http.ResponseWriter , r * http.Request ) {
111
+ w .WriteHeader (http .StatusCreated )
112
+ })
113
+
114
+ if _ , err := client .CreateApp (& AppManifest {
115
+ URL : github .String ("https://example.com" ),
116
+ HookAttributes : map [string ]string {
117
+ "url" : "https://example.com/hook" ,
118
+ },
119
+ }, "example" ); err != nil {
120
+ t .Fatalf ("CreateAppWithOrg: %v" , err )
121
+ }
122
+ }
You can’t perform that action at this time.
0 commit comments