Skip to content

Commit f8929b8

Browse files
authored
feat!: Add support for creating GitHub App with organizations (#3222)
Fixes: #3210. BREAKING CHANGE: The CreateApp function now requires two arguments: `AppManifest` and `orgName`, to support creating apps with organizations.
1 parent 7f7f194 commit f8929b8

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

scrape/apps.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"bytes"
1313
"encoding/json"
1414
"errors"
15+
"fmt"
1516
"net/http"
1617
"strconv"
1718
"strings"
@@ -134,8 +135,15 @@ type AppManifest struct {
134135
}
135136

136137
// 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)
139147
if err != nil {
140148
return nil, err
141149
}

scrape/apps_test.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,26 @@ func Test_CreateApp(t *testing.T) {
9797
HookAttributes: map[string]string{
9898
"url": "https://example.com/hook",
9999
},
100-
}); err != nil {
100+
}, ""); err != nil {
101101
t.Fatalf("CreateApp: %v", err)
102102
}
103103
}
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+
}

0 commit comments

Comments
 (0)