+
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions scrape/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"bytes"
"encoding/json"
"errors"
"fmt"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -134,8 +135,15 @@ type AppManifest struct {
}

// CreateApp creates a new GitHub App with the given manifest configuration.
func (c *Client) CreateApp(m *AppManifest) (*http.Response, error) {
u, err := c.baseURL.Parse("/settings/apps/new")
// orgName is optional, and if provided, the App will be created within the specified organization.
func (c *Client) CreateApp(m *AppManifest, orgName string) (*http.Response, error) {
url := "/settings/apps/new"

if orgName != "" {
url = fmt.Sprintf("/organizations/%v/settings/apps/new", orgName)
}

u, err := c.baseURL.Parse(url)
if err != nil {
return nil, err
}
Expand Down
21 changes: 20 additions & 1 deletion scrape/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,26 @@ func Test_CreateApp(t *testing.T) {
HookAttributes: map[string]string{
"url": "https://example.com/hook",
},
}); err != nil {
}, ""); err != nil {
t.Fatalf("CreateApp: %v", err)
}
}

func Test_CreateAppWithOrg(t *testing.T) {
client, mux, cleanup := setup()

defer cleanup()

mux.HandleFunc("/organizations/example/apps/settings/new", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusCreated)
})

if _, err := client.CreateApp(&AppManifest{
URL: github.String("https://example.com"),
HookAttributes: map[string]string{
"url": "https://example.com/hook",
},
}, "example"); err != nil {
t.Fatalf("CreateAppWithOrg: %v", err)
}
}
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载