Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat(bbc): handle webhook for repository pushes (#5162)
Joe Chenc477023f2c40
diff --git a/backend/plugin/vcs/bitbucket/bitbucket.go b/backend/plugin/vcs/bitbucket/bitbucket.goindex 972d9a92ab..11280af2de 100644--- a/backend/plugin/vcs/bitbucket/bitbucket.go+++ b/backend/plugin/vcs/bitbucket/bitbucket.go@@ -12,6 +12,7 @@ import ("net/http""net/url""path"+ "strconv""strings""time"@@ -208,7 +209,13 @@ func (p *Provider) GetDiffFileList(ctx context.Context, oauthCtx common.OauthConvar bbcDiffs []*CommitDiffStatpage := 1for {- url := fmt.Sprintf("%s/repositories/%s/diffstat/%s..%s?page=%d&pagelen=%d", p.APIURL(instanceURL), url.PathEscape(repositoryID), afterCommit, beforeCommit, page, apiPageSize)+ params := url.Values{}+ params.Add("pagelen", strconv.Itoa(apiPageSize))+ if page > 1 {+ params.Add("page", strconv.Itoa(page))+ }++ url := fmt.Sprintf("%s/repositories/%s/diffstat/%s..%s?%s", p.APIURL(instanceURL), url.PathEscape(repositoryID), afterCommit, beforeCommit, params.Encode())diffs, hasNextPage, err := p.fetchPaginatedDiffFileList(ctx, oauthCtx, instanceURL, url)if err != nil {return nil, errors.Wrap(err, "fetch paginated list")@@ -333,7 +340,14 @@ func (p *Provider) FetchAllRepositoryList(ctx context.Context, oauthCtx common.O// user has admin access to in given page. It returns the paginated results// along with a boolean indicating whether the next page exists.func (p *Provider) fetchPaginatedRepositoryList(ctx context.Context, oauthCtx common.OauthContext, instanceURL string, page int) (repos []*Repository, hasNextPage bool, err error) {- url := fmt.Sprintf(`%s/user/permissions/repositories?q=%s&page=%d&pagelen=%d`, p.APIURL(instanceURL), url.PathEscape(`permission="admin"`), page, apiPageSize)+ fmt.Println("fuck you", oauthCtx.AccessToken)+ params := url.Values{}+ params.Add("q", `permission="admin"`)+ params.Add("pagelen", strconv.Itoa(apiPageSize))+ if page > 1 {+ params.Add("page", strconv.Itoa(page))+ }+ url := fmt.Sprintf(`%s/user/permissions/repositories?%s`, p.APIURL(instanceURL), params.Encode())code, _, body, err := oauth.Get(ctx,p.client,@@ -429,9 +443,16 @@ func (p *Provider) FetchRepositoryFileList(ctx context.Context, oauthCtx common.// recursively in given page. It returns the paginated results along with a// boolean indicating whether the next page exists.func (p *Provider) fetchPaginatedRepositoryFileList(ctx context.Context, oauthCtx common.OauthContext, instanceURL, repositoryID, ref, filePath string, page int) (_ []*TreeEntry, hasNextPage bool, err error) {+ params := url.Values{}// NOTE: There is no way to ask the Bitbucket Cloud API to return all// subdirectories recursively, 10 levels down is just a good guess.- url := fmt.Sprintf("%s/repositories/%s/src/%s/%s?max_depth=10&q=%s&page=%d&pagelen=%d", p.APIURL(instanceURL), repositoryID, ref, url.PathEscape(filePath), url.QueryEscape(`type="commit_file"`), page, apiPageSize)+ params.Add("max_depth", "10")+ params.Add("q", `type="commit_file"`)+ params.Add("pagelen", strconv.Itoa(apiPageSize))+ if page > 1 {+ params.Add("page", strconv.Itoa(page))+ }+ url := fmt.Sprintf("%s/repositories/%s/src/%s/%s?%s", p.APIURL(instanceURL), repositoryID, ref, url.PathEscape(filePath), params.Encode())code, _, body, err := oauth.Get(ctx,p.client,@@ -478,7 +499,7 @@ func (p *Provider) fetchPaginatedRepositoryFileList(ctx context.Context, oauthCtfunc (p *Provider) CreateFile(ctx context.Context, oauthCtx common.OauthContext, instanceURL, repositoryID, filePath string, fileCommitCreate vcs.FileCommitCreate) error {var body bytes.Bufferw := multipart.NewWriter(&body)- part, err := w.CreateFormFile("filename", filePath)+ part, err := w.CreateFormField(filePath)if err != nil {return errors.Wrap(err, "failed to create form file")}@@ -486,15 +507,13 @@ func (p *Provider) CreateFile(ctx context.Context, oauthCtx common.OauthContext,if err != nil {return errors.Wrap(err, "failed to write file to form")}+ _ = w.WriteField("message", fileCommitCreate.CommitMessage)+ _ = w.WriteField("parents", fileCommitCreate.LastCommitID)+ _ = w.WriteField("branch", fileCommitCreate.Branch)_ = w.Close()- urlParams := &url.Values{}- urlParams.Set("message", url.QueryEscape(fileCommitCreate.CommitMessage))- urlParams.Set("parents", fileCommitCreate.LastCommitID)- urlParams.Set("branch", fileCommitCreate.Branch)-- url := fmt.Sprintf("%s/repositories/%s/src?%s", p.APIURL(instanceURL), repositoryID, urlParams.Encode())- code, _, resp, err := oauth.Post(+ url := fmt.Sprintf("%s/repositories/%s/src", p.APIURL(instanceURL), repositoryID)+ code, _, resp, err := oauth.PostWithHeader(ctx,p.client,url,@@ -509,6 +528,9 @@ func (p *Provider) CreateFile(ctx context.Context, oauthCtx common.OauthContext,},oauthCtx.Refresher,),+ map[string]string{+ "Content-Type": w.FormDataContentType(),+ },)if err != nil {return errors.Wrapf(err, "POST %s", url)@@ -622,12 +644,15 @@ func (p *Provider) ReadFileContent(ctx context.Context, oauthCtx common.OauthConreturn body, nil}+// Target is the API message for Bitbucket Cloud target.+type Target struct {+ Hash string `json:"hash"`+}+// Branch is the API message for Bitbucket Cloud branch.type Branch struct {Name string `json:"name"`- Target struct {- Hash string `json:"hash"`- } `json:"target"`+ Target Target `json:"target"`}// GetBranch gets the given branch in the repository.@@ -738,7 +763,13 @@ func (p *Provider) ListPullRequestFile(ctx context.Context, oauthCtx common.Oautvar bbcDiffs []*CommitDiffStatpage := 1for {- url := fmt.Sprintf("%s/repositories/%s/pullrequests/%s/diffstat?page=%d&pagelen=%d", p.APIURL(instanceURL), url.PathEscape(repositoryID), pullRequestID, page, apiPageSize)+ params := url.Values{}+ params.Add("pagelen", strconv.Itoa(apiPageSize))+ if page > 1 {+ params.Add("page", strconv.Itoa(page))+ }++ url := fmt.Sprintf("%s/repositories/%s/pullrequests/%s/diffstat?%s", p.APIURL(instanceURL), url.PathEscape(repositoryID), pullRequestID, params.Encode())diffs, hasNextPage, err := p.fetchPaginatedDiffFileList(ctx, oauthCtx, instanceURL, url)if err != nil {return nil, errors.Wrap(err, "fetch paginated list")@@ -865,6 +896,67 @@ func (*Provider) UpsertEnvironmentVariable(context.Context, common.OauthContext,return errors.New("not supported")}+// WebhookCommit is the API message for webhook commit.+type WebhookCommit struct {+ Hash string `json:"hash"`+ Date time.Time `json:"date"`+ Author struct {+ Raw string `json:"raw"`+ User struct {+ Nickname string `json:"nickname"`+ } `json:"user"`+ } `json:"author"`+ Message string `json:"message"`+ Links struct {+ HTML struct {+ Href string `json:"href"`+ } `json:"html"`+ } `json:"links"`+ Parents []struct {+ Hash string `json:"hash"`+ } `json:"parents"`+}++// WebhookPushEvent is the API message for webhook push event.+type WebhookPushEvent struct {+ Push struct {+ Changes []struct {+ Old struct {+ Target struct {+ Hash string `json:"hash"`+ } `json:"target"`+ } `json:"old"`+ New struct {+ Name string `json:"name"`+ Target struct {+ Hash string `json:"hash"`+ } `json:"target"`+ } `json:"new"`+ Commits []WebhookCommit `json:"commits"`+ } `json:"changes"`+ } `json:"push"`+ Repository struct {+ FullName string `json:"full_name"`+ Links struct {+ HTML struct {+ Href string `json:"href"`+ } `json:"html"`+ } `json:"links"`+ } `json:"repository"`+ Actor struct {+ Nickname string `json:"nickname"`+ } `json:"actor"`+}++// WebhookCreateOrUpdate represents a Bitbucket API request for creating or+// updating a webhook.+type WebhookCreateOrUpdate struct {+ Description string `json:"description"`+ URL string `json:"url"`+ Active bool `json:"active"`+ Events []string `json:"events"`+}+// CreateWebhook creates a webhook in the repository with given payload.//// Docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-repositories/#api-repositories-workspace-repo-slug-hooks-postdiff --git a/backend/plugin/vcs/bitbucket/bitbucket_test.go b/backend/plugin/vcs/bitbucket/bitbucket_test.goindex 6799a8d2b9..6cfb41a12f 100644--- a/backend/plugin/vcs/bitbucket/bitbucket_test.go+++ b/backend/plugin/vcs/bitbucket/bitbucket_test.go@@ -375,14 +375,11 @@ func TestProvider_FetchRepositoryFileList(t *testing.T) {func TestProvider_CreateFile(t *testing.T) {p := newMockProvider(func(r *http.Request) (*http.Response, error) {assert.Equal(t, "/2.0/repositories/username/slug/src", r.URL.Path)- assert.Equal(t, "Initial+commit", r.URL.Query().Get("message"))- assert.Empty(t, r.URL.Query().Get("parents"))- assert.Equal(t, "main", r.URL.Query().Get("branch"))-- body, err := io.ReadAll(r.Body)- require.NoError(t, err)- wantBodyContains := "Content-Disposition: form-data; name=\"filename\"; filename=\"repo/path/to/image.png\"\r\nContent-Type: application/octet-stream\r\n\r\n#!/bin/sh\nhalt"- assert.Contains(t, string(body), wantBodyContains)+ assert.Contains(t, r.Header.Get("Content-Type"), "multipart/form-data; boundary=")+ assert.Equal(t, "Initial commit", r.FormValue("message"))+ assert.Empty(t, r.FormValue("parents"))+ assert.Equal(t, "main", r.FormValue("branch"))+ assert.Equal(t, "#!/bin/sh\nhalt", r.FormValue("repo/path/to/image.png"))return &http.Response{StatusCode: http.StatusCreated,Body: io.NopCloser(strings.NewReader("")),@@ -409,14 +406,11 @@ func TestProvider_CreateFile(t *testing.T) {func TestProvider_OverwriteFile(t *testing.T) {p := newMockProvider(func(r *http.Request) (*http.Response, error) {assert.Equal(t, "/2.0/repositories/username/slug/src", r.URL.Path)- assert.Equal(t, "Initial+commit", r.URL.Query().Get("message"))- assert.Equal(t, "7638417db6d59f3c431d3e1f261cc637155684cd", r.URL.Query().Get("parents"))- assert.Equal(t, "main", r.URL.Query().Get("branch"))-- body, err := io.ReadAll(r.Body)- require.NoError(t, err)- wantBodyContains := "Content-Disposition: form-data; name=\"filename\"; filename=\"repo/path/to/image.png\"\r\nContent-Type: application/octet-stream\r\n\r\n#!/bin/sh\nhalt"- assert.Contains(t, string(body), wantBodyContains)+ assert.Contains(t, r.Header.Get("Content-Type"), "multipart/form-data; boundary=")+ assert.Equal(t, "Initial commit", r.FormValue("message"))+ assert.Equal(t, "7638417db6d59f3c431d3e1f261cc637155684cd", r.FormValue("parents"))+ assert.Equal(t, "main", r.FormValue("branch"))+ assert.Equal(t, "#!/bin/sh\nhalt", r.FormValue("repo/path/to/image.png"))return &http.Response{StatusCode: http.StatusOK,Body: io.NopCloser(strings.NewReader("")),diff --git a/backend/plugin/vcs/internal/oauth/oauth.go b/backend/plugin/vcs/internal/oauth/oauth.goindex 7a6c9015af..79be1255a8 100644--- a/backend/plugin/vcs/internal/oauth/oauth.go+++ b/backend/plugin/vcs/internal/oauth/oauth.go@@ -18,6 +18,10 @@ import (type TokenRefresher func(ctx context.Context, client *http.Client, oldToken *string) errorfunc requester(ctx context.Context, client *http.Client, method, url string, token *string, body io.Reader) func() (*http.Response, error) {+ return requesterWithHeader(ctx, client, method, url, token, body, nil)+}++func requesterWithHeader(ctx context.Context, client *http.Client, method, url string, token *string, body io.Reader, header map[string]string) func() (*http.Response, error) {// The body may be read multiple times but io.Reader is meant to be read once,// so we read the body first and build the reader every time.var bodyBytes []byte@@ -38,6 +42,10 @@ func requester(ctx context.Context, client *http.Client, method, url string, tokreq.Header.Set("Content-Type", "application/json")req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", *token))+ for k, v := range header {+ req.Header.Set(k, v)+ }+resp, err := client.Do(req)if err != nil {return nil, errors.Wrapf(err, "%s %s", method, url)@@ -49,7 +57,14 @@ func requester(ctx context.Context, client *http.Client, method, url string, tok// Post makes a HTTP POST request to the given URL using the token. It refreshes// token and retries the request in the case of the token has expired.func Post(ctx context.Context, client *http.Client, url string, token *string, body io.Reader, tokenRefresher TokenRefresher) (code int, header http.Header, respBody string, err error) {- return retry(ctx, client, token, tokenRefresher, requester(ctx, client, http.MethodPost, url, token, body))+ return PostWithHeader(ctx, client, url, token, body, tokenRefresher, nil)+}++// PostWithHeader makes a HTTP POST request to the given URL using the token and+// additional header. It refreshes token and retries the request in the case of+// the token has expired.+func PostWithHeader(ctx context.Context, client *http.Client, url string, token *string, body io.Reader, tokenRefresher TokenRefresher, header map[string]string) (code int, _ http.Header, respBody string, err error) {+ return retry(ctx, client, token, tokenRefresher, requesterWithHeader(ctx, client, http.MethodPost, url, token, body, header))}// Get makes a HTTP GET request to the given URL using the token. It refreshes@@ -133,6 +148,11 @@ func getOAuthErrorDetails(code int, body []byte) error {return nil}+ // Special case for Bitbucket OAuth error.+ if bytes.Contains(body, []byte("OAuth2 access token expired.")) {+ return &oauthError{}+ }+var oe oauthErrorif err := json.Unmarshal(body, &oe); err != nil {// If we failed to unmarshal body with oauth error, it's not oauthError and we should return nil.diff --git a/backend/server/project.go b/backend/server/project.goindex ba0c7cc065..96ac7e7d12 100644--- a/backend/server/project.go+++ b/backend/server/project.go@@ -21,6 +21,7 @@ import ("github.com/bytebase/bytebase/backend/common/log"api "github.com/bytebase/bytebase/backend/legacyapi"vcsPlugin "github.com/bytebase/bytebase/backend/plugin/vcs"+ "github.com/bytebase/bytebase/backend/plugin/vcs/bitbucket""github.com/bytebase/bytebase/backend/plugin/vcs/github""github.com/bytebase/bytebase/backend/plugin/vcs/gitlab""github.com/bytebase/bytebase/backend/store"@@ -1299,6 +1300,17 @@ func createVCSWebhook(ctx context.Context, vcsType vcsPlugin.Type, webhookEndpoiif err != nil {return "", errors.Wrap(err, "failed to marshal request body for creating webhook")}+ case vcsPlugin.Bitbucket:+ webhookPost := bitbucket.WebhookCreateOrUpdate{+ Description: "Bytebase GitOps",+ URL: fmt.Sprintf("%s/hook/bitbucket/%s", externalURL, webhookEndpointID),+ Active: true,+ Events: []string{"repo:push"},+ }+ webhookCreatePayload, err = json.Marshal(webhookPost)+ if err != nil {+ return "", errors.Wrap(err, "failed to marshal request body for creating webhook")+ }}webhookID, err := vcsPlugin.Get(vcsType, vcsPlugin.ProviderConfig{}).CreateWebhook(ctx,diff --git a/backend/server/webhook.go b/backend/server/webhook.goindex 8971ad68ad..69ae8f67da 100644--- a/backend/server/webhook.go+++ b/backend/server/webhook.go@@ -10,6 +10,7 @@ import ("fmt""io""net/http"+ "net/mail""path""path/filepath""sort"@@ -29,7 +30,7 @@ import (advisorDB "github.com/bytebase/bytebase/backend/plugin/advisor/db""github.com/bytebase/bytebase/backend/plugin/db""github.com/bytebase/bytebase/backend/plugin/vcs"- _ "github.com/bytebase/bytebase/backend/plugin/vcs/bitbucket" // Import to register the plugin.+ "github.com/bytebase/bytebase/backend/plugin/vcs/bitbucket""github.com/bytebase/bytebase/backend/plugin/vcs/github""github.com/bytebase/bytebase/backend/plugin/vcs/gitlab""github.com/bytebase/bytebase/backend/store"@@ -176,6 +177,142 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {return c.String(http.StatusOK, strings.Join(createdMessages, "\n"))})+ g.POST("/bitbucket/:id", func(c echo.Context) error {+ ctx := c.Request().Context()++ // This shouldn't happen as we only set up webhook to receive push event, just in case.+ eventType := c.Request().Header.Get("X-Event-Key")+ if eventType != "repo:push" {+ return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid webhook event type, got %q, want %q", eventType, "repo:push"))+ }++ body, err := io.ReadAll(c.Request().Body)+ if err != nil {+ return echo.NewHTTPError(http.StatusBadRequest, "Failed to read webhook request").SetInternal(err)+ }+ var pushEvent bitbucket.WebhookPushEvent+ if err := json.Unmarshal(body, &pushEvent); err != nil {+ return echo.NewHTTPError(http.StatusBadRequest, "Malformed push event").SetInternal(err)+ }+ repositoryID := pushEvent.Repository.FullName++ var allCreatedMessages []string+ for _, change := range pushEvent.Push.Changes {+ var nonBytebaseCommitList []bitbucket.WebhookCommit+ nonBytebaseCommitList = append(nonBytebaseCommitList, filterBitbucketBytebaseCommit(change.Commits)...)+ if len(nonBytebaseCommitList) == 0 {+ var commitList []string+ for _, change := range pushEvent.Push.Changes {+ for _, commit := range change.Commits {+ commitList = append(commitList, commit.Hash)+ }+ }+ log.Debug("all commits are created by Bytebase",+ zap.String("repoURL", pushEvent.Repository.Links.HTML.Href),+ zap.String("repoName", pushEvent.Repository.FullName),+ zap.String("commits", strings.Join(commitList, ", ")),+ )+ continue+ }++ ref := "refs/heads/" + change.New.Name+ filter := func(repo *api.Repository) (bool, error) {+ return s.isWebhookEventBranch(ref, repo.BranchFilter)+ }+ repositoryList, err := s.filterRepository(ctx, c.Param("id"), repositoryID, filter)+ if err != nil {+ return err+ }+ if len(repositoryList) == 0 {+ log.Debug("Empty handle repo list. Ignore this push event.")+ continue+ }+ repo := repositoryList[0]++ var commitList []vcs.Commit+ for _, commit := range nonBytebaseCommitList {+ before := strings.Repeat("0", 40)+ if len(commit.Parents) > 0 {+ before = commit.Parents[0].Hash+ }+ fileDiffList, err := vcs.Get(repo.VCS.Type, vcs.ProviderConfig{}).GetDiffFileList(+ ctx,+ common.OauthContext{+ ClientID: repo.VCS.ApplicationID,+ ClientSecret: repo.VCS.Secret,+ AccessToken: repo.AccessToken,+ RefreshToken: repo.RefreshToken,+ Refresher: utils.RefreshToken(ctx, s.store, repo.WebURL),+ },+ repo.VCS.InstanceURL,+ repo.ExternalID,+ before,+ commit.Hash,+ )+ if err != nil {+ return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Failed to get diff file list for commit %q", commit.Hash)).SetInternal(err)+ }++ var addedList, modifiedList []string+ for _, f := range fileDiffList {+ switch f.Type {+ case vcs.FileDiffTypeAdded:+ addedList = append(addedList, f.Path)+ case vcs.FileDiffTypeModified:+ modifiedList = append(modifiedList, f.Path)+ }+ }++ // Per Git convention, the message title and body are separated by two new line characters.+ messages := strings.SplitN(commit.Message, "\n\n", 2)+ messageTitle := messages[0]++ authorName := commit.Author.User.Nickname+ authorEmail := ""+ addr, err := mail.ParseAddress(commit.Author.Raw)+ if err == nil {+ authorName = addr.Name+ authorEmail = addr.Address+ }++ commitList = append(commitList,+ vcs.Commit{+ ID: commit.Hash,+ Title: messageTitle,+ Message: commit.Message,+ CreatedTs: commit.Date.Unix(),+ URL: commit.Links.HTML.Href,+ AuthorName: authorName,+ AuthorEmail: authorEmail,+ AddedList: addedList,+ ModifiedList: modifiedList,+ },+ )+ }++ createdMessages, err := s.processPushEvent(+ ctx,+ repositoryList,+ vcs.PushEvent{+ VCSType: vcs.Bitbucket,+ Ref: ref,+ Before: change.Old.Target.Hash,+ After: change.New.Target.Hash,+ RepositoryID: pushEvent.Repository.FullName,+ RepositoryURL: pushEvent.Repository.Links.HTML.Href,+ RepositoryFullPath: pushEvent.Repository.FullName,+ AuthorName: pushEvent.Actor.Nickname,+ CommitList: commitList,+ },+ )+ if err != nil {+ return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to process push event for commit %q", change.New.Target.Hash)).SetInternal(err)+ }+ allCreatedMessages = append(allCreatedMessages, createdMessages...)+ }+ return c.String(http.StatusOK, strings.Join(allCreatedMessages, "\n"))+ })+// id is the webhookEndpointID in repository// This endpoint is generated and injected into GitHub action & GitLab CI during the VCS setup.g.POST("/sql-review/:id", func(c echo.Context) error {@@ -498,7 +635,7 @@ func (s *Server) filterRepository(ctx context.Context, webhookEndpointID string,func (*Server) isWebhookEventBranch(pushEventRef, branchFilter string) (bool, error) {branch, err := parseBranchNameFromRefs(pushEventRef)if err != nil {- return false, echo.NewHTTPError(http.StatusBadRequest, "Invalid ref: %s", pushEventRef).SetInternal(err)+ return false, echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid ref: %s", pushEventRef)).SetInternal(err)}ok, err := filepath.Match(branchFilter, branch)if err != nil {@@ -1409,3 +1546,15 @@ func filterGitLabBytebaseCommit(list []gitlab.WebhookCommit) []gitlab.WebhookCom}return result}++func filterBitbucketBytebaseCommit(list []bitbucket.WebhookCommit) []bitbucket.WebhookCommit {+ bytebaseRaw := fmt.Sprintf("%s <%s>", vcs.BytebaseAuthorName, vcs.BytebaseAuthorEmail)+ var result []bitbucket.WebhookCommit+ for _, commit := range list {+ if commit.Author.Raw == bytebaseRaw {+ continue+ }+ result = append(result, commit)+ }+ return result+}diff --git a/frontend/src/types/oauth.ts b/frontend/src/types/oauth.tsindex 3ad75ef5a2..58eb562607 100644--- a/frontend/src/types/oauth.ts+++ b/frontend/src/types/oauth.ts@@ -58,7 +58,7 @@ export function openWindowForOAuth(return window.open(`${endpoint}?client_id=${applicationId}&redirect_uri=${encodeURIComponent(redirectUrl()- )}&state=${stateQueryParameter}&response_type=code&scope=repository:write`,+ )}&state=${stateQueryParameter}&response_type=code&scope=account%20repository:write%20webhook`,"oauth","location=yes,left=200,top=200,height=640,width=720,scrollbars=yes,status=yes");